'individual'); /* set during scripts work */ protected $_eventRegistrationsAtTeamCount = array(); /* structure: array(array(eventId => registrationsCount), array(eventId => registrationsCount),) */ protected $_eventsRegistrationCount = array(); /* structure: array(array(eventId => registrationsCount), array(eventId => registrationsCount),) */ protected $_teamsRegistrationCount = array(); /* structure: array(array(eventId => array(array(teamId => registrationsCount), array(teamId => registrationsCount)))*/ public function getEventObj($id = null) { if (null === $this->_eventObj) { $this->_eventObj = SiteMap::getObj('Event/Event.php', $id); $this->_eventObj->initFromDB(); } return $this->_eventObj; } protected function _formCreateRadioBoxList(Form $form, $name, array $list) { if (!is_array($list) || empty($list)) { return false; } $elList = array(); foreach ($list as $id => $title) { $elList[$id . '_open'] = $form->createElement('static', $name . '_open', '', '
'); $elList[$id] = $form->createElement('radio', $name, '', $title, $id); $elList[$id . '_close'] = $form->createElement('static', $name . '_close', '', '
'); } return $elList; } /** * @param $Doc SiteDoc * @return mixed null|string */ protected function _renderSelectedTeamTable($Doc) { if (null !== $Doc) { $smarty = $Doc->getSmarty(); return $smarty->fetch('Event/selectedTeamTable.tpl'); } else { return null; } } /** * @param $teams array * @return mixed */ protected function _renderTeamTable($teams) { /** @var $Doc Doc */ global $Doc; if (empty($teams)) { return ''; } $teamsTotal = $teams['teams']; if (!empty($teams['individualsNoTeam'])) { $teamsTotal[0] = array( 'id' => 0, 'teamname' => 'event', 'members' => $teams['individualsNoTeam'], ); } $smarty = $Doc->getSmarty(); $smarty->assign('teams', $teams); return $smarty->fetch('Event/teamTable.tpl'); // this is not the first return } protected function _addEventRegistrationJs($eventId, $teams, $memberCost) { /** @var $Doc Doc */ global $Doc; $existingTeams = array(); if (!empty($teams)) { if (!empty($teams['teams'])) { $existingTeams = $teams['teams']; } if (!empty($teams['individualsNoTeam'])) { $existingTeams[0]['id'] = 0; $existingTeams[0]['remain'] = 1; $existingTeams[0]['teamname'] = 'event'; $existingTeams[0]['members'] = $teams['individualsNoTeam']; } } $additionalMembersCount = (!empty($_POST['anotherUser']) && !empty($_POST['memberId']) && !empty($_POST['amountAdditional']) && ( count($_POST['anotherUser']) == count($_POST['memberId']) && count($_POST['anotherUser']) == count($_POST['amountAdditional']) ) ) ? (max(array_keys($_POST['memberId'])) + 1) : 0; $Doc->addItemProp('JSs', 'js/app/eventRegistrationForm.js'); $Doc->addItemProp('JSs', 'js/jshashtable.js'); $Doc->addItemProp('JSs', 'js/jquery.numberformatter.js'); $Doc->addInitFunction( 'App_EventRegistrationForm.initialize', array(array( 'teams' => $existingTeams, 'eventId' => $eventId, 'memberCost' => $memberCost, 'additionalMembersCount' => $additionalMembersCount, )) ); return $this; } /** * @param array $event - array of event DB data * @param int $teamsRegistrations - count of all teams registered members * @param int $eventRegistrations - count of all members registered to events * @param int $teamsCount - count of teams registered for event * @return eventAvailability */ protected function _getEventAvailability($event, $teamsRegistrations = 0, $eventRegistrations = 0, $teamsCount = 0) { $res = new EventAvailability(); $res->checkAvailability($event, $teamsRegistrations, $eventRegistrations, $teamsCount); return $res; // not the first return } /** * @param $Doc SiteDoc * @param $nEventID * @param string $lang * @param null $nMemberID * @return Form */ function getForm(&$Doc, $nEventID, $lang = 'eng', $nMemberID=null) { require_once 'class/Form/Form.class.php'; $form = new Form($Doc, 'eventform', 'post', Constant::get('BASE_URL') . '/' . CURR_PAGE . (strpos(CURR_PAGE, 'admin') === false ? ('/' . $nEventID) : '')); $formArr = $this->getFromDB($this->id); $form->setTitle($formArr['title'][$lang]); $FormMail_Field = SiteMap::getObj('Event/Form/Field/Field.php', $this->id); $list = $FormMail_Field->getList4Grid(array('order_by' => 'sorter')); $form->setRequiredNote($FormMail_Field->getErrorMsg('required_note', $lang, '')); $eventObj = $this->getEventObj($nEventID); $eventType = $eventObj->getData('id_type'); $adminPage = (0 === strpos(CURR_PAGE, 'admin/') || 'admin' == CURR_PAGE); if (4 == $eventType) { $teams = $this->getEventObj($nEventID)->getGroupedRegistrants($nEventID); if (!$adminPage) { $registrationLimit = $eventObj->getData('registration_limit'); if ($registrationLimit > 0) { $availability = $registrationLimit - $this->_getEventRegistrationsCount($nEventID); if ($availability < 0) { $availability = 0; } $form->addElement( 'static', 'event_availability', null, 'Event Availability: ' . $availability . ' of ' . $registrationLimit . ' spots available'); } $canRegisterNewTeam = true; $canRegisterAtExistingTeam = true; $canRegisterAsIndividual = true; $individualSpotsAvailableMsg = ''; if ($eventObj->getData('registration_limit') > 0 && $eventObj->getData('group_limit') > 0) { $teamsRegistrationsCount = $this->_getEventRegistrationsAtTeamCount($eventObj->getData('id')); $eventAvailability = $this->_getEventAvailability($eventObj->getData(), $teamsRegistrationsCount, $this->_getEventRegistrationsCount($nEventID), count($teams['teams'])); $canRegisterNewTeam = $eventAvailability->hasEventFreePlacesForNewTeam; $canRegisterAsIndividual = $eventAvailability->hasEventIndividualsFreePlaces; $canRegisterAtExistingTeam = $eventAvailability->hasEventFreePlaces; if ($eventAvailability->eventFreePlaces > $eventAvailability->eventIndividualFreePlaces) { $plural = $eventAvailability->eventIndividualFreePlaces > 1; $individualSpotsAvailableMsg = ' (' . $eventAvailability->eventIndividualFreePlaces . ' spot' . ($plural ? 's' : '') . ' available)'; } } $elListOptions = array(); if ($canRegisterNewTeam) { $elListOptions['newteam'] = 'Registering a New Team The only way to' . ' guarantee your desired foursome is to have all names and entire payment for your team at ' . 'time of registration.
Until your foursome is paid for, others may be able to sign up ' . 'for your team.
All spots must be paid for within 24 hours or they will be forfeited. ' . '
'; } if (!empty($teams['teams']) && $canRegisterAtExistingTeam) { $elListOptions['exisitingteam'] = 'Registering to an Existing Team'; } if ($canRegisterAsIndividual) { $elListOptions['individual'] = 'Registering as an Individual' . $individualSpotsAvailableMsg; } $elList = $this->_formCreateRadioBoxList( $form, 'team_option', $elListOptions ); $title = '1 How are you registering today?'; $form->addElement('header', '', $title); $form->addGroup($elList, 'registertype', 'Please choose', array('id' => 'registertype'), false); } else { $form->addElement( 'select', 'team_option', 'Choose register type', array( '' => 'Select One', 'individual' => 'Register as individual', 'newteam' => 'Create a New Team', 'exisitingteam' => 'Register in Existing Team' ), array('onchange' => 'showteaminfo()', 'onclick' => 'showteaminfo()', 'id' => 'registertype')); } $cTeamName = $this->db->queryOne('SELECT group_name FROM mn_Event WHERE id=' . (int)$nEventID); if (empty($cTeamName)) { $cTeamName = 'Team'; } $form->addElement('text', 'teamname', ucfirst($cTeamName) . ' Name', array('size' => 30, 'id' => 'newteam')); if (!$adminPage) { $form->addElement( 'static', 'team_table', '', $this->_renderTeamTable($teams) ); $this->_addEventRegistrationJs( $nEventID, $teams, $eventObj->getData('member_cost') ); $form->addElement('static', 'team_selected', '', $this->_renderSelectedTeamTable($Doc)); $form->addElement('hidden', 'id_team'); $this->_addUserEndAdditionalMemberField($form); } else { $form->addElement( 'select', 'id_team', ucfirst($cTeamName) . ' Name', array('' => 'Select One') + (array)$eventObj->getExistingTeams4Select(), array('id' => 'exisitingteam') ); } $form->setDefaults($this->_formDefaults); } if (!$adminPage) { $numText = 4 == $eventType ? '3 ' : ''; $form->addElement( 'header', 'paymentHeader', $numText . 'Please enter payment information to confirm your registration.' ); } foreach ($list['list'] as $field) { $field = $FormMail_Field->getFromDB($field['id']); $label = $field['label'][$lang]; $type = $field['type']; $name = "fild[{$field['id']}]"; switch ($type) { case 'select' : $form->addElement($type, $name, $label, array('' => 'Select One') + $this->_getOptions($field['value'])); break; case 'checkbox' : $form->addElement('advcheckbox', $name, $label, '', null, array('Off', 'On')); break; case 'checkboxes' : $checkboxes = array(); $i = 0; foreach ((array) $field['value'][$lang] as $value) { $checkboxes[] = Form::createElement('checkbox', $value, '', $value, array('value' => $value)); $i++; } $form->addGroup($checkboxes, $name, $label, '
'); break; case 'radioboxes' : $radioboxes = array(); $i = 0; foreach ($this->_getOptions($field['value']) as $value) { $radioboxes[] = Form::createElement('radio', null, null, $value, $value); $i++; } $form->addGroup($radioboxes, $name, $label, '
'); break; case 'textarea' : $form->addElement($type, $name, $label, array('cols' => 30, 'rows' => 8)); break; default : // case 'text': if ($name=='fild[2]') { $aYear[date('y')]=date('Y'); for ($i=1; $i<13; $i++) { $aMonth[sprintf('%02d',$i)]=sprintf('%02d',$i); $aYear[date('y',mktime(0,0,0,1,1,date('Y')+$i))]=date('Y')+$i; } $form->addGroup(array( Form::createElement('select','month','',$aMonth,array('style'=>'width:40px;')), Form::createElement('select','year','',$aYear,array('style'=>'width:60px;')) ), 'fild[2]', $label); } else $form->addElement($type, $name, $label, array('size' => 30)); break; } foreach ((array) $field['valid'] as $valid) { if ('file' == $type) { if ('required' == $valid) { $form->addRule($name, $FormMail_Field->getErrorMsg($valid, $lang, $label), 'uploadedfile'); } } else { $form->addRule($name, $FormMail_Field->getErrorMsg($valid, $lang, $label), $valid); $form->addRule($name, $FormMail_Field->getErrorMsg($valid, $lang, $label), $valid, null, 'client'); } } } if (!$adminPage) { $member = Session::getData('individual_user', 'individual_user'); if (is_null($member)) $member = Session::getData('individual_user_support', 'individual_user_support'); $field = Member::hasMemberCost($member) ? 'member_cost' : 'nonmember_cost'; $nAmount = $eventObj->getData($field); if ($nAmount) $form->addElement('hidden', 'amount', $nAmount, array('id' => 'amount')); } else { $memberObj = new Member(); $member = $memberObj->getFromDB($nMemberID); $nAmount = (Member::hasMemberCost($member) || !$eventObj->getData('nonmember_cost')) ? $eventObj->getData('member_cost') : $eventObj->getData('nonmember_cost'); $form->addElement('extended_text', 'amount', 'Amount', array('value'=>number_format($nAmount,2)),'$'); if (CURR_PAGE != 'admin/member/event_history') $form->addElement('checkbox', 'sendemail', 'Send Email Invitation'); } $form->updateElementAttr('fild[1]', array('maxlength' => 16)); if (!$nAmount) { $form->removeElement('fild[1]'); $form->removeElement('fild[2]'); $form->removeElement('fild[19]'); // security code } else { /** @var $creditCard HTML_QuickForm_extended_text */ $creditCard = $form->getElement('fild[1]'); if (!HTML_QuickForm::isError($creditCard)) { $creditCard->setAttribute('autocomplete', 'off'); // credit card number $creditCard->_after_text = '
Note: We will no longer be accepting American Express ' . ' as of October 1, 2012.
'; } /** @var $cvv HTML_QuickForm_extended_text */ $cvv = $form->getElement('fild[19]'); if (!HTML_QuickForm::isError($cvv)) { $cvv->setAttribute('autocomplete', 'off'); $cvv->setAttribute('class', 'ctip'); $cvv->_after_text = ' '; } } if (4 == $eventType && $adminPage) { $this->_addAdminAdditionalMemberField($form); } $form->addFormRule(array($this, 'validForm')); $form->setCancelType(FORM_CBT_CANCEL); $form->cancelUrl = BASE_URL . '/event/show/' . $nEventID; $form->setSubmitTitle('Send'); $form->addElement('hidden', 'action', 'submit'); $form->addElement('hidden', 'id_event', $nEventID); return $form; } /** * @param $form Form * @return Event_Form */ protected function _addUserEndAdditionalMemberField($form) { $title = '2 Do you need to register anyone else?' . ' (Registration requires payment)' . ' '; $form->addElement('header', '', $title); if (!empty($_POST['memberId']) && !empty($_POST['amountAdditional']) && !empty($_POST['anotherUser'])) { foreach ($_POST['memberId'] as $key => $memberId) { $elementName = 'memberId[' . $key . ']'; $form->addElement('hidden', $elementName, $memberId); } foreach ($_POST['amountAdditional'] as $key => $memberAmount) { $elementName = 'amountAdditional[' . $key . ']'; $form->addElement('hidden', $elementName, $memberAmount); } foreach ($_POST['anotherUser'] as $key => $user) { $elementName = 'anotherUser[' . $key . ']'; $form->addElement( 'extended_text', $elementName, 'Member Name', $user, '', ' Cancel' ); } } $form->addElement('button', 'addUser', 'Add Member'); return $this; } /** * @param $form Form * @return Event_Form */ protected function _addAdminAdditionalMemberField($form) { $form->addElement('header', '', 'Register Another Member Also'); $form->addElement('button', 'addUser', 'Add Member', array('onclick' => 'addanotheruser(this)')); if (isset($_POST['anothermember_emails'])) { foreach ($_POST['anothermember_emails'] as $nKey => $cEmail) { if (!empty($cEmail)) { $form->addElement('text', 'anothermember_emails[' . $nKey . ']', 'Email'); } } } return $this; } protected function _getEventRegistrationsCount($eventId) { if (empty($this->_eventsRegistrationCount[$eventId])) { $sql = "SELECT COUNT(*) FROM `{$this->db->tblEventFormReq}` WHERE `deleted` = 'n' AND `id_event` = " . $this->db->quote($eventId, 'integer'); $this->_eventsRegistrationCount[$eventId] = $this->db->queryOne($sql); } return $this->_eventsRegistrationCount[$eventId]; } /** * метод рахує скільки в івенті зареєстровано користувачів по командах * @param $eventId * @return mixed */ protected function _getEventRegistrationsAtTeamCount($eventId) { if (empty($this->_eventRegistrationsAtTeamCount[$eventId])) { $sql = "SELECT COUNT(*) FROM `{$this->db->tblEventFormReq}` WHERE `id_team` != 0 " . " AND `deleted` = 'n'" . " AND `id_event` = " . $this->db->quote($eventId, 'integer'); $this->_eventRegistrationsAtTeamCount[$eventId] = $this->db->queryOne($sql); } return $this->_eventRegistrationsAtTeamCount[$eventId]; } protected function _getTeamRegistrationsCount($eventId, $teamId) { if (empty($this->_teamsRegistrationCount[$eventId][$teamId])) { $sql = "SELECT COUNT(*) FROM `{$this->db->tblEventFormReq}` WHERE `id_team`=" . $teamId . " AND `deleted` = 'n'" . " AND `id_event` = " . $this->db->quote($eventId, 'integer'); $this->_teamsRegistrationCount[$eventId][$teamId] = $this->db->queryOne($sql); } return $this->_teamsRegistrationCount[$eventId][$teamId]; } protected function _getEventRegistrationLimitErrorMessage($limit) { return 'The registration limit for this event is ' . $limit . ' members.
' . 'Please see spots availability details below and re-check your submission. '; } protected function _getGroupLimitErrorMessage($limit, $groupName) { if (empty($groupName)) { $groupName = 'team'; } $msg = 'This ' . $groupName . ' is limited to '. $limit . ' members - and you can only register other members' . ' for spots in your own team. Please re-check your submission ' . 'and make the appropriate adjustments.'; return $msg; } protected function _isAdditionalMemberDataCountValid($data) { // errors if amounts, ids and inputs count is not equal if (empty($data['anotherUser']) || empty($data['memberId']) || empty($data['amountAdditional'])) { return true; } if (count($data['anotherUser']) != count($data['memberId']) || count($data['anotherUser']) != count($data['amountAdditional']) ) { return true; } return false; } protected function _getNotAllowedMembersIds($allMembersIds) { $sql = " SELECT `Member`.`id` FROM `{$this->db->tblMember}` AS `Member` WHERE `Member`.`id` IN (" . implode(',', $allMembersIds) . ") AND ( `Member`.`id_mncar_type` IN (" . Qs_Db::quote(Member::$hasRegistrationMncarIdTypes, 'integer') . ") OR `Member`.`id_mncar_l_type` IN (" . Qs_Db::quote(Member::$hasRegistrationMncarLIdTypes, 'integer') . ") OR `Member`.`id_misc_type` IN (" . Qs_Db::quote(Member::$hasRegistrationMiscIdTypes, 'integer') . ") ) "; $ids = $this->db->queryCol($sql); return array_diff($allMembersIds, $ids); } protected function _checkAdditionalMemberData($data, array &$errors) { foreach($data['memberId'] as $key => $id) { if (empty($id) || empty($data['anotherUser'][$key]) || !isset($data['amount'][$key])) { $errors['anotherUser[' . $key . ']'] = 'Please re-type the name of the member'; } } // errors if amounts, ids and inputs count is not equal if ($this->_isAdditionalMemberDataCountValid($data)) { $errors['team_option'] = 'The system found the errors. Please re-check your registration options ' . 'and make the appropriate adjustments.'; return $this; } $member = Session::getData('individual_user', 'individual_user'); $ownKey = array_search($member['id'], $data['memberId']); if (false !== $ownKey) { $errors['anotherUser[' . $ownKey . ']'] = 'You cannot add yourself here. Please re-check your registration ' . 'options and make the appropriate adjustments'; } //errors if selected the same members $repeatedMembersIndexes = array_diff( array_keys($data['memberId']), array_keys(array_unique($data['memberId'])) ); if (!empty($repeatedMembersIndexes)) { foreach ($repeatedMembersIndexes as $index) { $errors['anotherUser[' . $index . ']'] = 'This member is already selected above'; } return $this; // this is not the first return at method } //errors if some of members do not have permission $prohibitedIds = $this->_getNotAllowedMembersIds($data['memberId']); if (!empty($prohibitedIds)) { foreach ($prohibitedIds as $memberId) { $key = array_search($memberId, $data['memberId']); $errors['anotherUser[' . $key . ']'] = 'This member has no permission to access this event'; } } return $this; // this is not the first return at method } /** * @param array $event * @return Event_Form */ protected function _doRedirect2EventShow($event) { $errorMessage = $this->_getEventRegistrationLimitErrorMessage($event['registration_limit']); Session::setData('event/show', 'msg', $errorMessage); require_once 'class/HTTP.php'; skHTTP::redirect(Constant::get('BASE_URL') . '/event/show/' . $event['id']); return $this; } /** * @param array $event * @param int $memberCount * @param array $errors * @return Event_Form */ protected function _checkEventRegistrationLimit($event, $memberCount, &$errors) { if (empty($event['registration_limit'])) { return $this; } if (($event['registration_limit'] - $this->_getEventRegistrationsCount($event['id'])) < $memberCount) { if ($memberCount > 1) { $errors['team_option'] = $errors['event_availability'] = $this->_getEventRegistrationLimitErrorMessage($event['registration_limit']); } else { $this->_doRedirect2EventShow($event); } } return $this; // this is not the first return at method } /** * @param array $event * @param int $memberCount * @param array $data * @param array $errors * @return Event_Form */ protected function _checkEventGroupLimit($event, $memberCount, $data, &$errors) { if (4 != $event['id_type'] || empty($event['group_limit'])) { return $this; } if ('newteam' == $data['team_option']) { // user selected new team option $teamRegistrationsCount = 0; } elseif (!empty($data['id_team']) && 'exisitingteam' == $data['team_option']) {//user has selected specific team $teamRegistrationsCount = $this->_getTeamRegistrationsCount($data['id_event'], $data['id_team']); } else { // user has selects registering at existing team but has not select the specific team return $this; // this is not the first return at method } if (($memberCount + $teamRegistrationsCount) > $event['group_limit']) { /* team_table is used for userend, id_team - for admin end */ $errorMessage = $this->_getGroupLimitErrorMessage($event['group_limit'], $event['group_name']); if ('newteam' == $data['team_option']) { $errors['teamname'] = $errorMessage; } else { $errors['id_team'] = $errors['team_selected'] = $errors['team_table'] = $errorMessage; } } return $this; // this is not the first return at method AND redirect is at method } function validForm($aData) { $event = $this->getEventObj($aData['id_event'])->getData(); $aErrors = array(); if (4 == $event['id_type'] && empty($aData['team_option'])) { $aErrors['registertype'] = $aErrors['team_option'] = 'Please select an option'; } //checking event registration type availability $teams = $this->getEventObj($event['id'])->getGroupedRegistrants($event['id']); $teamsCount = $this->_getEventRegistrationsAtTeamCount($event['id']); if (!empty($teams['teams']) && is_array($teams['teams'])) { $teamsCount = count($teams['teams']); } $groupEventAvailability = $this->_getEventAvailability( $event, $this->_getEventRegistrationsAtTeamCount($event['id']), $this->_getEventRegistrationsCount($event['id']), $teamsCount ); if (!$groupEventAvailability->hasEventFreePlaces) { $this->_doRedirect2EventShow($event); } $nMemberCount = 1; if (!empty($aData['memberId']) && is_array($aData['memberId'])) { $nMemberCount += count(array_unique($aData['memberId'])); } else if (!empty($aData['anothermember_emails']) && is_array($aData['anothermember_emails'])) { $aData['anothermember_emails'] = array_filter($aData['anothermember_emails']); $nMemberCount += count(array_unique($aData['anothermember_emails'])); } //провірка чи є стільки індивідуальних місць if ('individual' == $aData['team_option']) { $hasIndividualPlaces = $groupEventAvailability->hasEventIndividualsFreePlaces; if ($hasIndividualPlaces && $event['registration_limit'] > 0 && $event['group_limit'] > 0) { $hasIndividualPlaces = $nMemberCount <= $groupEventAvailability->eventIndividualFreePlaces; } if (!$hasIndividualPlaces) { $aErrors['registertype'] = $aErrors['team_option'] = 'There are no spots available to register as' . ' individual. However feel free to register for one of the existing teams.'; } } //провірка чи є доступно стільки місць для нової команди if ('newteam' == $aData['team_option']) { if (!$groupEventAvailability->hasEventFreePlacesForNewTeam) { $aErrors['registertype'] = $aErrors['team_option'] = 'The number of registered teams is at' . ' capacity. Please choose another registration type. '; } elseif(empty($aData['teamname'])) { $aErrors['teamname'] = 'Please make sure to enter a new team\'s name'; } } if ('exisitingteam' == $aData['team_option'] && empty($aData['id_team'])) { $aErrors['id_team'] = $aErrors['team_table'] = 'Please select the team'; } /* validation of total registration limit */ $this->_checkEventRegistrationLimit($event, $nMemberCount, $aErrors); //validation for group_limit $this->_checkEventGroupLimit($event, $nMemberCount, $aData, $aErrors); // at user-end was set additional members for registration if (4 == $event['id_type'] && !empty($aData['memberId'])) { $this->_checkAdditionalMemberData($aData, $aErrors); } require_once ('class/Session.php'); $member = Session::getData('individual_user', 'individual_user'); if (isset($aData['anothermember_emails'])) { $aIDs = array(); $aData['anothermember_emails'] = array_filter($aData['anothermember_emails']); foreach ($aData['anothermember_emails'] as $nKey => $cEmail) { if (is_null($member)) $member = Session::getData('individual_user_support', 'individual_user_support'); $nID = $this->db->queryOne( 'SELECT id ' . 'FROM mn_Member ' . 'WHERE email = ' . $this->db->quote($cEmail) . ' ' . 'AND (id_mncar_type IN (' . Qs_Db::quote(Member::$hasRegistrationMncarIdTypes, 'integer') . ')' . ' OR id_mncar_l_type =IN (' . Qs_Db::quote(Member::$hasRegistrationMncarLIdTypes, 'integer') . ') ' . ' OR id_misc_type =IN (' . Qs_Db::quote(Member::$hasRegistrationMiscIdTypes, 'integer') . ')) ' ); if (!$nID) $aErrors['anothermember_emails[' . $nKey . ']'] = 'This email does not exist in db or ' . ' this member has no access to register to this event'; elseif ($nID == $member['id']) $aErrors['anothermember_emails[' . $nKey . ']'] = 'You can not add your email here'; elseif (in_array($nID, $aIDs)) $aErrors['anothermember_emails[' . $nKey . ']'] = 'Duplicate Email'; elseif ($this->db->queryOne( 'SELECT COUNT(*) FROM mn_EventFormReq WHERE id_member=' . $this->db->quote($nID) . ' AND deleted="n" AND id_event=' . $this->db->quote( $aData['id_event']))) $aErrors['anothermember_emails[' . $nKey . ']'] = 'This member already registered to this event'; else $aIDs[] = $nID; } $nGroupLimit = $event['group_limit']; $cGroupName = $event['group_name']; if ($aData['team_option'] == 'newteam' && $nGroupLimit && $nGroupLimit < $nMemberCount) {return array( 'anothermember_emails[0]' => 'Sorry, ' . $cGroupName . ' limit for this event is ' . $nGroupLimit . ' members');} if ($aData['team_option'] == 'exisitingteam' && $nGroupLimit) { $sql = "SELECT COUNT(*) FROM `{$this->db->tblEventFormReq}` WHERE `deleted` = 'n' AND `id_team` ={$this->db->quote($aData['id_team'], 'integer')} AND `id_event` = {$this->db->quote($aData['id_event'])}"; if ($nGroupLimit - $this->db->queryOne($sql) < $nMemberCount) return array( 'anothermember_emails[0]' => 'Sorry, ' . $cGroupName . ' limit for this event is ' . $nGroupLimit . ' members'); } } $eventYear = (false !== ($eventTime = strtotime($event['eventdate']))) ? idate('Y', $eventTime) : 0; $credentialSuffix = ($eventYear <= 2010) ? '_2010' : ''; if ((false === strpos(CURR_PAGE, 'admin/') && 'admin' != CURR_PAGE)&& isset($aData['amount']) && !count($aErrors)) { $auth_net_login_id = constant('AUTHORIZENET_API_LOGIN_ID' . $credentialSuffix); $auth_net_tran_key = constant('AUTHORIZENET_TRANSACTION_KEY' . $credentialSuffix); $auth_net_url = AUTHORIZENET_URL; $user=Session::getData('individual_user','individual_user'); if (is_null($user)) $user = Session::getData('individual_user_support', 'individual_user_support'); $authnet_values = array("x_login" => $auth_net_login_id, "x_version" => "3.1", "x_delim_char" => "|", "x_delim_data" => "TRUE", "x_test_request" => AUTHORIZENET_TEST_REQUEST, "x_type" => "AUTH_CAPTURE", "x_method" => "CC", "x_tran_key" => $auth_net_tran_key, "x_relay_response" => "FALSE", "x_card_num" => $aData['fild'][1], "x_card_code" => $aData['fild'][19], // security code "x_exp_date" => $aData['fild'][2]['month'].$aData['fild'][2]['year'], "x_amount" => number_format($aData['amount'] * $nMemberCount, 2), "x_first_name" => $user['first_name'], "x_last_name" => $user['last_name'], "x_address" => $user['address'], "x_city" => $user['city'], "x_state" => $user['state'], "x_zip" => $user['zip'], "x_country" => "USA", "x_email" => $user['email'], "x_cust_id" => $user['id'], "x_description" => $this->db->queryOne('SELECT name FROM mn_Event WHERE id='.$this->db->quote($aData['id_event'])), ); $authnet_fields = ""; foreach ($authnet_values as $key => $value) $authnet_fields .= "$key=" . urlencode($value) . "&"; $ch = curl_init($auth_net_url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($authnet_fields, "& ")); ### curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. ### $cResponce = curl_exec($ch); curl_close($ch); $this->getTable('TransactionLog')->insert(array( 'event_id' => $aData['id_event'], 'member_id' => $member['id'], 'response' => (string) $cResponce, )); $aResponce = explode('|', $cResponce); if ($aResponce[0] == 1) { $this->AuthorizeNetResponce = array('transaction_id' => $aResponce[6], 'amount' => $aResponce[9]); } else $aErrors['fild[1]'] = ($aResponce[0] == 3 ? 'There has been an error processing this transaction. #' : '') . $aResponce[3]; } if (!count($aErrors)) return true; else return $aErrors; } function _getOptions($list) { $options = array(); foreach ((array) $list['eng'] as $value) { $options[$value] = $value; } return $options; } }