예제 #1
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' || 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, $defaults);
     }
     //set default for country.
     CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults);
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     return $defaults;
 }
예제 #2
0
 /**
  * Set the default form values.
  *
  *
  * @return array
  *   the default array reference
  */
 public function setDefaultValues()
 {
     $defaults = 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);
         }
     }
     //set default for country.
     CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $defaults);
     return $defaults;
 }
예제 #3
0
 function setDefaultValues()
 {
     $defaults = array();
     $profileFields = CRM_Core_BAO_UFGroup::getFields($this->_profileID);
     $contactID = $this->_contactID;
     $entityCaseID = NULL;
     $cases = CRM_Case_BAO_Case::retrieveCaseIdsByContactId($contactID, FALSE, 'Application');
     $entityCaseID = end($cases);
     if ($contactID) {
         $options = array();
         $fields = array();
         foreach ($profileFields as $name => $field) {
             if (substr($name, 0, 7) == 'custom_') {
                 $id = substr($name, 7);
                 if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                     if ($entityCaseID) {
                         CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, $entityCaseID, CRM_Profile_Form::MODE_REGISTER);
                     }
                     if (!isset($defaults[$name])) {
                         CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, $contactID, CRM_Profile_Form::MODE_REGISTER);
                     }
                     $htmlType = $field['html_type'];
                     if ($htmlType == 'File') {
                         $this->assign('customname', $name);
                         $entityId = $entityCaseID;
                         $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $customFieldID);
                         if ($url) {
                             $customFiles[$field['name']]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
                             $deleteExtra = ts("Are you sure you want to delete attached file?");
                             $fileId = $url['file_id'];
                             $session = CRM_Core_Session::singleton();
                             $session->pushUserContext(CRM_Utils_System::url('civicrm/vacancy/apply', "reset=1&id={$this->_id}&cid={$contactID}"));
                             $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$customFieldID}&action=delete");
                             $text = ts("Delete Attached File");
                             $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&amp;confirmed=1'; else return false;\">{$text}</a>";
                             $this->assign('customFiles', $customFiles);
                         }
                     }
                 }
             } else {
                 $fields[$name] = 1;
             }
         }
         CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $defaults);
     }
     return $defaults;
 }
예제 #4
0
 function setDefaultValues()
 {
     if (!$this->_donorID) {
         return;
     }
     foreach ($this->_fields as $name => $dontcare) {
         $fields[$name] = 1;
     }
     require_once "CRM/Core/BAO/UFGroup.php";
     CRM_Core_BAO_UFGroup::setProfileDefaults($this->_donorID, $fields, $this->_defaults);
     //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);
             }
         }
     }
     return $this->_defaults;
 }
 /**
  * Set default values for the form. For edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public 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 && !empty($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');
             $defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
         }
     }
     if ($this->_priceSetId) {
         foreach ($this->_feeBlock as $key => $val) {
             if (empty($val['options'])) {
                 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.
     CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
     //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-17865 set custom field defaults
     if (!empty($this->_fields)) {
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 if (!isset($defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     return $defaults;
 }
예제 #6
0
 /**
  * Set default values for the form.
  */
 public function setDefaultValues()
 {
     $this->_defaults = array();
     if (!$this->_allowConfirmation && $this->_requireApproval) {
         $this->_defaults['bypass_payment'] = 1;
     }
     $contactID = $this->getContactID();
     CRM_Core_Payment_Form::setDefaultValues($this, $contactID);
     CRM_Event_BAO_Participant::formatFieldsAndSetProfileDefaults($contactID, $this);
     // Set default payment processor as default payment_processor radio button value
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $pid => $value) {
             if (!empty($value['is_default'])) {
                 $this->_defaults['payment_processor_id'] = $pid;
             }
         }
     }
     //if event is monetary and pay later is enabled and payment
     //processor is not available then freeze the pay later checkbox with
     //default check
     if (!empty($this->_values['event']['is_pay_later']) && !is_array($this->_paymentProcessor)) {
         $this->_defaults['is_pay_later'] = 1;
     }
     //set custom field defaults
     if (!empty($this->_fields)) {
         //load default campaign from page.
         if (array_key_exists('participant_campaign_id', $this->_fields)) {
             $this->_defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
         }
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 // fix for CRM-1743
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, NULL, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     //fix for CRM-3088, default value for discount set.
     $discountId = NULL;
     if (!empty($this->_values['discount'])) {
         $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
         if ($discountId) {
             if (isset($this->_values['event']['default_discount_fee_id'])) {
                 $discountKey = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_values['event']['default_discount_fee_id'], 'weight', 'id');
                 $this->_defaults['amount'] = key(array_slice($this->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
             }
         }
     }
     // add this event's default participant role to defaults array
     // (for cases where participant_role field is included in form via profile)
     if ($this->_values['event']['default_role_id']) {
         $this->_defaults['participant_role'] = $this->_defaults['participant_role_id'] = $this->_values['event']['default_role_id'];
     }
     if ($this->_priceSetId && !empty($this->_feeBlock)) {
         foreach ($this->_feeBlock as $key => $val) {
             if (empty($val['options'])) {
                 continue;
             }
             $optionFullIds = CRM_Utils_Array::value('option_full_ids', $val, array());
             foreach ($val['options'] as $keys => $values) {
                 if ($values['is_default'] && empty($values['is_full'])) {
                     if ($val['html_type'] == 'CheckBox') {
                         $this->_defaults["price_{$key}"][$keys] = 1;
                     } else {
                         $this->_defaults["price_{$key}"] = $keys;
                     }
                 }
             }
             $unsetSubmittedOptions[$val['id']] = $optionFullIds;
         }
         //reset values for all options those are full.
         CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
     }
     //set default participant fields, CRM-4320.
     $hasAdditionalParticipants = FALSE;
     if ($this->_allowConfirmation) {
         $this->_contactId = $contactID;
         $this->_discountId = $discountId;
         $forcePayLater = CRM_Utils_Array::value('is_pay_later', $this->_defaults, FALSE);
         $this->_defaults = array_merge($this->_defaults, CRM_Event_Form_EventFees::setDefaultValues($this));
         $this->_defaults['is_pay_later'] = $forcePayLater;
         if ($this->_additionalParticipantIds) {
             $hasAdditionalParticipants = TRUE;
             $this->_defaults['additional_participants'] = count($this->_additionalParticipantIds);
         }
     }
     $this->assign('hasAdditionalParticipants', $hasAdditionalParticipants);
     //         //hack to simplify credit card entry for testing
     //         $this->_defaults['credit_card_type']     = 'Visa';
     //         $this->_defaults['credit_card_number']   = '4807731747657838';
     //         $this->_defaults['cvv2']                 = '000';
     //         $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2010', 'M' => '05' );
     // to process Custom data that are appended to URL
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution', 'Participant'");
     if (!empty($getDefaults)) {
         $this->_defaults = array_merge($this->_defaults, $getDefaults);
     }
     return $this->_defaults;
 }
예제 #7
0
파일: Form.php 프로젝트: ksecor/civicrm
 /** 
  * This function sets the default values for the form. Note that in edit/view mode 
  * the default values are retrieved from the database 
  *  
  * @access public 
  * @return void 
  */
 function setDefaultsValues()
 {
     $this->_defaults = array();
     if ($this->_id) {
         CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, true);
     }
     //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)) {
             $htmlType = $field['html_type'];
             if (!CRM_Utils_Array::value($name, $this->_defaults) || $htmlType == 'File') {
                 CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode);
             }
             if ($htmlType == 'File') {
                 $url = CRM_Core_BAO_CustomField::getFileURL($this->_id, $customFieldID);
                 if ($url) {
                     $customFiles[$field['name']]['displayURL'] = "Attached File : {$url['file_url']}";
                     $deleteExtra = "Are you sure you want to delete attached file ?";
                     $fileId = $url['file_id'];
                     $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$this->_id}&fid={$customFieldID}&action=delete");
                     $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&amp;confirmed=1'; else return false;\">Delete Attached File</a>";
                 }
             }
         }
     }
     if (isset($customFiles)) {
         $this->assign('customFiles', $customFiles);
     }
     $this->setDefaults($this->_defaults);
 }
예제 #8
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;
 }
예제 #9
0
 /**
  * Set default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  *
  * @return void
  */
 public function setDefaultsValues()
 {
     $this->_defaults = array();
     if ($this->_multiRecordProfile && $this->_multiRecord == CRM_Core_Action::DELETE) {
         return;
     }
     if ($this->_mode != self::MODE_SEARCH) {
         // set default values for country / state to start with
         CRM_Core_BAO_UFGroup::setRegisterDefaults($this->_fields, $this->_defaults);
     }
     if ($this->_id && !$this->_multiRecordProfile) {
         if ($this->_isContactActivityProfile) {
             $contactFields = $activityFields = array();
             foreach ($this->_fields as $fieldName => $field) {
                 if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
                     $activityFields[$fieldName] = $field;
                 } else {
                     $contactFields[$fieldName] = $field;
                 }
             }
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $contactFields, $this->_defaults, TRUE);
             if ($this->_activityId) {
                 CRM_Core_BAO_UFGroup::setComponentDefaults($activityFields, $this->_activityId, 'Activity', $this->_defaults, TRUE);
             }
         } else {
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, TRUE);
         }
     }
     //set custom field defaults
     if ($this->_multiRecordProfile) {
         foreach ($this->_multiRecordFields as $key => $field) {
             $fieldIds[] = CRM_Core_BAO_CustomField::getKeyID($key);
         }
         $defaultValues = array();
         if ($this->_multiRecord && $this->_multiRecord == CRM_Core_Action::UPDATE) {
             $defaultValues = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_id, NULL, $fieldIds, TRUE);
             if ($this->_recordExists == TRUE) {
                 $defaultValues = $defaultValues[$this->_recordId];
             } else {
                 $defaultValues = NULL;
             }
         }
         if (!empty($defaultValues)) {
             foreach ($defaultValues as $key => $value) {
                 $name = "custom_{$key}";
                 $htmlType = $this->_multiRecordFields[$name]['html_type'];
                 if ($htmlType != 'File') {
                     if (isset($value)) {
                         CRM_Core_BAO_CustomField::setProfileDefaults($key, $name, $this->_defaults, $this->_id, $this->_mode, $value);
                     } else {
                         $this->_defaults[$name] = "";
                     }
                 }
                 if ($htmlType == 'File') {
                     $entityId = $this->_id;
                     if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) {
                         $entityId = $this->_activityId;
                     }
                     $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $key);
                     if ($url) {
                         $customFiles[$name]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
                         $deleteExtra = ts("Are you sure you want to delete attached file?");
                         $fileId = $url['file_id'];
                         $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$key}&action=delete");
                         $text = ts("Delete Attached File");
                         $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&amp;confirmed=1'; else return false;\">{$text}</a>";
                         // also delete the required rule that we've set on the form element
                         $this->removeFileRequiredRules($name);
                     }
                 }
             }
         }
     } else {
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 $htmlType = $field['html_type'];
                 if ((!isset($this->_defaults[$name]) || $htmlType == 'File') && CRM_Utils_Array::value('field_type', $field) != 'Activity') {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode);
                 }
                 if ($htmlType == 'File') {
                     $entityId = $this->_id;
                     if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) {
                         $entityId = $this->_activityId;
                     }
                     $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $customFieldID);
                     if ($url) {
                         $customFiles[$field['name']]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
                         $deleteExtra = ts("Are you sure you want to delete attached file?");
                         $fileId = $url['file_id'];
                         $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$customFieldID}&action=delete");
                         $text = ts("Delete Attached File");
                         $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&amp;confirmed=1'; else return false;\">{$text}</a>";
                         // also delete the required rule that we've set on the form element
                         $this->removeFileRequiredRules($field['name']);
                     }
                 }
             }
         }
     }
     if (isset($customFiles)) {
         $this->assign('customFiles', $customFiles);
     }
     if ($this->_multiRecordProfile) {
         $this->setDefaults($this->_defaults);
         return;
     }
     if (!empty($this->_defaults['image_URL'])) {
         list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String::unstupifyUrl($this->_defaults['image_URL']));
         list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
         $this->assign("imageWidth", $imageWidth);
         $this->assign("imageHeight", $imageHeight);
         $this->assign("imageThumbWidth", $imageThumbWidth);
         $this->assign("imageThumbHeight", $imageThumbHeight);
         $this->assign("imageURL", $this->_defaults['image_URL']);
         $this->removeFileRequiredRules('image_URL');
     }
     if (array_key_exists('contact_sub_type', $this->_defaults) && !empty($this->_defaults['contact_sub_type'])) {
         $this->_defaults['contact_sub_type'] = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($this->_defaults['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR));
     }
     $this->setDefaults($this->_defaults);
 }
예제 #10
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;
 }
예제 #11
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;
 }
예제 #12
0
 /**
  * This function sets the default values for the form.
  *
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     require_once 'CRM/Core/BAO/UFGroup.php';
     $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
     require_once "CRM/Core/BAO/CustomField.php";
     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);
 }
예제 #13
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 function setDefaultValues()
 {
     //set default values for applicaiton profile fields
     $profileFields = CRM_Core_BAO_UFGroup::getFields($this->_profileID);
     $contactID = $this->_contactID;
     if ($contactID) {
         $options = array();
         $fields = array();
         if (!empty($this->_fields)) {
             foreach ($this->_fields as $name => $dontCare) {
                 if (substr($name, 0, 7) == 'custom_') {
                     $id = substr($name, 7);
                     continue;
                 }
                 $fields[$name] = 1;
             }
         }
     }
     if (!empty($fields)) {
         CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
     }
     //set custom field defaults
     if (!empty($this->_fields)) {
         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, $contactID, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     return $this->_defaults;
 }
예제 #14
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 function buildQuickForm()
 {
     if ($this->_mode != CRM_PROFILE_FORM_MODE_REGISTER) {
         //check for mix profile (eg:  individual + other contact type)
         require_once "CRM/Core/BAO/UFField.php";
         if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
             CRM_Utils_System::setUFMessage(ts("This Profile includes fields for contact types other than 'Individuals' and can not be used to create/update contacts."));
             $config =& CRM_Core_Config::singleton();
             CRM_Utils_System::redirect($config->userFrameworkBaseURL);
         }
     }
     $this->assign('mode', $this->_mode);
     $this->assign('action', $this->_action);
     $this->assign('fields', $this->_fields);
     $this->assign('fieldset', $this->_fieldset);
     /*  if ($this->_mode & self::MODE_EDIT) {
             $group =& new CRM_Core_DAO_UFGroup();
             $group->id = $this->_gid;
             if ($group->find(true)) {
                 $this->assign('help_pre',  $group->help_pre);
                 $this->assign('help_post', $group->help_post);
             }
         }*/
     // do we need inactive options ?
     if ($this->_action & CRM_CORE_ACTION_VIEW) {
         $inactiveNeeded = true;
     } else {
         $inactiveNeeded = false;
     }
     // should we restrict what we display
     $admin = true;
     if ($this->_mode == CRM_PROFILE_FORM_MODE_EDIT) {
         $admin = false;
         $session =& CRM_Core_Session::singleton();
         // show all fields that are visibile: if we are a admin or the same user or in registration mode
         if (CRM_Utils_System::checkPermission('administer users') || $this->_id == $session->get('userID')) {
             $admin = true;
         }
     }
     require_once "CRM/Contribute/PseudoConstant.php";
     // 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 == CRM_PROFILE_FORM_MODE_REGISTER && substr($name, 0, 5) == 'email') {
             unset($this->_fields[$name]);
             continue;
         }
         $required = $this->_mode == CRM_PROFILE_FORM_MODE_SEARCH ? false : $field['is_required'];
         //if ( $field['name'] === 'state_province' ) {
         if (substr($field['name'], 0, 14) === 'state_province') {
             $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required);
         } else {
             if (substr($field['name'], 0, 7) === 'country') {
                 $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required);
             } else {
                 if ($field['name'] === 'birth_date') {
                     $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('birth'), $required);
                 } else {
                     if ($field['name'] === 'gender') {
                         $genderOptions = array();
                         $gender = CRM_Core_PseudoConstant::gender();
                         foreach ($gender as $key => $var) {
                             $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key);
                         }
                         $this->addGroup($genderOptions, $field['name'], $field['title']);
                         if ($required) {
                             $this->addRule($field['name'], ts('%1 is a required field.', array(1 => $field['title'])), 'required');
                         }
                     } else {
                         if ($field['name'] === 'individual_prefix') {
                             $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required);
                         } else {
                             if ($field['name'] === 'individual_suffix') {
                                 $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required);
                             } else {
                                 if ($field['name'] === 'preferred_communication_method') {
                                     $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_SelectValues::pcm());
                                 } else {
                                     if ($field['name'] === 'preferred_mail_format') {
                                         $this->add('select', $name, $field['title'], CRM_Core_SelectValues::pmf());
                                     } else {
                                         if (substr($field['name'], 0, 3) === 'is_' or substr($field['name'], 0, 7) === 'do_not_') {
                                             $this->add('checkbox', $name, $field['title'], $field['attributes'], $required);
                                         } else {
                                             if ($field['name'] === 'group') {
                                                 require_once 'CRM/Contact/Form/GroupTag.php';
                                                 CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_GROUP, true, $required, $field['title'], null);
                                             } else {
                                                 if ($field['name'] === 'tag') {
                                                     require_once 'CRM/Contact/Form/GroupTag.php';
                                                     CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_TAG, false, $required, null, $field['title']);
                                                 } else {
                                                     if (substr($field['name'], 0, 6) === 'custom') {
                                                         $customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name']);
                                                         CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $customFieldID, $inactiveNeeded, $required, false, $field['title']);
                                                         CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, $this->_id, $this->_mode);
                                                     } else {
                                                         if (in_array($field['name'], array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) {
                                                             $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('manual', 3, 1), $required);
                                                             $this->addRule($field['name'], ts('Select a valid date.'), 'qfDate');
                                                         } else {
                                                             if ($field['name'] == 'payment_instrument') {
                                                                 $this->add('select', 'payment_instrument', ts('Paid By'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
                                                             } else {
                                                                 if ($field['name'] == 'contribution_type') {
                                                                     $this->add('select', 'contribution_type', ts('Contribution Type'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::contributionType(), $required);
                                                                 } else {
                                                                     $this->add('text', $name, $field['title'], $field['attributes'], $required);
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (in_array($field['name'], array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) {
             $this->addRule($field['name'], ts('Please enter a valid amount.'), 'money');
         }
         if ($field['rule']) {
             if ($field['rule'] == 'email' && $this->_mode == CRM_PROFILE_FORM_MODE_SEARCH) {
                 continue;
             } else {
                 $this->addRule($name, ts('Please enter a valid %1', array(1 => $field['title'])), $field['rule']);
             }
         }
     }
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_CORE_ACTION_VIEW) {
         $this->freeze();
     }
     $this->setDefaults($defaults);
 }
예제 #15
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;
 }
예제 #16
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);
 }
 /**
  * @return array
  */
 public 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);
     }
     //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);
             }
         }
     }
     return $this->_defaults;
 }
예제 #18
0
 /**
  * Set default values for the form.
  */
 public 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);
 }
예제 #19
0
 /**
  * Set the default form values
  *
  * @access protected
  * @return array the default array reference
  */
 function &setDefaultValues()
 {
     $defaults = array();
     require_once "CRM/Profile/Form.php";
     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);
         }
     }
     return $defaults;
 }
예제 #20
0
 /**
  * Set the default values.
  */
 public function setDefaultValues()
 {
     // check if the user is registered and we have a contact ID
     $contactID = $this->getContactID();
     if (!empty($contactID)) {
         $fields = array();
         $removeCustomFieldTypes = array('Contribution', 'Membership');
         $contribFields = CRM_Contribute_BAO_Contribution::getContributionFields();
         // remove component related fields
         foreach ($this->_fields as $name => $dontCare) {
             //don't set custom data Used for Contribution (CRM-1344)
             if (substr($name, 0, 7) == 'custom_') {
                 $id = substr($name, 7);
                 if (!CRM_Core_BAO_CustomGroup::checkCustomField($id, $removeCustomFieldTypes)) {
                     continue;
                 }
                 // ignore component fields
             } elseif (array_key_exists($name, $contribFields) || substr($name, 0, 11) == 'membership_' || substr($name, 0, 13) == 'contribution_') {
                 continue;
             }
             $fields[$name] = 1;
         }
         if (!empty($fields)) {
             CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults);
         }
         $billingDefaults = $this->getProfileDefaults('Billing', $contactID);
         $this->_defaults = array_merge($this->_defaults, $billingDefaults);
     }
     if (!empty($this->_ccid) && !empty($this->_pendingAmount)) {
         $this->_defaults['total_amount'] = CRM_Utils_Money::format($this->_pendingAmount, NULL, '%a');
     }
     /*
      * hack to simplify credit card entry for testing
      *
      * $this->_defaults['credit_card_type']     = 'Visa';
      *         $this->_defaults['amount']               = 168;
      *         $this->_defaults['credit_card_number']   = '4111111111111111';
      *         $this->_defaults['cvv2']                 = '000';
      *         $this->_defaults['credit_card_exp_date'] = array('Y' => date('Y')+1, 'M' => '05');
      *         // hack to simplify direct debit entry for testing
      *         $this->_defaults['account_holder'] = 'Max Müller';
      *         $this->_defaults['bank_account_number'] = '12345678';
      *         $this->_defaults['bank_identification_number'] = '12030000';
      *         $this->_defaults['bank_name'] = 'Bankname';
      */
     //build set default for pledge overdue payment.
     if (!empty($this->_values['pledge_id'])) {
         //used to record completed pledge payment ids used later for honor default
         $completedContributionIds = array();
         $pledgePayments = CRM_Pledge_BAO_PledgePayment::getPledgePayments($this->_values['pledge_id']);
         $paymentAmount = 0;
         $duePayment = FALSE;
         foreach ($pledgePayments as $payId => $value) {
             if ($value['status'] == 'Overdue') {
                 $this->_defaults['pledge_amount'][$payId] = 1;
                 $paymentAmount += $value['scheduled_amount'];
             } elseif (!$duePayment && $value['status'] == 'Pending') {
                 $this->_defaults['pledge_amount'][$payId] = 1;
                 $paymentAmount += $value['scheduled_amount'];
                 $duePayment = TRUE;
             } elseif ($value['status'] == 'Completed' && $value['contribution_id']) {
                 $completedContributionIds[] = $value['contribution_id'];
             }
         }
         $this->_defaults['price_' . $this->_priceSetId] = $paymentAmount;
         if (count($completedContributionIds)) {
             $softCredit = array();
             foreach ($completedContributionIds as $id) {
                 $softCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($id);
             }
             if (isset($softCredit['soft_credit'])) {
                 $this->_defaults['soft_credit_type_id'] = $softCredit['soft_credit'][1]['soft_credit_type'];
                 //since honoree profile fieldname of fields are prefixed with 'honor'
                 //we need to reformat the fieldname to append prefix during setting default values
                 CRM_Core_BAO_UFGroup::setProfileDefaults($softCredit['soft_credit'][1]['contact_id'], CRM_Core_BAO_UFGroup::getFields($this->_honoreeProfileId), $defaults);
                 foreach ($defaults as $fieldName => $value) {
                     $this->_defaults['honor[' . $fieldName . ']'] = $value;
                 }
             }
         }
     } elseif (!empty($this->_values['pledge_block_id'])) {
         //set default to one time contribution.
         $this->_defaults['is_pledge'] = 0;
     }
     // to process Custom data that are appended to URL
     $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution'");
     $this->_defaults = array_merge($this->_defaults, $getDefaults);
     $config = CRM_Core_Config::singleton();
     // set default country from config if no country set
     if (empty($this->_defaults["billing_country_id-{$this->_bltID}"])) {
         $this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry;
     }
     // set default state/province from config if no state/province set
     if (empty($this->_defaults["billing_state_province_id-{$this->_bltID}"])) {
         $this->_defaults["billing_state_province_id-{$this->_bltID}"] = $config->defaultContactStateProvince;
     }
     $entityId = $memtypeID = NULL;
     if ($this->_priceSetId) {
         if ($this->_useForMember && !empty($this->_currentMemberships) || $this->_defaultMemTypeId) {
             $selectedCurrentMemTypes = array();
             foreach ($this->_priceSet['fields'] as $key => $val) {
                 foreach ($val['options'] as $keys => $values) {
                     $opMemTypeId = CRM_Utils_Array::value('membership_type_id', $values);
                     $priceFieldName = 'price_' . $values['price_field_id'];
                     $priceFieldValue = CRM_Price_BAO_PriceSet::getPriceFieldValueFromURL($this, $priceFieldName);
                     if (!empty($priceFieldValue)) {
                         CRM_Price_BAO_PriceSet::setDefaultPriceSetField($priceFieldName, $priceFieldValue, $val['html_type'], $this->_defaults);
                         // break here to prevent overwriting of default due to 'is_default'
                         // option configuration or setting of current membership or
                         // membership for related organization.
                         // The value sent via URL get's higher priority.
                         break;
                     } elseif ($opMemTypeId && in_array($opMemTypeId, $this->_currentMemberships) && !in_array($opMemTypeId, $selectedCurrentMemTypes)) {
                         CRM_Price_BAO_PriceSet::setDefaultPriceSetField($priceFieldName, $keys, $val['html_type'], $this->_defaults);
                         $memtypeID = $selectedCurrentMemTypes[] = $values['membership_type_id'];
                     } elseif (!empty($values['is_default']) && !$opMemTypeId && (!isset($this->_defaults[$priceFieldName]) || $val['html_type'] == 'CheckBox' && !isset($this->_defaults[$priceFieldName][$keys]))) {
                         CRM_Price_BAO_PriceSet::setDefaultPriceSetField($priceFieldName, $keys, $val['html_type'], $this->_defaults);
                         $memtypeID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_defaults[$priceFieldName], 'membership_type_id');
                     }
                 }
             }
             $entityId = CRM_Utils_Array::value('id', CRM_Member_BAO_Membership::getContactMembership($contactID, $memtypeID, NULL));
         } else {
             CRM_Price_BAO_PriceSet::setDefaultPriceSet($this, $this->_defaults);
         }
     }
     //set custom field defaults set by admin if value is not set
     if (!empty($this->_fields)) {
         //load default campaign from page.
         if (array_key_exists('contribution_campaign_id', $this->_fields)) {
             $this->_defaults['contribution_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values);
         }
         //set custom field defaults
         foreach ($this->_fields as $name => $field) {
             if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
                 if (!isset($this->_defaults[$name])) {
                     CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $entityId, CRM_Profile_Form::MODE_REGISTER);
                 }
             }
         }
     }
     if (!empty($this->_paymentProcessors)) {
         foreach ($this->_paymentProcessors as $pid => $value) {
             if (!empty($value['is_default'])) {
                 $this->_defaults['payment_processor_id'] = $pid;
             }
         }
     }
     return $this->_defaults;
 }
예제 #21
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return void
  */
 function setDefaultsValues()
 {
     $this->_defaults = array();
     if ($this->_id) {
         if ($this->_isContactActivityProfile) {
             $contactFields = $activityFields = array();
             foreach ($this->_fields as $fieldName => $field) {
                 if (CRM_Utils_Array::value('field_type', $field) == 'Activity') {
                     $activityFields[$fieldName] = $field;
                 } else {
                     $contactFields[$fieldName] = $field;
                 }
             }
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $contactFields, $this->_defaults, TRUE);
             if ($this->_activityId) {
                 CRM_Core_BAO_UFGroup::setComponentDefaults($activityFields, $this->_activityId, 'Activity', $this->_defaults, TRUE);
             }
         } else {
             CRM_Core_BAO_UFGroup::setProfileDefaults($this->_id, $this->_fields, $this->_defaults, TRUE);
         }
     }
     //set custom field defaults
     foreach ($this->_fields as $name => $field) {
         if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
             $htmlType = $field['html_type'];
             if ((!isset($this->_defaults[$name]) || $htmlType == 'File') && CRM_Utils_Array::value('field_type', $field) != 'Activity') {
                 CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults, $this->_id, $this->_mode);
             }
             if ($htmlType == 'File') {
                 $entityId = $this->_id;
                 if (CRM_Utils_Array::value('field_type', $field) == 'Activity' && $this->_activityId) {
                     $entityId = $this->_activityId;
                 }
                 $url = CRM_Core_BAO_CustomField::getFileURL($entityId, $customFieldID);
                 if ($url) {
                     $customFiles[$field['name']]['displayURL'] = ts("Attached File") . ": {$url['file_url']}";
                     $deleteExtra = ts("Are you sure you want to delete attached file?");
                     $fileId = $url['file_id'];
                     $deleteURL = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$entityId}&fid={$customFieldID}&action=delete");
                     $text = ts("Delete Attached File");
                     $customFiles[$field['name']]['deleteURL'] = "<a href=\"{$deleteURL}\" onclick = \"if (confirm( ' {$deleteExtra} ' )) this.href+='&amp;confirmed=1'; else return false;\">{$text}</a>";
                     // also delete the required rule that we've set on the form element
                     $this->removeFileRequiredRules($field['name']);
                 }
             }
         }
     }
     if (isset($customFiles)) {
         $this->assign('customFiles', $customFiles);
     }
     if (CRM_Utils_Array::value('image_URL', $this->_defaults)) {
         list($imageWidth, $imageHeight) = getimagesize($this->_defaults['image_URL']);
         list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact::getThumbSize($imageWidth, $imageHeight);
         $this->assign("imageWidth", $imageWidth);
         $this->assign("imageHeight", $imageHeight);
         $this->assign("imageThumbWidth", $imageThumbWidth);
         $this->assign("imageThumbHeight", $imageThumbHeight);
         $this->assign("imageURL", $this->_defaults['image_URL']);
     }
     if (array_key_exists('contact_sub_type', $this->_defaults) && !empty($this->_defaults['contact_sub_type'])) {
         $this->_defaults['contact_sub_type'] = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($this->_defaults['contact_sub_type'], CRM_Core_DAO::VALUE_SEPARATOR));
     }
     $this->setDefaults($this->_defaults);
 }