/** * 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; }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Core_BAO_UFField::retrieve($params, $defaults); // set it to null if so (avoids crappy E_NOTICE errors below $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults); $specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'county', 'phone', 'email', 'im', 'address_name'); if (!$defaults['location_type_id'] && in_array($defaults['field_name'], $specialFields)) { $defaults['location_type_id'] = 0; } $defaults['field_name'] = array($defaults['field_type'], $defaults['field_name'], $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults)); $this->_gid = $defaults['uf_group_id']; } else { $defaults['is_active'] = 1; } if ($this->_action & CRM_Core_Action::ADD) { $fieldValues = array('uf_group_id' => $this->_gid); $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues); } // lets trim all the whitespace $this->applyFilter('__ALL__', 'trim'); //hidden field to catch the group id in profile $this->add('hidden', 'group_id', $this->_gid); //hidden field to catch the field id in profile $this->add('hidden', 'field_id', $this->_id); $fields = array(); $fields['Individual'] =& CRM_Contact_BAO_Contact::importableFields('Individual', false, false, true); $fields['Household'] =& CRM_Contact_BAO_Contact::importableFields('Household', false, false, true); $fields['Organization'] =& CRM_Contact_BAO_Contact::importableFields('Organization', false, false, true); // add current employer for individuals $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer')); // unset unwanted fields $unsetFieldArray = array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id'); foreach ($unsetFieldArray as $value) { unset($fields['Individual'][$value]); unset($fields['Household'][$value]); unset($fields['Organization'][$value]); } require_once 'CRM/Core/BAO/Preferences.php'; $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true); if (!$addressOptions['county']) { unset($fields['Individual']['county']); unset($fields['Household']['county']); unset($fields['Organization']['county']); } //build the common contact fields array CRM-3037. foreach ($fields['Individual'] as $key => $value) { if (CRM_Utils_Array::value($key, $fields['Household']) && CRM_Utils_Array::value($key, $fields['Organization'])) { $fields['Contact'][$key] = $value; //as we move common fields to contacts. There fore these fields //are unset from resoective array's. unset($fields['Individual'][$key]); unset($fields['Household'][$key]); unset($fields['Organization'][$key]); } } // add current employer for individuals $fields['Contact']['id'] = array('name' => 'id', 'title' => ts('Internal Contact ID')); unset($fields['Contact']['contact_type']); // since we need a hierarchical list to display contact types & subtypes, // this is what we going to display in first selector $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(false, false); unset($contactTypes['']); // include Subtypes For Profile $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); foreach ($subTypes as $name => $val) { //custom fields for sub type $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name); if (array_key_exists($val['parent'], $fields)) { $fields[$name] = $fields[$val['parent']] + $subTypeFields; } else { $fields[$name] = $subTypeFields; } } unset($subTypes); if (CRM_Core_Permission::access('Quest')) { require_once 'CRM/Quest/BAO/Student.php'; $fields['Student'] =& CRM_Quest_BAO_Student::exportableFields(); } if (CRM_Core_Permission::access('CiviContribute')) { $contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields(); if (!empty($contribFields)) { unset($contribFields['is_test']); unset($contribFields['is_pay_later']); unset($contribFields['contribution_id']); $fields['Contribution'] =& $contribFields; } } if (CRM_Core_Permission::access('CiviEvent')) { require_once 'CRM/Event/BAO/Query.php'; $participantFields =& CRM_Event_BAO_Query::getParticipantFields(true); if (!empty($participantFields)) { unset($participantFields['external_identifier']); unset($participantFields['event_id']); unset($participantFields['participant_contact_id']); unset($participantFields['participant_is_test']); unset($participantFields['participant_fee_level']); unset($participantFields['participant_id']); unset($participantFields['participant_is_pay_later']); $fields['Participant'] =& $participantFields; } } if (CRM_Core_Permission::access('CiviMember')) { require_once 'CRM/Member/BAO/Membership.php'; $membershipFields =& CRM_Member_BAO_Membership::getMembershipFields(); unset($membershipFields['membership_id']); unset($membershipFields['join_date']); unset($membershipFields['membership_start_date']); unset($membershipFields['membership_type_id']); unset($membershipFields['membership_end_date']); unset($membershipFields['member_is_test']); unset($membershipFields['is_override']); unset($membershipFields['status_id']); unset($membershipFields['member_is_pay_later']); $fields['Membership'] =& $membershipFields; } $noSearchable = array(); foreach ($fields as $key => $value) { foreach ($value as $key1 => $value1) { //CRM-2676, replacing the conflict for same custom field name from different custom group. require_once 'CRM/Core/BAO/CustomField.php'; if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) { $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id'); $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title'); $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName; } else { $this->_mapperFields[$key][$key1] = $value1['title']; } $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1); // hide the 'is searchable' field for 'File' custom data if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) { if (!in_array($value1['title'], $noSearchable)) { $noSearchable[] = $value1['title']; } } } } $this->assign('noSearchable', $noSearchable); require_once 'CRM/Core/BAO/LocationType.php'; $this->_location_types =& CRM_Core_PseudoConstant::locationType(); $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault(); /* FIXME: dirty hack to make the default option show up first. This * avoids a mozilla browser bug with defaults on dynamically constructed * selector widgets. */ if ($defaultLocationType) { $defaultLocation = $this->_location_types[$defaultLocationType->id]; unset($this->_location_types[$defaultLocationType->id]); $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types; } $this->_location_types = array('Primary') + $this->_location_types; $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array(); $sel1 = array('' => '- select -') + $contactTypes; if (CRM_Core_Permission::access('Quest')) { $sel1['Student'] = 'Students'; } if (CRM_Core_Permission::access('CiviEvent')) { $sel1['Participant'] = 'Participants'; } if (!empty($contribFields)) { $sel1['Contribution'] = 'Contributions'; } if (!empty($membershipFields)) { $sel1['Membership'] = 'Membership'; } foreach ($sel1 as $key => $sel) { if ($key) { $sel2[$key] = $this->_mapperFields[$key]; } } $sel3[''] = null; $phoneTypes = CRM_Core_PseudoConstant::phoneType(); ksort($phoneTypes); foreach ($sel1 as $k => $sel) { if ($k) { foreach ($this->_location_types as $key => $value) { $sel4[$k]['phone'][$key] =& $phoneTypes; } } } foreach ($sel1 as $k => $sel) { if ($k) { if (is_array($this->_mapperFields[$k])) { foreach ($this->_mapperFields[$k] as $key => $value) { if ($hasLocationTypes[$k][$key]) { $sel3[$k][$key] = $this->_location_types; } else { $sel3[$key] = null; } } } } } $this->_defaults = array(); $js = "<script type='text/javascript'>\n"; $formName = "document.{$this->_name}"; $alreadyMixProfile = false; if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) { $alreadyMixProfile = true; } $this->assign('alreadyMixProfile', $alreadyMixProfile); $attributes = array('onclick' => "showLabel();mixProfile();", 'onblur' => 'showLabel();mixProfile();'); $sel =& $this->addElement('hierselect', "field_name", ts('Field Name'), $attributes); $formValues = array(); $formValues = $this->exportValues(); if (empty($formValues)) { for ($k = 1; $k < 4; $k++) { if (!$defaults['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } else { if (!empty($formValues['field_name'])) { foreach ($formValues['field_name'] as $value) { for ($k = 1; $k < 4; $k++) { if (!isset($formValues['field_name'][$k]) || !$formValues['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } else { $js .= "{$formName}['field_name[{$k}]'].style.display = '';\n"; } } } } else { for ($k = 1; $k < 4; $k++) { if (!isset($defaults['field_name'][$k])) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } } foreach ($sel2 as $k => $v) { if (is_array($sel2[$k])) { asort($sel2[$k]); } } $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); $js .= "</script>\n"; $this->assign('initHideBoxes', $js); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true, array("onChange" => "showHideSeletorSearch(this.value);")); //CRM-4363 $js = array('onclick' => "mixProfile();"); // should the field appear in selectors (as a column)? $this->add('checkbox', 'in_selector', ts('Results Column?'), null, null, $js); $this->add('checkbox', 'is_searchable', ts('Searchable?'), null, null, $js); // weight $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'weight'), true); $this->addRule('weight', ts('is a numeric field'), 'numeric'); $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'help_post')); // listings title $this->add('text', 'listings_title', ts('Listings Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'listings_title')); $this->addRule('listings_title', ts('Please enter a valid title for this field when displayed in user listings.'), 'title'); $this->add('checkbox', 'is_required', ts('Required?')); $this->add('checkbox', 'is_active', ts('Active?')); $this->add('checkbox', 'is_view', ts('View Only?')); // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) ); //$this->add( 'checkbox', 'is_match' , ts( 'Key to Match Contacts?' ) ); $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'label')); $js = null; if ($this->_hasSearchableORInSelector) { $js = array('onclick' => "return verify( );"); } // add buttons $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel')))); $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this); // if view mode pls freeze it with the done button. if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'")); } $this->setDefaults($defaults); }
/** * Get a list of fields which can be added to profiles. * * @param int $gid : UF group ID * @param array $defaults : Form defaults * @return array, multidimensional; e.g. $result['FieldGroup']['field_name']['label'] */ public static function getAvailableFields($gid = NULL, $defaults = array()) { $fields = array('Contact' => array(), 'Individual' => CRM_Contact_BAO_Contact::importableFields('Individual', FALSE, FALSE, TRUE, TRUE, TRUE), 'Household' => CRM_Contact_BAO_Contact::importableFields('Household', FALSE, FALSE, TRUE, TRUE, TRUE), 'Organization' => CRM_Contact_BAO_Contact::importableFields('Organization', FALSE, FALSE, TRUE, TRUE, TRUE)); // include hook injected fields $fields['Contact'] = array_merge($fields['Contact'], CRM_Contact_BAO_Query_Hook::singleton()->getFields()); // add current employer for individuals $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer')); $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); if (!$addressOptions['county']) { unset($fields['Individual']['county'], $fields['Household']['county'], $fields['Organization']['county']); } // break out common contact fields array CRM-3037. // from a UI perspective this makes very little sense foreach ($fields['Individual'] as $key => $value) { if (!empty($fields['Household'][$key]) && !empty($fields['Organization'][$key])) { $fields['Contact'][$key] = $value; unset($fields['Individual'][$key], $fields['Household'][$key], $fields['Organization'][$key]); } } // Internal field not exposed to forms unset($fields['Contact']['contact_type']); unset($fields['Contact']['master_id']); // convert phone extension in to psedo-field phone + phone extension //unset extension unset($fields['Contact']['phone_ext']); //add psedo field $fields['Contact']['phone_and_ext'] = array('name' => 'phone_and_ext', 'title' => ts('Phone and Extension'), 'hasLocationType' => 1); // include Subtypes For Profile $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); foreach ($subTypes as $name => $val) { //custom fields for sub type $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name, FALSE, FALSE, FALSE, TRUE, TRUE); if (array_key_exists($val['parent'], $fields)) { $fields[$name] = $fields[$val['parent']] + $subTypeFields; } else { $fields[$name] = $subTypeFields; } } if (CRM_Core_Permission::access('CiviContribute')) { $contribFields = CRM_Contribute_BAO_Contribution::getContributionFields(FALSE); if (!empty($contribFields)) { unset($contribFields['is_test']); unset($contribFields['is_pay_later']); unset($contribFields['contribution_id']); $contribFields['contribution_note'] = array('name' => 'contribution_note', 'title' => ts('Contribution Note')); $fields['Contribution'] = array_merge($contribFields, self::getContribBatchEntryFields()); } } if (CRM_Core_Permission::access('CiviEvent')) { $participantFields = CRM_Event_BAO_Query::getParticipantFields(); if ($participantFields) { // Remove fields not supported by profiles CRM_Utils_Array::remove($participantFields, 'external_identifier', 'event_id', 'participant_contact_id', 'participant_role_id', 'participant_status_id', 'participant_is_test', 'participant_fee_level', 'participant_id', 'participant_is_pay_later', 'participant_campaign'); if (isset($participantFields['participant_campaign_id'])) { $participantFields['participant_campaign_id']['title'] = ts('Campaign'); } $fields['Participant'] = $participantFields; } } if (CRM_Core_Permission::access('CiviMember')) { $membershipFields = CRM_Member_BAO_Membership::getMembershipFields(); // Remove fields not supported by profiles CRM_Utils_Array::remove($membershipFields, 'membership_id', 'membership_type_id', 'member_is_test', 'is_override', 'status_id', 'member_is_pay_later'); if ($gid && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'name') == 'membership_batch_entry') { $fields['Membership'] = array_merge($membershipFields, self::getMemberBatchEntryFields()); } else { $fields['Membership'] = $membershipFields; } } if (CRM_Core_Permission::access('CiviCase')) { $caseFields = CRM_Case_BAO_Query::getFields(TRUE); $caseFields = array_merge($caseFields, CRM_Core_BAO_CustomField::getFieldsForImport('Case')); if ($caseFields) { // Remove fields not supported by profiles CRM_Utils_Array::remove($caseFields, 'case_id', 'case_type', 'case_start_date', 'case_end_date', 'case_role', 'case_status', 'case_deleted'); } $fields['Case'] = $caseFields; } $activityFields = CRM_Activity_BAO_Activity::getProfileFields(); if ($activityFields) { // campaign related fields. if (isset($activityFields['activity_campaign_id'])) { $activityFields['activity_campaign_id']['title'] = ts('Campaign'); } $fields['Activity'] = $activityFields; } $fields['Formatting']['format_free_html_' . rand(1000, 9999)] = array('name' => 'free_html', 'import' => FALSE, 'export' => FALSE, 'title' => 'Free HTML'); // Sort by title foreach ($fields as &$values) { $values = CRM_Utils_Array::crmArraySortByField($values, 'title'); } //group selected and unwanted fields list $ufFields = $gid ? CRM_Core_BAO_UFGroup::getFields($gid, FALSE, NULL, NULL, NULL, TRUE, NULL, TRUE) : array(); $groupFieldList = array_merge($ufFields, array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id')); //unset selected fields foreach ($groupFieldList as $key => $value) { if (is_int($key)) { unset($fields['Individual'][$value], $fields['Household'][$value], $fields['Organization'][$value]); continue; } if (!empty($defaults['field_name']) && $defaults['field_name']['0'] == $value['field_type'] && $defaults['field_name']['1'] == $key) { continue; } unset($fields[$value['field_type']][$key]); } return $fields; }
/** * Browse all CiviCRM Profile group fields. * * @return void * @access public * @static */ function browse() { $ufField = array(); $ufFieldBAO = new CRM_Core_BAO_UFField(); // fkey is gid $ufFieldBAO->uf_group_id = $this->_gid; $ufFieldBAO->orderBy('weight', 'field_name'); $ufFieldBAO->find(); require_once "CRM/Core/BAO/UFField.php"; $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid); if ($profileType == 'Contribution' || $profileType == 'Membership' || $profileType == 'Activity' || $profileType == 'Participant') { $this->assign('skipCreate', true); } $locationType = array(); $locationType =& CRM_Core_PseudoConstant::locationType(); require_once 'CRM/Contact/BAO/Contact.php'; $fields =& CRM_Contact_BAO_Contact::exportableFields('All', false, true); require_once "CRM/Contribute/BAO/Contribution.php"; $fields = array_merge(CRM_Contribute_BAO_Contribution::getContributionFields(), $fields); if (CRM_Core_Permission::access('Quest')) { require_once 'CRM/Quest/BAO/Student.php'; $fields = array_merge(CRM_Quest_BAO_Student::exportableFields(), $fields); } $select = array(); foreach ($fields as $name => $field) { if ($name) { $select[$name] = $field['title']; } } $select['group'] = ts('Group(s)'); $select['tag'] = ts('Tag(s)'); while ($ufFieldBAO->fetch()) { $ufField[$ufFieldBAO->id] = array(); $phoneType = $locType = ''; CRM_Core_DAO::storeValues($ufFieldBAO, $ufField[$ufFieldBAO->id]); CRM_Core_DAO_UFField::addDisplayEnums($ufField[$ufFieldBAO->id]); $ufField[$ufFieldBAO->id]['label'] = $ufFieldBAO->label; $action = array_sum(array_keys($this->actionLinks())); if ($ufFieldBAO->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } if ($ufFieldBAO->is_reserved) { $action -= CRM_Core_Action::UPDATE; $action -= CRM_Core_Action::DISABLE; $action -= CRM_Core_Action::DELETE; } $ufField[$ufFieldBAO->id]['order'] = $ufField[$ufFieldBAO->id]['weight']; $ufField[$ufFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $ufFieldBAO->id, 'gid' => $this->_gid)); } $returnURL = CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}"); $filter = "uf_group_id = {$this->_gid}"; require_once 'CRM/Utils/Weight.php'; CRM_Utils_Weight::addOrder($ufField, 'CRM_Core_DAO_UFField', 'id', $returnURL, $filter); $this->assign('ufField', $ufField); // retrieve showBestResult from session $session = CRM_Core_Session::singleton(); $showBestResult = $session->get('showBestResult'); $this->assign('showBestResult', $showBestResult); $session->set('showBestResult', 0); }
/** * Function to actually build the form * * @return void * @access public */ function buildQuickForm() { if ($this->_action & CRM_CORE_ACTION_DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Core_BAO_UFField::retrieve($params, $defaults); $defaults['field_name'] = array($defaults['field_type'], $defaults['field_name'], $defaults['location_type_id'], $defaults['phone_type']); $this->_gid = $defaults['uf_group_id']; } else { $defaults['is_active'] = 1; } if ($this->_action & CRM_CORE_ACTION_ADD) { $uf =& new CRM_Core_DAO(); $sql = "SELECT weight FROM civicrm_uf_field WHERE uf_group_id = " . $this->_gid . " ORDER BY weight DESC LIMIT 0, 1"; $uf->query($sql); while ($uf->fetch()) { $defaults['weight'] = $uf->weight + 1; } if (empty($defaults['weight'])) { $defaults['weight'] = 1; } } // lets trim all the whitespace $this->applyFilter('__ALL__', 'trim'); //hidden field to catch the group id in profile $this->add('hidden', 'group_id', $this->_gid); //hidden field to catch the field id in profile $this->add('hidden', 'field_id', $this->_id); $fields = array(); $fields['Individual'] =& CRM_Contact_BAO_Contact::exportableFields('Individual'); $fields['Household'] =& CRM_Contact_BAO_Contact::exportableFields('Household'); $fields['Organization'] =& CRM_Contact_BAO_Contact::exportableFields('Organization'); $contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields(); if (!empty($contribFields)) { $fields['Contribution'] =& $contribFields; } foreach ($fields as $key => $value) { foreach ($value as $key1 => $value1) { $this->_mapperFields[$key][$key1] = $value1['title']; $hasLocationTypes[$key][$key1] = $value1['hasLocationType']; } } require_once 'CRM/Core/BAO/LocationType.php'; $this->_location_types =& CRM_Core_PseudoConstant::locationType(); $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault(); /* FIXME: dirty hack to make the default option show up first. This * avoids a mozilla browser bug with defaults on dynamically constructed * selector widgets. */ if ($defaultLocationType) { $defaultLocation = $this->_location_types[$defaultLocationType->id]; unset($this->_location_types[$defaultLocationType->id]); $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types; } $sel1 = array('' => '-select-') + CRM_Core_SelectValues::contactType(); if (!empty($contribFields)) { $sel1['Contribution'] = 'Contributions'; } foreach ($sel1 as $key => $sel) { if ($key) { $sel2[$key] = $this->_mapperFields[$key]; } } $sel3[''] = null; $phoneTypes = CRM_Core_SelectValues::phoneType(); foreach ($sel1 as $k => $sel) { if ($k) { foreach ($this->_location_types as $key => $value) { $sel4[$k]['phone'][$key] =& $phoneTypes; } } } foreach ($sel1 as $k => $sel) { if ($k) { foreach ($this->_mapperFields[$k] as $key => $value) { if ($hasLocationTypes[$k][$key]) { $sel3[$k][$key] = $this->_location_types; } else { $sel3[$key] = null; } } } } $this->_defaults = array(); $js = "<script type='text/javascript'>\n"; $formName = "document.{$this->_name}"; $sel =& $this->addElement('hierselect', "field_name", ts('Field Name'), 'onclick="showLabel();"'); $formValues = array(); //$formValues = $this->controller->exportValues( $this->_name ); $formValues = $_POST; // using $_POST since export values don't give values on first submit if (empty($formValues)) { for ($k = 1; $k < 4; $k++) { if (!$defaults['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } else { foreach ($formValues['field_name'] as $value) { for ($k = 1; $k < 4; $k++) { if (!$formValues['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } } $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); $js .= "</script>\n"; $this->assign('initHideBoxes', $js); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true); // should the field appear in selector? $this->add('checkbox', 'in_selector', ts('In Selector?')); // weight $this->add('text', 'weight', ts('Weight'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'weight'), true); $this->addRule('weight', ts(' is a numeric field'), 'numeric'); $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'help_post')); // listings title $this->add('text', 'listings_title', ts('Listings Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'listings_title')); $this->addRule('listings_title', ts('Please enter a valid title for this field when displayed in user listings.'), 'title'); $this->add('checkbox', 'is_required', ts('Required?')); $this->add('checkbox', 'is_active', ts('Active?')); $this->add('checkbox', 'is_searchable', ts('Searchable?')); $this->add('checkbox', 'is_view', ts('View Only?')); // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) ); //$this->add( 'checkbox', 'is_match' , ts( 'Key to Match Contacts?' ) ); $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'label')); // add buttons $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); $this->addFormRule(array('CRM_UF_Form_Field', 'formRule')); // if view mode pls freeze it with the done button. if ($this->_action & CRM_CORE_ACTION_VIEW) { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onClick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'")); } $this->setDefaults($defaults); }
/** * Set variables up before form is built. * * @return void */ public function preProcess() { $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this); $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); if ($this->_gid) { $this->_title = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'title'); $this->setPageTitle(ts('Profile Field')); $url = CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); $breadCrumb = array(array('title' => ts('CiviCRM Profile Fields'), 'url' => $url)); CRM_Utils_System::appendBreadCrumb($breadCrumb); } $showBestResult = CRM_Utils_Request::retrieve('sbr', 'Positive', CRM_Core_DAO::$_nullArray); if ($showBestResult) { $this->assign('showBestResult', $showBestResult); } $this->_fields = CRM_Contact_BAO_Contact::importableFields('All', TRUE, TRUE, TRUE, TRUE, TRUE); $this->_fields = array_merge(CRM_Activity_BAO_Activity::exportableFields('Activity'), $this->_fields); //unset campaign related fields. if (isset($this->_fields['activity_campaign_id'])) { $this->_fields['activity_campaign_id']['title'] = ts('Campaign'); if (isset($this->_fields['activity_campaign'])) { unset($this->_fields['activity_campaign']); } } if (CRM_Core_Permission::access('CiviContribute')) { $this->_fields = array_merge(CRM_Contribute_BAO_Contribution::getContributionFields(FALSE), $this->_fields); $this->_fields = array_merge(CRM_Core_BAO_UFField::getContribBatchEntryFields(), $this->_fields); } if (CRM_Core_Permission::access('CiviMember')) { $this->_fields = array_merge(CRM_Member_BAO_Membership::getMembershipFields(), $this->_fields); } if (CRM_Core_Permission::access('CiviEvent')) { $this->_fields = array_merge(CRM_Event_BAO_Query::getParticipantFields(), $this->_fields); } if (CRM_Core_Permission::access('CiviCase')) { $this->_fields = array_merge(CRM_Case_BAO_Query::getFields(), $this->_fields); } $this->_fields = array_merge($this->_fields, CRM_Contact_BAO_Query_Hook::singleton()->getFields()); $this->_selectFields = array(); foreach ($this->_fields as $name => $field) { // lets skip note for now since we dont support it if ($name == 'note') { continue; } $this->_selectFields[$name] = $field['title']; $this->_hasLocationTypes[$name] = CRM_Utils_Array::value('hasLocationType', $field); } // lets add group, tag and current_employer to this list $this->_selectFields['group'] = ts('Group(s)'); $this->_selectFields['tag'] = ts('Tag(s)'); $this->_selectFields['current_employer'] = ts('Current Employer'); $this->_selectFields['phone_and_ext'] = ts('Phone and Extension'); //CRM-4363 check for in selector or searchable fields. $this->_hasSearchableORInSelector = CRM_Core_BAO_UFField::checkSearchableORInSelector($this->_gid); $this->assign('fieldId', $this->_id); if ($this->_id) { $fieldTitle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFField', $this->_id, 'label'); $this->assign('fieldTitle', $fieldTitle); } }
/** * Browse all CiviCRM Profile group fields. * * @return void */ public function browse() { $resourceManager = CRM_Core_Resources::singleton(); if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) { $resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999, 'html-header'); } $ufField = array(); $ufFieldBAO = new CRM_Core_BAO_UFField(); // fkey is gid $ufFieldBAO->uf_group_id = $this->_gid; $ufFieldBAO->orderBy('weight', 'field_name'); $ufFieldBAO->find(); $otherModules = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_gid); $this->assign('otherModules', $otherModules); $isGroupReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_reserved'); $this->assign('isGroupReserved', $isGroupReserved); $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid); if ($profileType == 'Contribution' || $profileType == 'Membership' || $profileType == 'Activity' || $profileType == 'Participant') { $this->assign('skipCreate', TRUE); } $locationType = array(); $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $fields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE); $fields = array_merge(CRM_Contribute_BAO_Contribution::getContributionFields(), $fields); $select = array(); foreach ($fields as $name => $field) { if ($name) { $select[$name] = $field['title']; } } $select['group'] = ts('Group(s)'); $select['tag'] = ts('Tag(s)'); $visibility = CRM_Core_SelectValues::ufVisibility(); while ($ufFieldBAO->fetch()) { $ufField[$ufFieldBAO->id] = array(); $phoneType = $locType = ''; CRM_Core_DAO::storeValues($ufFieldBAO, $ufField[$ufFieldBAO->id]); $ufField[$ufFieldBAO->id]['visibility_display'] = $visibility[$ufFieldBAO->visibility]; $ufField[$ufFieldBAO->id]['label'] = $ufFieldBAO->label; $action = array_sum(array_keys($this->actionLinks())); if ($ufFieldBAO->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } if ($ufFieldBAO->is_reserved) { $action -= CRM_Core_Action::UPDATE; $action -= CRM_Core_Action::DISABLE; $action -= CRM_Core_Action::DELETE; } $ufField[$ufFieldBAO->id]['order'] = $ufField[$ufFieldBAO->id]['weight']; $ufField[$ufFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $ufFieldBAO->id, 'gid' => $this->_gid), ts('more'), FALSE, 'ufField.row.actions', 'UFField', $ufFieldBAO->id); } $returnURL = CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}"); $filter = "uf_group_id = {$this->_gid}"; CRM_Utils_Weight::addOrder($ufField, 'CRM_Core_DAO_UFField', 'id', $returnURL, $filter); $this->assign('ufField', $ufField); // retrieve showBestResult from session $session = CRM_Core_Session::singleton(); $showBestResult = $session->get('showBestResult'); $this->assign('showBestResult', $showBestResult); $session->set('showBestResult', 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; }
/** * Browse all CiviCRM Profile group fields. * * @return void * @access public * @static */ function browse() { $ufField = array(); $ufFieldBAO =& new CRM_Core_BAO_UFField(); // fkey is gid $ufFieldBAO->uf_group_id = $this->_gid; $ufFieldBAO->orderBy('weight', 'field_name'); $ufFieldBAO->find(); $locationType = array(); $locationType =& CRM_Core_PseudoConstant::locationType(); require_once 'CRM/Contact/BAO/Contact.php'; $fields =& CRM_Contact_BAO_Contact::exportableFields('All', false, true); $fields = array_merge(CRM_Contribute_BAO_Contribution::getContributionFields(), $fields); $select = array(); foreach ($fields as $name => $field) { if ($name) { $select[$name] = $field['title']; } } $select['group'] = ts('Group(s)'); $select['tag'] = ts('Tag(s)'); while ($ufFieldBAO->fetch()) { $ufField[$ufFieldBAO->id] = array(); $phoneType = $locType = ''; CRM_Core_DAO::storeValues($ufFieldBAO, $ufField[$ufFieldBAO->id]); CRM_Core_DAO_UFField::addDisplayEnums($ufField[$ufFieldBAO->id]); // fix the field_name value $ufField[$ufFieldBAO->id]['field_name'] = $select[$ufField[$ufFieldBAO->id]['field_name']]; if ($ufFieldBAO->location_type_id) { $locType = ' (' . $locationType[$ufFieldBAO->location_type_id] . ') '; } if ($ufFieldBAO->phone_type) { if ($ufFieldBAO->phone_type != 'Phone') { // this hack is to prevent Phone Phone $phoneType .= '-' . $ufFieldBAO->phone_type; } } $ufField[$ufFieldBAO->id]['field_name'] .= $phoneType . $locType; $action = array_sum(array_keys($this->actionLinks())); if ($ufFieldBAO->is_active) { $action -= CRM_CORE_ACTION_ENABLE; } else { $action -= CRM_CORE_ACTION_DISABLE; } $ufField[$ufFieldBAO->id]['action'] = CRM_Core_Action::formLink(CRM_UF_Page_Field::actionLinks(), $action, array('id' => $ufFieldBAO->id, 'gid' => $this->_gid)); } $this->assign('ufField', $ufField); }
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; }