/** * Function to set variables up before form is built * * @return void * @access public */ function preProcess() { //custom data related code $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', false); if ($this->_cdType) { $this->assign('cdType', true); return CRM_Custom_Form_CustomData::preProcess($this); } parent::preProcess(); if ($this->_id) { $this->assign('entityID', $this->_id); $eventType = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'event_type_id'); } else { $eventType = 'null'; } $showLocation = false; // when custom data is included in this page if (CRM_Utils_Array::value("hidden_custom", $_POST)) { $this->set('type', 'Event'); $this->set('subType', CRM_Utils_Array::value('event_type_id', $_POST)); $this->set('entityId', $this->_id); CRM_Custom_Form_Customdata::preProcess($this); CRM_Custom_Form_Customdata::buildQuickForm($this); CRM_Custom_Form_Customdata::setDefaultValues($this); } }
function preProcess() { //custom data related code $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', false); if ($this->_cdType) { $this->assign('cdType', true); return CRM_Custom_Form_CustomData::preProcess($this); } $this->_contactId = $this->get('contactId'); $this->_relationshipId = $this->get('id'); $this->_rtype = CRM_Utils_Request::retrieve('rtype', 'String', $this); $this->_rtypeId = CRM_Utils_Request::retrieve('relTypeId', 'String', $this); $this->_display_name_a = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'display_name'); $this->assign('sort_name_a', $this->_display_name_a); $this->_caseId = CRM_Utils_Request::retrieve('caseID', 'Integer', $this); //get the relationship values. $this->_values = array(); if ($this->_relationshipId) { $params = array('id' => $this->_relationshipId); CRM_Core_DAO::commonRetrieve('CRM_Contact_DAO_Relationship', $params, $this->_values); } if (!$this->_rtypeId) { $params = $this->controller->exportValues($this->_name); if (isset($params['relationship_type_id'])) { $this->_rtypeId = $params['relationship_type_id']; } else { if (!empty($this->_values)) { $this->_rtypeId = $this->_values['relationship_type_id'] . '_' . $this->_rtype; } } } //get the relationship type id $this->_relationshipTypeId = str_replace(array('_a_b', '_b_a'), array('', ''), $this->_rtypeId); //get the relationship type if (!$this->_rtype) { $this->_rtype = str_replace($this->_relationshipTypeId . '_', '', $this->_rtypeId); } $this->assign("rtype", $this->_rtype); require_once 'CRM/Core/PseudoConstant.php'; //use name as it remain constant, CRM-3336 $this->_allRelationshipNames = CRM_Core_PseudoConstant::relationshipType('name'); // when custom data is included in this page if (CRM_Utils_Array::value("hidden_custom", $_POST)) { CRM_Custom_Form_Customdata::preProcess($this); CRM_Custom_Form_Customdata::buildQuickForm($this); CRM_Custom_Form_Customdata::setDefaultValues($this); } }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $this->_showFeeBlock = CRM_Utils_Array::value('eventId', $_GET); $this->assign('showFeeBlock', false); $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); $this->_participantId = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $this->_context); // 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->assign('roleCustomDataTypeID', $this->_roleCustomDataTypeID); $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID); if ($this->_mode) { $this->assign('participantMode', $this->_mode); $this->_paymentProcessor = array('billing_mode' => 1); $validProcessors = array(); $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )"); foreach ($processors as $ppID => $label) { require_once 'CRM/Core/BAO/PaymentProcessor.php'; require_once 'CRM/Core/Payment.php'; $paymentProcessor =& CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) { continue; } else { if ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') { continue; } else { $paymentObject =& CRM_Core_Payment::singleton($this->_mode, 'Contribute', $paymentProcessor, $this); $error = $paymentObject->checkConfig(); if (empty($error)) { $validProcessors[$ppID] = $label; } $paymentObject = null; } } } if (empty($validProcessors)) { CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page')); } else { $this->_processors = $validProcessors; } // also check for billing information // get the billing location type $locationTypes =& CRM_Core_PseudoConstant::locationType(); $this->_bltID = array_search('Billing', $locationTypes); if (!$this->_bltID) { CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); } $this->set('bltID', $this->_bltID); $this->assign('bltID', $this->_bltID); $this->_fields = array(); require_once 'CRM/Core/Payment/Form.php'; CRM_Core_Payment_Form::setCreditCardFields($this); // this required to show billing block $this->assign_by_ref('paymentProcessor', $paymentProcessor); $this->assign('hidePayPalExpress', true); } if ($this->_showFeeBlock) { $this->assign('showFeeBlock', true); $this->assign('paid', true); return CRM_Event_Form_EventFees::preProcess($this); } //custom data related code $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', false); if ($this->_cdType) { $this->assign('cdType', true); return CRM_Custom_Form_CustomData::preProcess($this); } //check the mode when this form is called either single or as //search task action if ($this->_participantId || $this->_contactID || $this->_context == 'standalone') { $this->_single = true; $this->assign('urlPath', 'civicrm/contact/view/participant'); if (!$this->_participantId && !$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 $advanced = null; $builder = null; $session =& CRM_Core_Session::singleton(); $advanced = $session->get('isAdvanced'); $builder = $session->get('isSearchBuilder'); $searchType = "basic"; if ($advanced == 1) { $this->_action = CRM_Core_Action::ADVANCED; $searchType = "advanced"; } else { if ($advanced == 2 && ($builder = 1)) { $this->_action = CRM_Core_Action::PROFILE; $searchType = "builder"; } else { if ($advanced == 3) { $searchType = "custom"; } } } parent::preProcess(); $this->_single = false; $this->_contactID = null; //set ajax path, this used for custom data building $this->assign('urlPath', "civicrm/contact/search/{$searchType}"); $this->assign('urlPathVar', "_qf_Participant_display=true&qfKey={$this->controller->_key}"); } $this->assign('single', $this->_single); $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) { return; } if ($this->_participantId) { // assign participant id to the template $this->assign('participantId', $this->_participantId); $this->_roleId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $this->_participantId, 'role_id'); } // when fee amount is included in form if (CRM_Utils_Array::value('hidden_feeblock', $_POST) || CRM_Utils_Array::value('send_receipt', $_POST)) { 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 (CRM_Utils_Array::value("hidden_custom", $_POST)) { //custom data of type participant role CRM_Custom_Form_Customdata::preProcess($this, $this->_roleCustomDataTypeID, $_POST['role_id'], 1, 'Participant', $this->_participantId); 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->_participantId); 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->_participantId); 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->_participantId && $this->_action & CRM_Core_Action::UPDATE) { require_once 'CRM/Contribute/BAO/Contribution.php'; $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_participantId, 'Event'); } $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId); }
function setDefaultValues() { $defaults = array(); $defaults = parent::setDefaultValues(); if ($this->_action & CRM_Core_Action::DELETE) { return $defaults; } $params['id'] = $this->_id; if ($this->_noteId) { $defaults['note'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $this->_noteId, 'note'); } if ($this->_id) { CRM_Grant_BAO_Grant::retrieve($params, $defaults); // fix the display of the monetary value, CRM-4038 require_once 'CRM/Utils/Money.php'; if (isset($defaults['amount_total'])) { $defaults['amount_total'] = CRM_Utils_Money::format($defaults['amount_total'], null, '%a'); } if (isset($defaults['amount_requested'])) { $defaults['amount_requested'] = CRM_Utils_Money::format($defaults['amount_requested'], null, '%a'); } if (isset($defaults['amount_granted'])) { $defaults['amount_granted'] = CRM_Utils_Money::format($defaults['amount_granted'], null, '%a'); } $dates = array('application_received_date', 'decision_date', 'money_transfer_date', 'grant_due_date'); foreach ($dates as $key) { if (CRM_Utils_Array::value($key, $defaults)) { list($defaults[$key]) = CRM_Utils_Date::setDateDefaults($defaults[$key]); } } } else { require_once 'CRM/Utils/Date.php'; list($defaults['application_received_date']) = CRM_Utils_Date::setDateDefaults(); } // custom data set defaults $defaults += CRM_Custom_Form_Customdata::setDefaultValues($this); return $defaults; }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $this->_showFeeBlock = CRM_Utils_Array::value('eventId', $_GET); $this->assign('showFeeBlock', false); $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $this->_context); if ($this->_contactId) { require_once 'CRM/Contact/BAO/Contact.php'; $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); $this->assign('displayName', $displayName); } // 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) { $this->_id = null; } else { $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); } require_once 'CRM/Event/DAO/ParticipantPayment.php'; if ($this->_id) { $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'id', 'participant_id'); } // get the option value for custom data type require_once 'CRM/Core/OptionGroup.php'; $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->_paymentProcessor = array('billing_mode' => 1); $validProcessors = array(); $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )"); foreach ($processors as $ppID => $label) { require_once 'CRM/Core/BAO/PaymentProcessor.php'; require_once 'CRM/Core/Payment.php'; $paymentProcessor =& CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) { continue; } else { if ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') { continue; } else { $paymentObject =& CRM_Core_Payment::singleton($this->_mode, $paymentProcessor, $this); $error = $paymentObject->checkConfig(); if (empty($error)) { $validProcessors[$ppID] = $label; } $paymentObject = null; } } } if (empty($validProcessors)) { CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page')); } else { $this->_processors = $validProcessors; } // also check for billing information // get the billing location type $locationTypes =& CRM_Core_PseudoConstant::locationType(); $this->_bltID = array_search('Billing', $locationTypes); if (!$this->_bltID) { CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); } $this->set('bltID', $this->_bltID); $this->assign('bltID', $this->_bltID); $this->_fields = array(); require_once 'CRM/Core/Payment/Form.php'; CRM_Core_Payment_Form::setCreditCardFields($this); // this required to show billing block $this->assign_by_ref('paymentProcessor', $paymentProcessor); $this->assign('hidePayPalExpress', true); } if ($this->_showFeeBlock) { $this->assign('showFeeBlock', true); $this->assign('paid', true); return CRM_Event_Form_EventFees::preProcess($this); } //custom data related code $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', false); if ($this->_cdType) { $this->assign('cdType', true); return CRM_Custom_Form_CustomData::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; } parent::preProcess(); $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); $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) { 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 (CRM_Utils_Array::value('hidden_feeblock', $_POST) || CRM_Utils_Array::value('send_receipt', $_POST)) { 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 (CRM_Utils_Array::value("hidden_custom", $_POST)) { //custom data of type participant role if ($_POST['role_id']) { foreach ($_POST['role_id'] as $k => $val) { $roleID = $val; CRM_Custom_Form_Customdata::preProcess($this, $this->_roleCustomDataTypeID, $k, 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) { require_once 'CRM/Contribute/BAO/Contribution.php'; $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, 'Event'); } $this->set('onlinePendingContributionId', $this->_onlinePendingContributionId); $roleIds = CRM_Event_PseudoConstant::participantRole(); if (!empty($roleIds)) { $query = "\nSELECT civicrm_custom_group.name as name, \n civicrm_custom_group.id as id,\n extends_entity_column_value as value\n FROM civicrm_custom_group\n WHERE ( extends_entity_column_value REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', array_keys($roleIds)) . "[[:>:]]' \n OR extends_entity_column_value IS NULL )\n AND extends_entity_column_id = '{$this->_roleCustomDataTypeID}' \n AND extends = 'Participant'\n AND is_active = 1"; $dao =& CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { if ($dao->value) { $getRole = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->value); foreach ($getRole as $r) { if (!$r) { continue; } if (isset($this->_participantRoleIds[$r])) { $this->_participantRoleIds[$r] .= ',' . $dao->name; } else { $this->_participantRoleIds[$r] = $dao->name; } } } else { if (isset($this->_participantRoleIds[0])) { $this->_participantRoleIds[0] .= ',' . $dao->name; } else { $this->_participantRoleIds[0] = $dao->name; } } } $dao->free(); } foreach ($roleIds as $k => $v) { if (!isset($this->_participantRoleIds[$k])) { $this->_participantRoleIds[$k] = ''; } } $this->assign('participantRoleIds', $this->_participantRoleIds); }
/** * This function sets the default values for the form. * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $defaults = $this->_values; $fields = array(); if ($this->_action & CRM_Core_Action::DELETE) { return $defaults; } if (CRM_Utils_Array::value('is_test', $defaults)) { $this->assign("is_test", true); } if ($this->_id) { $startDate = CRM_Utils_Array::value('start_date', $this->_values); $createDate = CRM_Utils_Array::value('create_date', $this->_values); list($defaults['start_date']) = CRM_Utils_Date::setDateDefaults($startDate); list($defaults['create_date']) = CRM_Utils_Date::setDateDefaults($createDate); if ($this->_values['acknowledge_date']) { list($defaults['acknowledge_date']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('acknowledge_date', $this->_values)); } //check is this pledge pending // fix the display of the monetary value, CRM-4038 require_once 'CRM/Utils/Money.php'; if ($this->_isPending) { $defaults['eachPaymentAmount'] = $this->_values['amount'] / $this->_values['installments']; $defaults['eachPaymentAmount'] = CRM_Utils_Money::format($defaults['eachPaymentAmount'], null, '%a'); } else { $this->assign('start_date', $startDate); $this->assign('create_date', $createDate); } // fix the display of the monetary value, CRM-4038 if (isset($this->_values['amount'])) { $defaults['amount'] = CRM_Utils_Money::format($this->_values['amount'], null, '%a'); } } else { //default values. list($now) = CRM_Utils_Date::setDateDefaults(); $defaults['create_date'] = $now; $defaults['start_date'] = $now; $defaults['installments'] = 12; $defaults['frequency_interval'] = 1; $defaults['frequency_day'] = 1; $defaults['initial_reminder_day'] = 5; $defaults['max_reminders'] = 1; $defaults['additional_reminder_day'] = 5; $defaults['frequency_unit'] = array_search('monthly', $this->_freqUnits); $defaults['contribution_type_id'] = array_search('Donation', CRM_Contribute_PseudoConstant::contributionType()); } //assign status. $this->assign('status', CRM_Utils_Array::value(CRM_Utils_Array::value('status_id', $this->_values), CRM_Contribute_PseudoConstant::contributionStatus(), 'Pending')); //honoree contact. if ($this->_honorID) { require_once 'CRM/Contact/BAO/Contact.php'; $honorDefault = array(); $idParams = array('contact_id' => $this->_honorID); CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $ids); $honorType = CRM_Core_PseudoConstant::honor(); $defaults["honor_prefix_id"] = $honorDefault["prefix_id"]; $defaults["honor_first_name"] = CRM_Utils_Array::value("first_name", $honorDefault); $defaults["honor_last_name"] = CRM_Utils_Array::value("last_name", $honorDefault); $defaults["honor_email"] = CRM_Utils_Array::value("email", $honorDefault["location"][1]["email"][1]); $defaults["honor_type"] = $honorType[$defaults["honor_type_id"]]; } $this->assign('email', $this->userEmail); // custom data set defaults $defaults += CRM_Custom_Form_Customdata::setDefaultValues($this); return $defaults; }
function setDefaultValues() { $defaults = array(); if (isset($this->_id)) { $defaults = $this->_groupValues; if (CRM_Utils_Array::value('group_type', $defaults)) { $types = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($defaults['group_type'], 1, -1)); $defaults['group_type'] = array(); foreach ($types as $type) { $defaults['group_type'][$type] = 1; } } if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE && CRM_Core_Permission::check('administer Multiple Organizations')) { require_once 'CRM/Contact/BAO/GroupOrganization.php'; CRM_Contact_BAO_GroupOrganization::retrieve($this->_id, $defaults); if (CRM_Utils_Array::value('group_organization', $defaults)) { //used in edit mode $this->_groupOrganizationID = $defaults['group_organization']; } $this->assign('organizationID', $defaults['organization_id']); } } if (!CRM_Utils_Array::value('parents', $defaults)) { $defaults['parents'] = CRM_Core_BAO_Domain::getGroupId(); } // custom data set defaults $defaults += CRM_Custom_Form_Customdata::setDefaultValues($this); return $defaults; }
/** * This function sets the default values for the form. For edit/view mode * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) { return true; } eval('$defaults = CRM_Case_Form_Activity_' . $this->_activityTypeFile . '::setDefaultValues($this);'); $defaults = array_merge($defaults, CRM_Custom_Form_Customdata::setDefaultValues($this)); return $defaults; }
public function preProcess() { //custom data related code $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', false); if ($this->_cdType) { $this->assign('cdType', true); return CRM_Custom_Form_CustomData::preProcess($this); } // action $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'add'); $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); // check for edit permission if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page')); } $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $this->_context); if ($this->_id) { $this->_memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $this->_id, "membership_type_id"); } $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); if ($this->_mode) { $this->assign('membershipMode', $this->_mode); $this->_paymentProcessor = array('billing_mode' => 1); $validProcessors = array(); $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )"); foreach ($processors as $ppID => $label) { require_once 'CRM/Core/BAO/PaymentProcessor.php'; require_once 'CRM/Core/Payment.php'; $paymentProcessor =& CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) { continue; } else { if ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') { continue; } else { $paymentObject =& CRM_Core_Payment::singleton($this->_mode, 'Contribute', $paymentProcessor, $this); $error = $paymentObject->checkConfig(); if (empty($error)) { $validProcessors[$ppID] = $label; } $paymentObject = null; } } } if (empty($validProcessors)) { CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page')); } else { $this->_processors = $validProcessors; } // also check for billing information // get the billing location type $locationTypes =& CRM_Core_PseudoConstant::locationType(); $this->_bltID = array_search('Billing', $locationTypes); if (!$this->_bltID) { CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); } $this->set('bltID', $this->_bltID); $this->assign('bltID', $this->_bltID); $this->_fields = array(); require_once 'CRM/Core/Payment/Form.php'; CRM_Core_Payment_Form::setCreditCardFields($this); // this required to show billing block $this->assign_by_ref('paymentProcessor', $paymentProcessor); $this->assign('hidePayPalExpress', true); } //check whether membership status present or not if ($this->_action & CRM_Core_Action::ADD) { CRM_Member_BAO_Membership::statusAvilability($this->_contactID); } // when custom data is included in this page if (CRM_Utils_Array::value("hidden_custom", $_POST)) { CRM_Custom_Form_Customdata::preProcess($this); 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) { require_once 'CRM/Contribute/BAO/Contribution.php'; $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, 'Membership'); } $this->assign('onlinePendingContributionId', $this->_onlinePendingContributionId); parent::preProcess(); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { //check permission for action. if (!CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page')); } $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', false); if ($this->_cdType) { $this->assign('cdType', true); return CRM_Custom_Form_CustomData::preProcess($this); } $this->_formType = CRM_Utils_Array::value('formType', $_GET); // get price set id. $this->_priceSetId = CRM_Utils_Array::value('priceSetId', $_GET); $this->set('priceSetId', $this->_priceSetId); $this->assign('priceSetId', $this->_priceSetId); //get the pledge payment id $this->_ppID = CRM_Utils_Request::retrieve('ppid', 'Positive', $this); //get the contact id $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); //get the action. $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'add'); $this->assign('action', $this->_action); //get the contribution id if update $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $this->_context); //set the contribution mode. $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); $this->assign('contributionMode', $this->_mode); $this->_paymentProcessor = array('billing_mode' => 1); $this->assign('showCheckNumber', false); //ensure that processor has a valid config //only valid processors get display to user if ($this->_mode) { $validProcessors = array(); $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )"); foreach ($processors as $ppID => $label) { require_once 'CRM/Core/BAO/PaymentProcessor.php'; require_once 'CRM/Core/Payment.php'; $paymentProcessor =& CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) { continue; } else { if ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') { continue; } else { $paymentObject =& CRM_Core_Payment::singleton($this->_mode, 'Contribute', $paymentProcessor, $this); $error = $paymentObject->checkConfig(); if (empty($error)) { $validProcessors[$ppID] = $label; } $paymentObject = null; } } } if (empty($validProcessors)) { CRM_Core_Error::fatal(ts('You will need to configure the %1 settings for your Payment Processor before you can submit credit card transactions.', array(1 => $this->_mode))); } else { $this->_processors = $validProcessors; } } // this required to show billing block $this->assign_by_ref('paymentProcessor', $paymentProcessor); $this->assign('hidePayPalExpress', true); if ($this->_contactID) { require_once 'CRM/Contact/BAO/Contact/Location.php'; list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); $this->assign('displayName', $this->userDisplayName); } // also check for billing information // get the billing location type $locationTypes =& CRM_Core_PseudoConstant::locationType(); $this->_bltID = array_search('Billing', $locationTypes); if (!$this->_bltID) { CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); } $this->set('bltID', $this->_bltID); $this->assign('bltID', $this->_bltID); $this->_fields = array(); require_once 'CRM/Core/Payment.php'; require_once 'CRM/Core/Payment/Form.php'; // payment fields are depending on payment type if ($this->_processors['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) { CRM_Core_Payment_Form::setDirectDebitFields($this); } else { CRM_Core_Payment_Form::setCreditCardFields($this); } if ($this->_action & CRM_Core_Action::DELETE) { return; } $config =& CRM_Core_Config::singleton(); if (in_array("CiviPledge", $config->enableComponents) && !$this->_formType) { //get the payment values associated with given pledge payment id OR check for payments due. $this->_pledgeValues = array(); if ($this->_ppID) { $payParams = array('id' => $this->_ppID); require_once "CRM/Pledge/BAO/Payment.php"; CRM_Pledge_BAO_Payment::retrieve($payParams, $this->_pledgeValues['pledgePayment']); $this->_pledgeID = CRM_Utils_Array::value('pledge_id', $this->_pledgeValues['pledgePayment']); $paymentStatusID = CRM_Utils_Array::value('status_id', $this->_pledgeValues['pledgePayment']); $this->_id = CRM_Utils_Array::value('contribution_id', $this->_pledgeValues['pledgePayment']); //get all status $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(); if (!($paymentStatusID == array_search('Pending', $allStatus) || $paymentStatusID == array_search('Overdue', $allStatus))) { CRM_Core_Error::fatal(ts("Pledge payment status should be 'Pending' or 'Overdue'.")); } //get the pledge values associated with given pledge payment. require_once 'CRM/Pledge/BAO/Pledge.php'; $ids = array(); $pledgeParams = array('id' => $this->_pledgeID); CRM_Pledge_BAO_Pledge::getValues($pledgeParams, $this->_pledgeValues, $ids); $this->assign('ppID', $this->_ppID); } else { // Not making a pledge payment, so check if pledge payment(s) are due for this contact so we can alert the user. CRM-5206 if (isset($this->_contactID)) { require_once "CRM/Pledge/BAO/Pledge.php"; $contactPledges = array(); $contactPledges = CRM_Pledge_BAO_Pledge::getContactPledges($this->_contactID); if (!empty($contactPledges)) { $payments = null; $paymentsDue = null; $multipleDue = false; require_once "CRM/Pledge/BAO/Payment.php"; foreach ($contactPledges as $key => $pledgeId) { $payments = CRM_Pledge_BAO_Payment::getOldestPledgePayment($pledgeId); if ($payments) { if ($paymentsDue) { $multipleDue = true; break; } else { $paymentsDue = $payments; } } } if ($multipleDue) { // Show link to pledge tab since more than one pledge has a payment due $pledgeTab = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactID}&selectedChild=pledge"); CRM_Core_Session::setStatus(ts('This contact has pending or overdue pledge payments. <a href="%1">Click here to view their Pledges tab</a> and verify whether this contribution should be applied as a pledge payment.', array(1 => $pledgeTab))); } else { if ($paymentsDue) { // Show user link to oldest Pending or Overdue pledge payment require_once 'CRM/Utils/Date.php'; require_once 'CRM/Utils/Money.php'; $ppAmountDue = CRM_Utils_Money::format($payments['amount']); $ppSchedDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Payment', $payments['id'], 'scheduled_date')); if ($this->_mode) { $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge&mode=live"); } else { $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge"); } CRM_Core_Session::setStatus(ts('This contact has a pending or overdue pledge payment of %2 which is scheduled for %3. <a href="%1">Click here to apply this contribution as a pledge payment<a/>.', array(1 => $ppUrl, 2 => $ppAmountDue, 3 => $ppSchedDate))); } } } } } } $this->_values = array(); // current contribution id if ($this->_id) { $this->_online = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_FinancialTrxn', $this->_id, 'id', 'contribution_id'); if ($this->_online) { $this->assign('isOnline', true); } //to get Premium id $sql = "\nSELECT *\nFROM civicrm_contribution_product\nWHERE contribution_id = {$this->_id}\n"; $dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray); if ($dao->fetch()) { $this->_premiumID = $dao->id; $this->_productDAO = $dao; } $dao->free(); $ids = array(); $params = array('id' => $this->_id); require_once "CRM/Contribute/BAO/Contribution.php"; CRM_Contribute_BAO_Contribution::getValues($params, $this->_values, $ids); //unset the honor type id:when delete the honor_contact_id //and edit the contribution, honoree infomation pane open //since honor_type_id is present if (!CRM_Utils_Array::value('honor_contact_id', $this->_values)) { unset($this->_values['honor_type_id']); } //to get note id require_once 'CRM/Core/BAO/Note.php'; $daoNote =& new CRM_Core_BAO_Note(); $daoNote->entity_table = 'civicrm_contribution'; $daoNote->entity_id = $this->_id; if ($daoNote->find(true)) { $this->_noteID = $daoNote->id; $this->_values['note'] = $daoNote->note; } $this->_contributionType = $this->_values['contribution_type_id']; $csParams = array('contribution_id' => $this->_id); $softCredit = CRM_Contribute_BAO_Contribution::getSoftContribution($csParams, true); if (CRM_Utils_Array::value('soft_credit_to', $softCredit)) { $softCredit['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $softCredit['soft_credit_to'], 'sort_name'); } $this->_values['soft_credit_to'] = $softCredit['sort_name']; $this->_values['softID'] = $softCredit['soft_credit_id']; $this->_values['soft_contact_id'] = $softCredit['soft_credit_to']; $this->_values['pcp_made_through_id'] = $softCredit['pcp_id']; $this->_values['pcp_display_in_roll'] = $softCredit['pcp_display_in_roll']; $this->_values['pcp_roll_nickname'] = $softCredit['pcp_roll_nickname']; $this->_values['pcp_personal_note'] = $softCredit['pcp_personal_note']; //display check number field only if its having value or its offline mode. if (CRM_Utils_Array::value('payment_instrument_id', $this->_values) == CRM_Core_OptionGroup::getValue('payment_instrument', 'Check', 'name') || CRM_Utils_Array::value('check_number', $this->_values)) { $this->assign('showCheckNumber', true); } } // when custom data is included in this page if (CRM_Utils_Array::value("hidden_custom", $_POST)) { $this->set('type', 'Contribution'); $this->set('subType', $this->_contributionType); $this->set('entityId', $this->_id); CRM_Custom_Form_Customdata::preProcess($this); CRM_Custom_Form_Customdata::buildQuickForm($this); CRM_Custom_Form_Customdata::setDefaultValues($this); } require_once 'CRM/Price/BAO/Set.php'; $this->_lineItems = array(); if ($this->_id && ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution', $this->_id))) { $this->_priceSetId = $priceSetId; require_once 'CRM/Price/BAO/LineItem.php'; $this->_lineItems[] = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution'); } $this->assign('lineItem', empty($this->_lineItems) ? false : $this->_lineItems); }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues(&$form, &$defaults) { $defaults += CRM_Custom_Form_Customdata::setDefaultValues($form); }