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