/** * Build the form object elements for a phone object. * * @param CRM_Core_Form $form * Reference to the form object. * @param int $addressBlockCount * Block number to build. * @param bool $blockEdit * Is it block edit. */ public static function buildQuickForm(&$form, $addressBlockCount = NULL, $blockEdit = FALSE) { // passing this via the session is AWFUL. we need to fix this if (!$addressBlockCount) { $blockId = $form->get('Phone_Block_Count') ? $form->get('Phone_Block_Count') : 1; } else { $blockId = $addressBlockCount; } $form->applyFilter('__ALL__', 'trim'); //phone type select $form->addSelect("phone[{$blockId}][phone_type_id]", array('entity' => 'phone', 'class' => 'eight', 'placeholder' => NULL)); //main phone number with crm_phone class $form->add('text', "phone[{$blockId}][phone]", ts('Phone'), array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'), array('class' => 'crm_phone twelve'))); // phone extension $form->addElement('text', "phone[{$blockId}][phone_ext]", ts('Extension'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone_ext')); if (isset($form->_contactType) || $blockEdit) { //Block type select $form->addSelect("phone[{$blockId}][location_type_id]", array('entity' => 'phone', 'class' => 'eight', 'placeholder' => NULL)); //is_Primary radio $js = array('id' => 'Phone_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );'); $form->addElement('radio', "phone[{$blockId}][is_primary]", '', '', '1', $js); } // TODO: set this up as a group, we need a valid phone_type_id if we have a phone number // $form->addRule( "location[$locationId][phone][$locationId][phone]", ts('Phone number is not valid.'), 'phone' ); }
/** * This function provides the HTML form elements that are specific * to the Individual Contact Type * * @param CRM_Core_Form $form form object * @param int $inlineEditMode ( 1 for contact summary * top bar form and 2 for display name edit ) * * @access public * @return void */ public static function buildQuickForm(&$form, $inlineEditMode = NULL) { $form->applyFilter('__ALL__', 'trim'); if (!$inlineEditMode || $inlineEditMode == 1) { $nameFields = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 2'); //prefix $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); if (isset($nameFields['Prefix']) && !empty($prefix)) { $form->addSelect('prefix_id', array('class' => 'four', 'placeholder' => ' ')); } $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact'); if (isset($nameFields['Formal Title'])) { $form->addElement('text', 'formal_title', ts('Title'), $attributes['formal_title']); } // first_name if (isset($nameFields['First Name'])) { $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']); } //middle_name if (isset($nameFields['Middle Name'])) { $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']); } // last_name if (isset($nameFields['Last Name'])) { $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']); } // suffix $suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'); if (isset($nameFields['Suffix']) && $suffix) { $form->addSelect('suffix_id', array('class' => 'four', 'placeholder' => ' ')); } } if (!$inlineEditMode || $inlineEditMode == 2) { // nick_name $form->addElement('text', 'nick_name', ts('Nickname'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name')); // job title // override the size for UI to look better $attributes['job_title']['size'] = 30; $form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"'); //Current Employer Element $employerDataURL = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&org=1&employee_id=' . $form->_contactId, FALSE, NULL, FALSE); $form->assign('employerDataURL', $employerDataURL); $form->addElement('text', 'current_employer', ts('Current Employer'), ''); $form->addElement('hidden', 'current_employer_id', '', array('id' => 'current_employer_id')); $form->addElement('text', 'contact_source', ts('Source'), CRM_Utils_Array::value('source', $attributes)); } if (!$inlineEditMode) { $checkSimilar = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_ajax_check_similar', NULL, TRUE); if ($checkSimilar == null) { $checkSimilar = 0; } $form->assign('checkSimilar', $checkSimilar); //External Identifier Element $form->add('text', 'external_identifier', ts('External Id'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), FALSE); $form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')); $config = CRM_Core_Config::singleton(); CRM_Core_ShowHideBlocks::links($form, 'demographics', '', ''); } }
/** * This function provides the HTML form elements that are specific * to the Individual Contact Type * * @param CRM_Core_Form $form * Form object. * @param int $inlineEditMode * ( 1 for contact summary. * top bar form and 2 for display name edit ) * * @return void */ public static function buildQuickForm(&$form, $inlineEditMode = NULL) { $form->applyFilter('__ALL__', 'trim'); if (!$inlineEditMode || $inlineEditMode == 1) { $nameFields = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 2'); //prefix $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); if (isset($nameFields['Prefix']) && !empty($prefix)) { $form->addSelect('prefix_id', array('class' => 'eight', 'placeholder' => ' ', 'label' => ts('Prefix'))); } $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact'); if (isset($nameFields['Formal Title'])) { $form->addElement('text', 'formal_title', ts('Title'), $attributes['formal_title']); } // first_name if (isset($nameFields['First Name'])) { $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']); } //middle_name if (isset($nameFields['Middle Name'])) { $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']); } // last_name if (isset($nameFields['Last Name'])) { $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']); } // suffix $suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'); if (isset($nameFields['Suffix']) && $suffix) { $form->addSelect('suffix_id', array('class' => 'eight', 'placeholder' => ' ', 'label' => ts('Suffix'))); } } if (!$inlineEditMode || $inlineEditMode == 2) { // nick_name $form->addElement('text', 'nick_name', ts('Nickname'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name')); // job title // override the size for UI to look better $attributes['job_title']['size'] = 30; $form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"'); //Current Employer Element $props = array('api' => array('params' => array('contact_type' => 'Organization')), 'create' => TRUE); $form->addEntityRef('employer_id', ts('Current Employer'), $props); $attributes['source']['class'] = 'big'; $form->addElement('text', 'contact_source', ts('Source'), CRM_Utils_Array::value('source', $attributes)); } if (!$inlineEditMode) { $checkSimilar = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_ajax_check_similar', NULL, TRUE); if ($checkSimilar == NULL) { $checkSimilar = 0; } $form->assign('checkSimilar', $checkSimilar); //External Identifier Element $form->add('text', 'external_identifier', ts('External ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), FALSE); $form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier')); $config = CRM_Core_Config::singleton(); CRM_Core_ShowHideBlocks::links($form, 'demographics', '', ''); } }
/** * build the form elements for an IM object * * @param CRM_Core_Form $form reference to the form object * @param int $blockCount block number to build * @param boolean $blockEdit is it block edit * * @return void * @access public * @static */ static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) { if (!$blockCount) { $blockId = $form->get('IM_Block_Count') ? $form->get('IM_Block_Count') : 1; } else { $blockId = $blockCount; } $form->applyFilter('__ALL__', 'trim'); //IM provider select $form->addSelect("im[{$blockId}][provider_id]", array('entity' => 'im', 'class' => 'eight', 'placeholder' => NULL)); //Block type select $form->addSelect("im[{$blockId}][location_type_id]", array('entity' => 'im', 'class' => 'eight', 'placeholder' => NULL)); //IM box $form->addElement('text', "im[{$blockId}][name]", ts('Instant Messenger'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_IM', 'name')); //is_Primary radio $js = array('id' => 'IM_' . $blockId . '_IsPrimary'); if (!$blockEdit) { $js['onClick'] = 'singleSelect( this.id );'; } $form->addElement('radio', "im[{$blockId}][is_primary]", '', '', '1', $js); }
/** * Build the form object elements for Communication Preferences object. * * @param CRM_Core_Form $form * Reference to the form object. * * @return void */ public static function buildQuickForm(&$form) { // since the pcm - preferred comminication method is logically // grouped hence we'll use groups of HTML_QuickForm // checkboxes for DO NOT phone, email, mail // we take labels from SelectValues $privacy = $commPreff = $commPreference = array(); $privacyOptions = CRM_Core_SelectValues::privacy(); // we add is_opt_out as a separate checkbox below for display and help purposes so remove it here unset($privacyOptions['is_opt_out']); foreach ($privacyOptions as $name => $label) { $privacy[] = $form->createElement('advcheckbox', $name, NULL, $label); } $form->addGroup($privacy, 'privacy', ts('Privacy'), ' '); // preferred communication method $comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method', array('loclize' => TRUE)); foreach ($comm as $value => $title) { $commPreff[] = $form->createElement('advcheckbox', $value, NULL, $title); } $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Method(s)')); $form->addSelect('preferred_language'); if (!empty($privacyOptions)) { $commPreference['privacy'] = $privacyOptions; } if (!empty($comm)) { $commPreference['preferred_communication_method'] = $comm; } //using for display purpose. $form->assign('commPreference', $commPreference); $form->add('select', 'preferred_mail_format', ts('Email Format'), CRM_Core_SelectValues::pmf()); $form->add('checkbox', 'is_opt_out', ts('NO BULK EMAILS (User Opt Out)')); $communicationStyleOptions = array(); $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id', array('localize' => TRUE)); foreach ($communicationStyle as $key => $var) { $communicationStyleOptions[$key] = $form->createElement('radio', NULL, ts('Communication Style'), $var, $key, array('id' => "civicrm_communication_style_{$var}_{$key}")); } if (!empty($communicationStyleOptions)) { $form->addGroup($communicationStyleOptions, 'communication_style_id', ts('Communication Style')); } //check contact type and build filter clause accordingly for greeting types, CRM-4575 $greetings = self::getGreetingFields($form->_contactType); foreach ($greetings as $greeting => $fields) { $filter = array('contact_type' => $form->_contactType, 'greeting_type' => $greeting); //add addressee in Contact form $greetingTokens = CRM_Core_PseudoConstant::greeting($filter); if (!empty($greetingTokens)) { $form->addElement('select', $fields['field'], $fields['label'], array('' => ts('- select -')) + $greetingTokens); //custom addressee $form->addElement('text', $fields['customField'], $fields['customLabel'], CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']); } } }
/** * build the form elements for an Website object * * @param CRM_Core_Form $form reference to the form object * @param int $blockCount block number to build * * @return void * @access public * @static */ static function buildQuickForm(&$form, $blockCount = NULL) { if (!$blockCount) { $blockId = $form->get('Website_Block_Count') ? $form->get('Website_Block_Count') : 1; } else { $blockId = $blockCount; } $form->applyFilter('__ALL__', 'trim'); //Website type select $form->addSelect("website[{$blockId}][website_type_id]", array('entity' => 'website', 'class' => 'eight')); //Website box $form->addElement('text', "website[{$blockId}][url]", ts('Website'), array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) { this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') { this.value='';} else return false"))); $form->addRule("website[{$blockId}][url]", ts('Enter a valid web location beginning with \'http://\' or \'https://\'. EXAMPLE: http://www.mysite.org/'), 'url'); }
/** * build the form elements for an email object * * @param CRM_Core_Form $form reference to the form object * @param int $blockCount block number to build * @param boolean $blockEdit is it block edit * * @return void * @access public * @static */ static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE) { // passing this via the session is AWFUL. we need to fix this if (!$blockCount) { $blockId = $form->get('Email_Block_Count') ? $form->get('Email_Block_Count') : 1; } else { $blockId = $blockCount; } $form->applyFilter('__ALL__', 'trim'); //Email box $form->addElement('text', "email[{$blockId}][email]", ts('Email'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email')); $form->addRule("email[{$blockId}][email]", ts('Email is not valid.'), 'email'); if (isset($form->_contactType) || $blockEdit) { //Block type $form->addSelect("email[{$blockId}][location_type_id]", array('entity' => 'email', 'class' => 'eight', 'placeholder' => NULL)); $multipleBulk = CRM_Core_BAO_Email::isMultipleBulkMail(); //On-hold select if ($multipleBulk) { $holdOptions = array(0 => ts('- select -'), 1 => ts('On Hold Bounce'), 2 => ts('On Hold Opt Out')); $form->addElement('select', "email[{$blockId}][on_hold]", '', $holdOptions); } else { $form->addElement('advcheckbox', "email[{$blockId}][on_hold]", NULL); } //Bulkmail checkbox $form->assign('multipleBulk', $multipleBulk); if ($multipleBulk) { $js = array('id' => "Email_" . $blockId . "_IsBulkmail"); $form->addElement('advcheckbox', "email[{$blockId}][is_bulkmail]", NULL, '', $js); } else { $js = array('id' => "Email_" . $blockId . "_IsBulkmail"); if (!$blockEdit) { $js['onClick'] = 'singleSelect( this.id );'; } $form->addElement('radio', "email[{$blockId}][is_bulkmail]", '', '', '1', $js); } //is_Primary radio $js = array('id' => "Email_" . $blockId . "_IsPrimary"); if (!$blockEdit) { $js['onClick'] = 'singleSelect( this.id );'; } $form->addElement('radio', "email[{$blockId}][is_primary]", '', '', '1', $js); if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') { $form->add('textarea', "email[{$blockId}][signature_text]", ts('Signature (Text)'), array('rows' => 2, 'cols' => 40)); $form->addWysiwyg("email[{$blockId}][signature_html]", ts('Signature (HTML)'), array('rows' => 2, 'cols' => 40)); } } }
/** * @param CRM_Core_Form $form */ public function buildForm(&$form) { /** * You can define a custom title for the search form */ $this->setTitle('Find Contributors by Aggregate Totals'); /** * Define the search form fields here */ $form->add('text', 'min_amount', ts('Aggregate Total Between $')); $form->addRule('min_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money'); $form->add('text', 'max_amount', ts('...and $')); $form->addRule('max_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money'); $form->addDate('start_date', ts('Contribution Date From'), FALSE, array('formatType' => 'custom')); $form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom')); $form->addSelect('financial_type_id', array('entity' => 'contribution', 'multiple' => 'multiple', 'context' => 'search')); /** * If you are using the sample template, this array tells the template fields to render * for the search form. */ $form->assign('elements', array('min_amount', 'max_amount', 'start_date', 'end_date')); }
/** * Add profile field to a form. * * @param CRM_Core_Form $form * @param array $field * Properties. * @param int $mode * Profile mode. * @param int $contactId * @param bool $online * @param string $usedFor * For building up prefixed fieldname for special cases (e.g. onBehalf, Honor). * @param int $rowNumber * @param string $prefix * * @return null */ public static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $usedFor = NULL, $rowNumber = NULL, $prefix = '') { $defaultValues = array(); $fieldName = $field['name']; $title = $field['title']; $attributes = $field['attributes']; $rule = $field['rule']; $view = $field['is_view']; $required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required']; $search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE; $isShared = CRM_Utils_Array::value('is_shared', $field, 0); // do not display view fields in drupal registration form // CRM-4632 if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) { return NULL; } if ($usedFor == 'onbehalf') { $name = "onbehalf[{$fieldName}]"; } elseif ($usedFor == 'honor') { $name = "honor[{$fieldName}]"; } elseif ($contactId && !$online) { $name = "field[{$contactId}][{$fieldName}]"; } elseif ($rowNumber) { $name = "field[{$rowNumber}][{$fieldName}]"; } elseif (!empty($prefix)) { $name = $prefix . "[{$fieldName}]"; } else { $name = $fieldName; } $selectAttributes = array('class' => 'crm-select2', 'placeholder' => TRUE); if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) { $deleteExtra = json_encode(ts('Are you sure you want to delete contact image.')); $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "' . htmlspecialchars("if (confirm({$deleteExtra})) this.href+='&confirmed=1'; else return false;") . '"')); $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')), ts('more'), FALSE, 'contact.profileimage.delete', 'Contact', $form->get('id')); $form->assign('deleteURL', $deleteURL); } $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); if (substr($fieldName, 0, 14) === 'state_province') { $form->addChainSelect($name, array('label' => $title, 'required' => $required)); $config = CRM_Core_Config::singleton(); if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactStateProvince) { $defaultValues[$name] = $config->defaultContactStateProvince; $form->setDefaults($defaultValues); } } elseif (substr($fieldName, 0, 7) === 'country') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required, $selectAttributes); $config = CRM_Core_Config::singleton(); if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) { $defaultValues[$name] = $config->defaultContactCountry; $form->setDefaults($defaultValues); } } elseif (substr($fieldName, 0, 6) === 'county') { if ($addressOptions['county']) { $form->addChainSelect($name, array('label' => $title, 'required' => $required)); } } elseif (substr($fieldName, 0, 9) === 'image_URL') { $form->add('file', $name, $title, $attributes, $required); $form->addUploadElement($name); } elseif (substr($fieldName, 0, 2) === 'im') { $form->add('text', $name, $title, $attributes, $required); if (!$contactId) { if ($usedFor) { if (substr($name, -1) == ']') { $providerName = substr($name, 0, -1) . '-provider_id]'; } $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required); } else { $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required); } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) { $form->freeze($name . '-provider_id'); } } } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') { $form->addDate($name, $title, $required, array('formatType' => 'birth')); } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) { $form->addDate($name, $title, $required, array('formatType' => 'activityDate')); } elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') { list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo(); $sel =& $form->addElement('hierselect', $name, $title); $select = array('' => ts('- select -')); if (count($orgInfo) == 1 && $field['is_required']) { // we only have one org - so we should default to it. Not sure about defaulting to first type // as it could be missed - so adding a select // however, possibly that is more similar to the membership form if (count($types[1]) > 1) { $types[1] = $select + $types[1]; } } else { $orgInfo = $select + $orgInfo; } $sel->setOptions(array($orgInfo, $types)); } elseif (CRM_Utils_Array::value('name', $field) == 'membership_status') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required); } elseif (in_array($fieldName, array('gender_id', 'communication_style_id'))) { $options = array(); $pseudoValues = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $fieldName); foreach ($pseudoValues as $key => $var) { $options[$key] = $form->createElement('radio', NULL, ts($title), $var, $key); } $group = $form->addGroup($options, $name, $title); if ($required) { $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required'); } else { $group->setAttribute('allowClear', TRUE); } } elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') { $form->addSelect($name, array('label' => $title, 'entity' => 'contact', 'field' => $fieldName, 'class' => 'six', 'placeholder' => ''), $required); } elseif ($fieldName === 'contact_sub_type') { $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); if ($usedFor == 'onbehalf') { $profileType = 'Organization'; } elseif ($usedFor == 'honor') { $profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']); } else { $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL; if ($profileType == 'Contact') { $profileType = 'Individual'; } } $setSubtype = FALSE; if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $setSubtype = $profileType; $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array(); if ($setSubtype) { $subtypeList = array(); $subtypeList[$setSubtype] = $subtypes[$setSubtype]; } else { $subtypeList = $subtypes; } $form->add('select', $name, $title, $subtypeList, $required, array('class' => 'crm-select2', 'multiple' => TRUE)); } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) { //add email greeting, postal greeting, addressee, CRM-4575 $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE); if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) { $profileType = 'Individual'; } if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName); $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required); // add custom greeting element $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE); } elseif ($fieldName === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'); foreach ($communicationFields as $key => $var) { if ($key == '') { continue; } $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var); } $form->addGroup($communicationOptions, $name, $title, '<br/>'); } elseif ($fieldName === 'preferred_mail_format') { $form->add('select', $name, $title, CRM_Core_SelectValues::pmf()); } elseif ($fieldName === 'preferred_language') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contact_BAO_Contact::buildOptions('preferred_language')); } elseif ($fieldName == 'external_identifier') { $form->add('text', $name, $title, $attributes, $required); $contID = $contactId; if (!$contID) { $contID = $form->get('id'); } $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier')); } elseif ($fieldName === 'group') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name); } elseif ($fieldName === 'tag') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name); } elseif (substr($fieldName, 0, 4) === 'url-') { $form->add('text', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), $required); $form->addRule($name, ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url'); } elseif (substr($fieldName, -4) == 'note') { $form->add('textarea', $name, $title, $attributes, $required); } elseif (substr($fieldName, 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (substr($fieldName, 0, 14) === 'address_custom') { list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2); $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8)); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'send_receipt') { $form->addElement('checkbox', $name, $title); } elseif ($fieldName == 'soft_credit') { $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Soft Credit To'), array('create' => TRUE)); $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE); } elseif ($fieldName == 'product_name') { list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); $sel =& $form->addElement('hierselect', $name, $title); $products = array('0' => ts('- select -')) + $products; $sel->setOptions(array($products, $options)); } elseif ($fieldName == 'payment_instrument') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } elseif ($fieldName == 'financial_type') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), $required); } elseif ($fieldName == 'contribution_status_id') { $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(); $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); foreach (array('In Progress', 'Overdue', 'Refunded') as $suppress) { unset($contributionStatuses[CRM_Utils_Array::key($suppress, $statusName)]); } $form->add('select', $name, $title, array('' => ts('- select -')) + $contributionStatuses, $required); } elseif ($fieldName == 'soft_credit_type') { $name = "soft_credit_type[{$rowNumber}]"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_OptionGroup::values("soft_credit_type")); //CRM-15350: choose SCT field default value as 'Gift' for membership use //else (for contribution), use configured SCT default value $SCTDefaultValue = CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"); if ($field['field_type'] == 'Membership') { $SCTDefaultValue = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name'); } $form->addElement('hidden', 'sct_default_id', $SCTDefaultValue, array('id' => 'sct_default_id')); } elseif ($fieldName == 'currency') { $form->addCurrency($name, $title, $required); } elseif ($fieldName == 'contribution_page_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"'); } elseif ($fieldName == 'participant_register_date') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'activity_status_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required); } elseif ($fieldName == 'activity_engagement_level') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required); } elseif ($fieldName == 'activity_date_time') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'participant_status') { $cond = NULL; if ($online == TRUE) { $cond = 'visibility_id = 1'; } $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required); } elseif ($fieldName == 'participant_role') { if (!empty($field['is_multiple'])) { $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, ' ', TRUE); } else { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required); } } elseif ($fieldName == 'world_region') { $form->add('select', $name, $title, CRM_Core_PseudoConstant::worldRegion(), $required, $selectAttributes); } elseif ($fieldName == 'signature_html') { $form->add('wysiwyg', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif ($fieldName == 'signature_text') { $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif (substr($fieldName, -11) == 'campaign_id') { if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns)); $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="crm-select2 big"'); } } elseif ($fieldName == 'activity_details') { $form->add('wysiwyg', $fieldName, $title, array('rows' => 4, 'cols' => 60), $required); } elseif ($fieldName == 'activity_duration') { $form->add('text', $name, $title, $attributes, $required); $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger'); } else { if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') { $form->add('advcheckbox', $name, $title, $attributes, $required); } else { $form->add('text', $name, $title, $attributes, $required); } } static $hiddenSubtype = FALSE; if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) { // In registration mode params are submitted via POST and we don't have any clue // about profile-id or the profile-type (which could be a subtype) // To generalize the behavior and simplify the process, // lets always add the hidden //subtype value if there is any, and we won't have to // compute it while processing. if ($usedFor) { $form->addElement('hidden', $usedFor . '[contact_sub_type]', $field['field_type']); } else { $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']); } $hiddenSubtype = TRUE; } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) { $form->freeze($name); } //add the rules if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) { $form->addRule($name, ts('Please enter a valid amount.'), 'money'); } if ($rule) { if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) { $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule); } } }
/** * @param CRM_Core_Form $form */ public static function buildSearchForm(&$form) { $membershipStatus = CRM_Member_PseudoConstant::membershipStatus(); $form->add('select', 'membership_status_id', ts('Membership Status(s)'), $membershipStatus, FALSE, array('id' => 'membership_status_id', 'multiple' => 'multiple', 'class' => 'crm-select2')); $form->addSelect('membership_type_id', array('entity' => 'membership', 'multiple' => 'multiple', 'label' => ts('Membership Type(s)'), 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->addElement('text', 'member_source', ts('Source')); CRM_Core_Form_Date::buildDateRange($form, 'member_join_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'member_start_date', 1, '_low', '_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'member_end_date', 1, '_low', '_high', ts('From'), FALSE); $form->addYesNo('member_is_primary', ts('Primary Member?'), TRUE); $form->addYesNo('member_pay_later', ts('Pay Later?'), TRUE); $form->addYesNo('member_auto_renew', ts('Auto-Renew?'), TRUE); $form->addYesNo('member_test', ts('Membership is a Test?'), TRUE); // add all the custom searchable fields $extends = array('Membership'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('membershipGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'member_campaign_id'); $form->assign('validCiviMember', TRUE); $form->setDefaults(array('member_test' => 0)); }
/** * Add all the elements shared between case activity search and advanced search. * * * @param CRM_Core_Form $form * @return void */ public static function buildSearchForm(&$form) { $activityOptions = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE); $form->addSelect('activity_type_id', array('entity' => 'activity', 'label' => 'Activity Type(s)', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); CRM_Core_Form_Date::buildDateRange($form, 'activity_date', 1, '_low', '_high', ts('From'), FALSE, FALSE); $followUpActivity = array(1 => ts('Yes'), 2 => ts('No')); $form->addRadio('parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); $form->addRadio('followup_parent_id', NULL, $followUpActivity, array('allowClear' => TRUE)); $activityRoles = array(3 => ts('With'), 2 => ts('Assigned to'), 1 => ts('Added by')); $form->addRadio('activity_role', NULL, $activityRoles, array('allowClear' => TRUE)); $form->setDefaults(array('activity_role' => 3)); $activityStatus = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'status_id', array('flip' => 1, 'labelColumn' => 'name')); $form->addSelect('status_id', array('entity' => 'activity', 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))); $form->setDefaults(array('status_id' => array($activityStatus['Completed'], $activityStatus['Scheduled']))); $form->addElement('text', 'activity_subject', ts('Subject'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); $form->addYesNo('activity_test', ts('Activity is a Test?')); $activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity'); if ($activity_tags) { foreach ($activity_tags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "activity_tags[{$tagID}]", NULL, $tagName); } } $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity'); CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_activity', NULL, TRUE, TRUE); $surveys = CRM_Campaign_BAO_Survey::getSurveys(TRUE, FALSE, FALSE, TRUE); if ($surveys) { $form->add('select', 'activity_survey_id', ts('Survey / Petition'), array('' => ts('- none -')) + $surveys, FALSE, array('class' => 'crm-select2')); } $extends = array('Activity'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('activityGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($form, 'activity_campaign_id'); //add engagement level CRM-7775 $buildEngagementLevel = FALSE; $buildSurveyResult = FALSE; if (CRM_Campaign_BAO_Campaign::isCampaignEnable() && CRM_Campaign_BAO_Campaign::accessCampaign()) { $buildEngagementLevel = TRUE; $form->addSelect('activity_engagement_level', array('entity' => 'activity', 'context' => 'search')); // Add survey result field. $optionGroups = CRM_Campaign_BAO_Survey::getResultSets('name'); $resultOptions = array(); foreach ($optionGroups as $gid => $name) { if ($name) { $value = array(); $value = CRM_Core_OptionGroup::values($name); if (!empty($value)) { while (list($k, $v) = each($value)) { $resultOptions[$v] = $v; } } } } // If no survey result options have been created, don't build // the field to avoid clutter. if (count($resultOptions) > 0) { $buildSurveyResult = TRUE; asort($resultOptions); $form->add('select', 'activity_result', ts("Survey Result"), $resultOptions, FALSE, array('id' => 'activity_result', 'multiple' => 'multiple', 'class' => 'crm-select2')); } } $form->assign('buildEngagementLevel', $buildEngagementLevel); $form->assign('buildSurveyResult', $buildSurveyResult); $form->setDefaults(array('activity_test' => 0)); }
/** * Build form for address input fields. * * @param CRM_Core_Form $form * @param int $addressBlockCount * The index of the address array (if multiple addresses on a page). * @param bool $sharing * False, if we want to skip the address sharing features. * @param bool $inlineEdit * True when edit used in inline edit. * * @return void * */ public static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharing = TRUE, $inlineEdit = FALSE) { // passing this via the session is AWFUL. we need to fix this if (!$addressBlockCount) { $blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1; } else { $blockId = $addressBlockCount; } $config = CRM_Core_Config::singleton(); $countryDefault = $config->defaultContactCountry; $form->applyFilter('__ALL__', 'trim'); $js = array(); if (!$inlineEdit) { $js = array('onChange' => 'checkLocation( this.id );', 'placeholder' => NULL); } //make location type required for inline edit $form->addSelect("address[{$blockId}][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js, $inlineEdit); if (!$inlineEdit) { $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );'); } $form->addElement('checkbox', "address[{$blockId}][is_primary]", ts('Primary location for this contact'), ts('Primary location for this contact'), $js); if (!$inlineEdit) { $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );'); } $form->addElement('checkbox', "address[{$blockId}][is_billing]", ts('Billing location for this contact'), ts('Billing location for this contact'), $js); // hidden element to store master address id $form->addElement('hidden', "address[{$blockId}][master_id]"); $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $elements = array('address_name' => array(ts('Address Name'), $attributes['address_name'], NULL), 'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL), 'supplemental_address_1' => array(ts('Supplemental Address 1'), $attributes['supplemental_address_1'], NULL), 'supplemental_address_2' => array(ts('Supplemental Address 2'), $attributes['supplemental_address_2'], NULL), 'city' => array(ts('City'), $attributes['city'], NULL), 'postal_code' => array(ts('Zip / Postal Code'), array_merge($attributes['postal_code'], array('class' => 'crm_postal_code')), NULL), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12, 'class' => 'crm_postal_code_suffix'), NULL), 'country_id' => array(ts('Country'), $attributes['country_id'], 'country'), 'state_province_id' => array(ts('State/Province'), $attributes['state_province_id'], NULL), 'county_id' => array(ts('County'), $attributes['county_id'], NULL), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 12), NULL), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 12), NULL), 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL), 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL)); foreach ($elements as $name => $v) { list($title, $attributes, $select) = $v; $nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name; if (empty($addressOptions[$nameWithoutID])) { $continue = TRUE; if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && !empty($addressOptions['street_address_parsing'])) { $continue = FALSE; } if ($continue) { continue; } } //build normal select if country is not present in address block if ($name == 'state_province_id' && !$addressOptions['country']) { $select = 'stateProvince'; } if (!$select) { if ($name == 'state_province_id' || $name == 'county_id') { $form->addChainSelect("address[{$blockId}][{$name}]"); } else { if ($name == 'address_name') { $name = 'name'; } $form->addElement('text', "address[{$blockId}][{$name}]", $title, $attributes); } } else { $form->addElement('select', "address[{$blockId}][{$name}]", $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select()); } } $entityId = NULL; if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) { $entityId = $form->_values['address'][$blockId]['id']; } // CRM-11665 geocode override option $geoCode = FALSE; if (!empty($config->geocodeMethod)) { $geoCode = TRUE; $form->addElement('checkbox', "address[{$blockId}][manual_geo_code]", ts('Override automatic geocoding')); } $form->assign('geoCode', $geoCode); // Process any address custom data - $groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId); if (isset($groupTree) && is_array($groupTree)) { // use simplified formatted groupTree $groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form); // make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]' foreach ($groupTree as $id => $group) { foreach ($group['fields'] as $fldId => $field) { $groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name']; $groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]"; } } $defaults = array(); CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults); // since we change element name for address custom data, we need to format the setdefault values $addressDefaults = array(); foreach ($defaults as $key => $val) { if (empty($val)) { continue; } // inorder to set correct defaults for checkbox custom data, we need to converted flat key to array // this works for all types custom data $keyValues = explode('[', str_replace(']', '', $key)); $addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val; } $form->setDefaults($addressDefaults); // we setting the prefix to 'dnc_' below, so that we don't overwrite smarty's grouptree var. // And we can't set it to 'address_' because we want to set it in a slightly different format. CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_'); // during contact editing : if no address is filled // required custom data must not produce 'required' form rule error // more handling done in formRule func if (!$inlineEdit) { CRM_Contact_Form_Edit_Address::storeRequiredCustomDataInfo($form, $groupTree); } $template = CRM_Core_Smarty::singleton(); $tplGroupTree = $template->get_template_vars('address_groupTree'); $tplGroupTree = empty($tplGroupTree) ? array() : $tplGroupTree; $form->assign('address_groupTree', $tplGroupTree + array($blockId => $groupTree)); // unset the temp smarty var that got created $form->assign('dnc_groupTree', NULL); } // address custom data processing ends .. if ($sharing) { // shared address $form->addElement('checkbox', "address[{$blockId}][use_shared_address]", NULL, ts('Use another contact\'s address')); // Override the default profile links to add address form $profileLinks = CRM_Core_BAO_UFGroup::getCreateLinks(array('new_individual', 'new_organization', 'new_household'), 'shared_address'); $form->addEntityRef("address[{$blockId}][master_contact_id]", ts('Share With'), array('create' => $profileLinks)); } }
/** * @param CRM_Core_Form $form */ public static function location(&$form) { $config = CRM_Core_Config::singleton(); // Build location criteria based on _submitValues if // available; otherwise, use $form->_formValues. $formValues = $form->_submitValues; if (empty($formValues) && !empty($form->_formValues)) { $formValues = $form->_formValues; } $form->addElement('hidden', 'hidden_location', 1); $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); $elements = array('street_address' => array(ts('Street Address'), $attributes['street_address'], NULL, NULL), 'city' => array(ts('City'), $attributes['city'], NULL, NULL), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], NULL, NULL), 'country' => array(ts('Country'), $attributes['country_id'], 'country', FALSE), 'state_province' => array(ts('State/Province'), $attributes['state_province_id'], 'stateProvince', TRUE), 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE), 'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL, NULL), 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL, NULL), 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL, NULL), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL, NULL)); $parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', $addressOptions, 0); $form->assign('parseStreetAddress', $parseStreetAddress); foreach ($elements as $name => $v) { list($title, $attributes, $select, $multiSelect) = $v; if (in_array($name, array('street_number', 'street_name', 'street_unit'))) { if (!$parseStreetAddress) { continue; } } elseif (!$addressOptions[$name]) { continue; } if (!$attributes) { $attributes = $attributes[$name]; } if ($select) { if ($select == 'stateProvince' || $select == 'county') { $element = $form->addChainSelect($name); } else { $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select(); $element = $form->add('select', $name, $title, $selectElements, FALSE, array('class' => 'crm-select2')); } if ($multiSelect) { $element->setMultiple(TRUE); } } else { $form->addElement('text', $name, $title, $attributes); } if ($addressOptions['postal_code']) { $attr = array('class' => 'six') + (array) CRM_Utils_Array::value('postal_code', $attributes); $form->addElement('text', 'postal_code_low', NULL, $attr + array('placeholder' => ts('From'))); $form->addElement('text', 'postal_code_high', NULL, $attr + array('placeholder' => ts('To'))); } } // extend addresses with proximity search if (!empty($config->geocodeMethod)) { $form->addElement('text', 'prox_distance', ts('Find contacts within'), array('class' => 'six')); $form->addElement('select', 'prox_distance_unit', NULL, array('miles' => ts('Miles'), 'kilos' => ts('Kilometers'))); $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric'); } $form->addSelect('world_region', array('entity' => 'address', 'context' => 'search')); // select for location type $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $form->add('select', 'location_type', ts('Address Location'), $locationType, FALSE, array('multiple' => TRUE, 'class' => 'crm-select2', 'placeholder' => ts('Primary'))); // custom data extending addresses - $extends = array('Address'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('addressGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $elementName = 'custom_' . $field['id']; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $field['id'], FALSE, FALSE, TRUE); } } } }