コード例 #1
0
ファイル: Main.php プロジェクト: bhirsch/voipdrupal-4.7-1.0
 /** 
  * Function to set variables up before form is built 
  *                                                           
  * @return void 
  * @access public 
  */
 function preProcess()
 {
     parent::preProcess();
     $this->assign('intro_text', $this->_values['intro_text']);
     $this->assign('footer_text', $this->_values['footer_text']);
     // to process Custom data that are appended to URL
     require_once 'CRM/Core/BAO/CustomGroup.php';
     CRM_Core_BAO_CustomGroup::extractGetParams($this, 'Contribution');
 }
コード例 #2
0
ファイル: Main.php プロジェクト: nielosz/civicrm-core
 /**
  * Set the default values.
  */
 public function setDefaultValues()
 {
     // check if the user is registered and we have a contact ID
     $contactID = $this->getContactID();
     if (!empty($contactID)) {
         $fields = array();
         $removeCustomFieldTypes = array('Contribution', 'Membership');
         $contribFields = CRM_Contribute_BAO_Contribution::getContributionFields();
         // remove component related fields
         foreach ($this->_fields as $name => $dontCare) {
             //don't set custom data Used for Contribution (CRM-1344)
             if (substr($name, 0, 7) == 'custom_') {
                 $id = substr($name, 7);
                 if (!CRM_Core_BAO_CustomGroup::checkCustomField($id, $removeCustomFieldTypes)) {
                     continue;
                 }
                 // ignore component fields
             } elseif (array_key_exists($name, $contribFields) || substr($name, 0, 11) == 'membership_' || substr($name, 0, 13) == 'contribution_') {
                 continue;
             }
             $fields[$name] = 1;
         }
         if (!empty($fields)) {
             CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
         }
         $billingDefaults = $this->getProfileDefaults('Billing', $contactID);
         $this->_defaults = array_merge($this->_defaults, $billingDefaults);
     }
     if (!empty($this->_ccid) && !empty($this->_pendingAmount)) {
         $this->_defaults['total_amount'] = CRM_Utils_Money::format($this->_pendingAmount, NULL, '%a');
     }
     /*
      * hack to simplify credit card entry for testing
      *
      * $this->_defaults['credit_card_type']     = 'Visa';
      *         $this->_defaults['amount']               = 168;
      *         $this->_defaults['credit_card_number']   = '4111111111111111';
      *         $this->_defaults['cvv2']                 = '000';
      *         $this->_defaults['credit_card_exp_date'] = array('Y' => date('Y')+1, 'M' => '05');
      *         // hack to simplify direct debit entry for testing
      *         $this->_defaults['account_holder'] = 'Max Müller';
      *         $this->_defaults['bank_account_number'] = '12345678';
      *         $this->_defaults['bank_identification_number'] = '12030000';
      *         $this->_defaults['bank_name'] = 'Bankname';
      */
     //build set default for pledge overdue payment.
     if (!empty($this->_values['pledge_id'])) {
         //used to record completed pledge payment ids used later for honor default
         $completedContributionIds = array();
         $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($this->_values['pledge_id']);
         $paymentAmount = 0;
         $duePayment = FALSE;
         foreach ($pledgePayments as $payId => $value) {
             if ($value['status'] == 'Overdue') {
                 $this->_defaults['pledge_amount'][$payId] = 1;
                 $paymentAmount += $value['scheduled_amount'];
             } elseif (!$duePayment && $value['status'] == 'Pending') {
                 $this->_defaults['pledge_amount'][$payId] = 1;
                 $paymentAmount += $value['scheduled_amount'];
                 $duePayment = TRUE;
             } elseif ($value['status'] == 'Completed' && $value['contribution_id']) {
                 $completedContributionIds[] = $value['contribution_id'];
             }
         }
         $this->_defaults['price_' . $this->_priceSetId] = $paymentAmount;
         if (count($completedContributionIds)) {
             $softCredit = array();
             foreach ($completedContributionIds as $id) {
                 $softCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($id);
             }
             if (isset($softCredit['soft_credit'])) {
                 $this->_defaults['soft_credit_type_id'] = $softCredit['soft_credit'][1]['soft_credit_type'];
                 //since honoree profile fieldname of fields are prefixed with 'honor'
                 //we need to reformat the fieldname to append prefix during setting default values
                 CRM_Core_BAO_UFGroup::setProfileDefaults($softCredit['soft_credit'][1]['contact_id'], CRM_Core_BAO_UFGroup::getFields($this->_honoreeProfileId), $defaults);
                 foreach ($defaults as $fieldName => $value) {
                     $this->_defaults['honor[' . $fieldName . ']'] = $value;
                 }
             }
         }
     } elseif (!empty($this->_values['pledge_block_id'])) {
         //set default to one time contribution.
         $this->_defaults['is_pledge'] = 0;
     }
     // to process Custom data that are appended to URL
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution'");
     $this->_defaults = array_merge($this->_defaults, $getDefaults);
     $config = CRM_Core_Config::singleton();
     // set default country from config if no country set
     if (empty($this->_defaults["billing_country_id-{$this->_bltID}"])) {
         $this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
     }
     // set default state/province from config if no state/province set
     if (empty($this->_defaults["billing_state_province_id-{$this->_bltID}"])) {
         $this->_defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
     }
     $entityId = $memtypeID = NULL;
     if ($this->_priceSetId) {
         if ($this->_useForMember && !empty($this->_currentMemberships) || $this->_defaultMemTypeId) {
             $selectedCurrentMemTypes = array();
             foreach ($this->_priceSet['fields'] as $key => $val) {
                 foreach ($val['options'] as $keys => $values) {
                     $opMemTypeId = CRM_Utils_Array::value('membership_type_id', $values);
                     $priceFieldName = 'price_' . $values['price_field_id'];
                     $priceFieldValue = CRM_Price_BAO_PriceSet::getPriceFieldValueFromURL($this, $priceFieldName);
                     if (!empty($priceFieldValue)) {
                         CRM_Price_BAO_PriceSet::setDefaultPriceSetField($priceFieldName, $priceFieldValue, $val['html_type'], $this->_defaults);
                         // break here to prevent overwriting of default due to 'is_default'
                         // option configuration or setting of current membership or
                         // membership for related organization.
                         // The value sent via URL get's higher priority.
                         break;
                     } elseif ($opMemTypeId && in_array($opMemTypeId, $this->_currentMemberships) && !in_array($opMemTypeId, $selectedCurrentMemTypes)) {
                         CRM_Price_BAO_PriceSet::setDefaultPriceSetField($priceFieldName, $keys, $val['html_type'], $this->_defaults);
                         $memtypeID = $selectedCurrentMemTypes[] = $values['membership_type_id'];
                     } elseif (!empty($values['is_default']) && !$opMemTypeId && (!isset($this->_defaults[$priceFieldName]) || $val['html_type'] == 'CheckBox' && !isset($this->_defaults[$priceFieldName][$keys]))) {
                         CRM_Price_BAO_PriceSet::setDefaultPriceSetField($priceFieldName, $keys, $val['html_type'], $this->_defaults);
                         $memtypeID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_defaults[$priceFieldName], 'membership_type_id');
                     }
                 }
             }
             $entityId = CRM_Utils_Array::value('id', CRM_Member_BAO_Membership::getContactMembership($contactID, $memtypeID, NULL));
         } else {
             CRM_Price_BAO_PriceSet::setDefaultPriceSet($this, $this->_defaults);
         }
     }
     //set custom field defaults set by admin if value is not set
     if (!empty($this->_fields)) {
         //load default campaign from page.
         if (array_key_exists('contribution_campaign_id', $this->_fields)) {
             $this->_defaults['contribution_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values);
         }
         //set custom field defaults
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $entityId, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $pid => $value) {
             if (!empty($value['is_default'])) {
                 $this->_defaults['payment_processor_id'] = $pid;
             }
         }
     }
     return $this->_defaults;
 }
コード例 #3
0
 /**
  * This function sets the default values for the form. For edit/view mode
  * the default values are retrieved from the database
  * Adding discussion from CRM-11915 as code comments
  * When multiple payment processors are configured for a event and user does any selection changes for them on online event registeration page :
  * The 'Register' page gets loaded through ajax and following happens :
  * the setDefaults function is called with the variable _ppType set with selected payment processor type,
  * so in the 'if' condition checked whether the selected payment processor's billing mode is of 'billing form mode'. If its not, don't setDefaults for billing form and return instead.
  *- For payment processors of billing mode 'Notify' - return from setDefaults before the code for billing profile population execution .
  * (done this is because for payment processors with 'Notify' mode billing profile form doesn't get rendered on UI)
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     if ($this->_ppType && $this->_snippet && !($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM)) {
         // see function comment block for explanation of this
         return;
     }
     $this->_defaults = array();
     $contactID = $this->getContactID();
     $billingDefaults = $this->getProfileDefaults('Billing', $contactID);
     $this->_defaults = array_merge($this->_defaults, $billingDefaults);
     $config = CRM_Core_Config::singleton();
     // set default country from config if no country set
     // note the effect of this is to set the billing country to default to the site default
     // country if the person has an address but no country (for anonymous country is set above)
     // this could have implications if the billing profile is filled but hidden.
     // this behaviour has been in place for a while but the use of js to hide things has increased
     if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $this->_defaults)) {
         $this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
     }
     // set default state/province from config if no state/province set
     if (!CRM_Utils_Array::value("billing_state_province_id-{$this->_bltID}", $this->_defaults)) {
         $this->_defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
     }
     if ($this->_snippet) {
         // now fix all state country selectors
         CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
         return $this->_defaults;
     }
     if ($contactID) {
         $options = array();
         $fields = array();
         if (!empty($this->_fields)) {
             $removeCustomFieldTypes = array('Participant');
             foreach ($this->_fields as $name => $dontCare) {
                 if (substr($name, 0, 7) == 'custom_') {
                     $id = substr($name, 7);
                     if (!$this->_allowConfirmation && !CRM_Core_BAO_CustomGroup::checkCustomField($id, $removeCustomFieldTypes)) {
                         continue;
                     }
                     // ignore component fields
                 } elseif (substr($name, 0, 12) == 'participant_') {
                     continue;
                 }
                 $fields[$name] = 1;
             }
         }
     }
     if (!empty($fields)) {
         CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
     }
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     // Set default payment processor as default payment_processor radio button value
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $pid => $value) {
             if (CRM_Utils_Array::value('is_default', $value)) {
                 $this->_defaults['payment_processor'] = $pid;
             }
         }
     }
     //if event is monetary and pay later is enabled and payment
     //processor is not available then freeze the pay later checkbox with
     //default check
     if (CRM_Utils_Array::value('is_pay_later', $this->_values['event']) && !is_array($this->_paymentProcessor)) {
         $this->_defaults['is_pay_later'] = 1;
     }
     //set custom field defaults
     if (!empty($this->_fields)) {
         //load default campaign from page.
         if (array_key_exists('participant_campaign_id', $this->_fields)) {
             $this->_defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
         }
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 // fix for CRM-1743
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     //fix for CRM-3088, default value for discount set.
     $discountId = NULL;
     if (!empty($this->_values['discount'])) {
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if ($discountId) {
             if (isset($this->_values['event']['default_discount_fee_id'])) {
                 $discountKey = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_values['event']['default_discount_fee_id'], 'weight', 'id');
                 $this->_defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
             }
         }
     }
     // add this event's default participant role to defaults array
     // (for cases where participant_role field is included in form via profile)
     if ($this->_values['event']['default_role_id']) {
         $this->_defaults['participant_role'] = $this->_defaults['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     if ($this->_priceSetId && !empty($this->_feeBlock)) {
         foreach ($this->_feeBlock as $key => $val) {
             foreach ($val['options'] as $keys => $values) {
                 if ($values['is_default'] && !CRM_Utils_Array::value('is_full', $values)) {
                     if ($val['html_type'] == 'CheckBox') {
                         $this->_defaults["price_{$key}"][$keys] = 1;
                     } else {
                         $this->_defaults["price_{$key}"] = $keys;
                     }
                 }
             }
         }
     }
     //set default participant fields, CRM-4320.
     $hasAdditionalParticipants = FALSE;
     if ($this->_allowConfirmation) {
         $this->_contactId = $contactID;
         $this->_discountId = $discountId;
         $forcePayLater = CRM_Utils_Array::value('is_pay_later', $this->_defaults, FALSE);
         $this->_defaults = array_merge($this->_defaults, CRM_Event_Form_EventFees::setDefaultValues($this));
         $this->_defaults['is_pay_later'] = $forcePayLater;
         if ($this->_additionalParticipantIds) {
             $hasAdditionalParticipants = TRUE;
             $this->_defaults['additional_participants'] = count($this->_additionalParticipantIds);
         }
     }
     $this->assign('hasAdditionalParticipants', $hasAdditionalParticipants);
     //         //hack to simplify credit card entry for testing
     //         $this->_defaults['credit_card_type']     = 'Visa';
     //         $this->_defaults['credit_card_number']   = '4807731747657838';
     //         $this->_defaults['cvv2']                 = '000';
     //         $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2010', 'M' => '05' );
     // to process Custom data that are appended to URL
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution', 'Participant'");
     if (!empty($getDefaults)) {
         $this->_defaults = array_merge($this->_defaults, $getDefaults);
     }
     return $this->_defaults;
 }
コード例 #4
0
ファイル: Register.php プロジェクト: konadave/civicrm-core
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     $this->_defaults = array();
     if (!$this->_allowConfirmation && $this->_requireApproval) {
         $this->_defaults['bypass_payment'] = 1;
     }
     $contactID = $this->getContactID();
     CRM_Core_Payment_Form::setDefaultValues($this, $contactID);
     CRM_Event_BAO_Participant::formatFieldsAndSetProfileDefaults($contactID, $this);
     // Set default payment processor as default payment_processor radio button value
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $pid => $value) {
             if (!empty($value['is_default'])) {
                 $this->_defaults['payment_processor_id'] = $pid;
             }
         }
     }
     //if event is monetary and pay later is enabled and payment
     //processor is not available then freeze the pay later checkbox with
     //default check
     if (!empty($this->_values['event']['is_pay_later']) && !is_array($this->_paymentProcessor)) {
         $this->_defaults['is_pay_later'] = 1;
     }
     //set custom field defaults
     if (!empty($this->_fields)) {
         //load default campaign from page.
         if (array_key_exists('participant_campaign_id', $this->_fields)) {
             $this->_defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
         }
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 // fix for CRM-1743
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     //fix for CRM-3088, default value for discount set.
     $discountId = NULL;
     if (!empty($this->_values['discount'])) {
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if ($discountId) {
             if (isset($this->_values['event']['default_discount_fee_id'])) {
                 $discountKey = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_values['event']['default_discount_fee_id'], 'weight', 'id');
                 $this->_defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
             }
         }
     }
     // add this event's default participant role to defaults array
     // (for cases where participant_role field is included in form via profile)
     if ($this->_values['event']['default_role_id']) {
         $this->_defaults['participant_role'] = $this->_defaults['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     if ($this->_priceSetId && !empty($this->_feeBlock)) {
         foreach ($this->_feeBlock as $key => $val) {
             if (empty($val['options'])) {
                 continue;
             }
             $optionFullIds = CRM_Utils_Array::value('option_full_ids', $val, array());
             foreach ($val['options'] as $keys => $values) {
                 if ($values['is_default'] && empty($values['is_full'])) {
                     if ($val['html_type'] == 'CheckBox') {
                         $this->_defaults["price_{$key}"][$keys] = 1;
                     } else {
                         $this->_defaults["price_{$key}"] = $keys;
                     }
                 }
             }
             $unsetSubmittedOptions[$val['id']] = $optionFullIds;
         }
         //reset values for all options those are full.
         CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
     }
     //set default participant fields, CRM-4320.
     $hasAdditionalParticipants = FALSE;
     if ($this->_allowConfirmation) {
         $this->_contactId = $contactID;
         $this->_discountId = $discountId;
         $forcePayLater = CRM_Utils_Array::value('is_pay_later', $this->_defaults, FALSE);
         $this->_defaults = array_merge($this->_defaults, CRM_Event_Form_EventFees::setDefaultValues($this));
         $this->_defaults['is_pay_later'] = $forcePayLater;
         if ($this->_additionalParticipantIds) {
             $hasAdditionalParticipants = TRUE;
             $this->_defaults['additional_participants'] = count($this->_additionalParticipantIds);
         }
     }
     $this->assign('hasAdditionalParticipants', $hasAdditionalParticipants);
     //         //hack to simplify credit card entry for testing
     //         $this->_defaults['credit_card_type']     = 'Visa';
     //         $this->_defaults['credit_card_number']   = '4807731747657838';
     //         $this->_defaults['cvv2']                 = '000';
     //         $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2010', 'M' => '05' );
     // to process Custom data that are appended to URL
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution', 'Participant'");
     if (!empty($getDefaults)) {
         $this->_defaults = array_merge($this->_defaults, $getDefaults);
     }
     return $this->_defaults;
 }
コード例 #5
0
 function setDefaultValues()
 {
     // process defaults only once
     if (!empty($this->_defaults)) {
         // return $this->_defaults;
     }
     if ($this->_onbehalf) {
         return;
     }
     // check if the user is registered and we have a contact ID
     $session = CRM_Core_Session::singleton();
     $contactID = $this->_userID;
     if ($contactID) {
         $options = array();
         $fields = array();
         $removeCustomFieldTypes = array('Contribution', 'Membership');
         $contribFields = CRM_Contribute_BAO_Contribution::getContributionFields();
         // remove component related fields
         foreach ($this->_fields as $name => $dontCare) {
             //don't set custom data Used for Contribution (CRM-1344)
             if (substr($name, 0, 7) == 'custom_') {
                 $id = substr($name, 7);
                 if (!CRM_Core_BAO_CustomGroup::checkCustomField($id, $removeCustomFieldTypes)) {
                     continue;
                 }
                 // ignore component fields
             } elseif (array_key_exists($name, $contribFields) || substr($name, 0, 11) == 'membership_') {
                 continue;
             }
             $fields[$name] = 1;
         }
         $names = array('first_name', 'middle_name', 'last_name', "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}");
         foreach ($names as $name) {
             $fields[$name] = 1;
         }
         $fields["state_province-{$this->_bltID}"] = 1;
         $fields["country-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $fields['email-Primary'] = 1;
         CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
         // use primary email address if billing email address is empty
         if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults['email-Primary'])) {
             $this->_defaults["email-{$this->_bltID}"] = $this->_defaults['email-Primary'];
         }
         foreach ($names as $name) {
             if (!empty($this->_defaults[$name])) {
                 $this->_defaults['billing_' . $name] = $this->_defaults[$name];
             }
         }
     }
     //set custom field defaults set by admin if value is not set
     if (!empty($this->_fields)) {
         //load default campaign from page.
         if (array_key_exists('contribution_campaign_id', $this->_fields)) {
             $this->_defaults['contribution_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values);
         }
         //set custom field defaults
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     //set default membership for membershipship block
     if ($this->_membershipBlock) {
         $this->_defaults['selectMembership'] = $defaultMemType = $this->_defaultMemTypeId ? $this->_defaultMemTypeId : CRM_Utils_Array::value('membership_type_default', $this->_membershipBlock);
     }
     //         // hack to simplify credit card entry for testing
     //         $this->_defaults['credit_card_type']     = 'Visa';
     //         $this->_defaults['amount']               = 168;
     //         $this->_defaults['credit_card_number']   = '4807731747657838';
     //         $this->_defaults['cvv2']                 = '000';
     //         $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
     //         // hack to simplify direct debit entry for testing
     //         $this->_defaults['account_holder'] = 'Max Müller';
     //         $this->_defaults['bank_account_number'] = '12345678';
     //         $this->_defaults['bank_identification_number'] = '12030000';
     //         $this->_defaults['bank_name'] = 'Bankname';
     //build set default for pledge overdue payment.
     if (CRM_Utils_Array::value('pledge_id', $this->_values)) {
         //get all payment statuses.
         $statuses = array();
         $returnProperties = array('status_id');
         CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $this->_values['pledge_id'], $statuses, $returnProperties);
         $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
         $duePayment = FALSE;
         foreach ($statuses as $payId => $value) {
             if ($paymentStatusTypes[$value['status_id']] == 'Overdue') {
                 $this->_defaults['pledge_amount'][$payId] = 1;
             } elseif (!$duePayment && $paymentStatusTypes[$value['status_id']] == 'Pending') {
                 $this->_defaults['pledge_amount'][$payId] = 1;
                 $duePayment = TRUE;
             }
         }
     } elseif (CRM_Utils_Array::value('pledge_block_id', $this->_values)) {
         //set default to one time contribution.
         $this->_defaults['is_pledge'] = 0;
     }
     // to process Custom data that are appended to URL
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution'");
     if (!empty($getDefaults)) {
         $this->_defaults = array_merge($this->_defaults, $getDefaults);
     }
     $config = CRM_Core_Config::singleton();
     // set default country from config if no country set
     if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $this->_defaults)) {
         $this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
     }
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     if ($this->_priceSetId) {
         if ($this->_useForMember && !empty($this->_currentMemberships)) {
             $selectedCurrentMemTypes = array();
             foreach ($this->_priceSet['fields'] as $key => $val) {
                 $isHavingMemid = FALSE;
                 foreach ($val['options'] as $keys => $values) {
                     $opMemTypeId = CRM_Utils_Array::value('membership_type_id', $values);
                     if ($opMemTypeId && in_array($opMemTypeId, $this->_currentMemberships) && !in_array($opMemTypeId, $selectedCurrentMemTypes)) {
                         if ($val['html_type'] == 'CheckBox') {
                             $this->_defaults["price_{$key}"][$keys] = 1;
                         } else {
                             $this->_defaults["price_{$key}"] = $keys;
                         }
                         $selectedCurrentMemTypes[] = $values['membership_type_id'];
                     } elseif (CRM_Utils_Array::value('is_default', $values) && !$opMemTypeId && (!isset($this->_defaults["price_{$key}"]) || $val['html_type'] == 'CheckBox' && !isset($this->_defaults["price_{$key}"][$keys]))) {
                         if ($val['html_type'] == 'CheckBox') {
                             $this->_defaults["price_{$key}"][$keys] = 1;
                         } else {
                             $this->_defaults["price_{$key}"] = $keys;
                         }
                     }
                 }
             }
         } else {
             CRM_Price_BAO_Set::setDefaultPriceSet($this, $this->_defaults);
         }
     }
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $pid => $value) {
             if (CRM_Utils_Array::value('is_default', $value)) {
                 $this->_defaults['payment_processor'] = $pid;
             }
         }
     }
     return $this->_defaults;
 }
コード例 #6
0
 /**
  * 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()
 {
     $contactID = parent::getContactID();
     if ($contactID) {
         $options = array();
         $fields = array();
         require_once "CRM/Core/BAO/CustomGroup.php";
         if (!empty($this->_fields)) {
             $removeCustomFieldTypes = array('Participant');
             foreach ($this->_fields as $name => $dontCare) {
                 if (substr($name, 0, 7) == 'custom_') {
                     $id = substr($name, 7);
                     if (!$this->_allowConfirmation && !CRM_Core_BAO_CustomGroup::checkCustomField($id, $removeCustomFieldTypes)) {
                         continue;
                     }
                 } else {
                     if (substr($name, 0, 12) == 'participant_') {
                         //ignore component fields
                         continue;
                     }
                 }
                 $fields[$name] = 1;
             }
         }
         $names = array("first_name", "middle_name", "last_name", "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}");
         foreach ($names as $name) {
             $fields[$name] = 1;
         }
         $fields["state_province-{$this->_bltID}"] = 1;
         $fields["country-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $fields["email-Primary"] = 1;
         require_once 'CRM/Core/BAO/UFGroup.php';
         CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
         // use primary email address if billing email address is empty
         if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults["email-Primary"])) {
             $this->_defaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"];
         }
         foreach ($names as $name) {
             if (isset($this->_defaults[$name])) {
                 $this->_defaults["billing_" . $name] = $this->_defaults[$name];
             }
         }
     }
     //if event is monetary and pay later is enabled and payment
     //processor is not available then freeze the pay later checkbox with
     //default check
     if (CRM_Utils_Array::value('is_pay_later', $this->_values['event']) && !is_array($this->_paymentProcessor)) {
         $this->_defaults['is_pay_later'] = 1;
     }
     //set custom field defaults
     if (!empty($this->_fields)) {
         require_once "CRM/Core/BAO/CustomField.php";
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 if (!isset($this->_defaults[$name])) {
                     //fix for CRM-1743
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, null, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     //fix for CRM-3088, default value for discount set.
     $discountId = null;
     if (!empty($this->_values['discount'])) {
         require_once 'CRM/Core/BAO/Discount.php';
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if ($discountId) {
             if (isset($this->_values['event']['default_discount_fee_id'])) {
                 $discountKey = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $this->_values['event']['default_discount_fee_id'], 'weight', 'id');
                 $this->_defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, true));
             }
         }
     }
     $config = CRM_Core_Config::singleton();
     // set default country from config if no country set
     if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $this->_defaults)) {
         $this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
     }
     // now fix all state country selectors
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     // add this event's default participant role to defaults array (for cases where participant_role field is included in form via profile)
     if ($this->_values['event']['default_role_id']) {
         $this->_defaults['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     if ($this->_priceSetId) {
         foreach ($this->_feeBlock as $key => $val) {
             foreach ($val['options'] as $keys => $values) {
                 if ($values['is_default'] && !CRM_Utils_Array::value('is_full', $values)) {
                     if ($val['html_type'] == 'CheckBox') {
                         $this->_defaults["price_{$key}"][$keys] = 1;
                     } else {
                         $this->_defaults["price_{$key}"] = $keys;
                     }
                 }
             }
         }
     }
     //set default participant fields, CRM-4320.
     $hasAdditionalParticipants = false;
     if ($this->_allowConfirmation) {
         require_once 'CRM/Event/Form/EventFees.php';
         $this->_contactId = $contactID;
         $this->_discountId = $discountId;
         $forcePayLater = CRM_Utils_Array::value('is_pay_later', $this->_defaults, false);
         $this->_defaults = array_merge($this->_defaults, CRM_Event_Form_EventFees::setDefaultValues($this));
         $this->_defaults['is_pay_later'] = $forcePayLater;
         if ($this->_additionalParticipantIds) {
             $hasAdditionalParticipants = true;
             $this->_defaults['additional_participants'] = count($this->_additionalParticipantIds);
         }
     }
     $this->assign('hasAdditionalParticipants', $hasAdditionalParticipants);
     //         //hack to simplify credit card entry for testing
     //         $this->_defaults['credit_card_type']     = 'Visa';
     //         $this->_defaults['credit_card_number']   = '4807731747657838';
     //         $this->_defaults['cvv2']                 = '000';
     //         $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2010', 'M' => '05' );
     // to process Custom data that are appended to URL
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution', 'Participant'");
     if (!empty($getDefaults)) {
         $this->_defaults = array_merge($this->_defaults, $getDefaults);
     }
     return $this->_defaults;
 }
コード例 #7
0
ファイル: Main.php プロジェクト: bhirsch/civicrm
 function setDefaultValues()
 {
     // process defaults only once
     if (!empty($this->_defaults)) {
         // return $this->_defaults;
     }
     // check if the user is registered and we have a contact ID
     $session =& CRM_Core_Session::singleton();
     $contactID = $this->_userID;
     if ($contactID) {
         $options = array();
         $fields = array();
         require_once "CRM/Core/BAO/CustomGroup.php";
         $removeCustomFieldTypes = array('Contribution', 'Membership');
         require_once 'CRM/Contribute/BAO/Contribution.php';
         $contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields();
         // remove component related fields
         foreach ($this->_fields as $name => $dontCare) {
             //don't set custom data Used for Contribution (CRM-1344)
             if (substr($name, 0, 7) == 'custom_') {
                 $id = substr($name, 7);
                 if (!CRM_Core_BAO_CustomGroup::checkCustomField($id, $removeCustomFieldTypes)) {
                     continue;
                 }
             } else {
                 if (array_key_exists($name, $contribFields) || substr($name, 0, 11) == 'membership_') {
                     //ignore component fields
                     continue;
                 }
             }
             $fields[$name] = 1;
         }
         $names = array("first_name", "middle_name", "last_name", "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}");
         foreach ($names as $name) {
             $fields[$name] = 1;
         }
         $fields["state_province-{$this->_bltID}"] = 1;
         $fields["country-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $fields["email-Primary"] = 1;
         require_once "CRM/Core/BAO/UFGroup.php";
         CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
         // use primary email address if billing email address is empty
         if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults["email-Primary"])) {
             $this->_defaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"];
         }
         foreach ($names as $name) {
             if (!empty($this->_defaults[$name])) {
                 $this->_defaults["billing_" . $name] = $this->_defaults[$name];
             }
         }
     }
     //set custom field defaults set by admin if value is not set
     if (!empty($this->_fields)) {
         //set custom field defaults
         require_once "CRM/Core/BAO/CustomField.php";
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, null, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     //set default membership for membershipship block
     require_once 'CRM/Member/BAO/Membership.php';
     if ($this->_membershipBlock) {
         $this->_defaults['selectMembership'] = $this->_defaultMemTypeId ? $this->_defaultMemTypeId : CRM_Utils_Array::value('membership_type_default', $this->_membershipBlock);
     }
     if ($this->_membershipContactID) {
         $this->_defaults['is_for_organization'] = 1;
         $this->_defaults['org_option'] = 1;
     } elseif ($this->_values['is_for_organization']) {
         $this->_defaults['org_option'] = 0;
     }
     if ($this->_values['is_for_organization'] && !isset($this->_defaults['location'][1]['email'][1]['email'])) {
         $this->_defaults['location'][1]['email'][1]['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $this->_defaults);
     }
     //if contribution pay later is enabled and payment
     //processor is not available then freeze the pay later checkbox with
     //default check
     if (CRM_Utils_Array::value('is_pay_later', $this->_values) && empty($this->_paymentProcessor)) {
         $this->_defaults['is_pay_later'] = 1;
     }
     //         // hack to simplify credit card entry for testing
     //         $this->_defaults['credit_card_type']     = 'Visa';
     //         $this->_defaults['amount']               = 168;
     //         $this->_defaults['credit_card_number']   = '4807731747657838';
     //         $this->_defaults['cvv2']                 = '000';
     //         $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
     //         // hack to simplify direct debit entry for testing
     //         $this->_defaults['account_holder'] = 'Max Müller';
     //         $this->_defaults['bank_account_number'] = '12345678';
     //         $this->_defaults['bank_identification_number'] = '12030000';
     //         $this->_defaults['bank_name'] = 'Bankname';
     //build set default for pledge overdue payment.
     if (CRM_Utils_Array::value('pledge_id', $this->_values)) {
         //get all payment statuses.
         $statuses = array();
         $returnProperties = array('status_id');
         CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_Payment', 'pledge_id', $this->_values['pledge_id'], $statuses, $returnProperties);
         require_once 'CRM/Contribute/PseudoConstant.php';
         $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus();
         $duePayment = false;
         foreach ($statuses as $payId => $value) {
             if ($paymentStatusTypes[$value['status_id']] == 'Overdue') {
                 $this->_defaults['pledge_amount'][$payId] = 1;
             } else {
                 if (!$duePayment && $paymentStatusTypes[$value['status_id']] == 'Pending') {
                     $this->_defaults['pledge_amount'][$payId] = 1;
                     $duePayment = true;
                 }
             }
         }
     } else {
         if (CRM_Utils_Array::value('pledge_block_id', $this->_values)) {
             //set default to one time contribution.
             $this->_defaults['is_pledge'] = 0;
         }
     }
     // to process Custom data that are appended to URL
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution'");
     if (!empty($getDefaults)) {
         $this->_defaults = array_merge($this->_defaults, $getDefaults);
     }
     // now fix all state country selectors
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     if ($this->_priceSetId) {
         foreach ($this->_priceSet['fields'] as $key => $val) {
             foreach ($val['options'] as $keys => $values) {
                 if ($values['is_default']) {
                     if ($val['html_type'] == 'CheckBox') {
                         $this->_defaults["price_{$key}"][$keys] = 1;
                     } else {
                         $this->_defaults["price_{$key}"] = $keys;
                     }
                 }
             }
         }
     }
     return $this->_defaults;
 }