/**
  * This function sets the default values for the form. MobileProvider that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 public function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     if ($this->_priceSetId) {
         return CRM_Price_BAO_PriceSet::setDefaultPriceSet($this, $defaults);
     }
     $defaults = parent::setDefaultValues();
     //setting default join date and receive date
     list($now, $currentTime) = CRM_Utils_Date::setDateDefaults();
     if ($this->_action == CRM_Core_Action::ADD) {
         $defaults['receive_date'] = $now;
         $defaults['receive_date_time'] = $currentTime;
     }
     if (is_numeric($this->_memType)) {
         $defaults['membership_type_id'] = array();
         $defaults['membership_type_id'][0] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'member_of_contact_id', 'id');
         $defaults['membership_type_id'][1] = $this->_memType;
     } else {
         $defaults['membership_type_id'] = $this->_memType;
     }
     $defaults['num_terms'] = 1;
     if (CRM_Utils_Array::value('id', $defaults)) {
         if ($this->_onlinePendingContributionId) {
             $defaults['record_contribution'] = $this->_onlinePendingContributionId;
         } else {
             $contributionId = CRM_Core_DAO::singleValueQuery("\n  SELECT contribution_id\n  FROM civicrm_membership_payment\n  WHERE membership_id = {$this->_id}\n  ORDER BY contribution_id\n  DESC limit 1");
             if ($contributionId) {
                 $defaults['record_contribution'] = $contributionId;
             }
         }
     }
     if (CRM_Utils_Array::value('record_contribution', $defaults) && !$this->_mode) {
         $contributionParams = array('id' => $defaults['record_contribution']);
         $contributionIds = array();
         //keep main object campaign in hand.
         $memberCampaignId = CRM_Utils_Array::value('campaign_id', $defaults);
         CRM_Contribute_BAO_Contribution::getValues($contributionParams, $defaults, $contributionIds);
         //get back original object campaign id.
         $defaults['campaign_id'] = $memberCampaignId;
         if (CRM_Utils_Array::value('receive_date', $defaults)) {
             list($defaults['receive_date']) = CRM_Utils_Date::setDateDefaults($defaults['receive_date']);
         }
         // Contribution::getValues() over-writes the membership record's source field value - so we need to restore it.
         if (CRM_Utils_Array::value('membership_source', $defaults)) {
             $defaults['source'] = $defaults['membership_source'];
         }
     }
     //CRM-13420
     if (!CRM_Utils_Array::value('payment_instrument_id', $defaults)) {
         $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
     }
     // User must explicitly choose to send a receipt in both add and update mode.
     $defaults['send_receipt'] = 0;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         // in this mode by default uncheck this checkbox
         unset($defaults['record_contribution']);
     }
     if (CRM_Utils_Array::value('id', $defaults)) {
         $subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_id);
     }
     $alreadyAutoRenew = FALSE;
     if (CRM_Utils_Array::value('contribution_recur_id', $defaults) && !$subscriptionCancelled) {
         $defaults['auto_renew'] = 1;
         $alreadyAutoRenew = TRUE;
     }
     $this->assign('alreadyAutoRenew', $alreadyAutoRenew);
     $this->assign('member_is_test', CRM_Utils_Array::value('member_is_test', $defaults));
     $this->assign('membership_status_id', CRM_Utils_Array::value('status_id', $defaults));
     if (CRM_Utils_Array::value('is_pay_later', $defaults)) {
         $this->assign('is_pay_later', TRUE);
     }
     if ($this->_mode) {
         // set default country from config if no country set
         $config = CRM_Core_Config::singleton();
         if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $defaults)) {
             $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
         }
         if (!CRM_Utils_Array::value("billing_state_province_id-{$this->_bltID}", $defaults)) {
             $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
         }
         $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
         $defaults = array_merge($defaults, $billingDefaults);
         // now fix all state country selectors, set correct state based on country
         CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
         //             // hack to simplify credit card entry for testing
         //             $defaults['credit_card_type']     = 'Visa';
         //             $defaults['credit_card_number']   = '4807731747657838';
         //             $defaults['cvv2']                 = '000';
         //             $defaults['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
     }
     $dates = array('join_date', 'start_date', 'end_date');
     foreach ($dates as $key) {
         if (CRM_Utils_Array::value($key, $defaults)) {
             list($defaults[$key]) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults));
         }
     }
     //setting default join date if there is no join date
     if (!CRM_Utils_Array::value('join_date', $defaults)) {
         $defaults['join_date'] = $now;
     }
     if (CRM_Utils_Array::value('membership_end_date', $defaults)) {
         $this->assign('endDate', $defaults['membership_end_date']);
     }
     return $defaults;
 }
예제 #2
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;
 }
예제 #3
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()
 {
     $defaults = $unsetSubmittedOptions = array();
     $discountId = NULL;
     //fix for CRM-3088, default value for discount set.
     if (!empty($this->_values['discount'])) {
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if ($discountId && CRM_Utils_Array::value('default_discount_fee_id', $this->_values['event'])) {
             $discountKey = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $this->_values['event']['default_discount_fee_id'], 'weight', 'id');
             $defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
         }
     }
     if ($this->_priceSetId) {
         foreach ($this->_feeBlock as $key => $val) {
             if (!CRM_Utils_Array::value('options', $val)) {
                 continue;
             }
             $optionsFull = CRM_Utils_Array::value('option_full_ids', $val, array());
             foreach ($val['options'] as $keys => $values) {
                 if ($values['is_default'] && !in_array($keys, $optionsFull)) {
                     if ($val['html_type'] == 'CheckBox') {
                         $defaults["price_{$key}"][$keys] = 1;
                     } else {
                         $defaults["price_{$key}"] = $keys;
                     }
                 }
             }
             if (!empty($optionsFull)) {
                 $unsetSubmittedOptions[$val['id']] = $optionsFull;
             }
         }
     }
     //CRM-4320, setdefault additional participant values.
     if ($this->_allowConfirmation && $this->_additionalParticipantId) {
         //hack to get set default from eventFees.php
         $this->_discountId = $discountId;
         $this->_pId = $this->_additionalParticipantId;
         $this->_contactId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_additionalParticipantId, 'contact_id');
         $participantDefaults = CRM_Event_Form_EventFees::setDefaultValues($this);
         $participantDefaults = array_merge($this->_defaults, $participantDefaults);
         // use primary email address if billing email address is empty
         if (empty($this->_defaults["email-{$this->_bltID}"]) && !empty($this->_defaults["email-Primary"])) {
             $participantDefaults["email-{$this->_bltID}"] = $this->_defaults["email-Primary"];
         }
         $defaults = array_merge($defaults, $participantDefaults);
     }
     $defaults = array_merge($this->_defaults, $defaults);
     //reset values for all options those are full.
     if (!empty($unsetSubmittedOptions) && empty($_POST)) {
         $this->resetElementValue($unsetSubmittedOptions);
     }
     //load default campaign from page.
     if (array_key_exists('participant_campaign_id', $this->_fields)) {
         $defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
     }
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     return $defaults;
 }
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     $productID = $this->get('productID');
     $option = $this->get('option');
     $membershipTypeID = $this->get('membershipTypeID');
     $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
     if ($productID) {
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
     }
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     } else {
         if (is_array($membershipTypeID)) {
             $membershipTypeID = current($membershipTypeID);
         }
         $this->assign('is_quick_config', 1);
         $this->_params['is_quick_config'] = 1;
     }
     $this->assign('priceSetID', $this->_priceSetId);
     $this->assign('useForMember', $this->get('useForMember'));
     $params = $this->_params;
     $honor_block_is_active = $this->get('honor_block_is_active');
     if ($honor_block_is_active && (!empty($params["honor_first_name"]) && !empty($params["honor_last_name"]) || !empty($params["honor_email"]))) {
         $this->assign('honor_block_is_active', $honor_block_is_active);
         $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values));
         $prefix = CRM_Core_PseudoConstant::individualPrefix();
         $honor = CRM_Core_PseudoConstant::honor();
         $this->assign('honor_type', $honor[$params["honor_type_id"]]);
         $this->assign('honor_prefix', $params["honor_prefix_id"] ? $prefix[$params["honor_prefix_id"]] : ' ');
         $this->assign('honor_first_name', $params["honor_first_name"]);
         $this->assign('honor_last_name', $params["honor_last_name"]);
         $this->assign('honor_email', $params["honor_email"]);
     }
     $qParams = "reset=1&id={$this->_id}";
     //pcp elements
     if ($this->_pcpId) {
         $qParams .= "&pcpId={$this->_pcpId}";
         $this->assign('pcpBlock', TRUE);
         foreach (array('pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) {
             if (CRM_Utils_Array::value($val, $this->_params)) {
                 $this->assign($val, $this->_params[$val]);
             }
         }
     }
     $this->assign('qParams', $qParams);
     if ($membershipTypeID) {
         $transactionID = $this->get('membership_trx_id');
         $membershipAmount = $this->get('membership_amount');
         $renewalMode = $this->get('renewal_mode');
         $this->assign('membership_trx_id', $transactionID);
         $this->assign('membership_amount', $membershipAmount);
         $this->assign('renewal_mode', $renewalMode);
         CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, FALSE, $membershipTypeID, TRUE, NULL, $this->_membershipContactID);
     }
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign("is_separate_payment", $this->_separateMembershipPayment);
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if (CRM_Utils_Array::value('hidden_onbehalf_profile', $params)) {
         $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $profileId = $OnBehalfProfile[0];
         $fieldTypes = array('Contact', 'Organization');
         $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
         $fieldTypes = array_merge($fieldTypes, $contactSubType);
         if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
             $fieldTypes = array_merge($fieldTypes, array('Membership'));
         } else {
             $fieldTypes = array_merge($fieldTypes, array('Contribution'));
         }
         $this->buildCustom($profileId, 'onbehalfProfile', TRUE, TRUE, $fieldTypes);
     }
     $this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $this->_params));
     $this->assign('receive_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params)));
     $defaults = array();
     $options = array();
     $fields = array();
     $removeCustomFieldTypes = array('Contribution');
     foreach ($this->_fields as $name => $dontCare) {
         if ($name == 'onbehalf') {
             foreach ($dontCare as $key => $value) {
                 $fields['onbehalf'][$key] = 1;
             }
         } else {
             $fields[$name] = 1;
         }
     }
     $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
     $contact = $this->_params = $this->controller->exportValues('Main');
     foreach ($fields as $name => $dontCare) {
         if ($name == 'onbehalf') {
             foreach ($dontCare as $key => $value) {
                 //$defaults[$key] = $contact['onbehalf'][$key];
                 if (isset($contact['onbehalf'][$key])) {
                     $defaults[$key] = $contact['onbehalf'][$key];
                 }
                 if (isset($contact['onbehalf']["{$key}_id"])) {
                     $defaults["{$key}_id"] = $contact['onbehalf']["{$key}_id"];
                 }
             }
         } elseif (isset($contact[$name])) {
             $defaults[$name] = $contact[$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($contact[$timeField])) {
                     $defaults[$timeField] = $contact[$timeField];
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && CRM_Utils_Array::value($name . '_custom', $contact)) {
                 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
             }
         }
     }
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $this->_submitValues = array_merge($this->_submitValues, $defaults);
     $this->setDefaults($defaults);
     $values['entity_id'] = $this->_id;
     $values['entity_table'] = 'civicrm_contribution_page';
     CRM_Friend_BAO_Friend::retrieve($values, $data);
     $tellAFriend = FALSE;
     if ($this->_pcpId) {
         if ($this->_pcpBlock['is_tellfriend_enabled']) {
             $this->assign('friendText', ts('Tell a Friend'));
             $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp";
             $tellAFriend = TRUE;
         }
     } elseif (CRM_Utils_Array::value('is_active', $data)) {
         $friendText = $data['title'];
         $this->assign('friendText', $friendText);
         $subUrl = "eid={$this->_id}&pcomponent=contribute";
         $tellAFriend = TRUE;
     }
     if ($tellAFriend) {
         if ($this->_action & CRM_Core_Action::PREVIEW) {
             $url = CRM_Utils_System::url("civicrm/friend", "reset=1&action=preview&{$subUrl}");
         } else {
             $url = CRM_Utils_System::url("civicrm/friend", "reset=1&{$subUrl}");
         }
         $this->assign('friendURL', $url);
     }
     $this->freeze();
     // can we blow away the session now to prevent hackery
     // CRM-9491
     $this->controller->reset();
 }
예제 #5
0
 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);
     }
     //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);
                 }
             }
         }
     }
     //         // 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' => '2014', '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'])) {
         //get all pledge payment records of current pledge id.
         $pledgePayments = array();
         //used to record completed pledge payment ids used later for honor default
         $completedContributionIds = array();
         $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($this->_values['pledge_id']);
         $duePayment = FALSE;
         foreach ($pledgePayments as $payId => $value) {
             if ($value['status'] == 'Overdue') {
                 $this->_defaults['pledge_amount'][$payId] = 1;
             } elseif (!$duePayment && $value['status'] == 'Pending') {
                 $this->_defaults['pledge_amount'][$payId] = 1;
                 $duePayment = TRUE;
             } elseif ($value['status'] == 'Completed' && $value['contribution_id']) {
                 $completedContributionIds[] = $value['contribution_id'];
             }
         }
         if (!empty($this->_values['honor_block_is_active']) && 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'");
     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 (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;
     }
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     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);
                     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 (!empty($values['is_default']) && !$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_PriceSet::setDefaultPriceSet($this, $this->_defaults);
         }
     }
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $pid => $value) {
             if (!empty($value['is_default'])) {
                 $this->_defaults['payment_processor'] = $pid;
             }
         }
     }
     return $this->_defaults;
 }
예제 #6
0
 /**
  * This function sets the default values for the form.
  *
  * @access public
  *
  * @return void
  */
 function setDefaultValues()
 {
     $this->_defaults = array();
     if ($this->_contactId) {
         CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $this->_contactProfileFields, $this->_defaults, TRUE);
         if ($this->_activityProfileId) {
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactId, $this->_activityProfileFields, $this->_defaults, TRUE);
         }
     }
     //set custom field defaults
     foreach ($this->_contactProfileFields as $name => $field) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
             $htmlType = $field['html_type'];
             if (!isset($this->_defaults[$name])) {
                 CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_contactId, $this->_mode);
             }
         }
     }
     if ($this->_activityProfileFields) {
         foreach ($this->_activityProfileFields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $htmlType = $field['html_type'];
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_contactId, $this->_mode);
                 }
             }
         }
     }
     $this->setDefaults($this->_defaults);
     // add in all state country selectors for enabled countries
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
 }
예제 #7
0
 function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = $this->_values;
     //set defaults for pledge payment.
     if ($this->_ppID) {
         $defaults['total_amount'] = CRM_Utils_Array::value('scheduled_amount', $this->_pledgeValues['pledgePayment']);
         $defaults['honor_type_id'] = CRM_Utils_Array::value('honor_type_id', $this->_pledgeValues);
         $defaults['honor_contact_id'] = CRM_Utils_Array::value('honor_contact_id', $this->_pledgeValues);
         $defaults['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_pledgeValues);
         $defaults['currency'] = CRM_Utils_Array::value('currency', $this->_pledgeValues);
         $defaults['option_type'] = 1;
     }
     $fields = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     // set soft credit defaults
     CRM_Contribute_Form_SoftCredit::setDefaultValues($defaults, $this);
     if ($this->_mode) {
         $config = CRM_Core_Config::singleton();
         // set default country from config if no country set
         if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $defaults)) {
             $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
         }
         if (!CRM_Utils_Array::value("billing_state_province_id-{$this->_bltID}", $defaults)) {
             $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
         }
         $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
         $defaults = array_merge($defaults, $billingDefaults);
         // now fix all state country selectors, set correct state based on country
         CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     }
     if ($this->_id) {
         $this->_contactID = $defaults['contact_id'];
     }
     // Set $newCredit variable in template to control whether link to credit card mode is included
     CRM_Core_Payment::allowBackofficeCreditCard($this);
     // fix the display of the monetary value, CRM-4038
     if (isset($defaults['total_amount'])) {
         $defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'], NULL, '%a');
     }
     if (isset($defaults['non_deductible_amount'])) {
         $defaults['non_deductible_amount'] = CRM_Utils_Money::format($defaults['non_deductible_amount'], NULL, '%a');
     }
     if (isset($defaults['fee_amount'])) {
         $defaults['fee_amount'] = CRM_Utils_Money::format($defaults['fee_amount'], NULL, '%a');
     }
     if (isset($defaults['net_amount'])) {
         $defaults['net_amount'] = CRM_Utils_Money::format($defaults['net_amount'], NULL, '%a');
     }
     if ($this->_contributionType) {
         $defaults['financial_type_id'] = $this->_contributionType;
     }
     if (!CRM_Utils_Array::value('payment_instrument_id', $defaults)) {
         $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
     }
     if (CRM_Utils_Array::value('is_test', $defaults)) {
         $this->assign('is_test', TRUE);
     }
     if (isset($defaults['honor_contact_id'])) {
         $honorDefault = $ids = array();
         $this->_honorID = $defaults['honor_contact_id'];
         $honorType = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id');
         $idParams = array('id' => $defaults['honor_contact_id'], 'contact_id' => $defaults['honor_contact_id']);
         CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $ids);
         $defaults['honor_prefix_id'] = CRM_Utils_Array::value('prefix_id', $honorDefault);
         $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['email'][1]);
         $defaults['honor_type'] = $honorType[$defaults['honor_type_id']];
     }
     $this->assign('showOption', TRUE);
     // for Premium section
     if ($this->_premiumID) {
         $this->assign('showOption', FALSE);
         $options = isset($this->_options[$this->_productDAO->product_id]) ? $this->_options[$this->_productDAO->product_id] : "";
         if (!$options) {
             $this->assign('showOption', TRUE);
         }
         $options_key = CRM_Utils_Array::key($this->_productDAO->product_option, $options);
         if ($options_key) {
             $defaults['product_name'] = array($this->_productDAO->product_id, trim($options_key));
         } else {
             $defaults['product_name'] = array($this->_productDAO->product_id);
         }
         if ($this->_productDAO->fulfilled_date) {
             list($defaults['fulfilled_date']) = CRM_Utils_Date::setDateDefaults($this->_productDAO->fulfilled_date);
         }
     }
     if (isset($this->userEmail)) {
         $this->assign('email', $this->userEmail);
     }
     if (CRM_Utils_Array::value('is_pay_later', $defaults)) {
         $this->assign('is_pay_later', TRUE);
     }
     $this->assign('contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $defaults));
     $dates = array('receive_date', 'receipt_date', 'cancel_date', 'thankyou_date');
     foreach ($dates as $key) {
         if (CRM_Utils_Array::value($key, $defaults)) {
             list($defaults[$key], $defaults[$key . '_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults), 'activityDateTime');
         }
     }
     if (!$this->_id && !CRM_Utils_Array::value('receive_date', $defaults)) {
         list($defaults['receive_date'], $defaults['receive_date_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
     }
     $this->assign('receive_date', CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $defaults), CRM_Utils_Array::value('receive_date_time', $defaults)));
     $currency = CRM_Utils_Array::value('currency', $defaults);
     $this->assign('currency', $currency);
     // Hack to get currency info to the js layer. CRM-11440
     CRM_Utils_Money::format(1);
     $this->assign('currencySymbol', CRM_Utils_Array::value($currency, CRM_Utils_Money::$_currencySymbols));
     $this->assign('totalAmount', CRM_Utils_Array::value('total_amount', $defaults));
     //inherit campaign from pledge.
     if ($this->_ppID && CRM_Utils_Array::value('campaign_id', $this->_pledgeValues)) {
         $defaults['campaign_id'] = $this->_pledgeValues['campaign_id'];
     }
     $this->_defaults = $defaults;
     return $defaults;
 }
 public function setDefaultValues()
 {
     if ($this->_mode) {
         $defaults = $this->_values;
         $config = CRM_Core_Config::singleton();
         // set default country from config if no country set
         if (empty($defaults["billing_country_id-{$this->_bltID}"])) {
             $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
         }
         if (empty($defaults["billing_state_province_id-{$this->_bltID}"])) {
             $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
         }
         $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactId);
         $defaults = array_merge($defaults, $billingDefaults);
         // now fix all state country selectors, set correct state based on country
         CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     }
     // Set $newCredit variable in template to control whether link to credit card mode is included
     CRM_Core_Payment::allowBackofficeCreditCard($this);
 }
예제 #9
0
 /**
  * This function sets the default values for the form in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 static function setDefaultValues(&$form)
 {
     $defaults = array();
     if ($form->_eventId) {
         //get receipt text and financial type
         $returnProperities = array('confirm_email_text', 'financial_type_id', 'campaign_id', 'start_date');
         $details = array();
         CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities);
         if (!empty($details[$form->_eventId]['financial_type_id'])) {
             $defaults[$form->_pId]['financial_type_id'] = $details[$form->_eventId]['financial_type_id'];
         }
     }
     if ($form->_pId) {
         $ids = array();
         $params = array('id' => $form->_pId);
         CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
         if ($form->_action == CRM_Core_Action::UPDATE) {
             $discounts = array();
             if (!empty($form->_values['discount'])) {
                 foreach ($form->_values['discount'] as $key => $value) {
                     $value = current($value);
                     $discounts[$key] = $value['name'];
                 }
             }
             if ($form->_discountId && !empty($discounts[$defaults[$form->_pId]['discount_id']])) {
                 $form->assign('discount', $discounts[$defaults[$form->_pId]['discount_id']]);
             }
             $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
             $form->assign('fee_level', CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]));
         }
         $defaults[$form->_pId]['send_receipt'] = 0;
     } else {
         $defaults[$form->_pId]['send_receipt'] = strtotime(CRM_Utils_Array::value('start_date', $details[$form->_eventId])) >= time() ? 1 : 0;
         if ($form->_eventId && !empty($details[$form->_eventId]['confirm_email_text'])) {
             //set receipt text
             $defaults[$form->_pId]['receipt_text'] = $details[$form->_eventId]['confirm_email_text'];
         }
         list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults();
     }
     //CRM-11601 we should keep the record contribution
     //true by default while adding participant
     if ($form->_action == CRM_Core_Action::ADD && !$form->_mode && $form->_isPaidEvent) {
         $defaults[$form->_pId]['record_contribution'] = 1;
     }
     //CRM-13420
     if (empty($defaults['payment_instrument_id'])) {
         $defaults[$form->_pId]['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
     }
     if ($form->_mode) {
         $config = CRM_Core_Config::singleton();
         // set default country from config if no country set
         if (empty($defaults[$form->_pId]["billing_country_id-{$form->_bltID}"])) {
             $defaults[$form->_pId]["billing_country_id-{$form->_bltID}"] = $config->defaultContactCountry;
         }
         if (empty($defaults["billing_state_province_id-{$form->_bltID}"])) {
             $defaults[$form->_pId]["billing_state_province_id-{$form->_bltID}"] = $config->defaultContactStateProvince;
         }
         $billingDefaults = $form->getProfileDefaults('Billing', $form->_contactId);
         $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $billingDefaults);
         // now fix all state country selectors, set correct state based on country
         CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults[$form->_pId]);
         //             // hack to simplify credit card entry for testing
         //             $defaults[$form->_pId]['credit_card_type']     = 'Visa';
         //             $defaults[$form->_pId]['credit_card_number']   = '4807731747657838';
         //             $defaults[$form->_pId]['cvv2']                 = '000';
         //             $defaults[$form->_pId]['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
     }
     // if user has selected discount use that to set default
     if (isset($form->_discountId)) {
         $defaults[$form->_pId]['discount_id'] = $form->_discountId;
         //hack to set defaults for already selected discount value
         if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) {
             $form->_originalDiscountId = $defaults[$form->_pId]['discount_id'];
             if ($form->_originalDiscountId) {
                 $defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId;
             }
         }
         $discountId = $form->_discountId;
     } else {
         $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
     }
     if ($discountId) {
         $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
     } else {
         $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $form->_eventId);
     }
     if ($form->_action == CRM_Core_Action::ADD && $form->_eventId && $discountId) {
         // this case is for add mode, where we show discount automatically
         $defaults[$form->_pId]['discount_id'] = $discountId;
     }
     if ($priceSetId) {
         // get price set default values, CRM-4090
         if (in_array(get_class($form), array('CRM_Event_Form_Participant', 'CRM_Event_Form_Registration_Register', 'CRM_Event_Form_Registration_AdditionalParticipant'))) {
             $priceSetValues = self::setDefaultPriceSet($form->_pId, $form->_eventId);
             if (!empty($priceSetValues)) {
                 $defaults[$form->_pId] = array_merge($defaults[$form->_pId], $priceSetValues);
             }
         }
         if ($form->_action == CRM_Core_Action::ADD && !empty($form->_priceSet['fields'])) {
             foreach ($form->_priceSet['fields'] as $key => $val) {
                 foreach ($val['options'] as $keys => $values) {
                     if ($values['is_default']) {
                         if (get_class($form) != 'CRM_Event_Form_Participant' && !empty($values['is_full'])) {
                             continue;
                         }
                         if ($val['html_type'] == 'CheckBox') {
                             $defaults[$form->_pId]["price_{$key}"][$keys] = 1;
                         } else {
                             $defaults[$form->_pId]["price_{$key}"] = $keys;
                         }
                     }
                 }
             }
         }
         $form->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
         if ($form->_action == CRM_Core_Action::UPDATE) {
             $fee_level = $defaults[$form->_pId]['fee_level'];
             CRM_Event_BAO_Participant::fixEventLevel($fee_level);
             $form->assign('fee_level', $fee_level);
             $form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
         }
     }
     //CRM-4453
     if (!empty($defaults[$form->_pId]['participant_fee_currency'])) {
         $form->assign('fee_currency', $defaults[$form->_pId]['participant_fee_currency']);
     }
     // CRM-4395
     if ($contriId = $form->get('onlinePendingContributionId')) {
         $contribution = new CRM_Contribute_DAO_Contribution();
         $contribution->id = $contriId;
         $contribution->find(true);
         foreach (array('financial_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date', 'total_amount') as $f) {
             if ($f == 'receive_date') {
                 list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults($contribution->{$f});
             } else {
                 $defaults[$form->_pId][$f] = $contribution->{$f};
             }
         }
     }
     return $defaults[$form->_pId];
 }
예제 #10
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     $config = CRM_Core_Config::singleton();
     $i18n = CRM_Core_I18n::singleton();
     CRM_Utils_System::setTitle(ts('Settings - Localization'));
     $locales = CRM_Core_I18n::languages();
     $warningTitle = json_encode(ts("Warning"));
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
     if ($domain->locales) {
         // for multi-lingual sites, populate default language drop-down with available languages
         $lcMessages = array();
         foreach ($locales as $loc => $lang) {
             if (substr_count($domain->locales, $loc)) {
                 $lcMessages[$loc] = $lang;
             }
         }
         $this->addElement('select', 'lcMessages', ts('Default Language'), $lcMessages);
         // add language limiter and language adder
         $this->addCheckBox('languageLimit', ts('Available Languages'), array_flip($lcMessages), NULL, NULL, NULL, NULL, '   ');
         $this->addElement('select', 'addLanguage', ts('Add Language'), array_merge(array('' => ts('- select -')), array_diff($locales, $lcMessages)));
         // add the ability to return to single language
         $warning = ts('This will make your CiviCRM installation a single-language one again. THIS WILL DELETE ALL DATA RELATED TO LANGUAGES OTHER THAN THE DEFAULT ONE SELECTED ABOVE (and only that language will be preserved).');
         $this->assign('warning', $warning);
         $warning = json_encode($warning);
         $this->addElement('checkbox', 'makeSinglelingual', ts('Return to Single Language'), NULL, array('onChange' => "if (this.checked) CRM.alert({$warning}, {$warningTitle})"));
     } else {
         // for single-lingual sites, populate default language drop-down with all languages
         $this->addElement('select', 'lcMessages', ts('Default Language'), $locales);
         $warning = ts('Enabling multiple languages changes the schema of your database, so make sure you know what you are doing when enabling this function; making a database backup is strongly recommended.');
         $this->assign('warning', $warning);
         $warning = json_encode($warning);
         $validTriggerPermission = CRM_Core_DAO::checkTriggerViewPermission(TRUE);
         if ($validTriggerPermission && !$config->logging) {
             $this->addElement('checkbox', 'makeMultilingual', ts('Enable Multiple Languages'), NULL, array('onChange' => "if (this.checked) CRM.alert({$warning}, {$warningTitle})"));
         }
     }
     $this->addElement('checkbox', 'inheritLocale', ts('Inherit CMS Language'));
     $this->addElement('text', 'monetaryThousandSeparator', ts('Thousands Separator'), array('size' => 2));
     $this->addElement('text', 'monetaryDecimalPoint', ts('Decimal Delimiter'), array('size' => 2));
     $this->addElement('text', 'moneyformat', ts('Monetary Amount Display'));
     $this->addElement('text', 'moneyvalueformat', ts('Monetary Value Display'));
     $country = array();
     CRM_Core_PseudoConstant::populate($country, 'CRM_Core_DAO_Country', TRUE, 'name', 'is_active');
     $i18n->localizeArray($country, array('context' => 'country'));
     asort($country);
     $includeCountry =& $this->addElement('advmultiselect', 'countryLimit', ts('Available Countries') . ' ', $country, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect'));
     $includeCountry->setButtonAttributes('add', array('value' => ts('Add >>')));
     $includeCountry->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $includeState =& $this->addElement('advmultiselect', 'provinceLimit', ts('Available States and Provinces') . ' ', $country, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect'));
     $includeState->setButtonAttributes('add', array('value' => ts('Add >>')));
     $includeState->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $this->addElement('select', 'defaultContactCountry', ts('Default Country'), array('' => ts('- select -')) + $country);
     /***Default State/Province***/
     $stateCountryMap = array();
     $stateCountryMap[] = array('state_province' => 'defaultContactStateProvince', 'country' => 'defaultContactCountry');
     $countryDefault = isset($this->_submitValues['defaultContactCountry']) ? $this->_submitValues['defaultContactCountry'] : $config->defaultContactCountry;
     if ($countryDefault) {
         $selectStateProvinceOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
     } else {
         $selectStateProvinceOptions = array('' => ts('- select a country -'));
     }
     $i18n->localizeArray($selectStateProvinceOptions, array('context' => 'state_province'));
     asort($selectStateProvinceOptions);
     $this->addElement('select', 'defaultContactStateProvince', ts('Default State/Province'), $selectStateProvinceOptions);
     // state country js
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     $defaults = array();
     CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults);
     // we do this only to initialize currencySymbols, kinda hackish but works!
     $config->defaultCurrencySymbol();
     $symbol = $config->currencySymbols;
     foreach ($symbol as $key => $value) {
         $this->_currencySymbols[$key] = "{$key}";
         if ($value) {
             $this->_currencySymbols[$key] .= " ({$value})";
         }
     }
     $this->addElement('select', 'defaultCurrency', ts('Default Currency'), $this->_currencySymbols);
     $includeCurrency =& $this->addElement('advmultiselect', 'currencyLimit', ts('Available Currencies') . ' ', $this->_currencySymbols, array('size' => 5, 'style' => 'width:150px', 'class' => 'advmultiselect'));
     $includeCurrency->setButtonAttributes('add', array('value' => ts('Add >>')));
     $includeCurrency->setButtonAttributes('remove', array('value' => ts('<< Remove')));
     $this->addElement('text', 'legacyEncoding', ts('Legacy Encoding'));
     $this->addElement('text', 'customTranslateFunction', ts('Custom Translate Function'));
     $this->addElement('text', 'fieldSeparator', ts('Import / Export Field Separator'), array('size' => 2));
     $this->addFormRule(array('CRM_Admin_Form_Setting_Localization', 'formRule'));
     parent::buildQuickForm();
 }
예제 #11
0
파일: Proximity.php 프로젝트: hguru/224Civi
 function buildForm(&$form)
 {
     $config = CRM_Core_Config::singleton();
     $countryDefault = $config->defaultContactCountry;
     $form->add('text', 'distance', ts('Distance'), NULL, TRUE);
     $proxUnits = array('km' => ts('km'), 'miles' => ts('miles'));
     $form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, TRUE);
     $form->add('text', 'street_address', ts('Street Address'));
     $form->add('text', 'city', ts('City'));
     $form->add('text', 'postal_code', ts('Postal Code'));
     $stateCountryMap = array();
     $stateCountryMap[] = array('state_province' => 'state_province_id', 'country' => 'country_id');
     $defaults = array();
     if ($countryDefault) {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
         $defaults['country_id'] = $countryDefault;
     } else {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
     }
     $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
     $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
     $form->add('select', 'country_id', ts('Country'), $country, TRUE);
     $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::group();
     $form->addElement('select', 'group', ts('Group'), $group);
     $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
     $form->addElement('select', 'tag', ts('Tag'), $tag);
     // state country js, CRM-5233
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults);
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Proximity Search');
     /**
      * if you are using the standard template, this array tells the template what elements
      * are part of the search criteria
      */
     $form->assign('elements', array('distance', 'prox_distance_unit', 'street_address', 'city', 'postal_code', 'country_id', 'state_province_id', 'group', 'tag'));
 }
 function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = $this->_values;
     //set defaults for pledge payment.
     if ($this->_ppID) {
         $defaults['total_amount'] = CRM_Utils_Array::value('scheduled_amount', $this->_pledgeValues['pledgePayment']);
         $defaults['honor_type_id'] = CRM_Utils_Array::value('honor_type_id', $this->_pledgeValues);
         $defaults['honor_contact_id'] = CRM_Utils_Array::value('honor_contact_id', $this->_pledgeValues);
         $defaults['contribution_type_id'] = CRM_Utils_Array::value('contribution_type_id', $this->_pledgeValues);
         $defaults['currency'] = CRM_Utils_Array::value('currency', $this->_pledgeValues);
         $defaults['option_type'] = 1;
     }
     $fields = array();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     if ($this->_mode) {
         $billingFields = array();
         foreach ($this->_fields as $name => $dontCare) {
             if (strpos($name, 'billing_') === 0) {
                 $name = $idName = substr($name, 8);
                 if (in_array($name, array("state_province_id-{$this->_bltID}", "country_id-{$this->_bltID}"))) {
                     $name = str_replace('_id', '', $name);
                 }
                 $billingFields[$name] = 'billing_' . $idName;
             }
             $fields[$name] = 1;
         }
         if ($this->_contactID) {
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $defaults);
         }
         foreach ($billingFields as $name => $billingName) {
             $defaults[$billingName] = CRM_Utils_Array::value($name, $defaults);
         }
         $config = CRM_Core_Config::singleton();
         // set default country from config if no country set
         if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $defaults)) {
             $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
         }
         // now fix all state country selectors
         CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
         //             // hack to simplify credit card entry for testing
         //             $defaults['credit_card_type']     = 'Visa';
         //             $defaults['total_amount']         = 50;
         //             $defaults['credit_card_number']   = '4807731747657838';
         //             $defaults['cvv2']                 = '000';
         //             $defaults['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
     }
     if ($this->_id) {
         $this->_contactID = $defaults['contact_id'];
     }
     // fix the display of the monetary value, CRM-4038
     if (isset($defaults['total_amount'])) {
         $defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'], NULL, '%a');
     }
     if (isset($defaults['non_deductible_amount'])) {
         $defaults['non_deductible_amount'] = CRM_Utils_Money::format($defaults['non_deductible_amount'], NULL, '%a');
     }
     if (isset($defaults['fee_amount'])) {
         $defaults['fee_amount'] = CRM_Utils_Money::format($defaults['fee_amount'], NULL, '%a');
     }
     if (isset($defaults['net_amount'])) {
         $defaults['net_amount'] = CRM_Utils_Money::format($defaults['net_amount'], NULL, '%a');
     }
     if ($this->_contributionType) {
         $defaults['contribution_type_id'] = $this->_contributionType;
     }
     if (CRM_Utils_Array::value('is_test', $defaults)) {
         $this->assign('is_test', TRUE);
     }
     if (isset($defaults['honor_contact_id'])) {
         $honorDefault = $ids = array();
         $this->_honorID = $defaults['honor_contact_id'];
         $honorType = CRM_Core_PseudoConstant::honor();
         $idParams = array('id' => $defaults['honor_contact_id'], 'contact_id' => $defaults['honor_contact_id']);
         CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $ids);
         $defaults['honor_prefix_id'] = CRM_Utils_Array::value('prefix_id', $honorDefault);
         $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['email'][1]);
         $defaults['honor_type'] = $honorType[$defaults['honor_type_id']];
     }
     $this->assign('showOption', TRUE);
     // for Premium section
     if ($this->_premiumID) {
         $this->assign('showOption', FALSE);
         $options = isset($this->_options[$this->_productDAO->product_id]) ? $this->_options[$this->_productDAO->product_id] : "";
         if (!$options) {
             $this->assign('showOption', TRUE);
         }
         $options_key = CRM_Utils_Array::key($this->_productDAO->product_option, $options);
         if ($options_key) {
             $defaults['product_name'] = array($this->_productDAO->product_id, trim($options_key));
         } else {
             $defaults['product_name'] = array($this->_productDAO->product_id);
         }
         if ($this->_productDAO->fulfilled_date) {
             list($defaults['fulfilled_date']) = CRM_Utils_Date::setDateDefaults($this->_productDAO->fulfilled_date);
         }
     }
     if (isset($this->userEmail)) {
         $this->assign('email', $this->userEmail);
     }
     if (CRM_Utils_Array::value('is_pay_later', $defaults)) {
         $this->assign('is_pay_later', TRUE);
     }
     $this->assign('contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $defaults));
     $dates = array('receive_date', 'receipt_date', 'cancel_date', 'thankyou_date');
     foreach ($dates as $key) {
         if (CRM_Utils_Array::value($key, $defaults)) {
             list($defaults[$key], $defaults[$key . '_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults), 'activityDateTime');
         }
     }
     if (!$this->_id && !CRM_Utils_Array::value('receive_date', $defaults)) {
         list($defaults['receive_date'], $defaults['receive_date_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
     }
     $this->assign('receive_date', CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $defaults), CRM_Utils_Array::value('receive_date_time', $defaults)));
     $this->assign('currency', CRM_Utils_Array::value('currency', $defaults));
     $this->assign('totalAmount', CRM_Utils_Array::value('total_amount', $defaults));
     //inherit campaign from pledge.
     if ($this->_ppID && CRM_Utils_Array::value('campaign_id', $this->_pledgeValues)) {
         $defaults['campaign_id'] = $this->_pledgeValues['campaign_id'];
     }
     return $defaults;
 }
 /**
  * This function sets the default values for the form.
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 public function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = array();
     $defaults = parent::setDefaultValues();
     $this->_memType = $defaults['membership_type_id'];
     // set renewal_date and receive_date to today in correct input format (setDateDefaults uses today if no value passed)
     list($now, $currentTime) = CRM_Utils_Date::setDateDefaults();
     $defaults['renewal_date'] = $now;
     $defaults['receive_date'] = $now;
     $defaults['receive_date_time'] = $currentTime;
     if ($defaults['id']) {
         $defaults['record_contribution'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $defaults['id'], 'contribution_id', 'membership_id');
     }
     if (is_numeric($this->_memType)) {
         $defaults['membership_type_id'] = array();
         $defaults['membership_type_id'][0] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'member_of_contact_id', 'id');
         $defaults['membership_type_id'][1] = $this->_memType;
     } else {
         $defaults['membership_type_id'] = $this->_memType;
     }
     $defaults['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id');
     //CRM-13420
     if (!CRM_Utils_Array::value('payment_instrument_id', $defaults)) {
         $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
     }
     $defaults['total_amount'] = CRM_Utils_Money::format(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee'), NULL, '%a');
     $defaults['record_contribution'] = 0;
     $defaults['num_terms'] = 1;
     $defaults['send_receipt'] = 0;
     $renewalDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('renewal_date', $defaults), NULL, NULL, 'Y-m-d');
     $this->assign('renewalDate', $renewalDate);
     $this->assign('member_is_test', CRM_Utils_Array::value('member_is_test', $defaults));
     if ($this->_mode) {
         // set default country from config if no country set
         $config = CRM_Core_Config::singleton();
         if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $defaults)) {
             $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
         }
         if (!CRM_Utils_Array::value("billing_state_province_id-{$this->_bltID}", $defaults)) {
             $defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
         }
         $billingDefaults = $this->getProfileDefaults('Billing', $this->_contactID);
         $defaults = array_merge($defaults, $billingDefaults);
         // now fix all state country selectors, set correct state based on country
         CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     }
     return $defaults;
 }
예제 #14
0
파일: Form.php 프로젝트: ksecor/civicrm
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     //lets have single status message, CRM-4363
     $return = false;
     $statusMessage = null;
     //we should not allow component and mix profiles in search mode
     if ($this->_mode != self::MODE_REGISTER) {
         //check for mix profile fields (eg:  individual + other contact type)
         if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
             $statusMessage = ts('Profile search, view and edit are not supported for Profiles which include fields for more than one record type.');
         }
         $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
         if ($this->_id) {
             list($contactType, $contactSubType) = CRM_Contact_BAO_Contact::getContactTypes($this->_id);
             if ($profileType != 'Contact' && $contactType != $profileType && !CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
                 $return = true;
                 if (!$statusMessage) {
                     $statusMessage = ts('This profile is not configured for "%1" contact type.', array(1 => $contactType));
                 }
             }
             if ($contactSubType && CRM_Contact_BAO_ContactType::isaSubType($profileType) && $profileType != $contactSubType) {
                 $return = true;
                 if (!$statusMessage) {
                     $statusMessage = ts('This profile is not configured for "%1" contact subtype.', array(1 => $contactSubType));
                 }
             }
         }
         if (in_array($profileType, array("Membership", "Participant", "Contribution"))) {
             $return = true;
             if (!$statusMessage) {
                 $statusMessage = ts('Profile is not configured for the selected action.');
             }
         }
     }
     //lets have sigle status message,
     $this->assign('statusMessage', $statusMessage);
     if ($return) {
         return false;
     }
     $sBlocks = array();
     $hBlocks = array();
     $config =& CRM_Core_Config::singleton();
     $this->assign('id', $this->_id);
     $this->assign('mode', $this->_mode);
     $this->assign('action', $this->_action);
     $this->assign_by_ref('fields', $this->_fields);
     $this->assign('fieldset', isset($this->_fieldset) ? $this->_fieldset : "");
     // do we need inactive options ?
     if ($this->_action & CRM_Core_Action::VIEW) {
         $inactiveNeeded = true;
     } else {
         $inactiveNeeded = false;
     }
     $session =& CRM_Core_Session::singleton();
     // should we restrict what we display
     $admin = true;
     if ($this->_mode == self::MODE_EDIT) {
         $admin = false;
         // show all fields that are visibile: if we are a admin or the same user or in registration mode
         if (CRM_Core_Permission::check('administer users') || $this->_id == $session->get('userID')) {
             $admin = true;
         }
     }
     $userID = $session->get('userID');
     $anonUser = false;
     // if false, user is not logged-in.
     if (!$userID) {
         require_once 'CRM/Core/BAO/LocationType.php';
         $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
         $primaryLocationType = $defaultLocationType->id;
         $anonUser = true;
         $this->assign('anonUser', true);
     }
     $addCaptcha = array();
     $emailPresent = false;
     // cache the state country fields. based on the results, we could use our javascript solution
     // in create or register mode
     $stateCountryMap = array();
     // add the form elements
     foreach ($this->_fields as $name => $field) {
         // make sure that there is enough permission to expose this field
         if (!$admin && $field['visibility'] == 'User and User Admin Only' || CRM_Utils_Array::value('is_view', $field)) {
             unset($this->_fields[$name]);
             continue;
         }
         // since the CMS manages the email field, suppress the email display if in
         // register mode which occur within the CMS form
         if ($this->_mode == self::MODE_REGISTER && substr($name, 0, 5) == 'email') {
             unset($this->_fields[$name]);
             continue;
         }
         list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
         if ($prefixName == 'state_province' || $prefixName == 'country') {
             if (!array_key_exists($index, $stateCountryMap)) {
                 $stateCountryMap[$index] = array();
             }
             $stateCountryMap[$index][$prefixName] = $name;
         }
         CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode);
         if ($field['add_to_group_id']) {
             $addToGroupId = $field['add_to_group_id'];
         }
         //build array for captcha
         if ($field['add_captcha']) {
             $addCaptcha[$field['group_id']] = $field['add_captcha'];
         }
         if ($name == 'email-Primary' || ($name == 'email-' . isset($primaryLocationType) ? $primaryLocationType : "")) {
             $emailPresent = true;
             $this->_mail = $name;
         }
     }
     $setCaptcha = false;
     // do this only for CiviCRM created forms
     if ($this->_mode == self::MODE_CREATE) {
         if (!empty($addCaptcha)) {
             $setCaptcha = true;
         }
         if ($this->_gid) {
             $dao = new CRM_Core_DAO_UFGroup();
             $dao->id = $this->_gid;
             $dao->addSelect();
             $dao->addSelect('add_captcha', 'is_update_dupe');
             if ($dao->find(true)) {
                 if ($dao->add_captcha) {
                     $setCaptcha = true;
                 }
                 if ($dao->is_update_dupe) {
                     $this->_isUpdateDupe = true;
                 }
             }
         }
         if ($setCaptcha) {
             require_once 'CRM/Utils/ReCAPTCHA.php';
             $captcha =& CRM_Utils_ReCAPTCHA::singleton();
             $captcha->add($this);
             $this->assign("isCaptcha", true);
         }
     }
     if ($this->_mode != self::MODE_SEARCH) {
         if (isset($addToGroupId)) {
             $this->add('hidden', "group[{$addToGroupId}]", 1);
             $this->_addToGroupID = $addToGroupId;
         }
     }
     // also do state country js
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, null);
     if ($this->_mode == self::MODE_CREATE) {
         require_once 'CRM/Core/BAO/CMSUser.php';
         CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action);
     } else {
         $this->assign('showCMS', false);
     }
     $this->assign('groupId', $this->_gid);
     // now fix all state country selectors
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
     if ($this->_context == 'dialog') {
         $this->addElement('submit', $this->_duplicateButtonName, ts('Save Matching Contact'));
     }
 }
예제 #15
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;
 }
예제 #16
0
파일: Confirm.php 프로젝트: bhirsch/civicrm
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     require_once 'CRM/Contribute/BAO/Premium.php';
     $params = $this->_params;
     $honor_block_is_active = $this->get('honor_block_is_active');
     // make sure we have values for it
     if ($honor_block_is_active && (!empty($params["honor_first_name"]) && !empty($params["honor_last_name"]) || !empty($params["honor_email"]))) {
         $this->assign('honor_block_is_active', $honor_block_is_active);
         $this->assign("honor_block_title", CRM_Utils_Array::value('honor_block_title', $this->_values));
         require_once "CRM/Core/PseudoConstant.php";
         $prefix = CRM_Core_PseudoConstant::individualPrefix();
         $honor = CRM_Core_PseudoConstant::honor();
         $this->assign("honor_type", CRM_Utils_Array::value($params["honor_type_id"], $honor));
         $this->assign("honor_prefix", CRM_Utils_Array::value($params["honor_prefix_id"], $prefix));
         $this->assign("honor_first_name", $params["honor_first_name"]);
         $this->assign("honor_last_name", $params["honor_last_name"]);
         $this->assign("honor_email", $params["honor_email"]);
     }
     $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
     $amount_block_is_active = $this->get('amount_block_is_active');
     $this->assign('amount_block_is_active', $amount_block_is_active);
     if (CRM_Utils_Array::value('selectProduct', $params) && $params['selectProduct'] != 'no_thanks') {
         $option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params);
         $productID = $params['selectProduct'];
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, false, $productID, $option);
         $this->set('productID', $productID);
         $this->set('option', $option);
     }
     $config =& CRM_Core_Config::singleton();
     if (in_array("CiviMember", $config->enableComponents)) {
         if (isset($params['selectMembership']) && $params['selectMembership'] != 'no_thanks') {
             CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, false, $params['selectMembership'], false, null, $this->_membershipContactID);
         } else {
             $this->assign('membershipBlock', false);
         }
     }
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', true);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', true);
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign("is_separate_payment", $this->_separateMembershipPayment);
     $this->assign('lineItem', $this->_lineItem);
     $this->assign('priceSetID', $this->_priceSetId);
     if ($this->_paymentProcessor['payment_processor_type'] == 'Google_Checkout' && !$this->_params['is_pay_later']) {
         $this->_checkoutButtonName = $this->getButtonName('next', 'checkout');
         $this->add('image', $this->_checkoutButtonName, $this->_paymentProcessor['url_button'], array('class' => 'form-submit'));
         $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Go Back'))));
     } else {
         if ($this->_contributeMode == 'notify' || !$this->_values['is_monetary'] || $this->_amount <= 0.0 || $this->_params['is_pay_later'] || $this->_separateMembershipPayment && $this->_amount <= 0.0) {
             $contribButton = ts('Continue >>');
             $this->assign('button', 'Continue');
         } else {
             $contribButton = ts('Make Contribution');
             $this->assign('button', 'Make Contribution');
         }
         $this->addButtons(array(array('type' => 'next', 'name' => $contribButton, 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');")), array('type' => 'back', 'name' => ts('<< Go Back'))));
     }
     $defaults = array();
     $options = array();
     $fields = array();
     require_once "CRM/Core/BAO/CustomGroup.php";
     $removeCustomFieldTypes = array('Contribution');
     foreach ($this->_fields as $name => $dontCare) {
         $fields[$name] = 1;
     }
     $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
     $contact = $this->_params;
     foreach ($fields as $name => $dontCare) {
         if (isset($contact[$name])) {
             $defaults[$name] = $contact[$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($contact[$timeField])) {
                     $defaults[$timeField] = $contact[$timeField];
                 }
             } else {
                 if (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && CRM_Utils_Array::value($name . '_custom', $contact)) {
                     $defaults[$name . '_custom'] = $contact[$name . '_custom'];
                 }
             }
         }
     }
     // now fix all state country selectors
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $this->setDefaults($defaults);
     $this->freeze();
 }
예제 #17
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;
 }
예제 #18
0
 function setDefaultValues()
 {
     $this->_defaults = array();
     if ($this->_contactID) {
         foreach ($this->_fields as $name => $dontcare) {
             $fields[$name] = 1;
         }
         CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults);
     }
     $stateCountryMap = array();
     //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);
             }
         }
         if (substr($name, 0, 14) === 'state_province' || substr($name, 0, 7) === 'country' || substr($name, 0, 6) === 'county') {
             list($fieldName, $index) = CRM_Utils_System::explode('-', $name, 2);
             if (!array_key_exists($index, $stateCountryMap)) {
                 $stateCountryMap[$index] = array();
             }
             $stateCountryMap[$index][$fieldName] = $name;
         }
         // also take care of state country widget
         if (!empty($stateCountryMap)) {
             CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults);
         }
     }
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     return $this->_defaults;
 }
예제 #19
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     if ($this->_params[0]['amount'] || $this->_params[0]['amount'] == 0) {
         $this->_amount = array();
         foreach ($this->_params as $k => $v) {
             if (is_array($v)) {
                 foreach (array('first_name', 'last_name') as $name) {
                     if (isset($v['billing_' . $name]) && !isset($v[$name])) {
                         $v[$name] = $v['billing_' . $name];
                     }
                 }
                 if (CRM_Utils_Array::value('first_name', $v) && CRM_Utils_Array::value('last_name', $v)) {
                     $append = $v['first_name'] . ' ' . $v['last_name'];
                 } else {
                     //use an email if we have one
                     foreach ($v as $v_key => $v_val) {
                         if (substr($v_key, 0, 6) == 'email-') {
                             $append = $v[$v_key];
                         }
                     }
                 }
                 $this->_amount[$k]['amount'] = $v['amount'];
                 if (CRM_Utils_Array::value('discountAmount', $v)) {
                     $this->_amount[$k]['amount'] -= $v['discountAmount'];
                 }
                 $this->_amount[$k]['label'] = preg_replace('//', '', $v['amount_level']) . '  -  ' . $append;
                 $this->_part[$k]['info'] = CRM_Utils_Array::value('first_name', $v) . ' ' . CRM_Utils_Array::value('last_name', $v);
                 if (!CRM_Utils_Array::value('first_name', $v)) {
                     $this->_part[$k]['info'] = $append;
                 }
                 $this->_totalAmount = $this->_totalAmount + $this->_amount[$k]['amount'];
                 if (CRM_Utils_Array::value('is_primary', $v)) {
                     $this->set('primaryParticipantAmount', $this->_amount[$k]['amount']);
                 }
             }
         }
         $this->assign('part', $this->_part);
         $this->set('part', $this->_part);
         $this->assign('amounts', $this->_amount);
         $this->assign('totalAmount', $this->_totalAmount);
         $this->set('totalAmount', $this->_totalAmount);
     }
     $config = CRM_Core_Config::singleton();
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     }
     //display additional participants profile.
     $participantParams = $this->_params;
     $formattedValues = array();
     $count = 1;
     foreach ($participantParams as $participantNum => $participantValue) {
         if ($participantNum && $participantValue != 'skip') {
             //get the customPre profile info
             if (CRM_Utils_Array::value('additional_custom_pre_id', $this->_values)) {
                 $values = $groupName = array();
                 CRM_Event_BAO_Event::displayProfile($participantValue, $this->_values['additional_custom_pre_id'], $groupName, $values);
                 if (count($values)) {
                     $formattedValues[$count]['additionalCustomPre'] = $values;
                 }
                 $formattedValues[$count]['additionalCustomPreGroupTitle'] = CRM_Utils_Array::value('groupTitle', $groupName);
             }
             //get the customPost profile info
             if (CRM_Utils_Array::value('additional_custom_post_id', $this->_values)) {
                 $values = $groupName = array();
                 foreach ($this->_values['additional_custom_post_id'] as $gids) {
                     $val = array();
                     CRM_Event_BAO_Event::displayProfile($participantValue, $gids, $group, $val);
                     $values[$gids] = $val;
                     $groupName[$gids] = $group;
                 }
                 if (count($values)) {
                     $formattedValues[$count]['additionalCustomPost'] = $values;
                 }
                 if (isset($formattedValues[$count]['additionalCustomPre'])) {
                     $formattedValues[$count]['additionalCustomPost'] = array_diff_assoc($formattedValues[$count]['additionalCustomPost'], $formattedValues[$count]['additionalCustomPre']);
                 }
                 $formattedValues[$count]['additionalCustomPostGroupTitle'] = $groupName;
             }
             $count++;
         }
     }
     if (!empty($formattedValues) && $count > 1) {
         $this->assign('addParticipantProfile', $formattedValues);
         $this->set('addParticipantProfile', $formattedValues);
     }
     //cosider total amount.
     $this->assign('isAmountzero', $this->_totalAmount <= 0 ? TRUE : FALSE);
     if ($this->_paymentProcessor['payment_processor_type'] == 'Google_Checkout' && !CRM_Utils_Array::value('is_pay_later', $this->_params[0]) && !($this->_params[0]['amount'] == 0) && !$this->_allowWaitlist && !$this->_requireApproval) {
         $this->_checkoutButtonName = $this->getButtonName('next', 'checkout');
         $this->add('image', $this->_checkoutButtonName, $this->_paymentProcessor['url_button'], array('class' => 'form-submit'));
         $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Go Back'))));
     } else {
         $contribButton = ts('Continue');
         $this->addButtons(array(array('type' => 'next', 'name' => $contribButton, 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');")), array('type' => 'back', 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'name' => ts('Go Back'))));
     }
     $defaults = array();
     $fields = array();
     if (!empty($this->_fields)) {
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
     }
     $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
     foreach ($fields as $name => $dontCare) {
         if (isset($this->_params[0][$name])) {
             $defaults[$name] = $this->_params[0][$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($this->_params[0][$timeField])) {
                     $defaults[$timeField] = $this->_params[0][$timeField];
                 }
                 if (isset($this->_params[0]["{$name}_id"])) {
                     $defaults["{$name}_id"] = $this->_params[0]["{$name}_id"];
                 }
             } elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes) && !empty($this->_params[0][$name . '_custom'])) {
                 $defaults[$name . '_custom'] = $this->_params[0][$name . '_custom'];
             }
         }
     }
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $this->setDefaults($defaults);
     $this->freeze();
     //lets give meaningful status message, CRM-4320.
     $this->assign('isOnWaitlist', $this->_allowWaitlist);
     $this->assign('isRequireApproval', $this->_requireApproval);
     // Assign Participant Count to Lineitem Table
     $this->assign('pricesetFieldsCount', CRM_Price_BAO_Set::getPricesetCount($this->_priceSetId));
 }
예제 #20
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;
 }
예제 #21
0
파일: Confirm.php 프로젝트: bhirsch/voipdev
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     if ($this->_params[0]['amount'] || $this->_params[0]['amount'] == 0) {
         $this->_amount = array();
         foreach ($this->_params as $k => $v) {
             if (is_array($v)) {
                 if (CRM_Utils_Array::value("email-{$this->_bltID}", $v)) {
                     $append = $v["email-{$this->_bltID}"];
                 } else {
                     $append = $v['first_name'] . ' ' . $v['last_name'];
                 }
                 $this->_amount[$k]['amount'] = $v['amount'];
                 if (CRM_Utils_Array::value('discountAmount', $v)) {
                     $this->_amount[$k]['amount'] -= $v['discountAmount'];
                 }
                 $this->_amount[$k]['label'] = $v['amount_level'] . '  -  ' . $append;
                 $this->_totalAmount = $this->_totalAmount + $this->_amount[$k]['amount'];
                 if (CRM_Utils_Array::value('is_primary', $v)) {
                     $this->set('primaryParticipantAmount', $this->_amount[$k]['amount']);
                 }
             }
         }
         $this->assign('amount', $this->_amount);
         $this->assign('totalAmount', $this->_totalAmount);
         $this->set('totalAmount', $this->_totalAmount);
     }
     $config =& CRM_Core_Config::singleton();
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', true);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', true);
     $this->assign('lineItem', $this->_lineItem);
     //display additional participants profile.
     require_once 'CRM/Event/BAO/Event.php';
     $participantParams = $this->_params;
     $formattedValues = array();
     $count = 1;
     foreach ($participantParams as $participantNum => $participantValue) {
         if ($participantNum && $participantValue != 'skip') {
             //get the customPre profile info
             if (CRM_Utils_Array::value('additional_custom_pre_id', $this->_values)) {
                 $values = array();
                 $groupName = array();
                 CRM_Event_BAO_Event::displayProfile($participantValue, $this->_values['additional_custom_pre_id'], $groupName, $values);
                 if (count($values)) {
                     $formattedValues[$count]['additionalCustomPre'] = $values;
                 }
                 $formattedValues[$count]['additionalCustomPreGroupTitle'] = CRM_Utils_Array::value('groupTitle', $groupName);
             }
             //get the customPost profile info
             if (CRM_Utils_Array::value('additional_custom_post_id', $this->_values)) {
                 $values = array();
                 $groupName = array();
                 CRM_Event_BAO_Event::displayProfile($participantValue, $this->_values['additional_custom_post_id'], $groupName, $values);
                 if (count($values)) {
                     $formattedValues[$count]['additionalCustomPost'] = $values;
                 }
                 $formattedValues[$count]['additionalCustomPostGroupTitle'] = CRM_Utils_Array::value('groupTitle', $groupName);
             }
             $count++;
         }
     }
     if (!empty($formattedValues) && $count > 1) {
         $this->assign('addParticipantProfile', $formattedValues);
     }
     if ($this->_params[0]['amount'] == 0) {
         $this->assign('isAmountzero', 1);
     }
     if ($this->_paymentProcessor['payment_processor_type'] == 'Google_Checkout' && !CRM_Utils_Array::value('is_pay_later', $this->_params[0]) && !($this->_params[0]['amount'] == 0) && !$this->_allowWaitlist && !$this->_requireApproval) {
         $this->_checkoutButtonName = $this->getButtonName('next', 'checkout');
         $this->add('image', $this->_checkoutButtonName, $this->_paymentProcessor['url_button'], array('class' => 'form-submit'));
         $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Go Back'))));
     } else {
         $contribButton = ts('Continue >>');
         $this->addButtons(array(array('type' => 'back', 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'name' => ts('<< Go Back')), array('type' => 'next', 'name' => $contribButton, 'isDefault' => true, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"))));
     }
     $defaults = array();
     $fields = array();
     if (!empty($this->_fields)) {
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
     }
     $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
     foreach ($fields as $name => $dontCare) {
         if (isset($this->_params[0][$name])) {
             $defaults[$name] = $this->_params[0][$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($this->_params[0][$timeField])) {
                     $defaults[$timeField] = $this->_params[0][$timeField];
                 }
             } else {
                 if (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && CRM_Utils_Array::value($name . '_custom', $this->_params[0])) {
                     $defaults[$name . '_custom'] = $this->_params[0][$name . '_custom'];
                 }
             }
         }
     }
     // now fix all state country selectors
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $this->setDefaults($defaults);
     $this->freeze();
     //lets give meaningful status message, CRM-4320.
     $this->assign('isOnWaitlist', $this->_allowWaitlist);
     $this->assign('isRequireApproval', $this->_requireApproval);
 }
예제 #22
0
 function buildForm(&$form)
 {
     $config =& CRM_Core_Config::singleton();
     $countryDefault = $config->defaultContactCountry;
     $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::tag();
     $form->addElement('select', 'tag', ts('Tag'), $tag);
     $form->add('text', 'distance', ts('Distance'));
     $form->add('text', 'street_address', ts('Street Address'));
     $form->add('text', 'city', ts('City'));
     $form->add('text', 'postal_code', ts('Postal Code'));
     $stateCountryMap = array();
     $stateCountryMap[] = array('state_province' => 'state_province_id', 'country' => 'country_id');
     $defaults = array();
     if ($countryDefault) {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($countryDefault);
         $defaults['country_id'] = $countryDefault;
     } else {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
     }
     $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
     $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
     $form->add('select', 'country_id', ts('Country'), $country, true);
     $form->add('text', 'distance', ts('Radius for Proximity Search (in km)'), null, true);
     // state country js, CRM-5233
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     CRM_Core_BAO_Address::fixAllStateSelects($form, $defaults);
     /**
      * You can define a custom title for the search form
      */
     $this->setTitle('Proximity Search');
     /**
      * if you are using the standard template, this array tells the template what elements
      * are part of the search criteria
      */
     $form->assign('elements', array('tag', 'street_address', 'city', 'postal_code', 'country_id', 'state_province_id', 'distance'));
 }
예제 #23
0
 function setDefaultValues()
 {
     $this->_defaults = array();
     if ($this->_subscriptionDetails->contact_id) {
         $options = array();
         $fields = array();
         $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($this->_subscriptionDetails->contact_id, $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];
             }
         }
     }
     $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;
     }
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     return $this->_defaults;
 }
예제 #24
0
 /**
  * Set the default form values
  *
  * @access protected
  * @return array the default array reference
  */
 function &setDefaultValues()
 {
     $defaults = array();
     $stateCountryMap = array();
     foreach ($this->_fields as $name => $field) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name'])) {
             CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, null, CRM_Profile_Form::MODE_REGISTER);
         }
         //CRM-5403
         if (substr($name, 0, 14) === 'state_province' || substr($name, 0, 7) === 'country') {
             list($fieldName, $index) = CRM_Utils_System::explode('-', $name, 2);
             if (!array_key_exists($index, $stateCountryMap)) {
                 $stateCountryMap[$index] = array();
             }
             $stateCountryMap[$index][$fieldName] = $name;
         }
     }
     // also take care of state country widget
     if (!empty($stateCountryMap)) {
         require_once 'CRM/Core/BAO/Address.php';
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $defaults);
     }
     //set default for country.
     CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults);
     // now fix all state country selectors
     require_once 'CRM/Core/BAO/Address.php';
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     return $defaults;
 }
 /**
  * Function to build form for related contacts / on behalf of organization.
  *
  * @param $form              object  invoking Object
  * @param $contactType       string  contact type
  * @param $title             string  fieldset title
  *
  * @static
  */
 static function buildQuickForm(&$form)
 {
     $form->assign('fieldSetTitle', ts('Organization Details'));
     $form->assign('buildOnBehalfForm', TRUE);
     $session = CRM_Core_Session::singleton();
     $contactID = $session->get('userID');
     if ($contactID && count($form->_employers) >= 1) {
         $form->add('text', 'organization_id', ts('Select an existing related Organization OR enter a new one'));
         $form->add('hidden', 'onbehalfof_id', '', array('id' => 'onbehalfof_id'));
         $orgOptions = array(0 => ts('Select an existing organization'), 1 => ts('Enter a new organization'));
         $form->addRadio('org_option', ts('options'), $orgOptions);
         $form->setDefaults(array('org_option' => 0));
         $form->add('checkbox', 'mode', '');
     }
     $profileFields = CRM_Core_BAO_UFGroup::getFields($form->_profileId, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
     $fieldTypes = array('Contact', 'Organization');
     $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
     $fieldTypes = array_merge($fieldTypes, $contactSubType);
     if (is_array($form->_membershipBlock) && !empty($form->_membershipBlock)) {
         $fieldTypes = array_merge($fieldTypes, array('Membership'));
     } else {
         $fieldTypes = array_merge($fieldTypes, array('Contribution'));
     }
     $stateCountryMap = array();
     foreach ($profileFields as $name => $field) {
         if (in_array($field['field_type'], $fieldTypes)) {
             list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
             if (in_array($prefixName, array('state_province', 'country', 'county'))) {
                 if (!array_key_exists($index, $stateCountryMap)) {
                     $stateCountryMap[$index] = array();
                 }
                 $stateCountryMap[$index][$prefixName] = 'onbehalf[' . $name . ']';
             } elseif (in_array($prefixName, array('organization_name', 'email')) && !CRM_Utils_Array::value('is_required', $field)) {
                 $field['is_required'] = 1;
             }
             CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, TRUE);
         }
     }
     if (!empty($stateCountryMap)) {
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
         // now fix all state country selectors
         CRM_Core_BAO_Address::fixAllStateSelects($form, CRM_Core_DAO::$_nullArray);
     }
     $form->assign('onBehalfOfFields', $profileFields);
     $form->addElement('hidden', 'hidden_onbehalf_profile', 1);
 }
예제 #26
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     $params = $this->_params;
     $honor_block_is_active = $this->get('honor_block_is_active');
     // make sure we have values for it
     if ($honor_block_is_active && !empty($params['soft_credit_type_id'])) {
         $honorName = null;
         $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
         $this->assign('honor_block_is_active', $honor_block_is_active);
         $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
         CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']);
         $fieldTypes = array('Contact');
         $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']);
         $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
     }
     $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
     $amount_block_is_active = $this->get('amount_block_is_active');
     $this->assign('amount_block_is_active', $amount_block_is_active);
     if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
         $option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params);
         $productID = $params['selectProduct'];
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
         $this->set('productID', $productID);
         $this->set('option', $option);
     }
     $config = CRM_Core_Config::singleton();
     if (in_array('CiviMember', $config->enableComponents)) {
         if (isset($params['selectMembership']) && $params['selectMembership'] != 'no_thanks') {
             CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, $this->_membershipContactID, FALSE, $params['selectMembership'], FALSE);
         } else {
             $this->assign('membershipBlock', FALSE);
         }
     }
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if (!empty($params['hidden_onbehalf_profile'])) {
         $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $profileId = $OnBehalfProfile[0];
         $fieldTypes = array('Contact', 'Organization');
         $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
         $fieldTypes = array_merge($fieldTypes, $contactSubType);
         if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
             $fieldTypes = array_merge($fieldTypes, array('Membership'));
         } else {
             $fieldTypes = array_merge($fieldTypes, array('Contribution'));
         }
         $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
     }
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign('is_separate_payment', $this->_separateMembershipPayment);
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     } else {
         $this->assign('is_quick_config', 1);
         $this->_params['is_quick_config'] = 1;
     }
     $this->assign('priceSetID', $this->_priceSetId);
     $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name');
     if ($this->_paymentProcessor && $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('Google_Checkout', $paymentProcessorType) && !$this->_params['is_pay_later'] && !($this->_amount == 0)) {
         $this->_checkoutButtonName = $this->getButtonName('next', 'checkout');
         $this->add('image', $this->_checkoutButtonName, $this->_paymentProcessor['url_button'], array('class' => 'form-submit'));
         $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Go Back'))));
     } else {
         if ($this->_contributeMode == 'notify' || !$this->_values['is_monetary'] || $this->_amount <= 0.0 || $this->_params['is_pay_later'] || $this->_separateMembershipPayment && $this->_amount <= 0.0) {
             $contribButton = ts('Continue >>');
             $this->assign('button', ts('Continue'));
         } else {
             $contribButton = ts('Make Contribution');
             $this->assign('button', ts('Make Contribution'));
         }
         $this->addButtons(array(array('type' => 'next', 'name' => $contribButton, 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');")), array('type' => 'back', 'name' => ts('Go Back'))));
     }
     $defaults = array();
     $fields = array();
     foreach ($this->_fields as $name => $dontCare) {
         if ($name != 'onbehalf' || $name != 'honor') {
             $fields[$name] = 1;
         }
     }
     $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
     $contact = $this->_params;
     foreach ($fields as $name => $dontCare) {
         if (isset($contact[$name])) {
             $defaults[$name] = $contact[$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($contact[$timeField])) {
                     $defaults[$timeField] = $contact[$timeField];
                 }
                 if (isset($contact["{$name}_id"])) {
                     $defaults["{$name}_id"] = $contact["{$name}_id"];
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) {
                 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
             }
         }
     }
     $this->assign('useForMember', $this->get('useForMember'));
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $this->setDefaults($defaults);
     $this->freeze();
 }
예제 #27
0
파일: Batch.php 프로젝트: hguru/224Civi
 /**
  * This function sets the default values for the form.
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     if (empty($this->_fields)) {
         return;
     }
     $defaults = $sortName = array();
     foreach ($this->_contactIds as $contactId) {
         $details[$contactId] = array();
         //build sortname
         $sortName[$contactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'sort_name');
         CRM_Core_BAO_UFGroup::setProfileDefaults($contactId, $this->_fields, $defaults, FALSE);
     }
     $this->assign('sortName', $sortName);
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults, $this->_stateCountryCountyFields);
     return $defaults;
 }
 /**
  * Build the form
  *
  * @access public
  *
  * @return void
  */
 function buildQuickForm($form, $proxSearch)
 {
     // is proximity search required (2) or optional (1)?
     $proxRequired = $proxSearch == 2 ? TRUE : FALSE;
     $form->assign('proximity_search', TRUE);
     $form->add('text', 'prox_street_address', ts('Street Address'), NULL, FALSE);
     $form->add('text', 'prox_city', ts('City'), NULL, FALSE);
     $form->add('text', 'prox_postal_code', ts('Postal Code'), NULL, FALSE);
     $defaults = self::setDefaultValues($form);
     if (CRM_Utils_Array::value('prox_country_id', $defaults)) {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvinceForCountry($defaults['prox_country_id']);
     } else {
         $stateProvince = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince();
     }
     $form->add('select', 'prox_state_province_id', ts('State/Province'), $stateProvince, $proxRequired);
     $country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
     $form->add('select', 'prox_country_id', ts('Country'), $country, $proxRequired);
     $form->add('text', 'prox_distance', ts('Distance'), NULL, $proxRequired);
     $proxUnits = array('km' => ts('km'), 'miles' => ts('miles'));
     $form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, $proxRequired);
     // prox_distance_unit
     // state country js, CRM-5233
     $stateCountryMap = array();
     $stateCountryMap[] = array('state_province' => 'prox_state_province_id', 'country' => 'prox_country_id');
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $form->addFormRule(array('CRM_Contact_Form_Task_ProximityCommon', 'formRule'), $form);
 }
예제 #29
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     //lets have single status message, CRM-4363
     $return = FALSE;
     $statusMessage = NULL;
     CRM_Core_BAO_Address::checkContactSharedAddressFields($this->_fields, $this->_id);
     //we should not allow component and mix profiles in search mode
     if ($this->_mode != self::MODE_REGISTER) {
         //check for mix profile fields (eg:  individual + other contact type)
         if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
             if ($this->_mode & self::MODE_EDIT && $this->_isContactActivityProfile) {
                 $errors = self::validateContactActivityProfile($this->_activityId, $this->_id, $this->_gid);
                 if (!empty($errors)) {
                     $statusMessage = array_pop($errors);
                     $return = TRUE;
                 }
             } else {
                 $statusMessage = ts('Profile search, view and edit are not supported for Profiles which include fields for more than one record type.');
                 $return = TRUE;
             }
         }
         $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid);
         if ($this->_id) {
             $contactTypes = CRM_Contact_BAO_Contact::getContactTypes($this->_id);
             $contactType = $contactTypes[0];
             array_shift($contactTypes);
             $contactSubtypes = $contactTypes;
             $profileSubType = FALSE;
             if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) {
                 $profileSubType = $profileType;
                 $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType);
             }
             if ($profileType != 'Contact' && !$this->_isContactActivityProfile && ($profileSubType && !empty($contactSubtypes) && !in_array($profileSubType, $contactSubtypes) || $profileType != $contactType)) {
                 $return = TRUE;
                 if (!$statusMessage) {
                     $statusMessage = ts("This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.", array(1 => $profileSubType ? $profileSubType : $profileType));
                 }
             }
         }
         if (in_array($profileType, array("Membership", "Participant", "Contribution"))) {
             $return = TRUE;
             if (!$statusMessage) {
                 $statusMessage = ts('Profile is not configured for the selected action.');
             }
         }
     }
     //lets have sigle status message,
     $this->assign('statusMessage', $statusMessage);
     if ($return) {
         return FALSE;
     }
     $sBlocks = array();
     $hBlocks = array();
     $config = CRM_Core_Config::singleton();
     $this->assign('id', $this->_id);
     $this->assign('mode', $this->_mode);
     $this->assign('action', $this->_action);
     $this->assign_by_ref('fields', $this->_fields);
     $this->assign('fieldset', isset($this->_fieldset) ? $this->_fieldset : "");
     // do we need inactive options ?
     if ($this->_action & CRM_Core_Action::VIEW) {
         $inactiveNeeded = TRUE;
     } else {
         $inactiveNeeded = FALSE;
     }
     $session = CRM_Core_Session::singleton();
     // should we restrict what we display
     $admin = TRUE;
     if ($this->_mode == self::MODE_EDIT) {
         $admin = FALSE;
         // show all fields that are visibile:
         // if we are a admin OR the same user OR acl-user with access to the profile
         // or we have checksum access to this contact (i.e. the user without a login) - CRM-5909
         if (CRM_Core_Permission::check('administer users') || $this->_id == $session->get('userID') || $this->_isPermissionedChecksum || in_array($this->_gid, CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', CRM_Core_PseudoConstant::ufGroup()))) {
             $admin = TRUE;
         }
     }
     $userID = $session->get('userID');
     // if false, user is not logged-in.
     $anonUser = FALSE;
     if (!$userID) {
         $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
         $primaryLocationType = $defaultLocationType->id;
         $anonUser = TRUE;
         $this->assign('anonUser', TRUE);
     }
     $addCaptcha = array();
     $emailPresent = FALSE;
     // cache the state country fields. based on the results, we could use our javascript solution
     // in create or register mode
     $stateCountryMap = array();
     // add the form elements
     foreach ($this->_fields as $name => $field) {
         // make sure that there is enough permission to expose this field
         if (!$admin && $field['visibility'] == 'User and User Admin Only') {
             unset($this->_fields[$name]);
             continue;
         }
         // since the CMS manages the email field, suppress the email display if in
         // register mode which occur within the CMS form
         if ($this->_mode == self::MODE_REGISTER && substr($name, 0, 5) == 'email') {
             unset($this->_fields[$name]);
             continue;
         }
         list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
         if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
             if (!array_key_exists($index, $stateCountryMap)) {
                 $stateCountryMap[$index] = array();
             }
             $stateCountryMap[$index][$prefixName] = $name;
         }
         CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode);
         if ($field['add_to_group_id']) {
             $addToGroupId = $field['add_to_group_id'];
         }
         //build array for captcha
         if ($field['add_captcha']) {
             $addCaptcha[$field['group_id']] = $field['add_captcha'];
         }
         if ($name == 'email-Primary' || ($name == 'email-' . isset($primaryLocationType) ? $primaryLocationType : "")) {
             $emailPresent = TRUE;
             $this->_mail = $name;
         }
     }
     // add captcha only for create mode.
     if ($this->_mode == self::MODE_CREATE) {
         if (!$this->_isAddCaptcha && !empty($addCaptcha)) {
             $this->_isAddCaptcha = TRUE;
         }
         if ($this->_gid) {
             $dao = new CRM_Core_DAO_UFGroup();
             $dao->id = $this->_gid;
             $dao->addSelect();
             $dao->addSelect('add_captcha', 'is_update_dupe');
             if ($dao->find(TRUE)) {
                 if ($dao->add_captcha) {
                     $setCaptcha = TRUE;
                 }
                 if ($dao->is_update_dupe) {
                     $this->_isUpdateDupe = $dao->is_update_dupe;
                 }
             }
         }
     } else {
         $this->_isAddCaptcha = FALSE;
     }
     //finally add captcha to form.
     if ($this->_isAddCaptcha) {
         $captcha = CRM_Utils_ReCAPTCHA::singleton();
         $captcha->add($this);
     }
     $this->assign("isCaptcha", $this->_isAddCaptcha);
     if ($this->_mode != self::MODE_SEARCH) {
         if (isset($addToGroupId)) {
             $this->add('hidden', "add_to_group", $addToGroupId);
             $this->_addToGroupID = $addToGroupId;
         }
     }
     // also do state country js
     CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, NULL);
     if ($this->_mode == self::MODE_CREATE) {
         CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action);
     } else {
         $this->assign('showCMS', FALSE);
     }
     $this->assign('groupId', $this->_gid);
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
     if ($this->_context == 'dialog') {
         $this->addElement('submit', $this->_duplicateButtonName, ts('Save Matching Contact'));
     }
     $this->setDefaultsValues();
 }