PluginProbe
Property Hive / 1.4.6
Property Hive v1.4.6
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.6, at includes/ph-form-functions.php

1,055 lines 36.3 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
26 // We 100% need department so make sure it exists. If it doesn't, set a hidden field
27 if ( !isset($form_controls['department']) )
28 {
29 $original_form_controls = ph_get_search_form_fields();
30 $original_department = $original_form_controls['department'];
31 $original_department['type'] = 'hidden';
32
33 $form_controls['department'] = $original_department;
34 }
35
36 ph_get_template( 'global/search-form.php', array( 'form_controls' => $form_controls, 'id' => $id ) );
37
38 }
39
40 /**
41 * Get default fields to be shown on search forms
42 *
43 * @return array
44 */
45 function ph_get_search_form_fields()
46 {
47 $fields = array();
48
49 $departments = array();
50 $value = '';
51 if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' )
52 {
53 $departments['residential-sales'] = __( 'Sales', 'propertyhive' );
54 if ($value == '' && (get_option( 'propertyhive_primary_department' ) == 'residential-sales' || get_option( 'propertyhive_primary_department' ) === FALSE) )
55 {
56 $value = 'residential-sales';
57 }
58 }
59 if ( get_option( 'propertyhive_active_departments_lettings' ) == 'yes' )
60 {
61 $departments['residential-lettings'] = __( 'Lettings', 'propertyhive' );
62 if ($value == '' && get_option( 'propertyhive_primary_department' ) == 'residential-lettings')
63 {
64 $value = 'residential-lettings';
65 }
66 }
67 if ( get_option( 'propertyhive_active_departments_commercial' ) == 'yes' )
68 {
69 $departments['commercial'] = __( 'Commercial', 'propertyhive' );
70 if ($value == '' && get_option( 'propertyhive_primary_department' ) == 'commercial')
71 {
72 $value = 'commercial';
73 }
74 }
75
76 $fields['department'] = array(
77 'type' => 'radio',
78 'options' => $departments,
79 'value' => $value
80 );
81
82 if ( array_key_exists('residential-sales', $departments) || array_key_exists('residential-lettings', $departments) )
83 {
84 if ( array_key_exists('residential-sales', $departments) )
85 {
86 $prices = array(
87 '' => __( 'No preference', 'propertyhive' ),
88 '100000' => '&pound;100,000',
89 '150000' => '&pound;150,000',
90 '200000' => '&pound;200,000',
91 '250000' => '&pound;250,000',
92 '300000' => '&pound;300,000',
93 '500000' => '&pound;500,000',
94 '750000' => '&pound;750,000',
95 '1000000' => '&pound;1,000,000'
96 );
97
98 $fields['minimum_price'] = array(
99 'type' => 'select',
100 'show_label' => true,
101 'label' => __( 'Min Price', 'propertyhive' ),
102 'before' => '<div class="control control-minimum_price sales-only">',
103 'options' => $prices
104 );
105
106 $fields['maximum_price'] = array(
107 'type' => 'select',
108 'show_label' => true,
109 'label' => __( 'Max Price', 'propertyhive' ),
110 'before' => '<div class="control control-maximum_price sales-only">',
111 'options' => $prices
112 );
113 }
114
115 if ( array_key_exists('residential-lettings', $departments) )
116 {
117 $prices = array(
118 '' => __( 'No preference', 'propertyhive' ),
119 '500' => '&pound;500 PCM',
120 '600' => '&pound;600 PCM',
121 '750' => '&pound;750 PCM',
122 '1000' => '&pound;1000 PCM',
123 '1250' => '&pound;1250 PCM',
124 '1500' => '&pound;1500 PCM',
125 '2000' => '&pound;2000 PCM'
126 );
127
128 $fields['minimum_rent'] = array(
129 'type' => 'select',
130 'show_label' => true,
131 'label' => __( 'Min Rent', 'propertyhive' ),
132 'before' => '<div class="control control-minimum_rent lettings-only">',
133 'options' => $prices
134 );
135
136 $fields['maximum_rent'] = array(
137 'type' => 'select',
138 'show_label' => true,
139 'label' => __( 'Max Rent', 'propertyhive' ),
140 'before' => '<div class="control control-maximum_rent lettings-only">',
141 'options' => $prices
142 );
143 }
144
145 $fields['minimum_bedrooms'] = array(
146 'type' => 'select',
147 'show_label' => true,
148 'label' => __( 'Min Beds', 'propertyhive' ),
149 'before' => '<div class="control control-minimum_bedrooms residential-only">',
150 'options' => array( '' => __( 'No preference', 'propertyhive' ), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5)
151 );
152
153 $fields['property_type'] = array(
154 'type' => 'property_type',
155 'show_label' => true,
156 'before' => '<div class="control control-property_type residential-only">',
157 'label' => __( 'Type', 'propertyhive' ),
158 );
159 }
160
161 if ( array_key_exists('commercial', $departments) )
162 {
163 $sizes = array(
164 '' => __( 'No preference', 'propertyhive' ),
165 '250' => '250 sq ft',
166 '500' => '500 sq ft',
167 '1000' => '1,000 sq ft',
168 '2500' => '2,500 sq ft',
169 '5000' => '5,000 sq ft',
170 '10000' => '10,000 sq ft',
171 '25000' => '25,000 sq ft',
172 '50000' => '50,000 sq ft'
173 );
174
175 $fields['minimum_floor_area'] = array(
176 'type' => 'select',
177 'show_label' => true,
178 'label' => __( 'Min Floor Area', 'propertyhive' ),
179 'before' => '<div class="control control-minimum_floor_area commercial-only">',
180 'options' => $sizes
181 );
182
183 $fields['maximum_floor_area'] = array(
184 'type' => 'select',
185 'show_label' => true,
186 'label' => __( 'Max Floor Area', 'propertyhive' ),
187 'before' => '<div class="control control-maximum_floor_area commercial-only">',
188 'options' => $sizes
189 );
190
191 // Property Type
192 $options = array( '' => __( 'No preference', 'propertyhive' ) );
193 $args = array(
194 'hide_empty' => false,
195 'parent' => 0
196 );
197 $terms = get_terms( 'commercial_property_type', $args );
198
199 $selected_value = '';
200 if ( !empty( $terms ) && !is_wp_error( $terms ) )
201 {
202 foreach ($terms as $term)
203 {
204 $options[$term->term_id] = $term->name;
205
206 $args = array(
207 'hide_empty' => false,
208 'parent' => $term->term_id
209 );
210 $subterms = get_terms( 'commercial_property_type', $args );
211
212 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
213 {
214 foreach ($subterms as $term)
215 {
216 $options[$term->term_id] = '- ' . $term->name;
217 }
218 }
219 }
220 }
221
222 $fields['commercial_property_type'] = array(
223 'type' => 'select',
224 'show_label' => true,
225 'before' => '<div class="control control-commercial_property_type commercial-only">',
226 'label' => __( 'Type', 'propertyhive' ),
227 'options' => $options
228 );
229 }
230
231 return $fields;
232 }
233
234 /**
235 * Main function for drawing property enquiry form.
236 *
237 * @param string $id
238 * @return void
239 */
240 function propertyhive_enquiry_form()
241 {
242 $form_controls = ph_get_property_enquiry_form_fields();
243
244 $form_controls = apply_filters( 'propertyhive_property_enquiry_form_fields', $form_controls );
245
246 ph_get_template( 'global/make-enquiry-form.php',array( 'form_controls' => $form_controls ) );
247 }
248
249 /**
250 * Get default fields to be shown on search forms
251 *
252 * @return array
253 */
254 function ph_get_property_enquiry_form_fields()
255 {
256 global $post;
257
258 $fields = array();
259
260 $fields['property_id'] = array(
261 'type' => 'hidden',
262 'value' => $post->ID
263 );
264
265 $fields['name'] = array(
266 'type' => 'text',
267 'label' => __( 'Full Name', 'propertyhive' ),
268 'required' => true
269 );
270 if ( is_user_logged_in() )
271 {
272 $current_user = wp_get_current_user();
273
274 $fields['name']['value'] = $current_user->display_name;
275 }
276
277 $fields['email_address'] = array(
278 'type' => 'email',
279 'label' => __( 'Email Address', 'propertyhive' ),
280 'required' => true
281 );
282 if ( is_user_logged_in() )
283 {
284 $current_user = wp_get_current_user();
285
286 $fields['email_address']['value'] = $current_user->user_email;
287 }
288
289 $fields['telephone_number'] = array(
290 'type' => 'text',
291 'label' => __( 'Number', 'propertyhive' ),
292 'required' => true
293 );
294
295 $fields['message'] = array(
296 'type' => 'textarea',
297 'label' => __( 'Message', 'propertyhive' ),
298 'required' => true
299 );
300
301 return $fields;
302 }
303
304 /**
305 * Get default fields to be shown on applicant registration forms
306 *
307 * @return array
308 */
309 function ph_get_user_details_form_fields()
310 {
311 global $post;
312
313 if ( is_user_logged_in() )
314 {
315 $current_user = wp_get_current_user();
316
317 if ( $current_user instanceof WP_User )
318 {
319 $contact = new PH_Contact( '', $current_user->ID );
320 }
321 }
322
323 $fields = array();
324
325 $fields['name'] = array(
326 'type' => 'text',
327 'label' => __( 'Full Name', 'propertyhive' ),
328 'required' => true
329 );
330 if ( is_user_logged_in() && $current_user instanceof WP_User )
331 {
332 $fields['name']['value'] = $current_user->display_name;
333 }
334
335 $fields['email_address'] = array(
336 'type' => 'email',
337 'label' => __( 'Email Address', 'propertyhive' ),
338 'required' => true
339 );
340 if ( is_user_logged_in() && $current_user instanceof WP_User )
341 {
342 $fields['email_address']['value'] = $current_user->user_email;
343 }
344
345 $fields['telephone_number'] = array(
346 'type' => 'text',
347 'label' => __( 'Telephone Number', 'propertyhive' ),
348 'required' => false
349 );
350 if ( is_user_logged_in() && $current_user instanceof WP_User )
351 {
352 $fields['telephone_number']['value'] = $contact->telephone_number;
353 }
354
355 if ( get_option( 'propertyhive_applicant_users', '' ) == 'yes' )
356 {
357 $fields['password'] = array(
358 'type' => 'password',
359 'label' => __( 'Password', 'propertyhive' ),
360 'required' => true
361 );
362
363 $fields['password2'] = array(
364 'type' => 'password',
365 'label' => __( 'Confirm Password', 'propertyhive' ),
366 'required' => true
367 );
368 }
369
370 return $fields;
371 }
372
373 /**
374 * Get default fields to be shown on applicant registration forms
375 *
376 * @return array
377 */
378 function ph_get_applicant_requirements_form_fields()
379 {
380 global $post;
381
382 if ( is_user_logged_in() )
383 {
384 $current_user = wp_get_current_user();
385 $applicant_profile = false;
386
387 if ( $current_user instanceof WP_User )
388 {
389 $contact = new PH_Contact( '', $current_user->ID );
390
391 if ( is_array($contact->contact_types) && in_array('applicant', $contact->contact_types) )
392 {
393 if (
394 $contact->applicant_profiles != '' &&
395 $contact->applicant_profiles > 0 &&
396 $contact->applicant_profile_0 != '' &&
397 is_array($contact->applicant_profile_0)
398 )
399 {
400 $applicant_profile = $contact->applicant_profile_0;
401 }
402 }
403 }
404 }
405
406 $fields = array();
407
408 $departments = array();
409 $value = '';
410 if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' )
411 {
412 $departments['residential-sales'] = __( 'Buy', 'propertyhive' );
413 if ($value == '' && (get_option( 'propertyhive_primary_department' ) == 'residential-sales' || get_option( 'propertyhive_primary_department' ) === FALSE) )
414 {
415 $value = 'residential-sales';
416 }
417 }
418 if ( get_option( 'propertyhive_active_departments_lettings' ) == 'yes' )
419 {
420 $departments['residential-lettings'] = __( 'Rent', 'propertyhive' );
421 if ($value == '' && get_option( 'propertyhive_primary_department' ) == 'residential-lettings')
422 {
423 $value = 'residential-lettings';
424 }
425 }
426 $fields['department'] = array(
427 'type' => 'radio',
428 'label' => __( 'Looking To', 'propertyhive' ),
429 'required' => true,
430 'show_label' => true,
431 'value' => $value,
432 'options' => $departments
433 );
434 if ( is_user_logged_in() && isset($applicant_profile['department']) )
435 {
436 $fields['department']['value'] = $applicant_profile['department'];
437 }
438 if ( count($departments) == 1 )
439 {
440 $fields['department']['type'] = 'hidden';
441 }
442
443 $offices = array();
444 $value = '';
445
446 $args = array(
447 'post_type' => 'office',
448 'nopaging' => true,
449 'orderby' => 'title',
450 'order' => 'ASC'
451 );
452
453 $office_query = new WP_Query( $args );
454
455 if ( $office_query->have_posts() )
456 {
457 while ( $office_query->have_posts() )
458 {
459 $office_query->the_post();
460
461 $offices[get_the_ID()] = get_the_title();
462
463 if ( get_post_meta(get_the_ID(), 'primary', TRUE) == 1 )
464 {
465 $value = get_the_ID();
466 }
467 }
468 }
469 wp_reset_postdata();
470
471 $fields['office_id'] = array(
472 'type' => ( (count($offices) <= 1) ? 'hidden' : 'select' ),
473 'label' => __( 'Office', 'propertyhive' ),
474 'required' => false,
475 'show_label' => true,
476 'value' => $value,
477 'options' => $offices
478 );
479
480 $fields['maximum_price'] = array(
481 'type' => 'number',
482 'label' => __( 'Maximum Price', 'propertyhive' ),
483 'style' => 'max-width:150px;',
484 'before' => '<div class="control control-minimum_price sales-only">',
485 'required' => false
486 );
487 if ( is_user_logged_in() && isset($applicant_profile['max_price']) )
488 {
489 $fields['maximum_price']['value'] = $applicant_profile['max_price'];
490 }
491
492 $fields['maximum_rent'] = array(
493 'type' => 'number',
494 'label' => __( 'Maximum Rent', 'propertyhive' ) . ' (PCM)',
495 'style' => 'max-width:150px;',
496 'before' => '<div class="control control-minimum_price lettings-only">',
497 'required' => false
498 );
499 if ( is_user_logged_in() && isset($applicant_profile['max_rent']) )
500 {
501 $fields['maximum_rent']['value'] = $applicant_profile['max_rent'];
502 }
503
504 $fields['minimum_bedrooms'] = array(
505 'type' => 'number',
506 'label' => __( 'Minimum Bedrooms', 'propertyhive' ),
507 'style' => 'max-width:80px;',
508 'required' => false
509 );
510 if ( is_user_logged_in() && isset($applicant_profile['min_beds']) )
511 {
512 $fields['minimum_bedrooms']['value'] = $applicant_profile['min_beds'];
513 }
514
515 $args = array(
516 'hide_empty' => false,
517 'parent' => 0
518 );
519 $terms = get_terms( 'property_type', $args );
520
521 $options = array();
522
523 $selected_value = '';
524 if ( !empty( $terms ) && !is_wp_error( $terms ) )
525 {
526 $options = array( '' => __( 'All Property Types', 'properthive' ) );
527
528 foreach ($terms as $term)
529 {
530 $options[$term->term_id] = $term->name;
531
532 $args = array(
533 'hide_empty' => false,
534 'parent' => $term->term_id
535 );
536 $subterms = get_terms( 'property_type', $args );
537
538 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
539 {
540 foreach ($subterms as $term)
541 {
542 $options[$term->term_id] = '- ' . $term->name;
543 }
544 }
545 }
546 }
547
548 if ( !empty($options) )
549 {
550 $fields['property_type'] = array(
551 'type' => 'select',
552 'label' => __( 'Property Type', 'propertyhive' ),
553 'required' => false,
554 'options' => $options,
555 );
556
557 if ( is_user_logged_in() && isset($applicant_profile['property_types']) && is_array($applicant_profile['property_types']) && !empty($applicant_profile['property_types']) )
558 {
559 $fields['property_type']['value'] = $applicant_profile['property_types'][0];
560 }
561 }
562
563 $args = array(
564 'hide_empty' => false,
565 'parent' => 0
566 );
567 $terms = get_terms( 'location', $args );
568
569 $options = array();
570
571 $selected_value = '';
572 if ( !empty( $terms ) && !is_wp_error( $terms ) )
573 {
574 $options = array( '' => __( 'All Locations', 'properthive' ) );
575
576 foreach ($terms as $term)
577 {
578 $options[$term->term_id] = $term->name;
579
580 $args = array(
581 'hide_empty' => false,
582 'parent' => $term->term_id
583 );
584 $subterms = get_terms( 'location', $args );
585
586 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
587 {
588 foreach ($subterms as $term)
589 {
590 $options[$term->term_id] = '- ' . $term->name;
591 }
592 }
593 }
594 }
595
596 if ( !empty($options) )
597 {
598 $fields['location'] = array(
599 'type' => 'select',
600 'label' => __( 'Location', 'propertyhive' ),
601 'required' => false,
602 'options' => $options,
603 );
604
605 if ( is_user_logged_in() && isset($applicant_profile['locations']) && is_array($applicant_profile['locations']) && !empty($applicant_profile['locations']) )
606 {
607 $fields['location']['value'] = $applicant_profile['locations'][0];
608 }
609 }
610
611 $fields['additional_requirements'] = array(
612 'type' => 'textarea',
613 'label' => __( 'Additional Requirements', 'propertyhive' ),
614 'required' => false
615 );
616 if ( is_user_logged_in() && isset($applicant_profile['notes']) )
617 {
618 $fields['additional_requirements']['value'] = $applicant_profile['notes'];
619 }
620
621 return $fields;
622 }
623
624 /**
625 * Output individual field
626 *
627 * @return void
628 */
629 function ph_form_field( $key, $field )
630 {
631 global $post;
632
633 $output = '';
634
635 switch ($field['type'])
636 {
637 case "text":
638 case "email":
639 case "date":
640 case "number":
641 case "password":
642 {
643 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
644 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
645 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
646 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
647 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
648 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : ( ( $field['type'] == 'date' ) ? 'dd/mm/yyyy' : '' );
649 $field['required'] = isset( $field['required'] ) ? $field['required'] : false;
650 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
651
652 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
653 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
654 {
655 $field['value'] = $_GET[$key];
656 }
657 else
658 {
659 if ( isset($post->ID) )
660 {
661 $value = get_post_meta( $post->ID, '_' . $key, true );
662 if ( $value != '' )
663 {
664 $field['value'] = $value;
665 }
666 }
667 }
668
669 $output .= $field['before'];
670
671 if ($field['show_label'])
672 {
673 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
674 if ($field['required'])
675 {
676 $output .= '<span class="required"> *</span>';
677 }
678 $output .= '</label>';
679 }
680
681 $output .= '<input
682 type="' . esc_attr( $field['type'] ) . '"
683 name="' . esc_attr( $key ) . '"
684 id="' . esc_attr( $key ) . '"
685 value="' . esc_attr( $field['value'] ) . '"
686 placeholder="' . esc_attr( $field['placeholder'] ) . '"
687 class="' . esc_attr( $field['class'] ) . '"
688 style="' . esc_attr( $field['style'] ) . '"
689 ' . ( ($field['required']) ? 'required' : '' ) . '
690 >';
691
692 $output .= $field['after'];
693
694 break;
695 }
696 case "textarea":
697 {
698 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
699 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
700 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
701 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
702 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
703 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
704 $field['required'] = isset( $field['required'] ) ? $field['required'] : false;
705
706 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
707 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
708 {
709 $field['value'] = $_GET[$key];
710 }
711
712 $output .= $field['before'];
713
714 if ($field['show_label'])
715 {
716 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
717 if ($field['required'])
718 {
719 $output .= '<span class="required"> *</span>';
720 }
721 $output .= '</label>';
722 }
723
724 $output .= '<textarea
725 name="' . esc_attr( $key ) . '"
726 id="' . esc_attr( $key ) . '"
727 placeholder="' . esc_attr( $field['placeholder'] ) . '"
728 class="' . esc_attr( $field['class'] ) . '"
729 ' . ( ($field['required']) ? 'required' : '' ) . '
730 >' . esc_attr( $field['value'] ) . '</textarea>';
731
732 $output .= $field['after'];
733
734 break;
735 }
736 case "radio":
737 {
738 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
739 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
740 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
741 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : false;
742 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
743
744 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
745 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
746 {
747 $field['value'] = $_GET[$key];
748 }
749
750 $output .= $field['before'];
751
752 if ($field['show_label'])
753 {
754 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
755 }
756
757 foreach ( $field['options'] as $option_key => $value )
758 {
759 $output .= '<label><input
760 type="' . esc_attr( $field['type'] ) . '"
761 name="' . esc_attr( $key ) . '"
762 value="' . esc_attr( $option_key ) . '"
763 class="' . esc_attr( $field['class'] ) . '"
764 ' . checked( esc_attr( $field['value'] ), esc_attr( $option_key ), false ) . '
765 > ' . esc_html( $value ) . '</label>';
766 }
767
768 $output .= $field['after'];
769
770 break;
771 }
772 case "select":
773 {
774 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
775 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
776 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
777 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
778 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
779 $field['required'] = isset( $field['required'] ) ? $field['required'] : false;
780 $field['options'] = ( isset( $field['options'] ) && is_array( $field['options'] ) ) ? $field['options'] : array();
781
782 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
783 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
784 {
785 $field['value'] = $_GET[$key];
786 }
787
788 $output .= $field['before'];
789
790 if ($field['show_label'])
791 {
792 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
793 if ($field['required'])
794 {
795 $output .= '<span class="required"> *</span>';
796 }
797 $output .= '</label>';
798 }
799
800 $output .= '<select
801 name="' . esc_attr( $key ) . '"
802 id="' . esc_attr( $key ) . '"
803 class="' . esc_attr( $field['class'] ) . '"
804 >';
805
806 foreach ( $field['options'] as $option_key => $value )
807 {
808 $output .= '<option
809 value="' . esc_attr( $option_key ) . '"
810 ' . selected( esc_attr( $field['value'] ), esc_attr( $option_key ), false ) . '
811 >' . esc_html( $value ) . '</option>';
812 }
813
814 $output .= '</select>';
815
816 $output .= $field['after'];
817
818 break;
819 }
820 case "office":
821 {
822 $key = 'officeID';
823
824 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
825 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
826 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
827 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
828 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
829
830 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
831 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
832 {
833 $field['value'] = $_GET[$key];
834 }
835
836 $output .= $field['before'];
837
838 if ($field['show_label'])
839 {
840 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
841 }
842
843 $output .= '<select
844 name="' . esc_attr( $key ) . '"
845 id="' . esc_attr( $key ) . '"
846 class="' . esc_attr( $field['class'] ) . '"
847 >';
848
849 $output .= '<option
850 value=""
851 ' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . '
852 >' . esc_html( __( 'No preference', 'propertyhive' ) ) . '</option>';
853
854 $args = array(
855 'post_type' => 'office',
856 'nopaging' => true,
857 'orderby' => 'title',
858 'order' => 'ASC'
859 );
860 $office_query = new WP_Query($args);
861
862 if ($office_query->have_posts())
863 {
864 while ($office_query->have_posts())
865 {
866 $office_query->the_post();
867
868 $output .= '<option
869 value="' . esc_attr( $post->ID ) . '"
870 ' . selected( esc_attr( $field['value'] ), esc_attr( $post->ID ), false ) . '
871 >' . esc_html( get_the_title() ) . '</option>';
872
873 }
874 }
875 wp_reset_postdata();
876
877 $output .= '</select>';
878
879 $output .= $field['after'];
880
881 break;
882 }
883 case "country":
884 {
885 $key = 'country';
886
887 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
888 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
889 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
890 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
891 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
892
893 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
894 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
895 {
896 $field['value'] = $_GET[$key];
897 }
898
899 $output .= $field['before'];
900
901 if ($field['show_label'])
902 {
903 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
904 }
905
906 $output .= '<select
907 name="' . esc_attr( $key ) . '"
908 id="' . esc_attr( $key ) . '"
909 class="' . esc_attr( $field['class'] ) . '"
910 >';
911
912 $output .= '<option
913 value=""
914 ' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . '
915 >' . esc_html( __( 'No preference', 'propertyhive' ) ) . '</option>';
916
917 $countries = get_option( 'propertyhive_countries', array() );
918 if ( is_array($countries) && !empty($countries) )
919 {
920 $ph_countries = new PH_Countries;
921
922 foreach ( $countries as $country )
923 {
924 $ph_country = $ph_countries->get_country( $country );
925
926 if ( $ph_country !== FALSE )
927 {
928 $output .= '<option
929 value="' . esc_attr( $country ) . '"
930 ' . selected( esc_attr( $field['value'] ), esc_attr( $country ), false ) . '
931 >' . esc_html( $ph_country['name'] ) . '</option>';
932 }
933 }
934 }
935
936 $output .= '</select>';
937
938 $output .= $field['after'];
939
940 break;
941 }
942 case "hidden":
943 {
944 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
945 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
946 {
947 $field['value'] = $_GET[$key];
948 }
949
950 $output .= '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . $field['value'] . '">';
951 break;
952 }
953 case "html":
954 {
955 $field['html'] = isset( $field['html'] ) ? $field['html'] : '';
956 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
957 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
958
959 $output .= $field['before'];
960 $output .= $field['html'];
961 $output .= $field['after'];
962
963 break;
964 }
965 default:
966 {
967 if ( taxonomy_exists($field['type']) )
968 {
969 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
970 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
971 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
972 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
973 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
974 $field['blank_option'] = isset( $field['blank_option'] ) ? $field['blank_option'] : __( 'No preference', 'propertyhive' );
975
976 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
977 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
978 {
979 $field['value'] = $_GET[$key];
980 }
981
982 $output .= $field['before'];
983
984 if ($field['show_label'])
985 {
986 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
987 }
988
989 $output .= '<select
990 name="' . esc_attr( $key ) . '"
991 id="' . esc_attr( $key ) . '"
992 class="' . esc_attr( $field['class'] ) . '"
993 >';
994
995 $options = array( '' => $field['blank_option'] );
996 $args = array(
997 'hide_empty' => false,
998 'parent' => 0
999 );
1000 $terms = get_terms( $field['type'], $args );
1001
1002 $selected_value = '';
1003 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1004 {
1005 foreach ($terms as $term)
1006 {
1007 $options[$term->term_id] = $term->name;
1008
1009 $args = array(
1010 'hide_empty' => false,
1011 'parent' => $term->term_id
1012 );
1013 $subterms = get_terms( $field['type'], $args );
1014
1015 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
1016 {
1017 foreach ($subterms as $term)
1018 {
1019 $options[$term->term_id] = '- ' . $term->name;
1020
1021 $args = array(
1022 'hide_empty' => false,
1023 'parent' => $term->term_id
1024 );
1025 $subsubterms = get_terms( $field['type'], $args );
1026
1027 if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) )
1028 {
1029 foreach ($subsubterms as $term)
1030 {
1031 $options[$term->term_id] = '- ' . $term->name;
1032 }
1033 }
1034 }
1035 }
1036 }
1037 }
1038
1039 foreach ( $options as $option_key => $value )
1040 {
1041 $output .= '<option
1042 value="' . esc_attr( $option_key ) . '"
1043 ' . selected( esc_attr( $field['value'] ), esc_attr( $option_key ), false ) . '
1044 >' . esc_html( $value ) . '</option>';
1045 }
1046
1047 $output .= '</select>';
1048
1049 $output .= $field['after'];
1050 }
1051 }
1052 }
1053
1054 echo $output;
1055 }