Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Contact_Form_Search_Criteria { | |
8a4f27dc CW |
36 | /** |
37 | * @param $form CRM_Core_Form | |
38 | */ | |
6a488035 TO |
39 | static function basic(&$form) { |
40 | $form->addElement('hidden', 'hidden_basic', 1); | |
41 | ||
42 | if ($form->_searchOptions['contactType']) { | |
43 | // add checkboxes for contact type | |
b500fbea EM |
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); | |
6a488035 TO |
48 | |
49 | if ($contactTypes) { | |
50 | $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, | |
02ddf039 | 51 | array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;') |
6a488035 TO |
52 | ); |
53 | } | |
54 | } | |
55 | ||
56 | if ($form->_searchOptions['groups']) { | |
57 | // multiselect for groups | |
58 | if ($form->_group) { | |
59 | // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title) | |
f828fa2c | 60 | $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($form->_group, NULL, ' ', TRUE); |
6a488035 TO |
61 | |
62 | $form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE, | |
02ddf039 | 63 | array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2') |
6a488035 TO |
64 | ); |
65 | $groupOptions = CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('group_type'); | |
66 | $form->add('select', 'group_type', ts('Group Types'), $groupOptions, FALSE, | |
02ddf039 | 67 | array('id' => 'group_type', 'multiple' => 'multiple', 'class' => 'crm-select2') |
6a488035 TO |
68 | ); |
69 | $form->add('hidden','group_search_selected','group'); | |
70 | } | |
71 | } | |
72 | ||
73 | if ($form->_searchOptions['tags']) { | |
74 | // multiselect for categories | |
75 | $contactTags = CRM_Core_BAO_Tag::getTags(); | |
76 | ||
77 | if ($contactTags) { | |
78 | $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, | |
02ddf039 | 79 | array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;') |
6a488035 TO |
80 | ); |
81 | } | |
82 | ||
83 | $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); | |
4dff5e17 | 84 | CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE); |
f828fa2c | 85 | |
6a488035 TO |
86 | $used_for = CRM_Core_OptionGroup::values('tag_used_for'); |
87 | $tagsTypes = array(); | |
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 | |
f828fa2c | 96 | $tagsTypes[] = ts($value); |
6a488035 TO |
97 | $showAllTagTypes = true; |
98 | } | |
99 | } | |
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); | |
104 | } | |
105 | } | |
106 | ||
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')); | |
109 | ||
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')); | |
112 | ||
113 | //added contact source | |
114 | $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'contact_source')); | |
115 | ||
116 | //added job title | |
117 | $form->addElement('text', 'job_title', ts('Job Title'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'job_title')); | |
118 | ||
119 | ||
120 | //added internal ID | |
c8ef633b | 121 | $form->addElement('text', 'contact_id', ts('Contact ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'id')); |
5a0739f2 | 122 | $form->addRule('contact_id', ts('Please enter valid Contact ID'), 'positiveInteger'); |
6a488035 TO |
123 | |
124 | //added external ID | |
125 | $form->addElement('text', 'external_identifier', ts('External ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier')); | |
126 | ||
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)')); | |
129 | } | |
130 | ||
131 | // add checkbox for cms users only | |
8a4f27dc | 132 | $form->addYesNo('uf_user', ts('CMS User?'), TRUE); |
6a488035 TO |
133 | |
134 | // tag all search | |
135 | $form->add('text', 'tag_search', ts('All Tags')); | |
136 | ||
137 | // add search profiles | |
138 | ||
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'); | |
142 | ||
143 | // get component profiles | |
144 | $componentProfiles = array(); | |
145 | $componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types); | |
146 | ||
147 | $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1); | |
148 | $accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW); | |
149 | ||
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']; | |
154 | } | |
155 | } | |
156 | ||
157 | $form->addElement('select', | |
158 | 'uf_group_id', | |
159 | ts('Search Views'), | |
160 | array( | |
161 | '0' => ts('- default view -')) + $searchProfiles | |
162 | ); | |
163 | ||
164 | $componentModes = CRM_Contact_Form_Search::getModeSelect(); | |
165 | ||
166 | // unset contributions or participants if user does not have | |
167 | // permission on them | |
168 | if (!CRM_Core_Permission::access('CiviContribute')) { | |
169 | unset($componentModes['2']); | |
170 | } | |
171 | ||
172 | if (!CRM_Core_Permission::access('CiviEvent')) { | |
173 | unset($componentModes['3']); | |
174 | } | |
175 | ||
176 | if (!CRM_Core_Permission::access('CiviMember')) { | |
177 | unset($componentModes['5']); | |
178 | } | |
179 | ||
180 | if (!CRM_Core_Permission::check('view all activities')) { | |
181 | unset($componentModes['4']); | |
182 | } | |
183 | ||
184 | if (count($componentModes) > 1) { | |
185 | $form->addElement('select', | |
186 | 'component_mode', | |
187 | ts('Display Results As'), | |
188 | $componentModes | |
189 | ); | |
190 | } | |
191 | ||
192 | $form->addElement('select', | |
193 | 'operator', | |
194 | ts('Search Operator'), | |
195 | array('AND' => ts('AND'), | |
196 | 'OR' => ts('OR'), | |
197 | ) | |
198 | ); | |
199 | ||
200 | // add the option to display relationships | |
201 | $rTypes = CRM_Core_PseudoConstant::relationshipType(); | |
202 | $rSelect = array('' => ts('- Select Relationship Type-')); | |
203 | foreach ($rTypes as $rid => $rValue) { | |
204 | if ($rValue['label_a_b'] == $rValue['label_b_a']) { | |
205 | $rSelect[$rid] = $rValue['label_a_b']; | |
206 | } | |
207 | else { | |
208 | $rSelect["{$rid}_a_b"] = $rValue['label_a_b']; | |
209 | $rSelect["{$rid}_b_a"] = $rValue['label_b_a']; | |
210 | } | |
211 | } | |
212 | ||
213 | $form->addElement('select', | |
214 | 'display_relationship_type', | |
215 | ts('Display Results as Relationship'), | |
216 | $rSelect | |
217 | ); | |
218 | ||
219 | // checkboxes for DO NOT phone, email, mail | |
220 | // we take labels from SelectValues | |
221 | $t = CRM_Core_SelectValues::privacy(); | |
222 | $form->add('select', | |
223 | 'privacy_options', | |
224 | ts('Privacy'), | |
225 | $t, | |
226 | FALSE, | |
227 | array( | |
228 | 'id' => 'privacy_options', | |
229 | 'multiple' => 'multiple', | |
02ddf039 | 230 | 'class' => 'crm-select2', |
6a488035 TO |
231 | ) |
232 | ); | |
233 | ||
234 | $form->addElement('select', | |
235 | 'privacy_operator', | |
236 | ts('Operator'), | |
237 | array('OR' => ts('OR'), | |
238 | 'AND' => ts('AND'), | |
239 | ) | |
240 | ); | |
241 | ||
242 | $options = array( | |
243 | 1 => ts('Exclude'), | |
244 | 2 => ts('Include by Privacy Option(s)'), | |
245 | ); | |
b847e6e7 | 246 | $form->addRadio('privacy_toggle', ts('Privacy Options'), $options, array('allowClear' => FALSE)); |
6a488035 TO |
247 | |
248 | // preferred communication method | |
e7e657f0 | 249 | $comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'); |
6a488035 TO |
250 | |
251 | $commPreff = array(); | |
252 | foreach ($comm as $k => $v) { | |
253 | $commPreff[] = $form->createElement('advcheckbox', $k, NULL, $v); | |
254 | } | |
255 | ||
256 | $onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, ts('')); | |
257 | $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold')); | |
258 | ||
259 | $form->addGroup($commPreff, 'preferred_communication_method', ts('Preferred Communication Method')); | |
260 | ||
261 | //CRM-6138 Preferred Language | |
c7130c3e | 262 | $form->addSelect('preferred_language', array('class' => 'twenty', 'option_url' => NULL)); |
6a488035 TO |
263 | |
264 | // Phone search | |
265 | $form->addElement('text', 'phone_numeric', ts('Phone Number'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone')); | |
b2b0530a | 266 | $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); |
b4f964d9 | 267 | $phoneType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); |
6a488035 TO |
268 | $form->add('select', 'phone_location_type_id', ts('Phone Location'), array('' => ts('- any -')) + $locationType); |
269 | $form->add('select', 'phone_phone_type_id', ts('Phone Type'), array('' => ts('- any -')) + $phoneType); | |
270 | } | |
271 | ||
272 | ||
86538308 | 273 | /** |
12fbb7b3 | 274 | * @param CRM_Core_Form $form |
86538308 | 275 | */ |
6a488035 | 276 | static function location(&$form) { |
12fbb7b3 | 277 | $config = CRM_Core_Config::singleton(); |
6a488035 TO |
278 | // Build location criteria based on _submitValues if |
279 | // available; otherwise, use $form->_formValues. | |
280 | $formValues = $form->_submitValues; | |
281 | ||
282 | if (empty($formValues) && !empty($form->_formValues)) { | |
283 | $formValues = $form->_formValues; | |
284 | } | |
285 | ||
286 | $form->addElement('hidden', 'hidden_location', 1); | |
287 | ||
288 | $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
289 | 'address_options', TRUE, NULL, TRUE | |
290 | ); | |
291 | ||
292 | $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); | |
293 | ||
294 | $elements = array( | |
295 | 'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL, NULL), | |
296 | 'city' => array(ts('City'), $attributes['city'], NULL, NULL), | |
297 | 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], NULL, NULL), | |
6a488035 | 298 | 'country' => array(ts('Country'), $attributes['country_id'], 'country', FALSE), |
757069de | 299 | 'state_province' => array(ts('State/Province'), $attributes['state_province_id'], 'stateProvince', TRUE), |
c927c151 | 300 | 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE), |
6a488035 TO |
301 | 'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL, NULL), |
302 | 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL, NULL), | |
303 | 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL, NULL), | |
304 | 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL, NULL), | |
305 | ); | |
306 | ||
307 | $parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', $addressOptions, 0); | |
308 | $form->assign('parseStreetAddress', $parseStreetAddress); | |
309 | foreach ($elements as $name => $v) { | |
310 | list($title, $attributes, $select, $multiSelect) = $v; | |
311 | ||
312 | if (in_array($name, | |
313 | array('street_number', 'street_name', 'street_unit') | |
314 | )) { | |
315 | if (!$parseStreetAddress) { | |
316 | continue; | |
317 | } | |
318 | } | |
319 | elseif (!$addressOptions[$name]) { | |
320 | continue; | |
321 | } | |
322 | ||
323 | if (!$attributes) { | |
324 | $attributes = $attributes[$name]; | |
325 | } | |
326 | ||
327 | if ($select) { | |
c927c151 CW |
328 | if ($select == 'stateProvince' || $select == 'county') { |
329 | $element = $form->addChainSelect($name); | |
6a488035 TO |
330 | } |
331 | else { | |
332 | $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select(); | |
02ddf039 | 333 | $element = $form->add('select', $name, $title, $selectElements, FALSE, array('class' => 'crm-select2')); |
6a488035 TO |
334 | } |
335 | if ($multiSelect) { | |
336 | $element->setMultiple(TRUE); | |
337 | } | |
338 | } | |
339 | else { | |
340 | $form->addElement('text', $name, $title, $attributes); | |
341 | } | |
342 | ||
343 | if ($addressOptions['postal_code']) { | |
12fbb7b3 CW |
344 | $attr = array('class' => 'six') + (array) CRM_Utils_Array::value('postal_code', $attributes); |
345 | $form->addElement('text', 'postal_code_low', NULL, $attr + array('placeholder' => ts('From'))); | |
346 | $form->addElement('text', 'postal_code_high', NULL, $attr + array('placeholder' => ts('To'))); | |
6a488035 TO |
347 | } |
348 | } | |
349 | ||
350 | // extend addresses with proximity search | |
12fbb7b3 CW |
351 | if (!empty($config->geocodeMethod)) { |
352 | $form->addElement('text', 'prox_distance', ts('Find contacts within'), array('class' => 'six')); | |
353 | $form->addElement('select', 'prox_distance_unit', NULL, array( | |
354 | 'miles' => ts('Miles'), | |
355 | 'kilos' => ts('Kilometers') | |
356 | )); | |
357 | $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric'); | |
358 | } | |
6a488035 | 359 | |
920600e1 | 360 | $form->addSelect('world_region', array('entity' => 'address', 'placeholder' => ts('- any -'), 'option_url' => NULL)); |
6a488035 | 361 | |
d8a8bb0b | 362 | // select for location type |
b2b0530a | 363 | $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); |
d8a8bb0b CW |
364 | $form->add('select', 'location_type', ts('Address Location'), $locationType, FALSE, array( |
365 | 'multiple' => TRUE, | |
366 | 'class' => 'crm-select2', | |
367 | 'placeholder' => ts('Primary'), | |
368 | )); | |
6a488035 TO |
369 | |
370 | // custom data extending addresses - | |
371 | $extends = array('Address'); | |
372 | $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); | |
373 | if ($groupDetails) { | |
374 | $form->assign('addressGroupTree', $groupDetails); | |
375 | foreach ($groupDetails as $group) { | |
376 | foreach ($group['fields'] as $field) { | |
377 | $elementName = 'custom_' . $field['id']; | |
378 | CRM_Core_BAO_CustomField::addQuickFormElement($form, | |
379 | $elementName, | |
380 | $field['id'], | |
381 | FALSE, FALSE, TRUE | |
382 | ); | |
383 | } | |
384 | } | |
385 | } | |
386 | } | |
387 | ||
86538308 | 388 | /** |
c490a46a | 389 | * @param CRM_Core_Form $form |
86538308 | 390 | */ |
6a488035 TO |
391 | static function activity(&$form) { |
392 | $form->add('hidden', 'hidden_activity', 1); | |
393 | CRM_Activity_BAO_Query::buildSearchForm($form); | |
394 | } | |
395 | ||
86538308 | 396 | /** |
c490a46a | 397 | * @param CRM_Core_Form $form |
86538308 | 398 | */ |
6a488035 TO |
399 | static function changeLog(&$form) { |
400 | $form->add('hidden', 'hidden_changeLog', 1); | |
401 | ||
402 | // block for change log | |
403 | $form->addElement('text', 'changed_by', ts('Modified By'), NULL); | |
404 | ||
405 | $dates = array(1 => ts('Added'), 2 => ts('Modified')); | |
b847e6e7 | 406 | $form->addRadio('log_date', NULL, $dates, array('allowClear' => TRUE), '<br />'); |
6a488035 TO |
407 | |
408 | CRM_Core_Form_Date::buildDateRange($form, 'log_date', 1, '_low', '_high', ts('From'), FALSE, FALSE); | |
409 | } | |
410 | ||
86538308 | 411 | /** |
c490a46a | 412 | * @param CRM_Core_Form $form |
86538308 | 413 | */ |
6a488035 TO |
414 | static function task(&$form) { |
415 | $form->add('hidden', 'hidden_task', 1); | |
416 | } | |
417 | ||
86538308 EM |
418 | /** |
419 | * @param $form | |
420 | */ | |
6a488035 TO |
421 | static function relationship(&$form) { |
422 | $form->add('hidden', 'hidden_relationship', 1); | |
423 | ||
424 | $allRelationshipType = array(); | |
425 | $allRelationshipType = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE); | |
02ddf039 | 426 | $form->add('select', 'relation_type_id', ts('Relationship Type'), array('' => ts('- select -')) + $allRelationshipType, FALSE, array('class' => 'crm-select2')); |
6a488035 | 427 | $form->addElement('text', 'relation_target_name', ts('Target Contact'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); |
5ea73a9f | 428 | // relation status |
9e4a7990 | 429 | $relStatusOption = array(ts('Active'), ts('Inactive'), ts('All')); |
6a488035 TO |
430 | $form->addRadio('relation_status', ts('Relationship Status'), $relStatusOption); |
431 | $form->setDefaults(array('relation_status' => 0)); | |
5ea73a9f | 432 | // relation permission |
9e4a7990 | 433 | $relPermissionOption = array(ts('Any'), ts('Yes'), ts('No') ); |
5ea73a9f DG |
434 | $form->addRadio('relation_permission', ts('Permissioned Relationship?'), $relPermissionOption); |
435 | $form->setDefaults(array('relation_permission' => 0)); | |
6a488035 TO |
436 | |
437 | //add the target group | |
438 | if ($form->_group) { | |
439 | $form->add('select', 'relation_target_group', ts('Target Contact(s) in Group'), $form->_group, FALSE, | |
02ddf039 | 440 | array('id' => 'relation_target_group', 'multiple' => 'multiple', 'class' => 'crm-select2') |
6a488035 TO |
441 | ); |
442 | } | |
ad682134 | 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); | |
6a488035 TO |
445 | |
446 | // Add reltionship dates | |
447 | CRM_Core_Form_Date::buildDateRange($form, 'relation_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE); | |
448 | ||
449 | // add all the custom searchable fields | |
450 | $relationship = array('Relationship'); | |
451 | $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $relationship); | |
452 | if ($groupDetails) { | |
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, | |
459 | $elementName, | |
460 | $fieldId, | |
461 | FALSE, FALSE, TRUE | |
462 | ); | |
463 | } | |
464 | } | |
465 | } | |
466 | } | |
467 | ||
86538308 EM |
468 | /** |
469 | * @param $form | |
470 | */ | |
6a488035 TO |
471 | static function demographics(&$form) { |
472 | $form->add('hidden', 'hidden_demographics', 1); | |
473 | // radio button for gender | |
474 | $genderOptions = array(); | |
26cf88b5 | 475 | $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); |
6a488035 TO |
476 | foreach ($gender as $key => $var) { |
477 | $genderOptions[$key] = $form->createElement('radio', NULL, | |
478 | ts('Gender'), $var, $key, | |
479 | array('id' => "civicrm_gender_{$var}_{$key}") | |
480 | ); | |
481 | } | |
b847e6e7 | 482 | $form->addGroup($genderOptions, 'gender_id', ts('Gender'))->setAttribute('allowClear', TRUE); |
6a488035 TO |
483 | |
484 | CRM_Core_Form_Date::buildDateRange($form, 'birth_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); | |
485 | ||
486 | CRM_Core_Form_Date::buildDateRange($form, 'deceased_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); | |
487 | ||
488 | ||
489 | // radio button for is_deceased | |
8a4f27dc | 490 | $form->addYesNo( 'is_deceased', ts('Deceased'), TRUE); |
6a488035 TO |
491 | } |
492 | ||
86538308 EM |
493 | /** |
494 | * @param $form | |
495 | */ | |
6a488035 TO |
496 | static function notes(&$form) { |
497 | $form->add('hidden', 'hidden_notes', 1); | |
498 | ||
499 | $options = array( | |
500 | 2 => ts('Body Only'), | |
501 | 3 => ts('Subject Only'), | |
502 | 6 => ts('Both'), | |
503 | ); | |
504 | $form->addRadio('note_option', '', $options); | |
505 | ||
506 | $form->addElement('text', 'note', ts('Note Text'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); | |
507 | ||
508 | $form->setDefaults(array('note_option' => 6)); | |
509 | } | |
510 | ||
511 | /** | |
512 | * Generate the custom Data Fields based | |
513 | * on the is_searchable | |
514 | * | |
515 | * @access private | |
516 | * | |
2a6da8d7 EM |
517 | * @param $form |
518 | * | |
6a488035 TO |
519 | * @return void |
520 | */ | |
521 | static function custom(&$form) { | |
522 | $form->add('hidden', 'hidden_custom', 1); | |
523 | $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), | |
524 | CRM_Contact_BAO_ContactType::subTypes() | |
525 | ); | |
526 | $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, | |
527 | $extends | |
528 | ); | |
529 | ||
530 | $form->assign('groupTree', $groupDetails); | |
531 | ||
532 | foreach ($groupDetails as $key => $group) { | |
533 | $_groupTitle[$key] = $group['name']; | |
534 | CRM_Core_ShowHideBlocks::links($form, $group['name'], '', ''); | |
535 | ||
536 | $groupId = $group['id']; | |
537 | foreach ($group['fields'] as $field) { | |
538 | $fieldId = $field['id']; | |
539 | $elementName = 'custom_' . $fieldId; | |
540 | ||
541 | CRM_Core_BAO_CustomField::addQuickFormElement($form, | |
542 | $elementName, | |
543 | $fieldId, | |
544 | FALSE, FALSE, TRUE | |
545 | ); | |
546 | } | |
547 | } | |
548 | ||
549 | //TODO: validate for only one state if prox_distance isset | |
550 | } | |
551 | ||
86538308 EM |
552 | /** |
553 | * @param $form | |
554 | */ | |
6a488035 TO |
555 | static function CiviCase(&$form) { |
556 | //Looks like obsolete code, since CiviCase is a component, but might be used by HRD | |
557 | $form->add('hidden', 'hidden_CiviCase', 1); | |
558 | CRM_Case_BAO_Query::buildSearchForm($form); | |
559 | } | |
560 | } | |
561 |