예제 #1
0
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $this->_showFeeBlock = CRM_Utils_Array::value('eventId', $_GET);
     $this->assign('showFeeBlock', FALSE);
     $this->assign('feeBlockPaid', FALSE);
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     $this->_eID = CRM_Utils_Request::retrieve('eid', 'Positive', $this);
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $this->_context);
     if ($this->_contactId) {
         $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
         $this->assign('displayName', $displayName);
         $this->setPageTitle(ts('Event Registration for %1', array(1 => $displayName)));
     } else {
         $this->setPageTitle(ts('Event Registration'));
     }
     // check the current path, if search based, then dont get participantID
     // CRM-5792
     $path = CRM_Utils_System::currentPath();
     if (strpos($path, 'civicrm/contact/search') === 0 || strpos($path, 'civicrm/group/search') === 0) {
         $this->_id = NULL;
     } else {
         $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     }
     if ($this->_id) {
         $this->assign('participantId', $this->_id);
         $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'id', 'participant_id');
         $this->assign('hasPayment', $this->_paymentId);
         // CRM-12615 - Get payment information from the primary registration
         if (!$this->_paymentId && $this->_action == CRM_Core_Action::UPDATE) {
             $registered_by_id = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'registered_by_id', 'id');
             if ($registered_by_id) {
                 $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $registered_by_id, 'id', 'participant_id');
                 $this->assign('registeredByParticipantId', $registered_by_id);
             }
         }
     }
     // get the option value for custom data type
     $this->_roleCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantRole', 'name');
     $this->_eventNameCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventName', 'name');
     $this->_eventTypeCustomDataTypeID = CRM_Core_OptionGroup::getValue('custom_data_type', 'ParticipantEventType', 'name');
     $this->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID);
     $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID);
     $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID);
     if ($this->_mode) {
         $this->assign('participantMode', $this->_mode);
         $this->assignPaymentRelatedVariables();
     }
     if ($this->_showFeeBlock) {
         $this->assign('showFeeBlock', TRUE);
         $isMonetary = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_showFeeBlock, 'is_monetary');
         if ($isMonetary) {
             $this->assign('feeBlockPaid', TRUE);
         }
         return CRM_Event_Form_EventFees::preProcess($this);
     }
     //check the mode when this form is called either single or as
     //search task action
     if ($this->_id || $this->_contactId || $this->_context == 'standalone') {
         $this->_single = TRUE;
         $this->assign('urlPath', 'civicrm/contact/view/participant');
         if (!$this->_id && !$this->_contactId) {
             $breadCrumbs = array(array('title' => ts('CiviEvent Dashboard'), 'url' => CRM_Utils_System::url('civicrm/event', 'reset=1')));
             CRM_Utils_System::appendBreadCrumb($breadCrumbs);
         }
     } else {
         //set the appropriate action
         $context = $this->get('context');
         $urlString = 'civicrm/contact/search';
         $this->_action = CRM_Core_Action::BASIC;
         switch ($context) {
             case 'advanced':
                 $urlString = 'civicrm/contact/search/advanced';
                 $this->_action = CRM_Core_Action::ADVANCED;
                 break;
             case 'builder':
                 $urlString = 'civicrm/contact/search/builder';
                 $this->_action = CRM_Core_Action::PROFILE;
                 break;
             case 'basic':
                 $urlString = 'civicrm/contact/search/basic';
                 $this->_action = CRM_Core_Action::BASIC;
                 break;
             case 'custom':
                 $urlString = 'civicrm/contact/search/custom';
                 $this->_action = CRM_Core_Action::COPY;
                 break;
         }
         CRM_Contact_Form_Task::preProcessCommon($this);
         $this->_single = FALSE;
         $this->_contactId = NULL;
         //set ajax path, this used for custom data building
         $this->assign('urlPath', $urlString);
         $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}");
     }
     $this->assign('single', $this->_single);
     if (!$this->_id) {
         $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     }
     $this->assign('action', $this->_action);
     // check for edit permission
     if (!CRM_Core_Permission::checkActionPermission('CiviEvent', $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         // check delete permission for contribution
         if ($this->_id && $this->_paymentId && !CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
             CRM_Core_Error::fatal(ts("This Participant is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record."));
         }
         return;
     }
     if ($this->_id) {
         // assign participant id to the template
         $this->assign('participantId', $this->_id);
         $this->_roleId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'role_id');
     }
     // when fee amount is included in form
     if (!empty($_POST['hidden_feeblock']) || !empty($_POST['send_receipt'])) {
         CRM_Event_Form_EventFees::preProcess($this);
         CRM_Event_Form_EventFees::buildQuickForm($this);
         CRM_Event_Form_EventFees::setDefaultValues($this);
     }
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         // Custom data of type participant role
         // Note: Some earlier commits imply $_POST['role_id'] could be a comma separated string,
         //       not sure if that ever really happens
         if (!empty($_POST['role_id'])) {
             foreach ($_POST['role_id'] as $roleID) {
                 CRM_Custom_Form_CustomData::preProcess($this, $this->_roleCustomDataTypeID, $roleID, 1, 'Participant', $this->_id);
                 CRM_Custom_Form_CustomData::buildQuickForm($this);
                 CRM_Custom_Form_CustomData::setDefaultValues($this);
             }
         }
         //custom data of type participant event
         CRM_Custom_Form_CustomData::preProcess($this, $this->_eventNameCustomDataTypeID, $_POST['event_id'], 1, 'Participant', $this->_id);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
         // custom data of type participant event type
         $eventTypeId = NULL;
         if ($eventId = CRM_Utils_Array::value('event_id', $_POST)) {
             $eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'event_type_id', 'id');
         }
         CRM_Custom_Form_CustomData::preProcess($this, $this->_eventTypeCustomDataTypeID, $eventTypeId, 1, 'Participant', $this->_id);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
         //custom data of type participant, ( we 'null' to reset subType and subName)
         CRM_Custom_Form_CustomData::preProcess($this, 'null', 'null', 1, 'Participant', $this->_id);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // CRM-4395, get the online pending contribution id.
     $this->_onlinePendingContributionId = NULL;
     if (!$this->_mode && $this->_id && $this->_action & CRM_Core_Action::UPDATE) {
         $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, 'Event');
     }
     $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId);
 }
예제 #2
0
 /**
  * Build all the data structures needed to build the form.
  *
  * @param
  *
  * @return void
  */
 public function preProcess()
 {
     //special case for custom search, directly give option to download csv file
     $customSearchID = $this->get('customSearchID');
     if ($customSearchID) {
         CRM_Export_BAO_Export::exportCustom($this->get('customSearchClass'), $this->get('formValues'), $this->get(CRM_Utils_Sort::SORT_ORDER));
     }
     $this->_selectAll = FALSE;
     $this->_exportMode = self::CONTACT_EXPORT;
     $this->_componentIds = array();
     $this->_componentClause = NULL;
     // get the submitted values based on search
     if ($this->_action == CRM_Core_Action::ADVANCED) {
         $values = $this->controller->exportValues('Advanced');
     } elseif ($this->_action == CRM_Core_Action::PROFILE) {
         $values = $this->controller->exportValues('Builder');
     } elseif ($this->_action == CRM_Core_Action::COPY) {
         $values = $this->controller->exportValues('Custom');
     } else {
         // we need to determine component export
         $stateMachine = $this->controller->getStateMachine();
         $formName = CRM_Utils_System::getClassName($stateMachine);
         $componentName = explode('_', $formName);
         $components = array('Contribute', 'Member', 'Event', 'Pledge', 'Case', 'Grant', 'Activity');
         if (in_array($componentName[1], $components)) {
             switch ($componentName[1]) {
                 case 'Contribute':
                     $this->_exportMode = self::CONTRIBUTE_EXPORT;
                     break;
                 case 'Member':
                     $this->_exportMode = self::MEMBER_EXPORT;
                     break;
                 case 'Event':
                     $this->_exportMode = self::EVENT_EXPORT;
                     break;
                 case 'Pledge':
                     $this->_exportMode = self::PLEDGE_EXPORT;
                     break;
                 case 'Case':
                     $this->_exportMode = self::CASE_EXPORT;
                     break;
                 case 'Grant':
                     $this->_exportMode = self::GRANT_EXPORT;
                     break;
                 case 'Activity':
                     $this->_exportMode = self::ACTIVITY_EXPORT;
                     break;
             }
             $className = "CRM_{$componentName[1]}_Form_Task";
             $className::preProcessCommon($this, TRUE);
             $values = $this->controller->exportValues('Search');
         } else {
             $values = $this->controller->exportValues('Basic');
         }
     }
     $count = 0;
     $this->_matchingContacts = FALSE;
     if (CRM_Utils_Array::value('radio_ts', $values) == 'ts_sel') {
         foreach ($values as $key => $value) {
             if (strstr($key, 'mark_x')) {
                 $count++;
             }
             if ($count > 2) {
                 $this->_matchingContacts = TRUE;
                 break;
             }
         }
     }
     $componentMode = $this->get('component_mode');
     switch ($componentMode) {
         case 2:
             CRM_Contribute_Form_Task::preProcessCommon($this, TRUE);
             $this->_exportMode = self::CONTRIBUTE_EXPORT;
             $componentName = array('', 'Contribute');
             break;
         case 3:
             CRM_Event_Form_Task::preProcessCommon($this, TRUE);
             $this->_exportMode = self::EVENT_EXPORT;
             $componentName = array('', 'Event');
             break;
         case 4:
             CRM_Activity_Form_Task::preProcessCommon($this, TRUE);
             $this->_exportMode = self::ACTIVITY_EXPORT;
             $componentName = array('', 'Activity');
             break;
         case 5:
             CRM_Member_Form_Task::preProcessCommon($this, TRUE);
             $this->_exportMode = self::MEMBER_EXPORT;
             $componentName = array('', 'Member');
             break;
         case 6:
             CRM_Case_Form_Task::preProcessCommon($this, TRUE);
             $this->_exportMode = self::CASE_EXPORT;
             $componentName = array('', 'Case');
             break;
     }
     $this->_task = $values['task'];
     if ($this->_exportMode == self::CONTACT_EXPORT) {
         $contactTasks = CRM_Contact_Task::taskTitles();
         $taskName = $contactTasks[$this->_task];
         $component = FALSE;
         CRM_Contact_Form_Task::preProcessCommon($this, TRUE);
     } else {
         $this->assign('taskName', "Export {$componentName['1']}");
         $className = "CRM_{$componentName[1]}_Task";
         $componentTasks = $className::tasks();
         $taskName = $componentTasks[$this->_task];
         $component = TRUE;
     }
     if ($this->_componentTable) {
         $query = "\nSELECT count(*)\nFROM   {$this->_componentTable}\n";
         $totalSelectedRecords = CRM_Core_DAO::singleValueQuery($query);
     } else {
         $totalSelectedRecords = count($this->_componentIds);
     }
     $this->assign('totalSelectedRecords', $totalSelectedRecords);
     $this->assign('taskName', $taskName);
     $this->assign('component', $component);
     // all records actions = save a search
     if ($values['radio_ts'] == 'ts_all' || $this->_task == CRM_Contact_Task::SAVE_SEARCH) {
         $this->_selectAll = TRUE;
         $rowCount = $this->get('rowCount');
         if ($rowCount > 2) {
             $this->_matchingContacts = TRUE;
         }
         $this->assign('totalSelectedRecords', $rowCount);
     }
     $this->assign('matchingContacts', $this->_matchingContacts);
     $this->set('componentIds', $this->_componentIds);
     $this->set('selectAll', $this->_selectAll);
     $this->set('exportMode', $this->_exportMode);
     $this->set('componentClause', $this->_componentClause);
     $this->set('componentTable', $this->_componentTable);
 }
예제 #3
0
 /**
  * build all the data structures needed to build the form
  *
  * @param
  * @return void
  * @access public
  */
 function preProcess()
 {
     //special case for custom search, directly give option to download csv file
     $customSearchID = $this->get('customSearchID');
     if ($customSearchID) {
         require_once 'CRM/Export/BAO/Export.php';
         CRM_Export_BAO_Export::exportCustom($this->get('customSearchClass'), $this->get('formValues'), $this->get(CRM_Utils_Sort::SORT_ORDER));
     }
     $this->_selectAll = false;
     $this->_exportMode = self::CONTACT_EXPORT;
     // get the submitted values based on search
     if ($this->_action == CRM_Core_Action::ADVANCED) {
         $values = $this->controller->exportValues('Advanced');
     } else {
         if ($this->_action == CRM_Core_Action::PROFILE) {
             $values = $this->controller->exportValues('Builder');
         } else {
             if ($this->_action == CRM_Core_Action::COPY) {
                 $values = $this->controller->exportValues('Custom');
             } else {
                 // we need to determine component export
                 $stateMachine =& $this->controller->getStateMachine();
                 $formName = CRM_Utils_System::getClassName($stateMachine);
                 $componentName = explode('_', $formName);
                 $components = array('Contribute', 'Member', 'Event', 'Pledge', 'Case', 'Grant', 'Activity');
                 if (in_array($componentName[1], $components)) {
                     eval('$this->_exportMode = self::' . strtoupper($componentName[1]) . '_EXPORT;');
                     require_once "CRM/{$componentName[1]}/Form/Task.php";
                     eval('CRM_' . $componentName[1] . '_Form_Task::preProcessCommon( $this, true );');
                     $values = $this->controller->exportValues('Search');
                 } else {
                     $values = $this->controller->exportValues('Basic');
                 }
             }
         }
     }
     $componentMode = $this->get('component_mode');
     switch ($componentMode) {
         case 2:
             require_once "CRM/Contribute/Form/Task.php";
             CRM_Contribute_Form_Task::preProcessCommon($this, true);
             $this->_exportMode = self::CONTRIBUTE_EXPORT;
             $componentName = array('', 'Contribute');
             break;
         case 3:
             require_once "CRM/Event/Form/Task.php";
             CRM_Event_Form_Task::preProcessCommon($this, true);
             $this->_exportMode = self::EVENT_EXPORT;
             $componentName = array('', 'Event');
             break;
         case 4:
             require_once "CRM/Activity/Form/Task.php";
             CRM_Activity_Form_Task::preProcessCommon($this, true);
             $this->_exportMode = self::ACTIVITY_EXPORT;
             $componentName = array('', 'Activity');
             break;
     }
     require_once 'CRM/Contact/Task.php';
     $this->_task = $values['task'];
     if ($this->_exportMode == self::CONTACT_EXPORT) {
         $contactTasks = CRM_Contact_Task::taskTitles();
         $taskName = $contactTasks[$this->_task];
         require_once "CRM/Contact/Form/Task.php";
         CRM_Contact_Form_Task::preProcessCommon($this, true);
     } else {
         $this->assign('taskName', "Export {$componentName['1']}");
         eval('$componentTasks = CRM_' . $componentName[1] . '_Task::tasks();');
         $taskName = $componentTasks[$this->_task];
     }
     if ($this->_componentTable) {
         $query = "\nSELECT count(*)\nFROM   {$this->_componentTable}\n";
         $totalSelectedRecords = CRM_Core_DAO::singleValueQuery($query);
     } else {
         $totalSelectedRecords = count($this->_componentIds);
     }
     $this->assign('totalSelectedRecords', $totalSelectedRecords);
     $this->assign('taskName', $taskName);
     // all records actions = save a search
     if ($values['radio_ts'] == 'ts_all' || $this->_task == CRM_Contact_Task::SAVE_SEARCH) {
         $this->_selectAll = true;
         $this->assign('totalSelectedRecords', $this->get('rowCount'));
     }
     $this->set('componentIds', $this->_componentIds);
     $this->set('selectAll', $this->_selectAll);
     $this->set('exportMode', $this->_exportMode);
     $this->set('componentClause', $this->_componentClause);
     $this->set('componentTable', $this->_componentTable);
 }
 static function preProcessCommon(&$form, $useTable = true)
 {
     $form->_contactIds = array();
     $form->_contactTypes = array();
     $form->_searchFrom = $searchformName = 'contact';
     $searchFrom = $form->get('searchFormName');
     $pages = $form->controller->_pages;
     $prefix = 'contact';
     if ($pages[$searchFrom]) {
         $prefix = $pages[$searchFrom]->getVar('_prefix');
         if ($prefix == 'member_') {
             $searchformName = 'member';
         }
     }
     if ($searchformName == 'member') {
         $form->_searchFrom = $searchformName;
         $values = $form->controller->exportValues($form->get('searchFormName'));
         $ids = array();
         if ($values['radio_ts'] == 'ts_sel') {
             foreach ($values as $name => $value) {
                 if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
                     $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
                 }
             }
         } else {
             $queryParams = $form->get('queryParams');
             $sortOrder = null;
             if ($form->get(CRM_Utils_Sort::SORT_ORDER)) {
                 $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER);
             }
             $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_MEMBER);
             $query->_distinctComponentClause = ' civicrm_membership.id';
             $query->_groupByComponentClause = ' GROUP BY civicrm_membership.id ';
             $result = $query->searchQuery(0, 0, $sortOrder);
             while ($result->fetch()) {
                 $ids[] = $result->membership_id;
             }
         }
         if (!empty($ids)) {
             $form->_componentClause = ' civicrm_membership.id IN ( ' . implode(',', $ids) . ' ) ';
             $form->assign('totalSelectedMembers', count($ids));
         }
         $form->_memberIds = $form->_componentIds = $ids;
         $form->_contactIds =& CRM_Core_DAO::getContactIDsFromComponent($ids, 'civicrm_membership');
         $form->assign('totalSelectedContacts', count($form->_contactIds));
     } else {
         parent::preProcessCommon($form);
     }
 }