PluginProbe
Property Hive / 1.4.46
Property Hive v1.4.46
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.46, at includes/admin/class-ph-admin-applicant-list.php

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