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 / admin / class-ph-admin-applicant-list.php

class-ph-admin-applicant-list.php in Property Hive 1.4.62, at includes/admin/class-ph-admin-applicant-list.php

678 lines 33.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Admin Generate Applicant List Class.
4 *
5 * @author PropertyHive
6 * @category Admin
7 * @package PropertyHive/Admin
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
13 if ( ! class_exists( 'PH_Admin_Applicant_List' ) ) :
14
15 /**
16 * PH_Admin_Applicant_List
17 */
18 class PH_Admin_Applicant_List {
19
20 /**
21 * Handles the display of the main Property Hive reports page in admin.
22 *
23 * @access public
24 * @return void
25 */
26 public static function output() {
27
28 $property_types = array();
29 $locations = array();
30 ?>
31 <div class="wrap propertyhive">
32
33 <h1>Generate Applicant List</h1>
34
35 <form method="post" id="mainform" action="" enctype="multipart/form-data" class="applicant-list-form">
36
37 <input type="hidden" name="submitted" value="1">
38
39 <div id="poststuff" class="propertyhive_meta_box">
40
41 <p class="form-field">
42 <label>Looking For</label>
43 <select name="department">
44 <?php
45
46 $departments = ph_get_departments();
47
48 $department_options = array();
49 foreach ( $departments as $key => $value )
50 {
51 if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' )
52 {
53 $department_options[$key] = $value;
54 }
55 }
56
57 foreach ( $department_options as $key => $department )
58 {
59 echo '<option value="' . $key . '"';
60 if ( isset($_POST['department']) && $_POST['department'] == $key )
61 {
62 echo ' selected';
63 }
64 elseif ( !isset($_POST['department']) && $key == get_option( 'propertyhive_primary_department' ) )
65 {
66 echo ' selected';
67 }
68 echo '>' . $department . '</option>';
69 }
70 ?>
71
72 </select>
73 </p>
74
75 <p class="form-field sales-only">
76 <label>Price</label>
77 <input type="text" name="maximum_price" value="<?php if ( isset($_POST['maximum_price']) ) { echo esc_attr( $_POST['maximum_price'] ); } ?>">
78 </p>
79
80 <p class="form-field lettings-only">
81 <label>Rent (PCM)</label>
82 <input type="text" name="maximum_rent" value="<?php if ( isset($_POST['maximum_rent']) ) { echo esc_attr( $_POST['maximum_rent'] ); } ?>">
83 </p>
84
85 <p class="form-field residential-only">
86 <label>Bedrooms</label>
87 <input type="number" name="minimum_bedrooms" class="short" value="<?php if ( isset($_POST['minimum_bedrooms']) ) { echo esc_attr( $_POST['minimum_bedrooms'] ); } ?>">
88 </p>
89
90 <p class="form-field residential-only">
91 <label>Property Types</label>
92 <select id="property_types" name="property_types[]" multiple="multiple" data-placeholder="Start typing to add property types..." class="multiselect attribute_values">
93 <?php
94 $options = array( '' => '' );
95 $args = array(
96 'hide_empty' => false,
97 'parent' => 0
98 );
99 $terms = get_terms( 'property_type', $args );
100
101 if ( !empty( $terms ) && !is_wp_error( $terms ) )
102 {
103 foreach ($terms as $term)
104 {
105 $property_types[$term->term_id] = esc_html( $term->name );
106
107 echo '<option value="' . esc_attr( $term->term_id ) . '"';
108 if ( isset($_POST['property_types']) && in_array( $term->term_id, $_POST['property_types'] ) )
109 {
110 echo ' selected';
111 }
112 echo '>' . esc_html( $term->name ) . '</option>';
113
114 $args = array(
115 'hide_empty' => false,
116 'parent' => $term->term_id
117 );
118 $subterms = get_terms( 'property_type', $args );
119
120 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
121 {
122 foreach ($subterms as $term)
123 {
124 $property_types[$term->term_id] = esc_html( $term->name );
125
126 echo '<option value="' . esc_attr( $term->term_id ) . '"';
127 if ( isset($_POST['property_types']) && in_array( $term->term_id, $_POST['property_types'] ) )
128 {
129 echo ' selected';
130 }
131 echo '>- ' . esc_html( $term->name ) . '</option>';
132 }
133 }
134 }
135 }
136 ?>
137 </select>
138 </p>
139
140 <p class="form-field">
141 <label>Location</label>
142 <select id="locations" name="locations[]" multiple="multiple" data-placeholder="Start typing to add locations..." class="multiselect attribute_values">
143 <?php
144 $options = array( '' => '' );
145 $args = array(
146 'hide_empty' => false,
147 'parent' => 0
148 );
149 $terms = get_terms( 'location', $args );
150
151 if ( !empty( $terms ) && !is_wp_error( $terms ) )
152 {
153 foreach ($terms as $term)
154 {
155 $locations[$term->term_id] = esc_html( $term->name );
156
157 echo '<option value="' . esc_attr( $term->term_id ) . '"';
158 if ( isset($_POST['locations']) && in_array( $term->term_id, $_POST['locations'] ) )
159 {
160 echo ' selected';
161 }
162 echo '>' . esc_html( $term->name ) . '</option>';
163
164 $args = array(
165 'hide_empty' => false,
166 'parent' => $term->term_id
167 );
168 $subterms = get_terms( 'location', $args );
169
170 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
171 {
172 foreach ($subterms as $term)
173 {
174 $locations[$term->term_id] = esc_html( $term->name );
175
176 echo '<option value="' . esc_attr( $term->term_id ) . '"';
177 if ( isset($_POST['locations']) && in_array( $term->term_id, $_POST['locations'] ) )
178 {
179 echo ' selected';
180 }
181 echo '>- ' . esc_html( $term->name ) . '</option>';
182
183 $args = array(
184 'hide_empty' => false,
185 'parent' => $term->term_id
186 );
187 $subsubterms = get_terms( 'location', $args );
188
189 if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) )
190 {
191 foreach ($subsubterms as $term)
192 {
193 $locations[$term->term_id] = esc_html( $term->name );
194
195 echo '<option value="' . esc_attr( $term->term_id ) . '"';
196 if ( isset($_POST['locations']) && in_array( $term->term_id, $_POST['locations'] ) )
197 {
198 echo ' selected';
199 }
200 echo '>- - ' . esc_html( $term->name ) . '</option>';
201 }
202 }
203 }
204 }
205 }
206 }
207 ?>
208 </select>
209 </p>
210
211 <p class="form-field">
212 <input type="submit" value="<?php echo __( 'Generate Applicant List', 'propertyhive' ); ?>" class="button-primary">
213 </p>
214
215 </div>
216
217 </form>
218
219 <div class="applicant-list-results">
220
221 <?php
222 if ( isset($_POST['submitted']) && $_POST['submitted'] == '1' )
223 {
224 $search_property_types = array();
225 if ( isset($_POST['department']) && ( $_POST['department'] == 'residential-sales' || $_POST['department'] == 'residential-lettings' ) )
226 {
227 if ( isset($_POST['property_types']) && is_array($_POST['property_types']) && !empty($_POST['property_types']) )
228 {
229 foreach ( $_POST['property_types'] as $property_type )
230 {
231 $search_property_types[] = (int)$property_type;
232
233 $args = array(
234 'hide_empty' => false,
235 'parent' => $property_type
236 );
237 $terms = get_terms( 'property_type', $args );
238
239 if ( !empty( $terms ) && !is_wp_error( $terms ) )
240 {
241 foreach ($terms as $term)
242 {
243 $search_property_types[] = $term->term_id;
244
245 $args = array(
246 'hide_empty' => false,
247 'parent' => $term->term_id
248 );
249 $subterms = get_terms( 'property_type', $args );
250
251 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
252 {
253 foreach ($subterms as $term)
254 {
255 $search_property_types[] = $term->term_id;
256 }
257 }
258 }
259 }
260 }
261 }
262 $search_property_types = array_unique($search_property_types);
263 }
264
265 $search_locations = array();
266 if ( isset($_POST['locations']) && is_array($_POST['locations']) && !empty($_POST['locations']) )
267 {
268 foreach ( $_POST['locations'] as $location )
269 {
270 $search_locations[] = (int)$location;
271
272 $args = array(
273 'hide_empty' => false,
274 'parent' => $location
275 );
276 $terms = get_terms( 'location', $args );
277
278 if ( !empty( $terms ) && !is_wp_error( $terms ) )
279 {
280 foreach ($terms as $term)
281 {
282 $search_locations[] = $term->term_id;
283
284 $args = array(
285 'hide_empty' => false,
286 'parent' => $term->term_id
287 );
288 $subterms = get_terms( 'location', $args );
289
290 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
291 {
292 foreach ($subterms as $term)
293 {
294 $search_locations[] = $term->term_id;
295 }
296 }
297 }
298 }
299 }
300 }
301 $search_locations = array_unique($search_locations);
302
303 $args = array(
304 'post_type' => 'contact',
305 'fields' => 'ids',
306 'nopaging' => true,
307 );
308
309 $args['meta_query'] = array();
310
311 $args['meta_query'][] = array(
312 'key' => '_contact_types',
313 'value' => 'applicant',
314 'compare' => 'LIKE'
315 );
316
317 $applicant_query = new WP_Query($args);
318
319 $results = array();
320
321 if ( $applicant_query->have_posts() )
322 {
323 while ( $applicant_query->have_posts() )
324 {
325 $applicant_query->the_post();
326
327 $num_applicant_profiles = get_post_meta( get_the_ID(), '_applicant_profiles', TRUE );
328 if ( $num_applicant_profiles == '' )
329 {
330 $num_applicant_profiles = 0;
331 }
332
333 for ( $i = 0; $i < $num_applicant_profiles; ++$i )
334 {
335 $profile = get_post_meta( get_the_ID(), '_applicant_profile_' . $i, TRUE );
336
337 $match = true;
338
339 if ( !isset($profile['send_matching_properties']) || ( isset($profile['send_matching_properties']) && $profile['send_matching_properties'] != 'yes' ) )
340 {
341 $match = false;
342 }
343
344 if ( isset($_POST['department']) )
345 {
346 if ( isset($profile['department']) && $profile['department'] != ph_clean($_POST['department']) )
347 {
348 $match = false;
349 }
350 }
351
352 if ( isset($_POST['department']) && $_POST['department'] == 'residential-sales' )
353 {
354 if ( isset($_POST['maximum_price']) && ph_clean($_POST['maximum_price']) != '' )
355 {
356 $price = preg_replace("/[^0-9]/", '', ph_clean($_POST['maximum_price']));
357
358 if ( isset($profile['max_price_actual']) && $profile['max_price_actual'] != '' && $profile['max_price_actual'] != 0 && $profile['max_price_actual'] < $price )
359 {
360 $match = false;
361 }
362 }
363 }
364 if ( isset($_POST['department']) && $_POST['department'] == 'residential-lettings' )
365 {
366 if ( isset($_POST['maximum_rent']) && ph_clean($_POST['maximum_rent']) != '' )
367 {
368 $price = preg_replace("/[^0-9]/", '', ph_clean($_POST['maximum_rent']));
369
370 if ( isset($profile['max_rent_actual']) && $profile['max_rent_actual'] != '' && $profile['max_rent_actual'] != 0 && $profile['max_rent_actual'] < $price )
371 {
372 $match = false;
373 }
374 }
375 }
376 if ( isset($_POST['department']) && ( $_POST['department'] == 'residential-sales' || $_POST['department'] == 'residential-lettings' ) )
377 {
378 if ( isset($_POST['minimum_bedrooms']) && ph_clean($_POST['minimum_bedrooms']) != '' )
379 {
380 $beds = preg_replace("/[^0-9]/", '', ph_clean($_POST['minimum_bedrooms']));
381
382 if ( isset($profile['min_beds']) && $profile['min_beds'] != '' && $profile['min_beds'] != 0 && $profile['min_beds'] > $beds )
383 {
384 $match = false;
385 }
386 }
387
388 // Property Types
389 if ( isset($_POST['property_types']) && is_array($_POST['property_types']) && !empty($_POST['property_types']) )
390 {
391 $found_type = false;
392 foreach ( $search_property_types as $search_property_type )
393 {
394 if ( isset($profile['property_types']) && is_array($profile['property_types']) && in_array($search_property_type, $profile['property_types']) )
395 {
396 $found_type = true;
397 }
398 }
399
400 if ( !$found_type )
401 {
402 $match = false;
403 }
404 }
405 }
406
407 if ( isset($_POST['locations']) && is_array($_POST['locations']) && !empty($_POST['locations']) )
408 {
409 $found_type = false;
410 foreach ( $search_locations as $search_location )
411 {
412 if ( isset($profile['locations']) && is_array($profile['locations']) && in_array($search_location, $profile['locations']) )
413 {
414 $found_type = true;
415 }
416 }
417
418 if ( !$found_type )
419 {
420 $match = false;
421 }
422 }
423
424 if ( $match )
425 {
426 $contact_details = array();
427 if ( get_post_meta( get_the_ID(), '_telephone_number', TRUE ) != '' )
428 {
429 $contact_details[] = 'T: ' . get_post_meta( get_the_ID(), '_telephone_number', TRUE );
430 }
431 if ( get_post_meta( get_the_ID(), '_email_address', TRUE ) != '' )
432 {
433 $contact_details[] = 'E: ' . get_post_meta( get_the_ID(), '_email_address', TRUE );
434 }
435 $results[] = array(
436 'name' => get_the_title(),
437 'edit_link' => get_edit_post_link(get_the_ID()),
438 'contact_details' => implode("<br>", $contact_details),
439 'profile' => $profile
440 );
441 }
442 }
443 }
444 }
445
446 wp_reset_postdata();
447 ?>
448 <br>
449 <div class="applicant-list-results">
450 <h3><?php echo number_format(count($results)); ?> Applicants Found Matching Your Criteria</h3>
451 <table width="100%" cellpadding="8" cellspacing="0">
452 <thead>
453 <tr>
454 <th style="text-align:left;">Applicant Name</th>
455 <th style="text-align:left;">Contact Details</th>
456 <th style="text-align:left;">Requirements</th>
457 </tr>
458 </thead>
459 <tbody>
460 <?php
461 if ( !empty($results) )
462 {
463 foreach ( $results as $result )
464 {
465 ?>
466 <tr>
467 <td><a href="<?php echo $result['edit_link'] ?>" target="_blank"><?php echo $result['name']; ?></a></td>
468 <td><?php echo ( ( $result['contact_details'] != '' ) ? $result['contact_details'] : '-' ); ?></td>
469 <td><?php
470 if ( isset($result['profile']['department']) )
471 {
472 switch ( $result['profile']['department'] )
473 {
474 case "residential-sales":
475 {
476 $output = array();
477 if ( isset($result['profile']['max_price']) && $result['profile']['max_price'] != '' && $result['profile']['max_price'] != 0 )
478 {
479 $output[] = '<strong>Max Price:</strong> &pound;' . number_format($result['profile']['max_price']);
480 }
481 if ( isset($result['profile']['min_beds']) && $result['profile']['min_beds'] != '' && $result['profile']['min_beds'] != 0 )
482 {
483 $output[] = '<strong>Min Beds:</strong> ' . number_format($result['profile']['min_beds']);
484 }
485 if ( isset($result['profile']['property_types']) && is_array($result['profile']['property_types']) && !empty($result['profile']['property_types']) )
486 {
487 $output_types = array();
488 foreach ( $result['profile']['property_types'] as $profile_type )
489 {
490 $output_types[] = $property_types[$profile_type];
491 }
492 $output[] = '<strong>Property Types:</strong> ' . implode(", ", $output_types);
493 }
494 if ( isset($result['profile']['locations']) && is_array($result['profile']['locations']) && !empty($result['profile']['locations']) )
495 {
496 $output_locations = array();
497 foreach ( $result['profile']['locations'] as $profile_location )
498 {
499 $output_locations[] = $locations[$profile_location];
500 }
501 $output[] = '<strong>Locations:</strong> ' . implode(", ", $output_locations);
502 }
503 if ( isset($result['profile']['notes']) && $result['profile']['notes'] != '' )
504 {
505 $output[] = '<strong>Additional Requirements:</strong> ' . nl2br($result['profile']['notes']);
506 }
507 echo( !empty($output) ? implode("<br>", $output) : '-' );
508 break;
509 }
510 case "residential-lettings":
511 {
512 $output = array();
513 if ( isset($result['profile']['max_rent']) && $result['profile']['max_rent'] != '' && $result['profile']['max_rent'] != 0 )
514 {
515 $output[] = '<strong>Max Rent:</strong> &pound;' . number_format($result['profile']['max_rent']) . $result['profile']['rent_frequency'];
516 }
517 if ( isset($result['profile']['min_beds']) && $result['profile']['min_beds'] != '' && $result['profile']['min_beds'] != 0 )
518 {
519 $output[] = '<strong>Min Beds:</strong> ' . number_format($result['profile']['min_beds']);
520 }
521 if ( isset($result['profile']['property_types']) && is_array($result['profile']['property_types']) && !empty($result['profile']['property_types']) )
522 {
523 $output_types = array();
524 foreach ( $result['profile']['property_types'] as $profile_type )
525 {
526 $output_types[] = $property_types[$profile_type];
527 }
528 $output[] = '<strong>Property Types:</strong> ' . implode(", ", $output_types);
529 }
530 if ( isset($result['profile']['locations']) && is_array($result['profile']['locations']) && !empty($result['profile']['locations']) )
531 {
532 $output_locations = array();
533 foreach ( $result['profile']['locations'] as $profile_location )
534 {
535 $output_locations[] = $locations[$profile_location];
536 }
537 $output[] = '<strong>Locations:</strong> ' . implode(", ", $output_locations);
538 }
539 if ( isset($result['profile']['notes']) && $result['profile']['notes'] != '' )
540 {
541 $output[] = '<strong>Additional Requirements:</strong> ' . nl2br($result['profile']['notes']);
542 }
543 echo( !empty($output) ? implode("<br>", $output) : '-' );
544 break;
545 }
546 case "commercial":
547 {
548 $output = array();
549 /*if ( isset($result['profile']['max_price']) && $result['profile']['max_price'] != '' && $result['profile']['max_price'] != 0 )
550 {
551 $output[] = '<strong>Max Price:</strong> &pound;' . number_format($result['profile']['max_price']);
552 }
553 if ( isset($result['profile']['min_beds']) && $result['profile']['min_beds'] != '' && $result['profile']['min_beds'] != 0 )
554 {
555 $output[] = '<strong>Min Beds:</strong> ' . number_format($result['profile']['min_beds']);
556 }
557 if ( isset($result['profile']['property_types']) && is_array($result['profile']['property_types']) && !empty($result['profile']['property_types']) )
558 {
559 $output_types = array();
560 foreach ( $result['profile']['property_types'] as $profile_type )
561 {
562 $output_types[] = $property_types[$profile_type];
563 }
564 $output[] = '<strong>Property Types:</strong> ' . implode(", ", $output_types);
565 }*/
566 if ( isset($result['profile']['locations']) && is_array($result['profile']['locations']) && !empty($result['profile']['locations']) )
567 {
568 $output_locations = array();
569 foreach ( $result['profile']['locations'] as $profile_location )
570 {
571 $output_locations[] = $locations[$profile_location];
572 }
573 $output[] = '<strong>Locations:</strong> ' . implode(", ", $output_locations);
574 }
575 if ( isset($result['profile']['notes']) && $result['profile']['notes'] != '' )
576 {
577 $output[] = '<strong>Additional Requirements:</strong> ' . nl2br($result['profile']['notes']);
578 }
579 echo( !empty($output) ? implode("<br>", $output) : '-' );
580 break;
581 }
582 }
583 }
584 ?></td>
585 </tr>
586 <?php
587 }
588 }
589 else
590 {
591 ?>
592 <tr>
593 <td colspan="3" style="text-align:center"><?php echo __( 'No matching applicants found', 'propertyhive' ); ?></td>
594 </tr>
595 <?php
596 }
597 ?>
598 </tbody>
599 </table>
600 </div>
601 <?php
602 }
603 ?>
604
605 </div>
606
607 </div>
608 <script>
609
610 function toggleDepartmentFields()
611 {
612 if (jQuery('#mainform').length > 0)
613 {
614 // There may be multiple forms on the page so treat each one individually
615 jQuery('#mainform').each(function()
616 {
617 var selectedDepartment = "residential-sales"; // TODO: Use default from settings
618
619 var selected = jQuery(this).find('[name=\'department\']');
620
621 jQuery(this).find('.sales-only').hide();
622 jQuery(this).find('.lettings-only').hide();
623 jQuery(this).find('.residential-only').hide();
624 jQuery(this).find('.commercial-only').hide();
625
626 if (selected.length > 0)
627 {
628 selectedDepartment = selected.val();
629
630 // controls won't always be display:block so we should get the
631 // first visible component (that isnt sales/lettings-only) and
632 // use that display
633 var display = 'block';
634
635 if (selectedDepartment == 'residential-sales')
636 {
637 jQuery(this).find('.sales-only').css('display', display);
638 jQuery(this).find('.residential-only').css('display', display);
639 }
640 else if (selectedDepartment == 'residential-lettings')
641 {
642 jQuery(this).find('.lettings-only').css('display', display);
643 jQuery(this).find('.residential-only').css('display', display);
644 }
645 else if (selectedDepartment == 'commercial')
646 {
647 jQuery(this).find('.commercial-only').css('display', display);
648 }
649 }
650 });
651 }
652 }
653
654 jQuery( function(jQuery) {
655
656 // Multiselect
657 jQuery("#mainform select.multiselect").chosen();
658
659 toggleDepartmentFields();
660
661 jQuery('#mainform [name=\'department\']').change(function()
662 {
663 toggleDepartmentFields();
664 });
665
666 });
667
668 jQuery(window).resize(function() {
669 toggleDepartmentFields();
670 });
671
672 </script>
673 <?php
674 }
675
676 }
677
678 endif;