PluginProbe
Property Hive / 1.4.62
Property Hive v1.4.62
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / ph-form-functions.php

ph-form-functions.php in Property Hive 1.4.62, at includes/ph-form-functions.php

1,518 lines 56.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Form Functions
4 *
5 * Functions related to drawing forms on the frontend.
6 *
7 * @author PropertyHive
8 * @category Core
9 * @package PropertyHive/Functions
10 * @version 1.0.0
11 */
12
13 /**
14 * Main function for drawing entire property search form. We give the ability for an ID to be passed so differently formatted forms can be used
15 * (ie. a homepage search form might be different from a search form on search results)
16 *
17 * @param string $id
18 * @return void
19 */
20 function ph_get_search_form( $id = 'default' ) {
21
22 $form_controls = ph_get_search_form_fields();
23
24 $form_controls = apply_filters( 'propertyhive_search_form_fields_' . $id, $form_controls );
25 $form_controls = apply_filters( 'propertyhive_search_form_fields', $form_controls );
26
27 // We 100% need department so make sure it exists. If it doesn't, set a hidden field
28 if ( !isset($form_controls['department']) )
29 {
30 $original_form_controls = ph_get_search_form_fields();
31 $original_department = $original_form_controls['department'];
32 $original_department['type'] = 'hidden';
33
34 $form_controls['department'] = $original_department;
35 }
36
37 // append hidden order and view fields so these are maintained should a new search be performed
38 foreach ( $_REQUEST as $key => $value )
39 {
40 if ( isset($form_controls[$key]) )
41 continue;
42
43 if ( $key == 'officeID' && isset($form_controls['office']) )
44 continue;
45
46 if ( $key == 'paged' )
47 continue;
48
49 if (
50 ( $key == 'minimum_price' || $key == 'maximum_price' ) && array_key_exists('price_slider', $form_controls) ||
51 ( $key == 'minimum_rent' || $key == 'maximum_rent' ) && array_key_exists('rent_slider', $form_controls) ||
52 ( $key == 'minimum_bedrooms' || $key == 'maximum_bedrooms' ) && array_key_exists('bedrooms_slider', $form_controls)
53 )
54 continue;
55
56 // we've received a field that isn't a standard form control so let's store it in a hidden field so it's not lost
57 if ( is_array($value) )
58 {
59 foreach ( $value as $i => $val )
60 {
61 $form_controls[$key . '-' . $i] = array('type' => 'hidden', 'name' => $key . '[]', 'value' => stripslashes( ph_clean( $val) ));
62 }
63 }
64 else
65 {
66 $form_controls[$key] = array('type' => 'hidden', 'value' => stripslashes( ph_clean( $value) ));
67 }
68 }
69
70 $form_controls = apply_filters( 'propertyhive_search_form_fields_after_' . $id, $form_controls );
71 $form_controls = apply_filters( 'propertyhive_search_form_fields_after', $form_controls );
72
73 ph_get_template( 'global/search-form.php', array( 'form_controls' => $form_controls, 'id' => $id ) );
74
75 }
76
77 /**
78 * Get default fields to be shown on search forms
79 *
80 * @return array
81 */
82 function ph_get_search_form_fields()
83 {
84 $fields = array();
85
86 $departments = ph_get_departments();
87
88 $department_options = array();
89 $default_value = '';
90
91 foreach ( $departments as $key => $value )
92 {
93 if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' )
94 {
95 $department_options[$key] = $value;
96
97 if ($default_value == '' && get_option( 'propertyhive_primary_department' ) == $key )
98 {
99 $default_value = $key;
100 }
101 }
102 }
103
104 $fields['department'] = array(
105 'type' => 'radio',
106 'options' => $department_options,
107 'value' => $default_value
108 );
109
110 if ( array_key_exists('residential-sales', $departments) || array_key_exists('residential-lettings', $departments) )
111 {
112 if ( array_key_exists('residential-sales', $departments) )
113 {
114 $prices = array(
115 '' => __( 'No preference', 'propertyhive' ),
116 '100000' => '&pound;100,000',
117 '150000' => '&pound;150,000',
118 '200000' => '&pound;200,000',
119 '250000' => '&pound;250,000',
120 '300000' => '&pound;300,000',
121 '500000' => '&pound;500,000',
122 '750000' => '&pound;750,000',
123 '1000000' => '&pound;1,000,000'
124 );
125
126 $fields['minimum_price'] = array(
127 'type' => 'select',
128 'show_label' => true,
129 'label' => __( 'Min Price', 'propertyhive' ),
130 'before' => '<div class="control control-minimum_price sales-only">',
131 'options' => $prices
132 );
133
134 $fields['maximum_price'] = array(
135 'type' => 'select',
136 'show_label' => true,
137 'label' => __( 'Max Price', 'propertyhive' ),
138 'before' => '<div class="control control-maximum_price sales-only">',
139 'options' => $prices
140 );
141 }
142
143 if ( array_key_exists('residential-lettings', $departments) )
144 {
145 $prices = array(
146 '' => __( 'No preference', 'propertyhive' ),
147 '500' => '&pound;500 PCM',
148 '600' => '&pound;600 PCM',
149 '750' => '&pound;750 PCM',
150 '1000' => '&pound;1000 PCM',
151 '1250' => '&pound;1250 PCM',
152 '1500' => '&pound;1500 PCM',
153 '2000' => '&pound;2000 PCM'
154 );
155
156 $fields['minimum_rent'] = array(
157 'type' => 'select',
158 'show_label' => true,
159 'label' => __( 'Min Rent', 'propertyhive' ),
160 'before' => '<div class="control control-minimum_rent lettings-only">',
161 'options' => $prices
162 );
163
164 $fields['maximum_rent'] = array(
165 'type' => 'select',
166 'show_label' => true,
167 'label' => __( 'Max Rent', 'propertyhive' ),
168 'before' => '<div class="control control-maximum_rent lettings-only">',
169 'options' => $prices
170 );
171 }
172
173 $fields['minimum_bedrooms'] = array(
174 'type' => 'select',
175 'show_label' => true,
176 'label' => __( 'Min Beds', 'propertyhive' ),
177 'before' => '<div class="control control-minimum_bedrooms residential-only">',
178 'options' => array( '' => __( 'No preference', 'propertyhive' ), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5)
179 );
180
181 $fields['property_type'] = array(
182 'type' => 'property_type',
183 'show_label' => true,
184 'before' => '<div class="control control-property_type residential-only">',
185 'label' => __( 'Type', 'propertyhive' ),
186 );
187 }
188
189 if ( array_key_exists('commercial', $departments) )
190 {
191 $sizes = array(
192 '' => __( 'No preference', 'propertyhive' ),
193 '250' => '250 sq ft',
194 '500' => '500 sq ft',
195 '1000' => '1,000 sq ft',
196 '2500' => '2,500 sq ft',
197 '5000' => '5,000 sq ft',
198 '10000' => '10,000 sq ft',
199 '25000' => '25,000 sq ft',
200 '50000' => '50,000 sq ft'
201 );
202
203 $fields['minimum_floor_area'] = array(
204 'type' => 'select',
205 'show_label' => true,
206 'label' => __( 'Min Floor Area', 'propertyhive' ),
207 'before' => '<div class="control control-minimum_floor_area commercial-only">',
208 'options' => $sizes
209 );
210
211 $fields['maximum_floor_area'] = array(
212 'type' => 'select',
213 'show_label' => true,
214 'label' => __( 'Max Floor Area', 'propertyhive' ),
215 'before' => '<div class="control control-maximum_floor_area commercial-only">',
216 'options' => $sizes
217 );
218
219 // Property Type
220 $options = array( '' => __( 'No preference', 'propertyhive' ) );
221 $args = array(
222 'hide_empty' => false,
223 'parent' => 0
224 );
225 $terms = get_terms( 'commercial_property_type', $args );
226
227 $selected_value = '';
228 if ( !empty( $terms ) && !is_wp_error( $terms ) )
229 {
230 foreach ($terms as $term)
231 {
232 $options[$term->term_id] = $term->name;
233
234 $args = array(
235 'hide_empty' => false,
236 'parent' => $term->term_id
237 );
238 $subterms = get_terms( 'commercial_property_type', $args );
239
240 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
241 {
242 foreach ($subterms as $term)
243 {
244 $options[$term->term_id] = '- ' . $term->name;
245 }
246 }
247 }
248 }
249
250 $fields['commercial_property_type'] = array(
251 'type' => 'select',
252 'show_label' => true,
253 'before' => '<div class="control control-commercial_property_type commercial-only">',
254 'label' => __( 'Type', 'propertyhive' ),
255 'options' => $options
256 );
257 }
258
259 return $fields;
260 }
261
262 /**
263 * Main function for drawing property enquiry form.
264 *
265 * @param string $id
266 * @return void
267 */
268 function propertyhive_enquiry_form( $property_id = '' )
269 {
270 $form_controls = ph_get_property_enquiry_form_fields( $property_id );
271
272 $form_controls = apply_filters( 'propertyhive_property_enquiry_form_fields', $form_controls );
273
274 ph_get_template( 'global/make-enquiry-form.php',array( 'form_controls' => $form_controls ) );
275 }
276
277 /**
278 * Get default fields to be shown on search forms
279 *
280 * @return array
281 */
282 function ph_get_property_enquiry_form_fields( $property_id = '' )
283 {
284 global $post;
285
286 $fields = array();
287
288 $fields['property_id'] = array(
289 'type' => 'hidden',
290 'value' => ( $property_id != '' ? $property_id : $post->ID )
291 );
292
293 $fields['name'] = array(
294 'type' => 'text',
295 'label' => __( 'Full Name', 'propertyhive' ),
296 'required' => true
297 );
298 if ( is_user_logged_in() )
299 {
300 $current_user = wp_get_current_user();
301
302 $fields['name']['value'] = $current_user->display_name;
303 }
304
305 $fields['email_address'] = array(
306 'type' => 'email',
307 'label' => __( 'Email Address', 'propertyhive' ),
308 'required' => true
309 );
310 if ( is_user_logged_in() )
311 {
312 $current_user = wp_get_current_user();
313
314 $fields['email_address']['value'] = $current_user->user_email;
315 }
316
317 $fields['telephone_number'] = array(
318 'type' => 'text',
319 'label' => __( 'Number', 'propertyhive' ),
320 'required' => true
321 );
322
323 $fields['message'] = array(
324 'type' => 'textarea',
325 'label' => __( 'Message', 'propertyhive' ),
326 'required' => true
327 );
328
329 if ( get_option( 'propertyhive_property_enquiry_form_disclaimer', '' ) != '' )
330 {
331 $disclaimer = get_option( 'propertyhive_property_enquiry_form_disclaimer', '' );
332
333 $fields['disclaimer'] = array(
334 'type' => 'checkbox',
335 'label' => $disclaimer,
336 'label_style' => 'width:100%;',
337 'required' => true
338 );
339 }
340
341 return $fields;
342 }
343
344 /**
345 * Get default fields to be shown on applicant registration forms
346 *
347 * @return array
348 */
349 function ph_get_user_details_form_fields()
350 {
351 global $post;
352
353 if ( is_user_logged_in() )
354 {
355 $current_user = wp_get_current_user();
356
357 if ( $current_user instanceof WP_User )
358 {
359 $contact = new PH_Contact( '', $current_user->ID );
360 }
361 }
362
363 $fields = array();
364
365 $fields['name'] = array(
366 'type' => 'text',
367 'label' => __( 'Full Name', 'propertyhive' ),
368 'required' => true
369 );
370 if ( is_user_logged_in() && $current_user instanceof WP_User )
371 {
372 $fields['name']['value'] = $current_user->display_name;
373 }
374
375 $fields['email_address'] = array(
376 'type' => 'email',
377 'label' => __( 'Email Address', 'propertyhive' ),
378 'required' => true
379 );
380 if ( is_user_logged_in() && $current_user instanceof WP_User )
381 {
382 $fields['email_address']['value'] = $current_user->user_email;
383 }
384
385 $fields['telephone_number'] = array(
386 'type' => 'text',
387 'label' => __( 'Telephone Number', 'propertyhive' ),
388 'required' => false
389 );
390 if ( is_user_logged_in() && $current_user instanceof WP_User )
391 {
392 $fields['telephone_number']['value'] = $contact->telephone_number;
393 }
394
395 if ( get_option( 'propertyhive_applicant_users', '' ) == 'yes' )
396 {
397 $fields['password'] = array(
398 'type' => 'password',
399 'label' => __( 'Password', 'propertyhive' ),
400 'required' => true
401 );
402
403 $fields['password2'] = array(
404 'type' => 'password',
405 'label' => __( 'Confirm Password', 'propertyhive' ),
406 'required' => true
407 );
408 }
409
410 return $fields;
411 }
412
413 /**
414 * Get default fields to be shown on applicant registration forms
415 *
416 * @return array
417 */
418 function ph_get_applicant_requirements_form_fields()
419 {
420 global $post;
421
422 if ( is_user_logged_in() )
423 {
424 $current_user = wp_get_current_user();
425 $applicant_profile = false;
426
427 if ( $current_user instanceof WP_User )
428 {
429 $contact = new PH_Contact( '', $current_user->ID );
430
431 if ( is_array($contact->contact_types) && in_array('applicant', $contact->contact_types) )
432 {
433 if (
434 $contact->applicant_profiles != '' &&
435 $contact->applicant_profiles > 0 &&
436 $contact->applicant_profile_0 != '' &&
437 is_array($contact->applicant_profile_0)
438 )
439 {
440 $applicant_profile = $contact->applicant_profile_0;
441 }
442 }
443 }
444 }
445
446 $fields = array();
447
448 $offices = array();
449 $value = '';
450
451 $args = array(
452 'post_type' => 'office',
453 'nopaging' => true,
454 'orderby' => 'title',
455 'order' => 'ASC'
456 );
457
458 $office_query = new WP_Query( $args );
459
460 if ( $office_query->have_posts() )
461 {
462 while ( $office_query->have_posts() )
463 {
464 $office_query->the_post();
465
466 $offices[get_the_ID()] = get_the_title();
467
468 if ( get_post_meta(get_the_ID(), 'primary', TRUE) == 1 )
469 {
470 $value = get_the_ID();
471 }
472 }
473 }
474 wp_reset_postdata();
475
476 $fields['office_id'] = array(
477 'type' => ( (count($offices) <= 1) ? 'hidden' : 'select' ),
478 'label' => __( 'Office', 'propertyhive' ),
479 'required' => false,
480 'show_label' => true,
481 'value' => $value,
482 'options' => $offices
483 );
484
485 $departments = array();
486 $value = '';
487 if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' )
488 {
489 $departments['residential-sales'] = __( 'Properties To Buy', 'propertyhive' );
490 if ($value == '' && (get_option( 'propertyhive_primary_department' ) == 'residential-sales' || get_option( 'propertyhive_primary_department' ) === FALSE) )
491 {
492 $value = 'residential-sales';
493 }
494 }
495 if ( get_option( 'propertyhive_active_departments_lettings' ) == 'yes' )
496 {
497 $departments['residential-lettings'] = __( 'Properties For Rent', 'propertyhive' );
498 if ($value == '' && get_option( 'propertyhive_primary_department' ) == 'residential-lettings')
499 {
500 $value = 'residential-lettings';
501 }
502 }
503 if ( get_option( 'propertyhive_active_departments_commercial' ) == 'yes' )
504 {
505 $departments['commercial'] = __( 'Commercial Properties', 'propertyhive' );
506 if ($value == '' && get_option( 'propertyhive_primary_department' ) == 'commercial')
507 {
508 $value = 'commercial';
509 }
510 }
511 $fields['department'] = array(
512 'type' => 'radio',
513 'label' => __( 'Looking For', 'propertyhive' ),
514 'required' => true,
515 'show_label' => true,
516 'value' => $value,
517 'options' => $departments
518 );
519 if ( is_user_logged_in() && isset($applicant_profile['department']) )
520 {
521 $fields['department']['value'] = $applicant_profile['department'];
522 }
523 if ( count($departments) == 1 )
524 {
525 $fields['department']['type'] = 'hidden';
526 }
527
528 if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' || get_option( 'propertyhive_active_departments_lettings' ) == 'yes' )
529 {
530 $fields['maximum_price'] = array(
531 'type' => 'number',
532 'label' => __( 'Maximum Price', 'propertyhive' ),
533 'style' => 'max-width:150px;',
534 'before' => '<div class="control control-minimum_price sales-only">',
535 'required' => false
536 );
537 if ( is_user_logged_in() && isset($applicant_profile['max_price']) )
538 {
539 $fields['maximum_price']['value'] = $applicant_profile['max_price'];
540 }
541
542 $fields['maximum_rent'] = array(
543 'type' => 'number',
544 'label' => __( 'Maximum Rent', 'propertyhive' ) . ' (PCM)',
545 'style' => 'max-width:150px;',
546 'before' => '<div class="control control-minimum_price lettings-only">',
547 'required' => false
548 );
549 if ( is_user_logged_in() && isset($applicant_profile['max_rent']) )
550 {
551 $fields['maximum_rent']['value'] = $applicant_profile['max_rent'];
552 }
553
554 $fields['minimum_bedrooms'] = array(
555 'type' => 'number',
556 'label' => __( 'Minimum Bedrooms', 'propertyhive' ),
557 'style' => 'max-width:80px;',
558 'before' => '<div class="control control-minimum_bedrooms residential-only">',
559 'required' => false
560 );
561 if ( is_user_logged_in() && isset($applicant_profile['min_beds']) )
562 {
563 $fields['minimum_bedrooms']['value'] = $applicant_profile['min_beds'];
564 }
565
566 $args = array(
567 'hide_empty' => false,
568 'parent' => 0
569 );
570 $terms = get_terms( 'property_type', $args );
571
572 $options = array();
573
574 $selected_value = '';
575 if ( !empty( $terms ) && !is_wp_error( $terms ) )
576 {
577 $options = array( '' => __( 'All Property Types', 'propertyhive' ) );
578
579 foreach ($terms as $term)
580 {
581 $options[$term->term_id] = $term->name;
582
583 $args = array(
584 'hide_empty' => false,
585 'parent' => $term->term_id
586 );
587 $subterms = get_terms( 'property_type', $args );
588
589 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
590 {
591 foreach ($subterms as $term)
592 {
593 $options[$term->term_id] = '- ' . $term->name;
594 }
595 }
596 }
597 }
598
599 if ( !empty($options) )
600 {
601 $fields['property_type'] = array(
602 'type' => 'select',
603 'label' => __( 'Property Type', 'propertyhive' ),
604 'before' => '<div class="control control-property_type residential-only">',
605 'required' => false,
606 'options' => $options,
607 );
608
609 if ( is_user_logged_in() && isset($applicant_profile['property_types']) && is_array($applicant_profile['property_types']) && !empty($applicant_profile['property_types']) )
610 {
611 $fields['property_type']['value'] = $applicant_profile['property_types'][0];
612 }
613 }
614 }
615
616 if ( get_option( 'propertyhive_active_departments_commercial' ) == 'yes' )
617 {
618 $fields['available_as_sale'] = array(
619 'type' => 'checkbox',
620 'label' => __( 'For Sale', 'propertyhive' ),
621 'before' => '<div class="control control-available_as_sale commercial-only">',
622 'required' => false,
623 );
624 if ( is_user_logged_in() && isset($applicant_profile['available_as']) && in_array('sale', $applicant_profile['available_as']) )
625 {
626 $fields['available_as_sale']['checked'] = true;
627 }
628
629 $fields['available_as_rent'] = array(
630 'type' => 'checkbox',
631 'label' => __( 'To Rent', 'propertyhive' ),
632 'before' => '<div class="control control-available_as_rent commercial-only">',
633 'required' => false,
634 );
635 if ( is_user_logged_in() && isset($applicant_profile['available_as']) && in_array('rent', $applicant_profile['available_as']) )
636 {
637 $fields['available_as_rent']['checked'] = true;
638 }
639
640 $fields['minimum_floor_area'] = array(
641 'type' => 'number',
642 'label' => __( 'Min Floor Area (Sq Ft)', 'propertyhive' ),
643 'style' => 'max-width:150px;',
644 'before' => '<div class="control control-minimum_floor_area commercial-only">',
645 'required' => false
646 );
647 if ( is_user_logged_in() && isset($applicant_profile['min_floor_area']) )
648 {
649 $fields['minimum_floor_area']['value'] = $applicant_profile['min_floor_area'];
650 }
651
652 $fields['maximum_floor_area'] = array(
653 'type' => 'number',
654 'label' => __( 'Max Floor Area (Sq Ft)', 'propertyhive' ),
655 'style' => 'max-width:150px;',
656 'before' => '<div class="control control-maximum_floor_area commercial-only">',
657 'required' => false
658 );
659 if ( is_user_logged_in() && isset($applicant_profile['max_floor_area']) )
660 {
661 $fields['maximum_floor_area']['value'] = $applicant_profile['max_floor_area'];
662 }
663
664 $args = array(
665 'hide_empty' => false,
666 'parent' => 0
667 );
668 $terms = get_terms( 'commercial_property_type', $args );
669
670 $options = array();
671
672 $selected_value = '';
673 if ( !empty( $terms ) && !is_wp_error( $terms ) )
674 {
675 $options = array( '' => __( 'All Property Types', 'propertyhive' ) );
676
677 foreach ($terms as $term)
678 {
679 $options[$term->term_id] = $term->name;
680
681 $args = array(
682 'hide_empty' => false,
683 'parent' => $term->term_id
684 );
685 $subterms = get_terms( 'commercial_property_type', $args );
686
687 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
688 {
689 foreach ($subterms as $term)
690 {
691 $options[$term->term_id] = '- ' . $term->name;
692 }
693 }
694 }
695 }
696
697 if ( !empty($options) )
698 {
699 $fields['commercial_property_type'] = array(
700 'type' => 'select',
701 'label' => __( 'Property Type', 'propertyhive' ),
702 'before' => '<div class="control control-commercial_property_type commercial-only">',
703 'required' => false,
704 'options' => $options,
705 );
706
707 if ( is_user_logged_in() && isset($applicant_profile['commercial_property_types']) && is_array($applicant_profile['commercial_property_types']) && !empty($applicant_profile['commercial_property_types']) )
708 {
709 $fields['commercial_property_type']['value'] = $applicant_profile['commercial_property_types'][0];
710 }
711 }
712 }
713
714 $args = array(
715 'hide_empty' => false,
716 'parent' => 0
717 );
718 $terms = get_terms( 'location', $args );
719
720 $options = array();
721
722 $selected_value = '';
723 if ( !empty( $terms ) && !is_wp_error( $terms ) )
724 {
725 $options = array( '' => __( 'All Locations', 'propertyhive' ) );
726
727 foreach ($terms as $term)
728 {
729 $options[$term->term_id] = $term->name;
730
731 $args = array(
732 'hide_empty' => false,
733 'parent' => $term->term_id
734 );
735 $subterms = get_terms( 'location', $args );
736
737 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
738 {
739 foreach ($subterms as $term)
740 {
741 $options[$term->term_id] = '- ' . $term->name;
742 }
743 }
744 }
745 }
746
747 if ( !empty($options) )
748 {
749 $fields['location'] = array(
750 'type' => 'select',
751 'label' => __( 'Location', 'propertyhive' ),
752 'required' => false,
753 'options' => $options,
754 );
755
756 if ( is_user_logged_in() && isset($applicant_profile['locations']) && is_array($applicant_profile['locations']) && !empty($applicant_profile['locations']) )
757 {
758 $fields['location']['value'] = $applicant_profile['locations'][0];
759 }
760 }
761
762 $fields['additional_requirements'] = array(
763 'type' => 'textarea',
764 'label' => __( 'Additional Requirements', 'propertyhive' ),
765 'required' => false
766 );
767 if ( is_user_logged_in() && isset($applicant_profile['notes']) )
768 {
769 $fields['additional_requirements']['value'] = $applicant_profile['notes'];
770 }
771
772 return $fields;
773 }
774
775 /**
776 * Output individual field
777 *
778 * @return void
779 */
780 function ph_form_field( $key, $field )
781 {
782 global $post;
783
784 $output = '';
785
786 switch ($field['type'])
787 {
788 case "text":
789 case "email":
790 case "date":
791 case "number":
792 case "password":
793 {
794 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
795 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
796 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
797 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
798 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
799 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : ( ( $field['type'] == 'date' ) ? 'dd/mm/yyyy' : '' );
800 $field['required'] = isset( $field['required'] ) ? $field['required'] : false;
801 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
802
803 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
804 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
805 {
806 $field['value'] = sanitize_text_field( wp_unslash( $_GET[$key] ) );
807 }
808 else
809 {
810 if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) )
811 {
812 $value = get_post_meta( $post->ID, '_' . $key, true );
813 if ( $value != '' )
814 {
815 $field['value'] = $value;
816 }
817 }
818 }
819
820 $output .= $field['before'];
821
822 if ($field['show_label'])
823 {
824 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
825 if ($field['required'])
826 {
827 $output .= '<span class="required"> *</span>';
828 }
829 $output .= '</label>';
830 }
831
832 $output .= '<input
833 type="' . esc_attr( $field['type'] ) . '"
834 name="' . esc_attr( $key ) . '"
835 id="' . esc_attr( $key ) . '"
836 value="' . esc_attr( $field['value'] ) . '"
837 placeholder="' . esc_attr( $field['placeholder'] ) . '"
838 class="' . esc_attr( $field['class'] ) . '"
839 style="' . esc_attr( $field['style'] ) . '"
840 ' . ( ($field['required']) ? 'required' : '' ) . '
841 >';
842
843 $output .= $field['after'];
844
845 break;
846 }
847 case "textarea":
848 {
849 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
850 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
851 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
852 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
853 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
854 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
855 $field['required'] = isset( $field['required'] ) ? $field['required'] : false;
856
857 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
858 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
859 {
860 $field['value'] = sanitize_textarea_field( wp_unslash( $_GET[$key] ) );
861 }
862 else
863 {
864 if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) )
865 {
866 $value = get_post_meta( $post->ID, '_' . $key, true );
867 if ( $value != '' )
868 {
869 $field['value'] = $value;
870 }
871 }
872 }
873
874 $output .= $field['before'];
875
876 if ($field['show_label'])
877 {
878 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
879 if ($field['required'])
880 {
881 $output .= '<span class="required"> *</span>';
882 }
883 $output .= '</label>';
884 }
885
886 $output .= '<textarea
887 name="' . esc_attr( $key ) . '"
888 id="' . esc_attr( $key ) . '"
889 placeholder="' . esc_attr( $field['placeholder'] ) . '"
890 class="' . esc_attr( $field['class'] ) . '"
891 ' . ( ($field['required']) ? 'required' : '' ) . '
892 >' . esc_attr( $field['value'] ) . '</textarea>';
893
894 $output .= $field['after'];
895
896 break;
897 }
898 case "checkbox":
899 {
900 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
901 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
902 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
903 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
904 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
905 $field['label_style'] = isset( $field['label_style'] ) ? $field['label_style'] : '';
906 $field['value'] = isset( $field['value'] ) ? $field['value'] : 'yes';
907 $field['checked'] = isset( $field['checked'] ) ? $field['checked'] : false;
908 if ( isset( $_GET[$key] ) && sanitize_text_field(wp_unslash($_GET[$key])) == $field['value'] )
909 {
910 $field['checked'] = true;
911 }
912 else
913 {
914 if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) )
915 {
916 $value = get_post_meta( $post->ID, '_' . $key, true );
917 if ( $value == 'yes' )
918 {
919 $field['checked'] = true;
920 }
921 }
922 }
923
924 $output .= $field['before'];
925
926 $output .= '<label style="' . esc_attr( $field['label_style'] ) . '"><input
927 type="' . esc_attr( $field['type'] ) . '"
928 name="' . esc_attr( $key ) . '"
929 value="' . esc_attr( $field['value'] ) . '"
930 class="' . esc_attr( $field['class'] ) . '"
931 ' . checked( $field['checked'], true, false ) . '
932 >';
933 if ($field['show_label'])
934 {
935 $output .= ' <span>' . $field['label'] . '</span>';
936 }
937 $output .= '</label>';
938
939 $output .= $field['after'];
940
941 break;
942 }
943 case "radio":
944 {
945 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
946 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
947 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
948 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : false;
949 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
950
951 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
952 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
953 {
954 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
955 }
956
957 $output .= $field['before'];
958
959 if ($field['show_label'])
960 {
961 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
962 }
963
964 foreach ( $field['options'] as $option_key => $value )
965 {
966 $output .= '<label><input
967 type="' . esc_attr( $field['type'] ) . '"
968 name="' . esc_attr( $key ) . '"
969 value="' . esc_attr( $option_key ) . '"
970 class="' . esc_attr( $field['class'] ) . '"
971 ' . checked( esc_attr( $field['value'] ), esc_attr( $option_key ), false ) . '
972 > ' . esc_html( $value ) . '</label>';
973 }
974
975 $output .= $field['after'];
976
977 break;
978 }
979 case "select":
980 {
981 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
982 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
983 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
984 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
985 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
986 $field['required'] = isset( $field['required'] ) ? $field['required'] : false;
987 $field['options'] = ( isset( $field['options'] ) && is_array( $field['options'] ) ) ? $field['options'] : array();
988 $field['multiselect'] = isset( $field['multiselect'] ) ? $field['multiselect'] : false;
989
990 if ( $field['multiselect'] )
991 {
992 wp_enqueue_script( 'multiselect' );
993 }
994
995 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
996 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
997 {
998 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
999 }
1000 else
1001 {
1002 if ( !is_post_type_archive('property') && isset($post->ID) )
1003 {
1004 $value = get_post_meta( $post->ID, '_' . $key, true );
1005 if ( $value != '' )
1006 {
1007 $field['value'] = $value;
1008 }
1009 }
1010 }
1011
1012 $output .= $field['before'];
1013
1014 if ($field['show_label'])
1015 {
1016 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
1017 if ($field['required'])
1018 {
1019 $output .= '<span class="required"> *</span>';
1020 }
1021 $output .= '</label>';
1022 }
1023
1024 $blank_option = '';
1025 foreach ( $field['options'] as $option_key => $value )
1026 {
1027 if ( $field['multiselect'] && $option_key == '' )
1028 {
1029 $blank_option = $value;
1030 continue;
1031 }
1032 }
1033
1034 $output .= '<select
1035 name="' . esc_attr( $key ) . ( $field['multiselect'] ? '[]' : '' ) . '"
1036 id="' . esc_attr( $key ) . '"
1037 class="' . esc_attr( $field['class'] ) . ( $field['multiselect'] ? ' ph-form-multiselect' : '' ) . '"
1038 ' . ( $field['multiselect'] ? ' multiple="multiple"' : '' ) . '
1039 data-blank-option="' . esc_attr($blank_option) . '"
1040 >';
1041
1042 foreach ( $field['options'] as $option_key => $value )
1043 {
1044 if ( $field['multiselect'] && $option_key == '' )
1045 {
1046 // Skip because we don't want a blank option in the multiselect. Instead use $value as the placeholder
1047 continue;
1048 }
1049
1050 $output .= '<option
1051 value="' . esc_attr( $option_key ) . '"';
1052 if ( !$field['multiselect'] )
1053 {
1054 $output .= selected( esc_attr( $field['value'] ), esc_attr( $option_key ), false );
1055 }
1056 else
1057 {
1058 if ( isset($_REQUEST[$key]) && is_array($_REQUEST[$key]) && in_array($option_key, $_REQUEST[$key]) )
1059 {
1060 $output .= ' selected';
1061 }
1062 }
1063 $output .= '>' . esc_html( $value ) . '</option>';
1064 }
1065
1066 $output .= '</select>';
1067
1068 $output .= $field['after'];
1069
1070 break;
1071 }
1072 case "office":
1073 {
1074 $key = 'officeID';
1075
1076 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
1077 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1078 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1079 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
1080 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
1081 $field['multiselect'] = isset( $field['multiselect'] ) ? $field['multiselect'] : false;
1082
1083 if ( $field['multiselect'] )
1084 {
1085 wp_enqueue_script( 'multiselect' );
1086 }
1087
1088 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1089 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1090 {
1091 $field['value'] = (int)$_GET[$key];
1092 }
1093
1094 $output .= $field['before'];
1095
1096 if ($field['show_label'])
1097 {
1098 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
1099 }
1100
1101 $output .= '<select
1102 name="' . esc_attr( $key ) . ( $field['multiselect'] ? '[]' : '' ) . '"
1103 id="' . esc_attr( $key ) . '"
1104 class="' . esc_attr( $field['class'] ) . ( $field['multiselect'] ? ' ph-form-multiselect' : '' ) . '"
1105 ' . ( $field['multiselect'] ? ' multiple="multiple"' : '' ) . '
1106 data-blank-option="' . esc_attr( __( 'No preference', 'propertyhive' ) ) . '"
1107 >';
1108
1109 if ( !$field['multiselect'] )
1110 {
1111 $output .= '<option
1112 value=""
1113 ' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . '
1114 >' . esc_html( __( 'No preference', 'propertyhive' ) ) . '</option>';
1115 }
1116
1117 $args = array(
1118 'post_type' => 'office',
1119 'nopaging' => true,
1120 'orderby' => 'title',
1121 'order' => 'ASC'
1122 );
1123 $office_query = new WP_Query($args);
1124
1125 if ($office_query->have_posts())
1126 {
1127 while ($office_query->have_posts())
1128 {
1129 $office_query->the_post();
1130
1131 $output .= '<option
1132 value="' . esc_attr( $post->ID ) . '" ';
1133 if ( !$field['multiselect'] )
1134 {
1135 $output .= selected( esc_attr( $field['value'] ), esc_attr( $post->ID ), false );
1136 }
1137 else
1138 {
1139 if ( isset($_REQUEST[$key]) && is_array($_REQUEST[$key]) && in_array($post->ID, $_REQUEST[$key]) )
1140 {
1141 $output .= ' selected';
1142 }
1143 }
1144 $output .= '>' . esc_html( get_the_title() ) . '</option>';
1145
1146 }
1147 }
1148 wp_reset_postdata();
1149
1150 $output .= '</select>';
1151
1152 $output .= $field['after'];
1153
1154 break;
1155 }
1156 case "country":
1157 {
1158 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
1159 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1160 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1161 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
1162 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
1163
1164 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1165 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1166 {
1167 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
1168 }
1169
1170 $output .= $field['before'];
1171
1172 if ($field['show_label'])
1173 {
1174 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
1175 }
1176
1177 $output .= '<select
1178 name="' . esc_attr( $key ) . '"
1179 id="' . esc_attr( $key ) . '"
1180 class="' . esc_attr( $field['class'] ) . '"
1181 >';
1182
1183 $output .= '<option
1184 value=""
1185 ' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . '
1186 >' . esc_html( __( 'No preference', 'propertyhive' ) ) . '</option>';
1187
1188 $countries = get_option( 'propertyhive_countries', array() );
1189 if ( is_array($countries) && !empty($countries) )
1190 {
1191 $ph_countries = new PH_Countries;
1192
1193 foreach ( $countries as $country )
1194 {
1195 $ph_country = $ph_countries->get_country( $country );
1196
1197 if ( $ph_country !== FALSE )
1198 {
1199 $output .= '<option
1200 value="' . esc_attr( $country ) . '"
1201 ' . selected( esc_attr( $field['value'] ), esc_attr( $country ), false ) . '
1202 >' . esc_html( $ph_country['name'] ) . '</option>';
1203 }
1204 }
1205 }
1206
1207 $output .= '</select>';
1208
1209 $output .= $field['after'];
1210
1211 break;
1212 }
1213 case "slider":
1214 {
1215 wp_enqueue_script('jquery');
1216 wp_enqueue_script('jquery-ui-core');
1217 wp_enqueue_script('jquery-ui-slider');
1218 wp_enqueue_style( 'jquery-ui-style', PH()->plugin_url() . '/assets/css/jquery-ui/jquery-ui.css', array(), PH_VERSION );
1219
1220 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1221 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1222 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
1223 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
1224 $field['min'] = isset( $field['min'] ) ? $field['min'] : '';
1225 $field['max'] = isset( $field['max'] ) ? $field['max'] : '';
1226 $field['step'] = isset( $field['step'] ) ? $field['step'] : '1';
1227
1228 $output .= $field['before'];
1229
1230 if ($field['show_label'])
1231 {
1232 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
1233 $output .= ' - <span id="search-form-slider-value-' . $key . '" class="search-form-slider-value"></span>';
1234 $output .= '</label>';
1235 }
1236
1237 $output .= '<div id="search-form-slider-' . $key . '" class="search-form-slider" style="min-width:150px;"></div>';
1238 switch ( $key )
1239 {
1240 case "price_slider":
1241 {
1242 $output .= '<input type="hidden" name="minimum_price" id="min_slider_value-' . $key . '" value="' . ( isset($_GET['minimum_price']) ? ph_clean($_GET['minimum_price']) : '' ) . '">';
1243 $output .= '<input type="hidden" name="maximum_price" id="max_slider_value-' . $key . '" value="' . ( isset($_GET['maximum_price']) ? ph_clean($_GET['maximum_price']) : '' ) . '">';
1244 break;
1245 }
1246 case "rent_slider":
1247 {
1248 $output .= '<input type="hidden" name="minimum_rent" id="min_slider_value-' . $key . '" value="' . ( isset($_GET['minimum_rent']) ? ph_clean($_GET['minimum_rent']) : '' ) . '">';
1249 $output .= '<input type="hidden" name="maximum_rent" id="max_slider_value-' . $key . '" value="' . ( isset($_GET['maximum_rent']) ? ph_clean($_GET['maximum_rent']) : '' ) . '">';
1250 break;
1251 }
1252 case "bedrooms_slider":
1253 {
1254 $output .= '<input type="hidden" name="minimum_bedrooms" id="min_slider_value-' . $key . '" value="' . ( isset($_GET['minimum_bedrooms']) ? ph_clean($_GET['minimum_bedrooms']) : '' ) . '">';
1255 $output .= '<input type="hidden" name="maximum_bedrooms" id="max_slider_value-' . $key . '" value="' . ( isset($_GET['maximum_bedrooms']) ? ph_clean($_GET['maximum_bedrooms']) : '' ) . '">';
1256 break;
1257 }
1258 }
1259
1260 $output .= $field['after'];
1261
1262 $value = '';
1263 $prefix = '';
1264 $suffix = '';
1265
1266 if ( $key == 'price_slider' || $key == 'rent_slider' )
1267 {
1268 $prefix = '£';
1269
1270 $search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' );
1271
1272 $ph_countries = new PH_Countries();
1273 $countries = $ph_countries->countries;
1274
1275 foreach ( $countries as $country_code => $country )
1276 {
1277 if ( isset($country['currency_code']) && $country['currency_code'] == $search_form_currency )
1278 {
1279 if ( $country['currency_prefix'] === true )
1280 {
1281 $prefix = $country['currency_symbol'];
1282 $suffix = '';
1283 }
1284 else
1285 {
1286 $prefix = '';
1287 $suffix = $country['currency_symbol'];
1288 }
1289 break;
1290 }
1291 }
1292 }
1293
1294 switch ( $key )
1295 {
1296 case "price_slider":
1297 {
1298 if ( $field['min'] != '' && $field['max'] != '' )
1299 {
1300 $value = 'values: [ ' . ( isset($_GET['minimum_price']) && $_GET['minimum_price'] != '' ? ph_clean($_GET['minimum_price']) : $field['min'] ) . ', ' . ( isset($_GET['maximum_price']) && $_GET['maximum_price'] != '' ? ph_clean($_GET['maximum_price']) : $field['max'] ) . ' ],';
1301 }
1302 break;
1303 }
1304 case "rent_slider":
1305 {
1306 if ( $field['min'] != '' && $field['max'] != '' )
1307 {
1308 $value = 'values: [ ' . ( isset($_GET['minimum_rent']) && $_GET['minimum_rent'] != '' ? ph_clean($_GET['minimum_rent']) : $field['min'] ) . ', ' . ( isset($_GET['maximum_rent']) && $_GET['maximum_rent'] != '' ? ph_clean($_GET['maximum_rent']) : $field['max'] ) . ' ],';
1309 }
1310 break;
1311 }
1312 case "bedrooms_slider":
1313 {
1314 if ( $field['min'] != '' && $field['max'] != '' )
1315 {
1316 $value = 'values: [ ' . ( isset($_GET['minimum_bedrooms']) && $_GET['minimum_bedrooms'] != '' ? ph_clean($_GET['minimum_bedrooms']) : $field['min'] ) . ', ' . ( isset($_GET['maximum_bedrooms']) && $_GET['maximum_bedrooms'] != '' ? ph_clean($_GET['maximum_bedrooms']) : $field['max'] ) . ' ],';
1317 }
1318 break;
1319 }
1320 }
1321
1322 $output .= '<script>
1323 jQuery(document).ready(function()
1324 {
1325 jQuery( "#search-form-slider-' . $key . '" ).slider({
1326 range: ' . ( ( $field['min'] != '' && $field['max'] != '' ) ? 'true' : 'false' ) . ',
1327 step: ' . $field['step'] . ',
1328 ' . ( $field['min'] != '' ? 'min: ' . $field['min'] . ',' : '' ) . '
1329 ' . ( $field['max'] != '' ? 'max: ' . $field['max'] . ',' : '' ) . '
1330 ' . $value . '
1331 slide: function( event, ui ) {
1332 jQuery( "#search-form-slider-value-' . $key . '" ).html( "' . $prefix . '" + ui.values[ 0 ].toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,") + "' . $suffix . '" + " - ' . $prefix . '" + ui.values[ 1 ].toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,") + "' . $suffix . '" );
1333 jQuery( "#min_slider_value-' . $key . '" ).val( ui.values[0] );
1334 jQuery( "#max_slider_value-' . $key . '" ).val( ui.values[1] );
1335 }
1336 });
1337 jQuery( "#search-form-slider-value-' . $key . '" ).html( "' . $prefix . '" + jQuery( "#search-form-slider-' . $key . '" ).slider( "values", 0 ).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,") + "' . $suffix . '" + " - ' . $prefix . '" + jQuery( "#search-form-slider-' . $key . '" ).slider( "values", 1 ).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,") + "' . $suffix . '" );
1338 });
1339 </script>';
1340
1341 break;
1342 }
1343 case "hidden":
1344 {
1345 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1346 $field['name'] = isset( $field['name'] ) ? $field['name'] : $key;
1347 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1348 {
1349 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
1350 }
1351
1352 $output .= '<input type="hidden" name="' . esc_attr( $field['name'] ) . '" value="' . $field['value'] . '">';
1353 break;
1354 }
1355 case "html":
1356 {
1357 $field['html'] = isset( $field['html'] ) ? $field['html'] : '';
1358 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1359 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1360
1361 $output .= $field['before'];
1362 $output .= $field['html'];
1363 $output .= $field['after'];
1364
1365 break;
1366 }
1367 case "recaptcha":
1368 {
1369 $field['site_key'] = isset( $field['site_key'] ) ? $field['site_key'] : '';
1370
1371 $output .= '<script src="https://www.google.com/recaptcha/api.js"></script>
1372 <div class="g-recaptcha" data-sitekey="' . $field['site_key'] . '"></div>';
1373 break;
1374 }
1375 default:
1376 {
1377 if ( taxonomy_exists($field['type']) )
1378 {
1379 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
1380 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1381 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1382 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
1383 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
1384 $field['blank_option'] = isset( $field['blank_option'] ) ? $field['blank_option'] : __( 'No preference', 'propertyhive' );
1385 $field['parent_terms_only'] = isset( $field['parent_terms_only'] ) ? $field['parent_terms_only'] : false;
1386 $field['multiselect'] = isset( $field['multiselect'] ) ? $field['multiselect'] : false;
1387
1388 if ( $field['multiselect'] )
1389 {
1390 wp_enqueue_script( 'multiselect' );
1391 }
1392
1393 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1394 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1395 {
1396 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
1397 }
1398
1399 $output .= $field['before'];
1400
1401 if ($field['show_label'])
1402 {
1403 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
1404 }
1405
1406 $output .= '<select
1407 name="' . esc_attr( $key ) . ( $field['multiselect'] ? '[]' : '' ) . '"
1408 id="' . esc_attr( $key ) . '"
1409 class="' . esc_attr( $field['class'] ) . ( $field['multiselect'] ? ' ph-form-multiselect' : '' ) . '"
1410 ' . ( $field['multiselect'] ? ' multiple="multiple"' : '' ) . '
1411 data-blank-option="' . esc_attr($field['blank_option']) . '"
1412 >';
1413
1414 $options = array( '' => $field['blank_option'] );
1415 $args = array(
1416 'hide_empty' => false,
1417 'parent' => 0
1418 );
1419 $terms = get_terms( $field['type'], $args );
1420
1421 $selected_value = '';
1422 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1423 {
1424 foreach ($terms as $term)
1425 {
1426 $options[$term->term_id] = $term->name;
1427
1428 if (
1429 !isset($field['parent_terms_only'])
1430 ||
1431 (
1432 isset($field['parent_terms_only']) &&
1433 $field['parent_terms_only'] === false
1434 )
1435 )
1436 {
1437 $args = array(
1438 'hide_empty' => false,
1439 'parent' => $term->term_id
1440 );
1441 $subterms = get_terms( $field['type'], $args );
1442
1443 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
1444 {
1445 foreach ($subterms as $term)
1446 {
1447 $options[$term->term_id] = '- ' . $term->name;
1448
1449 $args = array(
1450 'hide_empty' => false,
1451 'parent' => $term->term_id
1452 );
1453 $subsubterms = get_terms( $field['type'], $args );
1454
1455 if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) )
1456 {
1457 foreach ($subsubterms as $term)
1458 {
1459 $options[$term->term_id] = '- ' . $term->name;
1460 }
1461 }
1462 }
1463 }
1464 }
1465 }
1466 }
1467
1468 foreach ( $options as $option_key => $value )
1469 {
1470 if ( $field['multiselect'] && $option_key == '' )
1471 {
1472 // Skip because we don't want a blank option in the multiselect. Instead use $value as the placeholder
1473 continue;
1474 }
1475
1476 $output .= '<option
1477 value="' . esc_attr( $option_key ) . '"';
1478 if ( !$field['multiselect'] )
1479 {
1480 $output .= selected( esc_attr( $field['value'] ), esc_attr( $option_key ), false );
1481 }
1482 else
1483 {
1484 if ( isset($_REQUEST[$key]) && is_array($_REQUEST[$key]) && in_array($option_key, $_REQUEST[$key]) )
1485 {
1486 $output .= ' selected';
1487 }
1488 }
1489 $output .= '>' . esc_html( $value ) . '</option>';
1490 }
1491
1492 $output .= '</select>';
1493
1494 $output .= $field['after'];
1495
1496 if ( $field['type'] == 'availability' )
1497 {
1498 $availability_departments = get_option( 'propertyhive_availability_departments', array() );
1499 if ( !is_array($availability_departments) ) { $availability_departments = array(); }
1500
1501 if ( !empty($availability_departments) )
1502 {
1503 ?>
1504 <script>
1505 var selected_availability = '<?php echo ( isset($_REQUEST[$key]) && $_REQUEST[$key] != '' ? (int)$_REQUEST[$key] : '' ); ?>';
1506 var availability_departments = <?php echo json_encode($availability_departments); ?>;
1507 var availabilities = <?php echo json_encode($options); ?>;
1508 var availabilities_order = <?php echo json_encode(array_keys($options)); ?>;
1509 </script>
1510 <?php
1511 }
1512 }
1513 }
1514 }
1515 }
1516
1517 echo $output;
1518 }