3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
35 class CRM_Contact_Form_Search_Criteria
{
37 * @param CRM_Core_Form $form
39 public static function basic(&$form) {
40 $form->addElement('hidden', 'hidden_basic', 1);
42 if ($form->_searchOptions
['contactType']) {
43 // add checkboxes for contact type
44 //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
45 // this is loaded onto then replace with something like '__' & test
46 $separator = CRM_Core_DAO
::VALUE_SEPARATOR
;
47 $contactTypes = CRM_Contact_BAO_ContactType
::getSelectElements(FALSE, TRUE, $separator);
50 $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE,
51 array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;')
56 if ($form->_searchOptions
['groups']) {
57 // multiselect for groups
59 // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title)
60 $groupHierarchy = CRM_Contact_BAO_Group
::getGroupsHierarchy($form->_group
, NULL, ' ', TRUE);
62 $form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE,
63 array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2')
65 $groupOptions = CRM_Core_BAO_OptionValue
::getOptionValuesAssocArrayFromName('group_type');
66 $form->add('select', 'group_type', ts('Group Types'), $groupOptions, FALSE,
67 array('id' => 'group_type', 'multiple' => 'multiple', 'class' => 'crm-select2')
69 $form->add('hidden', 'group_search_selected', 'group');
73 if ($form->_searchOptions
['tags']) {
74 // multiselect for categories
75 $contactTags = CRM_Core_BAO_Tag
::getTags();
78 $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE,
79 array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;')
83 $parentNames = CRM_Core_BAO_Tag
::getTagSet('civicrm_contact');
84 CRM_Core_Form_Tag
::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE);
86 $used_for = CRM_Core_OptionGroup
::values('tag_used_for');
88 $showAllTagTypes = FALSE;
89 foreach ($used_for as $key => $value) {
90 //check tags for every type and find if there are any defined
91 $tags = CRM_Core_BAO_Tag
::getTagsUsedFor($key, FALSE, TRUE, NULL);
92 // check if there are tags other than contact type, if no - keep checkbox hidden on adv search
93 // we will hide searching contact by attachments tags until it will be implemented in core
94 if (count($tags) && $key != 'civicrm_file' && $key != 'civicrm_contact') {
95 //if tags exists then add type to display in adv search form help text
96 $tagsTypes[] = ts($value);
97 $showAllTagTypes = TRUE;
100 $tagTypesText = implode(" or ", $tagsTypes);
101 if ($showAllTagTypes) {
102 $form->add('checkbox', 'all_tag_types', ts('Include tags used for %1', array(1 => $tagTypesText)));
103 $form->add('hidden', 'tag_types_text', $tagTypesText);
107 // add text box for last name, first name, street name, city
108 $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
110 // add text box for last name, first name, street name, city
111 $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
113 //added contact source
114 $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'contact_source'));
117 $form->addElement('text', 'job_title', ts('Job Title'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'job_title'));
121 $form->addElement('text', 'contact_id', ts('Contact ID'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'id'));
122 $form->addRule('contact_id', ts('Please enter valid Contact ID'), 'positiveInteger');
125 $form->addElement('text', 'external_identifier', ts('External ID'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'));
127 if (CRM_Core_Permission
::check('access deleted contacts') and CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'contact_undelete', NULL)) {
128 $form->add('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
131 // add checkbox for cms users only
132 $form->addYesNo('uf_user', ts('CMS User?'), TRUE);
135 $form->add('text', 'tag_search', ts('All Tags'));
137 // add search profiles
139 // FIXME: This is probably a part of profiles - need to be
140 // FIXME: eradicated from here when profiles are reworked.
141 $types = array('Participant', 'Contribution', 'Membership');
143 // get component profiles
144 $componentProfiles = array();
145 $componentProfiles = CRM_Core_BAO_UFGroup
::getProfiles($types);
147 $ufGroups = CRM_Core_BAO_UFGroup
::getModuleUFGroup('Search Profile', 1);
148 $accessibleUfGroups = CRM_Core_Permission
::ufGroup(CRM_Core_Permission
::VIEW
);
150 $searchProfiles = array();
151 foreach ($ufGroups as $key => $var) {
152 if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
153 $searchProfiles[$key] = $var['title'];
157 $form->addElement('select',
161 '0' => ts('- default view -')
165 $componentModes = CRM_Contact_Form_Search
::getModeSelect();
167 // unset contributions or participants if user does not have
168 // permission on them
169 if (!CRM_Core_Permission
::access('CiviContribute')) {
170 unset($componentModes['2']);
173 if (!CRM_Core_Permission
::access('CiviEvent')) {
174 unset($componentModes['3']);
177 if (!CRM_Core_Permission
::access('CiviMember')) {
178 unset($componentModes['5']);
181 if (!CRM_Core_Permission
::check('view all activities')) {
182 unset($componentModes['4']);
185 if (count($componentModes) > 1) {
186 $form->addElement('select',
188 ts('Display Results As'),
193 $form->addElement('select',
195 ts('Search Operator'),
202 // add the option to display relationships
203 $rTypes = CRM_Core_PseudoConstant
::relationshipType();
204 $rSelect = array('' => ts('- Select Relationship Type-'));
205 foreach ($rTypes as $rid => $rValue) {
206 if ($rValue['label_a_b'] == $rValue['label_b_a']) {
207 $rSelect[$rid] = $rValue['label_a_b'];
210 $rSelect["{$rid}_a_b"] = $rValue['label_a_b'];
211 $rSelect["{$rid}_b_a"] = $rValue['label_b_a'];
215 $form->addElement('select',
216 'display_relationship_type',
217 ts('Display Results as Relationship'),
221 // checkboxes for DO NOT phone, email, mail
222 // we take labels from SelectValues
223 $t = CRM_Core_SelectValues
::privacy();
230 'id' => 'privacy_options',
231 'multiple' => 'multiple',
232 'class' => 'crm-select2',
236 $form->addElement('select',
247 2 => ts('Include by Privacy Option(s)'),
249 $form->addRadio('privacy_toggle', ts('Privacy Options'), $options, array('allowClear' => FALSE));
251 // preferred communication method
252 $comm = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
254 $commPreff = array();
255 foreach ($comm as $k => $v) {
256 $commPreff[] = $form->createElement('advcheckbox', $k, NULL, $v);
259 $onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, ts(''));
260 $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold'));
262 $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method'));
264 //CRM-6138 Preferred Language
265 $form->addSelect('preferred_language', array('class' => 'twenty', 'context' => 'search'));
268 $form->addElement('text', 'phone_numeric', ts('Phone Number'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Phone', 'phone'));
269 $locationType = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id');
270 $phoneType = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Phone', 'phone_type_id');
271 $form->add('select', 'phone_location_type_id', ts('Phone Location'), array('' => ts('- any -')) +
$locationType);
272 $form->add('select', 'phone_phone_type_id', ts('Phone Type'), array('' => ts('- any -')) +
$phoneType);
277 * @param CRM_Core_Form $form
279 public static function location(&$form) {
280 $config = CRM_Core_Config
::singleton();
281 // Build location criteria based on _submitValues if
282 // available; otherwise, use $form->_formValues.
283 $formValues = $form->_submitValues
;
285 if (empty($formValues) && !empty($form->_formValues
)) {
286 $formValues = $form->_formValues
;
289 $form->addElement('hidden', 'hidden_location', 1);
291 $addressOptions = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
292 'address_options', TRUE, NULL, TRUE
295 $attributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Address');
298 'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL, NULL),
299 'city' => array(ts('City'), $attributes['city'], NULL, NULL),
300 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], NULL, NULL),
301 'country' => array(ts('Country'), $attributes['country_id'], 'country', FALSE),
302 'state_province' => array(ts('State/Province'), $attributes['state_province_id'], 'stateProvince', TRUE),
303 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE),
304 'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL, NULL),
305 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL, NULL),
306 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL, NULL),
307 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL, NULL),
310 $parseStreetAddress = CRM_Utils_Array
::value('street_address_parsing', $addressOptions, 0);
311 $form->assign('parseStreetAddress', $parseStreetAddress);
312 foreach ($elements as $name => $v) {
313 list($title, $attributes, $select, $multiSelect) = $v;
316 array('street_number', 'street_name', 'street_unit')
318 if (!$parseStreetAddress) {
322 elseif (!$addressOptions[$name]) {
327 $attributes = $attributes[$name];
331 if ($select == 'stateProvince' ||
$select == 'county') {
332 $element = $form->addChainSelect($name);
335 $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant
::$select();
336 $element = $form->add('select', $name, $title, $selectElements, FALSE, array('class' => 'crm-select2'));
339 $element->setMultiple(TRUE);
343 $form->addElement('text', $name, $title, $attributes);
346 if ($addressOptions['postal_code']) {
347 $attr = array('class' => 'six') +
(array) CRM_Utils_Array
::value('postal_code', $attributes);
348 $form->addElement('text', 'postal_code_low', NULL, $attr +
array('placeholder' => ts('From')));
349 $form->addElement('text', 'postal_code_high', NULL, $attr +
array('placeholder' => ts('To')));
353 // extend addresses with proximity search
354 if (!empty($config->geocodeMethod
)) {
355 $form->addElement('text', 'prox_distance', ts('Find contacts within'), array('class' => 'six'));
356 $form->addElement('select', 'prox_distance_unit', NULL, array(
357 'miles' => ts('Miles'),
358 'kilos' => ts('Kilometers'),
360 $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric');
363 $form->addSelect('world_region', array('entity' => 'address', 'context' => 'search'));
365 // select for location type
366 $locationType = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id');
367 $form->add('select', 'location_type', ts('Address Location'), $locationType, FALSE, array(
369 'class' => 'crm-select2',
370 'placeholder' => ts('Primary'),
373 // custom data extending addresses -
374 $extends = array('Address');
375 $groupDetails = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, TRUE, $extends);
377 $form->assign('addressGroupTree', $groupDetails);
378 foreach ($groupDetails as $group) {
379 foreach ($group['fields'] as $field) {
380 $elementName = 'custom_' . $field['id'];
381 CRM_Core_BAO_CustomField
::addQuickFormElement($form,
392 * @param CRM_Core_Form $form
394 public static function activity(&$form) {
395 $form->add('hidden', 'hidden_activity', 1);
396 CRM_Activity_BAO_Query
::buildSearchForm($form);
400 * @param CRM_Core_Form $form
402 public static function changeLog(&$form) {
403 $form->add('hidden', 'hidden_changeLog', 1);
405 // block for change log
406 $form->addElement('text', 'changed_by', ts('Modified By'), NULL);
408 $dates = array(1 => ts('Added'), 2 => ts('Modified'));
409 $form->addRadio('log_date', NULL, $dates, array('allowClear' => TRUE), '<br />');
411 CRM_Core_Form_Date
::buildDateRange($form, 'log_date', 1, '_low', '_high', ts('From'), FALSE, FALSE);
415 * @param CRM_Core_Form $form
417 public static function task(&$form) {
418 $form->add('hidden', 'hidden_task', 1);
424 public static function relationship(&$form) {
425 $form->add('hidden', 'hidden_relationship', 1);
427 $allRelationshipType = array();
428 $allRelationshipType = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
429 $form->add('select', 'relation_type_id', ts('Relationship Type'), array('' => ts('- select -')) +
$allRelationshipType, FALSE, array('class' => 'crm-select2'));
430 $form->addElement('text', 'relation_target_name', ts('Target Contact'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
432 $relStatusOption = array(ts('Active'), ts('Inactive'), ts('All'));
433 $form->addRadio('relation_status', ts('Relationship Status'), $relStatusOption);
434 $form->setDefaults(array('relation_status' => 0));
435 // relation permission
436 $relPermissionOption = array(ts('Any'), ts('Yes'), ts('No'));
437 $form->addRadio('relation_permission', ts('Permissioned Relationship?'), $relPermissionOption);
438 $form->setDefaults(array('relation_permission' => 0));
440 //add the target group
442 $form->add('select', 'relation_target_group', ts('Target Contact(s) in Group'), $form->_group
, FALSE,
443 array('id' => 'relation_target_group', 'multiple' => 'multiple', 'class' => 'crm-select2')
446 CRM_Core_Form_Date
::buildDateRange($form, 'relation_start_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
447 CRM_Core_Form_Date
::buildDateRange($form, 'relation_end_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
449 // Add reltionship dates
450 CRM_Core_Form_Date
::buildDateRange($form, 'relation_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
452 // add all the custom searchable fields
453 $relationship = array('Relationship');
454 $groupDetails = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, TRUE, $relationship);
456 $form->assign('relationshipGroupTree', $groupDetails);
457 foreach ($groupDetails as $group) {
458 foreach ($group['fields'] as $field) {
459 $fieldId = $field['id'];
460 $elementName = 'custom_' . $fieldId;
461 CRM_Core_BAO_CustomField
::addQuickFormElement($form,
474 public static function demographics(&$form) {
475 $form->add('hidden', 'hidden_demographics', 1);
476 // radio button for gender
477 $genderOptions = array();
478 $gender = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id');
479 foreach ($gender as $key => $var) {
480 $genderOptions[$key] = $form->createElement('radio', NULL,
481 ts('Gender'), $var, $key,
482 array('id' => "civicrm_gender_{$var}_{$key}")
485 $form->addGroup($genderOptions, 'gender_id', ts('Gender'))->setAttribute('allowClear', TRUE);
487 CRM_Core_Form_Date
::buildDateRange($form, 'birth_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
489 CRM_Core_Form_Date
::buildDateRange($form, 'deceased_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
492 // radio button for is_deceased
493 $form->addYesNo('is_deceased', ts('Deceased'), TRUE);
499 public static function notes(&$form) {
500 $form->add('hidden', 'hidden_notes', 1);
503 2 => ts('Body Only'),
504 3 => ts('Subject Only'),
507 $form->addRadio('note_option', '', $options);
509 $form->addElement('text', 'note', ts('Note Text'), CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
511 $form->setDefaults(array('note_option' => 6));
515 * Generate the custom Data Fields based
516 * on the is_searchable
523 public static function custom(&$form) {
524 $form->add('hidden', 'hidden_custom', 1);
525 $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'),
526 CRM_Contact_BAO_ContactType
::subTypes()
528 $groupDetails = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, TRUE,
532 $form->assign('groupTree', $groupDetails);
534 foreach ($groupDetails as $key => $group) {
535 $_groupTitle[$key] = $group['name'];
536 CRM_Core_ShowHideBlocks
::links($form, $group['name'], '', '');
538 $groupId = $group['id'];
539 foreach ($group['fields'] as $field) {
540 $fieldId = $field['id'];
541 $elementName = 'custom_' . $fieldId;
543 CRM_Core_BAO_CustomField
::addQuickFormElement($form,
551 //TODO: validate for only one state if prox_distance isset
557 public static function CiviCase(&$form) {
558 //Looks like obsolete code, since CiviCase is a component, but might be used by HRD
559 $form->add('hidden', 'hidden_CiviCase', 1);
560 CRM_Case_BAO_Query
::buildSearchForm($form);