3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2016
33 class CRM_Contact_Form_Search_Criteria
{
35 * @param CRM_Core_Form $form
37 public static function basic(&$form) {
38 $form->addElement('hidden', 'hidden_basic', 1);
40 if ($form->_searchOptions
['contactType']) {
41 $contactTypes = CRM_Contact_BAO_ContactType
::getSelectElements();
44 $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE,
45 array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;')
50 if ($form->_searchOptions
['groups']) {
51 // multiselect for groups
53 // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title)
54 $groupHierarchy = CRM_Contact_BAO_Group
::getGroupsHierarchy($form->_group
, NULL, ' ', TRUE);
56 $form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE,
57 array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')
59 $groupOptions = CRM_Core_BAO_OptionValue
::getOptionValuesAssocArrayFromName('group_type');
60 $form->add('select', 'group_type', ts('Group Types'), $groupOptions, FALSE,
61 array('id' => 'group_type', 'multiple' => 'multiple', 'class' => 'crm-select2')
63 $form->add('hidden', 'group_search_selected', 'group');
67 if ($form->_searchOptions
['tags']) {
68 // multiselect for categories
69 $contactTags = CRM_Core_BAO_Tag
::getTags();
72 $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE,
73 array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;')
77 $parentNames = CRM_Core_BAO_Tag
::getTagSet('civicrm_contact');
78 CRM_Core_Form_Tag
::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE);
80 $used_for = CRM_Core_OptionGroup
::values('tag_used_for');
82 $showAllTagTypes = FALSE;
83 foreach ($used_for as $key => $value) {
84 //check tags for every type and find if there are any defined
85 $tags = CRM_Core_BAO_Tag
::getTagsUsedFor($key, FALSE, TRUE, NULL);
86 // check if there are tags other than contact type, if no - keep checkbox hidden on adv search
87 // we will hide searching contact by attachments tags until it will be implemented in core
88 if (count($tags) && $key != 'civicrm_file' && $key != 'civicrm_contact') {
89 //if tags exists then add type to display in adv search form help text
90 $tagsTypes[] = ts($value);
91 $showAllTagTypes = TRUE;
94 $tagTypesText = implode(" or ", $tagsTypes);
95 if ($showAllTagTypes) {
96 $form->add('checkbox', 'all_tag_types', ts('Include tags used for %1', array(1 => $tagTypesText)));
97 $form->add('hidden', 'tag_types_text', $tagTypesText);
101 // add text box for last name, first name, street name, city
102 $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
104 // add text box for last name, first name, street name, city
105 $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
107 //added contact source
108 $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'contact_source'));
111 $form->addElement('text', 'job_title', ts('Job Title'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'job_title'));
114 $form->add('number', 'contact_id', ts('Contact ID'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'id') +
array('min' => 1));
115 $form->addRule('contact_id', ts('Please enter valid Contact ID'), 'positiveInteger');
118 $form->addElement('text', 'external_identifier', ts('External ID'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'));
120 if (CRM_Core_Permission
::check('access deleted contacts') and Civi
::settings()->get('contact_undelete')) {
121 $form->add('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
124 // add checkbox for cms users only
125 $form->addYesNo('uf_user', ts('CMS User?'), TRUE);
128 $form->add('text', 'tag_search', ts('All Tags'));
130 // add search profiles
132 // FIXME: This is probably a part of profiles - need to be
133 // FIXME: eradicated from here when profiles are reworked.
134 $types = array('Participant', 'Contribution', 'Membership');
136 // get component profiles
137 $componentProfiles = array();
138 $componentProfiles = CRM_Core_BAO_UFGroup
::getProfiles($types);
140 $ufGroups = CRM_Core_BAO_UFGroup
::getModuleUFGroup('Search Profile', 1);
141 $accessibleUfGroups = CRM_Core_Permission
::ufGroup(CRM_Core_Permission
::VIEW
);
143 $searchProfiles = array();
144 foreach ($ufGroups as $key => $var) {
145 if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
146 $searchProfiles[$key] = $var['title'];
152 ts('Views For Display Contacts'),
154 '0' => ts('- default view -'),
157 array('class' => 'crm-select2')
160 $componentModes = CRM_Contact_Form_Search
::getModeSelect();
161 $enabledComponents = CRM_Core_Component
::getEnabledComponents();
163 // unset disabled components that must should have been enabled
164 // to the option be viable
165 if (!array_key_exists('CiviMail', $enabledComponents)) {
166 unset($componentModes['8']);
169 // unset contributions or participants if user does not have
170 // permission on them
171 if (!CRM_Core_Permission
::access('CiviContribute')) {
172 unset($componentModes['2']);
175 if (!CRM_Core_Permission
::access('CiviEvent')) {
176 unset($componentModes['3']);
179 if (!CRM_Core_Permission
::access('CiviMember')) {
180 unset($componentModes['5']);
183 if (!CRM_Core_Permission
::check('view all activities')) {
184 unset($componentModes['4']);
187 if (count($componentModes) > 1) {
190 ts('Display Results As'),
193 array('class' => 'crm-select2')
199 ts('Search Operator'),
204 array('allowClear' => FALSE)
207 // add the option to display relationships
208 $rTypes = CRM_Core_PseudoConstant
::relationshipType();
209 $rSelect = array('' => ts('- Select Relationship Type-'));
210 foreach ($rTypes as $rid => $rValue) {
211 if ($rValue['label_a_b'] == $rValue['label_b_a']) {
212 $rSelect[$rid] = $rValue['label_a_b'];
215 $rSelect["{$rid}_a_b"] = $rValue['label_a_b'];
216 $rSelect["{$rid}_b_a"] = $rValue['label_b_a'];
220 $form->addElement('select',
221 'display_relationship_type',
222 ts('Display Results as Relationship'),
224 array('class' => 'crm-select2')
227 // checkboxes for DO NOT phone, email, mail
228 // we take labels from SelectValues
229 $t = CRM_Core_SelectValues
::privacy();
236 'id' => 'privacy_options',
237 'multiple' => 'multiple',
238 'class' => 'crm-select2',
242 $form->addElement('select',
253 2 => ts('Include by Privacy Option(s)'),
255 $form->addRadio('privacy_toggle', ts('Privacy Options'), $options, array('allowClear' => FALSE));
257 // preferred communication method
259 $onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, '');
260 $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold'));
262 $form->addSelect('preferred_communication_method',
263 array('entity' => 'contact', 'multiple' => 'multiple', 'label' => ts('Preferred Communication Method'), 'option_url' => NULL, 'placeholder' => ts('- any -')));
265 //CRM-6138 Preferred Language
266 $form->addSelect('preferred_language', array('class' => 'twenty', 'context' => 'search'));
269 $form->addElement('text', 'phone_numeric', ts('Phone'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Phone', 'phone'));
270 $locationType = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id');
271 $phoneType = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Phone', 'phone_type_id');
272 $form->add('select', 'phone_location_type_id', ts('Phone Location'), array('' => ts('- any -')) +
$locationType, FALSE, array('class' => 'crm-select2'));
273 $form->add('select', 'phone_phone_type_id', ts('Phone Type'), array('' => ts('- any -')) +
$phoneType, FALSE, array('class' => 'crm-select2'));
278 * @param CRM_Core_Form $form
280 public static function location(&$form) {
281 $config = CRM_Core_Config
::singleton();
282 // Build location criteria based on _submitValues if
283 // available; otherwise, use $form->_formValues.
284 $formValues = $form->_submitValues
;
286 if (empty($formValues) && !empty($form->_formValues
)) {
287 $formValues = $form->_formValues
;
290 $form->addElement('hidden', 'hidden_location', 1);
292 $addressOptions = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
293 'address_options', TRUE, NULL, TRUE
296 $attributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Address');
299 'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL, NULL),
300 'city' => array(ts('City'), $attributes['city'], NULL, NULL),
301 'postal_code' => array(ts('Postal Code'), $attributes['postal_code'], NULL, NULL),
302 'country' => array(ts('Country'), $attributes['country_id'], 'country', FALSE),
303 'state_province' => array(ts('State/Province'), $attributes['state_province_id'], 'stateProvince', TRUE),
304 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE),
305 'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL, NULL),
306 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL, NULL),
307 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL, NULL),
308 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL, NULL),
311 $parseStreetAddress = CRM_Utils_Array
::value('street_address_parsing', $addressOptions, 0);
312 $form->assign('parseStreetAddress', $parseStreetAddress);
313 foreach ($elements as $name => $v) {
314 list($title, $attributes, $select, $multiSelect) = $v;
317 array('street_number', 'street_name', 'street_unit')
319 if (!$parseStreetAddress) {
323 elseif (!$addressOptions[$name]) {
328 $attributes = $attributes[$name];
332 if ($select == 'stateProvince' ||
$select == 'county') {
333 $element = $form->addChainSelect($name);
336 $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant
::$select();
337 $element = $form->add('select', $name, $title, $selectElements, FALSE, array('class' => 'crm-select2'));
340 $element->setMultiple(TRUE);
344 $form->addElement('text', $name, $title, $attributes);
347 if ($addressOptions['postal_code']) {
348 $attr = array('class' => 'six') +
(array) CRM_Utils_Array
::value('postal_code', $attributes);
349 $form->addElement('text', 'postal_code_low', NULL, $attr +
array('placeholder' => ts('From')));
350 $form->addElement('text', 'postal_code_high', NULL, $attr +
array('placeholder' => ts('To')));
354 // extend addresses with proximity search
355 if (!empty($config->geocodeMethod
)) {
356 $form->addElement('text', 'prox_distance', ts('Find contacts within'), array('class' => 'six'));
357 $form->addElement('select', 'prox_distance_unit', NULL, array(
358 'miles' => ts('Miles'),
359 'kilos' => ts('Kilometers'),
361 $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric');
364 $form->addSelect('world_region', array('entity' => 'address', 'context' => 'search'));
366 // select for location type
367 $locationType = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id');
368 $form->add('select', 'location_type', ts('Address Location'), $locationType, FALSE, array(
370 'class' => 'crm-select2',
371 'placeholder' => ts('Primary'),
374 // custom data extending addresses -
375 $extends = array('Address');
376 $groupDetails = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, TRUE, $extends);
378 $form->assign('addressGroupTree', $groupDetails);
379 foreach ($groupDetails as $group) {
380 foreach ($group['fields'] as $field) {
381 $elementName = 'custom_' . $field['id'];
382 CRM_Core_BAO_CustomField
::addQuickFormElement($form, $elementName, $field['id'], FALSE, TRUE);
389 * @param CRM_Core_Form $form
391 public static function activity(&$form) {
392 $form->add('hidden', 'hidden_activity', 1);
393 CRM_Activity_BAO_Query
::buildSearchForm($form);
397 * @param CRM_Core_Form $form
399 public static function changeLog(&$form) {
400 $form->add('hidden', 'hidden_changeLog', 1);
402 // block for change log
403 $form->addElement('text', 'changed_by', ts('Modified By'), NULL);
405 $dates = array(1 => ts('Added'), 2 => ts('Modified'));
406 $form->addRadio('log_date', NULL, $dates, array('allowClear' => TRUE), '<br />');
408 CRM_Core_Form_Date
::buildDateRange($form, 'log_date', 1, '_low', '_high', ts('From'), FALSE, FALSE);
412 * @param CRM_Core_Form $form
414 public static function task(&$form) {
415 $form->add('hidden', 'hidden_task', 1);
421 public static function relationship(&$form) {
422 $form->add('hidden', 'hidden_relationship', 1);
424 $allRelationshipType = array();
425 $allRelationshipType = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
426 $form->add('select', 'relation_type_id', ts('Relationship Type'), array('' => ts('- select -')) +
$allRelationshipType, FALSE, array('class' => 'crm-select2'));
427 $form->addElement('text', 'relation_target_name', ts('Target Contact'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
429 $relStatusOption = array(ts('Active'), ts('Inactive'), ts('All'));
430 $form->addRadio('relation_status', ts('Relationship Status'), $relStatusOption);
431 $form->setDefaults(array('relation_status' => 0));
432 // relation permission
433 $relPermissionOption = array(ts('Any'), ts('Yes'), ts('No'));
434 $form->addRadio('relation_permission', ts('Permissioned Relationship?'), $relPermissionOption);
435 $form->setDefaults(array('relation_permission' => 0));
437 //add the target group
439 $form->add('select', 'relation_target_group', ts('Target Contact(s) in Group'), $form->_group
, FALSE,
440 array('id' => 'relation_target_group', 'multiple' => 'multiple', 'class' => 'crm-select2')
443 CRM_Core_Form_Date
::buildDateRange($form, 'relation_start_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
444 CRM_Core_Form_Date
::buildDateRange($form, 'relation_end_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
446 // Add reltionship dates
447 CRM_Core_Form_Date
::buildDateRange($form, 'relation_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
449 // add all the custom searchable fields
450 $relationship = array('Relationship');
451 $groupDetails = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, TRUE, $relationship);
453 $form->assign('relationshipGroupTree', $groupDetails);
454 foreach ($groupDetails as $group) {
455 foreach ($group['fields'] as $field) {
456 $fieldId = $field['id'];
457 $elementName = 'custom_' . $fieldId;
458 CRM_Core_BAO_CustomField
::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
467 public static function demographics(&$form) {
468 $form->add('hidden', 'hidden_demographics', 1);
469 // radio button for gender
470 $genderOptions = array();
471 $gender = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id');
472 foreach ($gender as $key => $var) {
473 $genderOptions[$key] = $form->createElement('radio', NULL,
474 ts('Gender'), $var, $key,
475 array('id' => "civicrm_gender_{$var}_{$key}")
478 $form->addGroup($genderOptions, 'gender_id', ts('Gender'))->setAttribute('allowClear', TRUE);
480 $form->add('text', 'age_low', ts('Min Age'), array('size' => 6));
481 $form->addRule('age_low', ts('Please enter a positive integer'), 'positiveInteger');
482 $form->add('text', 'age_high', ts('Max Age'), array('size' => 6));
483 $form->addRule('age_high', ts('Please enter a positive integer'), 'positiveInteger');
484 $form->addDate('age_asof_date', ts('Age as of Date'), FALSE, array('formatType' => 'searchDate'));
486 CRM_Core_Form_Date
::buildDateRange($form, 'birth_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
488 CRM_Core_Form_Date
::buildDateRange($form, 'deceased_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
490 // radio button for is_deceased
491 $form->addYesNo('is_deceased', ts('Deceased'), TRUE);
497 public static function notes(&$form) {
498 $form->add('hidden', 'hidden_notes', 1);
501 2 => ts('Body Only'),
502 3 => ts('Subject Only'),
505 $form->addRadio('note_option', '', $options);
507 $form->addElement('text', 'note', ts('Note Text'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
509 $form->setDefaults(array('note_option' => 6));
513 * Generate the custom Data Fields based for those with is_searchable = 1.
515 * @param CRM_Contact_Form_Search $form
517 public static function custom(&$form) {
518 $form->add('hidden', 'hidden_custom', 1);
519 $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'),
520 CRM_Contact_BAO_ContactType
::subTypes()
522 $groupDetails = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, TRUE,
526 $form->assign('groupTree', $groupDetails);
528 foreach ($groupDetails as $key => $group) {
529 $_groupTitle[$key] = $group['name'];
530 CRM_Core_ShowHideBlocks
::links($form, $group['name'], '', '');
532 foreach ($group['fields'] as $field) {
533 $fieldId = $field['id'];
534 $elementName = 'custom_' . $fieldId;
535 CRM_Core_BAO_CustomField
::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
543 public static function CiviCase(&$form) {
544 //Looks like obsolete code, since CiviCase is a component, but might be used by HRD
545 $form->add('hidden', 'hidden_CiviCase', 1);
546 CRM_Case_BAO_Query
::buildSearchForm($form);