PluginProbe
Property Hive / 1.4.59
Property Hive v1.4.59
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.59, at includes/ph-form-functions.php

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