PluginProbe
Property Hive / 2.2.4
Property Hive v2.2.4
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 / settings / class-ph-settings-emails.php

class-ph-settings-emails.php in Property Hive 2.2.4, at includes/admin/settings/class-ph-settings-emails.php

758 lines 30.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Email Settings
4 *
5 * @author PropertyHive
6 * @category Admin
7 * @package PropertyHive/Admin
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 if ( ! class_exists( 'PH_Settings_Emails' ) ) :
16
17 /**
18 * PH_Settings_Emails.
19 */
20 class PH_Settings_Emails extends PH_Settings_Page {
21
22 /**
23 * Constructor.
24 */
25 public function __construct() {
26 $this->id = 'email';
27 $this->label = __( 'Emails', 'propertyhive' );
28
29 add_filter( 'propertyhive_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
30 add_action( 'propertyhive_sections_' . $this->id, array( $this, 'output_sections' ) );
31 add_action( 'propertyhive_settings_' . $this->id, array( $this, 'output' ) );
32 add_action( 'propertyhive_settings_save_' . $this->id, array( $this, 'save' ) );
33
34 add_action( 'propertyhive_admin_field_email_queue', array( $this, 'email_queue_setting' ) );
35 }
36
37 /**
38 * Get sections.
39 *
40 * @return array
41 */
42 public function get_sections() {
43 $sections = array(
44 '' => __( 'Email Options', 'propertyhive' ),
45 'enquiry-auto-responder' => __( 'Enquiry Auto-Responder', 'propertyhive' ),
46 );
47
48 if ( get_option('propertyhive_module_disabled_contacts', '') != 'yes' )
49 {
50 $sections['match'] = __( 'Property Match', 'propertyhive' );
51 }
52
53 if (
54 get_option('propertyhive_module_disabled_viewings', '') != 'yes' ||
55 get_option('propertyhive_module_disabled_appraisals', '') != 'yes'
56 )
57 {
58 $sections['booking-confirmation'] = __( 'Booking Confirmations & Cancellations', 'propertyhive' );
59 }
60
61 if ( get_option('propertyhive_module_disabled_contacts', '') != 'yes' )
62 {
63 $sections['log'] = __( 'Email Queue', 'propertyhive' );
64 }
65
66 return apply_filters( 'propertyhive_get_sections_' . $this->id, $sections );
67 }
68
69 /**
70 * Get settings array.
71 *
72 * @return array
73 */
74 public function get_settings() {
75 $settings = array(
76
77 array( 'title' => __( 'Email Sender Settings', 'propertyhive' ), 'type' => 'title', 'id' => 'email_sender_options' ),
78
79 array(
80 'title' => __( '"From" Email Address', 'propertyhive' ),
81 'id' => 'propertyhive_email_from_address',
82 'type' => 'text',
83 'css' => 'min-width:300px;',
84 'default' => get_option('admin_email'),
85 'autoload' => false,
86 'desc_tip' => false,
87 ),
88
89 array( 'type' => 'sectionend', 'id' => 'email_sender_options' ),
90
91 array( 'title' => __( 'Email Template Settings', 'propertyhive' ), 'type' => 'title', 'id' => 'email_template_options' ),
92
93 array(
94 'title' => __( 'Header Image URL', 'propertyhive' ),
95 'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'propertyhive' ),
96 'id' => 'propertyhive_email_header_image',
97 'type' => 'text',
98 'css' => 'min-width:300px;',
99 'placeholder' => 'http://',
100 'default' => '',
101 'autoload' => false,
102 'desc_tip' => true,
103 ),
104
105 array(
106 'title' => __( 'Email Background Colour', 'propertyhive' ),
107 'desc' => __( 'The background colour for Property Hive email templates.', 'propertyhive' ),
108 'id' => 'propertyhive_email_background_color',
109 'type' => 'color',
110 'css' => 'width:6em;',
111 'default' => '#f7f7f7',
112 'autoload' => false,
113 'desc_tip' => true,
114 ),
115
116 array(
117 'title' => __( 'Body Background Colour', 'propertyhive' ),
118 'desc' => __( 'The main body background colour.', 'propertyhive' ),
119 'id' => 'propertyhive_email_body_background_color',
120 'type' => 'color',
121 'css' => 'width:6em;',
122 'default' => '#ffffff',
123 'autoload' => false,
124 'desc_tip' => true,
125 ),
126
127 array(
128 'title' => __( 'Body Text Colour', 'propertyhive' ),
129 'desc' => __( 'The main body text colour.', 'propertyhive' ),
130 'id' => 'propertyhive_email_text_color',
131 'type' => 'color',
132 'css' => 'width:6em;',
133 'default' => '#333333',
134 'autoload' => false,
135 'desc_tip' => true,
136 ),
137
138 array( 'type' => 'sectionend', 'id' => 'email_template_options' ),
139
140 );
141
142 $settings = apply_filters( 'propertyhive_email_settings', $settings );
143
144 return apply_filters( 'propertyhive_get_settings_' . $this->id, $settings );
145 }
146
147 /**
148 * Get enquiry auto-responder settings array
149 *
150 * @return array
151 */
152 public function get_enquiry_autoresponder_settings() {
153
154 return apply_filters( 'propertyhive_enquiry_autoresponder_settings', array(
155
156 array( 'title' => __( 'Enquiry Auto-Responder Settings', 'propertyhive' ), 'type' => 'title', 'id' => 'enquiry_auto_responder_email_options' ),
157
158 array(
159 'title' => __( 'Auto-Responder Enabled', 'propertyhive' ),
160 'id' => 'propertyhive_enquiry_auto_responder',
161 'type' => 'checkbox',
162 'default' => '',
163 ),
164
165 array(
166 'title' => __( 'Auto-Responder Email Subject', 'propertyhive' ),
167 'id' => 'propertyhive_enquiry_auto_responder_email_subject',
168 'type' => 'text',
169 'css' => 'min-width:300px;',
170 ),
171
172 array(
173 'title' => __( 'Auto-Responder Email Body', 'propertyhive' ),
174 'id' => 'propertyhive_enquiry_auto_responder_email_body',
175 'type' => 'textarea',
176 'css' => 'min-width:300px; height:110px;',
177 ),
178
179 array( 'type' => 'sectionend', 'id' => 'enquiry_auto_responder_email_options' )
180
181 ) ); // End settings
182 }
183
184 /**
185 * Get property match settings settings array
186 *
187 * @return array
188 */
189 public function get_property_match_settings() {
190
191 $settings = array();
192
193 $settings[] = array( 'title' => __( 'Property Match Email Settings', 'propertyhive' ), 'type' => 'title', 'id' => 'applicant_match_email_options' );
194
195 $settings[] = array(
196 'title' => __( 'Default Email Subject', 'propertyhive' ),
197 'id' => 'propertyhive_property_match_default_email_subject',
198 'type' => 'text',
199 'css' => 'min-width:300px;',
200 );
201
202 $settings[] = array(
203 'title' => __( 'Default Email Body', 'propertyhive' ),
204 'id' => 'propertyhive_property_match_default_email_body',
205 'type' => 'textarea',
206 'css' => 'min-width:300px; height:110px;',
207 );
208
209 $settings[] = array(
210 'title' => __( 'Default From Email Address', 'propertyhive' ),
211 'id' => 'propertyhive_property_match_default_from',
212 'type' => 'select',
213 'default' => '',
214 'css' => 'min-width:300px;',
215 'options' => array(
216 '' => __( 'User Email Address', 'propertyhive' ),
217 'default_from_email' => __( 'Default "From" Email Address', 'propertyhive' ),
218 ),
219 'desc' => '<p>' . __( 'This sets the email address that manual matches will be sent from by default. This can still be edited when you go to send the match.<br>Automatic matches, if enabled, will still be sent from the email address of the office that most of the properties in the match belong to.', 'propertyhive' ) . '</p>',
220 );
221
222 $options = array();
223 $args = array(
224 'hide_empty' => false,
225 'parent' => 0
226 );
227 $terms = get_terms( 'availability', $args );
228
229 if ( !empty( $terms ) && !is_wp_error( $terms ) )
230 {
231 foreach ($terms as $term)
232 {
233 $options[$term->term_id] = $term->name;
234 }
235 }
236 $settings[] = array(
237 'title' => __( 'Only Include Properties With Statuses', 'propertyhive' ),
238 'id' => 'propertyhive_property_match_statuses',
239 'type' => 'multiselect',
240 'css' => 'min-width:300px; height:110px;',
241 'options' => $options,
242 'desc' => '<p>' . __( 'By default, all on market properties will come back in matches when sending properties to applicants. If you wish to only send properties with a certain status you can choose this here. For example, maybe you don\'t want Sold STC properties to be sent. Hold ctrl/cmd whilst clicking to select multiple.<br>This will also affect the Similar Properties included in the Auto Responder above, if applicable.', 'propertyhive' ) . '</p>',
243 );
244
245 $time_offset = (int) get_option('gmt_offset') * 60 * 60;
246
247 $settings[] = array(
248 'title' => __( 'Automatically Send Matching Properties To Applicants', 'propertyhive' ),
249 'desc' => __( 'Enabling this setting will mean applicants will automatically get sent properties.<br><br>
250 - This will only apply to properties added from the moment this option is activated.<br>
251 - When enabled, this can be disabled on a per-applicant basis by going into their record.<br>
252 - When sending out lots of emails we recommend using <a href="https://en-gb.wordpress.org/plugins/tags/smtp" target="_blank">a plugin</a> to send them out using SMTP. Your web developer or hosting company should be able to advise on this.', 'propertyhive' ) . ( ( get_option( 'propertyhive_auto_property_match', '' ) == 'yes' && get_option( 'propertyhive_auto_property_match_enabled_date', '' ) != '' ) ? '<br><br>Enabled on ' . date("jS F Y H:i", strtotime(get_option( 'propertyhive_auto_property_match_enabled_date', '' )) + $time_offset) : '' ),
253 'id' => 'propertyhive_auto_property_match',
254 'type' => 'checkbox',
255 'default' => '',
256 );
257
258 $settings[] = array( 'type' => 'sectionend', 'id' => 'applicant_match_email_options' );
259
260 return apply_filters( 'propertyhive_property_match_settings', $settings ); // End settings
261 }
262
263 /**
264 * Get booking confirmation email settings array
265 *
266 * @return array
267 */
268 public function get_booking_confirmation_settings() {
269
270 $settings = array();
271
272 if ( get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
273 {
274 //Applicant
275 $settings[] = array( 'title' => __( 'Applicant Viewing Booking Confirmations', 'propertyhive' ), 'type' => 'title', 'id' => 'applicant_viewing_booking_confirmation_email_options' );
276
277 $settings[] = array(
278 'title' => __( 'Default Email Subject', 'propertyhive' ),
279 'id' => 'propertyhive_viewing_applicant_booking_confirmation_email_subject',
280 'type' => 'text',
281 'css' => 'min-width:300px;',
282 );
283
284 $settings[] = array(
285 'title' => __( 'Default Email Body', 'propertyhive' ),
286 'id' => 'propertyhive_viewing_applicant_booking_confirmation_email_body',
287 'type' => 'textarea',
288 'css' => 'min-width:300px; height:110px;',
289 );
290
291 $settings[] = array( 'type' => 'sectionend', 'id' => 'applicant_viewing_booking_confirmation_email_options' );
292
293 $settings[] = array( 'title' => __( 'Applicant Viewing Cancellation Notifications', 'propertyhive' ), 'type' => 'title', 'id' => 'applicant_viewing_cancellation_notification_email_options' );
294
295 $settings[] = array(
296 'title' => __( 'Default Email Subject', 'propertyhive' ),
297 'id' => 'propertyhive_viewing_applicant_cancellation_notification_email_subject',
298 'type' => 'text',
299 'css' => 'min-width:300px;',
300 );
301
302 $settings[] = array(
303 'title' => __( 'Default Email Body', 'propertyhive' ),
304 'id' => 'propertyhive_viewing_applicant_cancellation_notification_email_body',
305 'type' => 'textarea',
306 'css' => 'min-width:300px; height:110px;',
307 );
308
309 $settings[] = array( 'type' => 'sectionend', 'id' => 'applicant_viewing_cancellation_notification_email_options' );
310
311 // Owner
312 $settings[] = array( 'title' => __( 'Owner/Landlord Viewing Booking Confirmations', 'propertyhive' ), 'type' => 'title', 'id' => 'owner_viewing_booking_confirmation_email_options' );
313
314 $settings[] = array(
315 'title' => __( 'Default Email Subject', 'propertyhive' ),
316 'id' => 'propertyhive_viewing_owner_booking_confirmation_email_subject',
317 'type' => 'text',
318 'css' => 'min-width:300px;',
319 );
320
321 $settings[] = array(
322 'title' => __( 'Default Email Body', 'propertyhive' ),
323 'id' => 'propertyhive_viewing_owner_booking_confirmation_email_body',
324 'type' => 'textarea',
325 'css' => 'min-width:300px; height:110px;',
326 );
327
328 $settings[] = array( 'type' => 'sectionend', 'id' => 'owner_viewing_booking_confirmation_email_options' );
329
330 $settings[] = array( 'title' => __( 'Owner/Landlord Viewing Cancellation Notifications', 'propertyhive' ), 'type' => 'title', 'id' => 'owner_viewing_cancellation_notification_email_options' );
331
332 $settings[] = array(
333 'title' => __( 'Default Email Subject', 'propertyhive' ),
334 'id' => 'propertyhive_viewing_owner_cancellation_notification_email_subject',
335 'type' => 'text',
336 'css' => 'min-width:300px;',
337 );
338
339 $settings[] = array(
340 'title' => __( 'Default Email Body', 'propertyhive' ),
341 'id' => 'propertyhive_viewing_owner_cancellation_notification_email_body',
342 'type' => 'textarea',
343 'css' => 'min-width:300px; height:110px;',
344 );
345
346 $settings[] = array( 'type' => 'sectionend', 'id' => 'owner_viewing_cancellation_notification_email_options' );
347
348 // Attending Negotiator
349 $settings[] = array( 'title' => __( 'Attending Negotiator Viewing Booking Confirmations', 'propertyhive' ), 'type' => 'title', 'id' => 'attending_negotiator_viewing_booking_confirmation_email_options' );
350
351 $settings[] = array(
352 'title' => __( 'Default Email Subject', 'propertyhive' ),
353 'id' => 'propertyhive_viewing_attending_negotiator_booking_confirmation_email_subject',
354 'type' => 'text',
355 'css' => 'min-width:300px;',
356 );
357
358 $settings[] = array(
359 'title' => __( 'Default Email Body', 'propertyhive' ),
360 'id' => 'propertyhive_viewing_attending_negotiator_booking_confirmation_email_body',
361 'type' => 'textarea',
362 'css' => 'min-width:300px; height:110px;',
363 );
364
365 $settings[] = array( 'type' => 'sectionend', 'id' => 'attending_negotiator_viewing_booking_confirmation_email_options' );
366
367 $settings[] = array( 'title' => __( 'Attending Negotiator Viewing Cancellation Notifications', 'propertyhive' ), 'type' => 'title', 'id' => 'attending_negotiator_viewing_cancellation_notifications_email_options' );
368
369 $settings[] = array(
370 'title' => __( 'Default Email Subject', 'propertyhive' ),
371 'id' => 'propertyhive_viewing_attending_negotiator_cancellation_notification_email_subject',
372 'type' => 'text',
373 'css' => 'min-width:300px;',
374 );
375
376 $settings[] = array(
377 'title' => __( 'Default Email Body', 'propertyhive' ),
378 'id' => 'propertyhive_viewing_attending_negotiator_cancellation_notification_email_body',
379 'type' => 'textarea',
380 'css' => 'min-width:300px; height:110px;',
381 );
382
383 $settings[] = array( 'type' => 'sectionend', 'id' => 'attending_negotiator_viewing_cancellation_notifications_email_options' );
384 }
385
386 if ( get_option('propertyhive_module_disabled_appraisals', '') != 'yes' )
387 {
388 // Owner
389 $settings[] = array( 'title' => __( 'Owner/Landlord Appraisal Booking Confirmations', 'propertyhive' ), 'type' => 'title', 'id' => 'owner_appraisal_booking_confirmation_email_options' );
390
391 $settings[] = array(
392 'title' => __( 'Default Email Subject', 'propertyhive' ),
393 'id' => 'propertyhive_appraisal_owner_booking_confirmation_email_subject',
394 'type' => 'text',
395 'css' => 'min-width:300px;',
396 );
397
398 $settings[] = array(
399 'title' => __( 'Default Email Body', 'propertyhive' ),
400 'id' => 'propertyhive_appraisal_owner_booking_confirmation_email_body',
401 'type' => 'textarea',
402 'css' => 'min-width:300px; height:110px;',
403 );
404
405 $settings[] = array( 'type' => 'sectionend', 'id' => 'owner_appraisal_booking_confirmation_email_options' );
406 }
407
408 if ( get_option('propertyhive_module_disabled_appraisals', '') != 'yes' || get_option('propertyhive_module_disabled_viewings', '') != 'yes' )
409 {
410 // Owner
411 $settings[] = array( 'title' => __( 'Booking Confirmations & Cancellations', 'propertyhive' ), 'type' => 'title', 'id' => 'booking_confirmation_email_options' );
412
413 $settings[] = array(
414 'title' => __( 'Sent From Email Address', 'propertyhive' ),
415 'id' => 'propertyhive_confirmations_default_from',
416 'type' => 'select',
417 'default' => '',
418 'css' => 'min-width:300px;',
419 'options' => array(
420 '' => __( 'Default "From" Email Address', 'propertyhive' ),
421 'office' => __( 'Office Email Address', 'propertyhive' ),
422 'user' => __( 'User Email Address', 'propertyhive' ),
423 ),
424 'desc' => '<p>' . __( 'This sets the email address that booking confirmations and cancellation notifications come from and that will receive the response should someone reply.', 'propertyhive' ) . '</p>',
425 );
426
427 $settings[] = array(
428 'title' => __( 'Customise Emails Before Sending', 'propertyhive' ),
429 'id' => 'propertyhive_customise_confirmation_emails',
430 'type' => 'checkbox',
431 'desc' => 'With this ticked you\'ll be able to customise the subject and body of any emails before they get sent. This can be useful for adding any appraisal/viewing-specific details to the email. If left unticked, the default subject and body set above will be used.'
432 );
433
434 $settings[] = array( 'type' => 'sectionend', 'id' => 'booking_confirmation_email_options' );
435 }
436
437 return apply_filters( 'propertyhive_booking_confirmation_settings', $settings ); // End general map settings
438 }
439
440 /**
441 * Get email queue settings array
442 *
443 * @return array
444 */
445 public function get_email_queue_settings() {
446
447 return apply_filters( 'propertyhive_email_queue_settings', array(
448
449 array( 'title' => __( 'Email Queue', 'propertyhive' ), 'type' => 'title', 'desc' => '', 'id' => 'email_queue_options' ),
450
451 array(
452 'type' => 'email_queue'
453 ),
454
455 array( 'type' => 'sectionend', 'id' => 'email_queue_options'),
456
457 ) ); // End general map settings
458 }
459
460 /**
461 * Output email queue
462 *
463 * @access public
464 * @return void
465 */
466 public function email_queue_setting()
467 {
468 global $wpdb, $post;
469
470 $additional_query = '';
471 $additional_query_string = '';
472 if ( isset($_GET['date_from']) && sanitize_text_field($_GET['date_from']) != '' )
473 {
474 $additional_query_string .= '&date_from=' . sanitize_text_field($_GET['date_from']);
475 if ( sanitize_text_field($_GET['date_from']) != 'all' )
476 {
477 $additional_query .= " AND send_at >= '" . sanitize_text_field($_GET['date_from']) . " 00:00:00' ";
478 }
479 }
480 else
481 {
482 // Default to 30 days
483 $additional_query .= " AND send_at >= '" . date("Y-m-d", strtotime('-30 days')) . " 00:00:00' ";
484 }
485 ?>
486 <tr valign="top">
487 <td style="padding:0">
488
489 <p>Some processes, such as property matching, can result in a lot of emails being sent at once. To cater for this we queue emails and send them out in batches at regular intervals.</p>
490
491 <p>Using this screen you can see which emails have been sent, which have failed, and how many are queued to be sent.</p>
492
493 <br>
494
495 <p><strong><?php
496 $next_due = wp_next_scheduled( 'propertyhive_process_email_log' );
497
498 if ( $next_due == FALSE )
499 {
500 echo 'Whoops. WordPress doesn\'t have the emails automated task scheduled. A quick fix for this is to deactivate, then re-activate the plugin.';
501 }
502 else
503 {
504 echo esc_html(__( 'Next scheduled to run at', 'propertyhive' ) . ' ' . date("H:i jS F Y", $next_due));
505 }
506 ?></strong> <a href="<?php echo esc_url(admin_url('admin.php?page=ph-settings&tab=email&section=log&custom_email_log_cron=propertyhive_process_email_log' )); ?>" class="button">Run Now</a></p>
507
508 <br>
509
510 <ul class="subsubsub">
511 <?php
512 $emails = $wpdb->get_var("
513 SELECT COUNT(*)
514 FROM " . $wpdb->prefix . "ph_email_log
515 ");
516 ?>
517 <li class="all"><a href="<?php echo esc_url(admin_url('admin.php?page=ph-settings&tab=email&section=log' . $additional_query_string)); ?>"<?php if ( !isset($_GET['status']) || (isset($_GET['status']) && $_GET['status'] == '') ) { echo ' class="current"'; } ?>>All <span class="count">(<?php echo number_format($emails); ?>)</span></a> |</li>
518 <?php
519 $emails = $wpdb->get_var("
520 SELECT COUNT(*)
521 FROM " . $wpdb->prefix . "ph_email_log
522 WHERE
523 status = ''
524 ");
525 ?>
526 <li class="queued"><a href="<?php echo esc_url(admin_url('admin.php?page=ph-settings&tab=email&section=log&status=queued' . $additional_query_string)); ?>"<?php if ( isset($_GET['status']) && $_GET['status'] == 'queued' ) { echo ' class="current"'; } ?>>Queued <span class="count">(<?php echo number_format($emails); ?>)</span></a> |</li>
527 <?php
528 $emails = $wpdb->get_var("
529 SELECT COUNT(*)
530 FROM " . $wpdb->prefix . "ph_email_log
531 WHERE
532 status IN ('fail1', 'fail2')
533 ");
534 ?>
535 <li class="failed"><a href="<?php echo esc_url(admin_url('admin.php?page=ph-settings&tab=email&section=log&status=failed' . $additional_query_string)); ?>"<?php if ( isset($_GET['status']) && $_GET['status'] == 'failed' ) { echo ' class="current"'; } ?>>Failed <span class="count">(<?php echo number_format($emails); ?>)</span></a> |</li>
536 <?php
537 $emails = $wpdb->get_var("
538 SELECT COUNT(*)
539 FROM " . $wpdb->prefix . "ph_email_log
540 WHERE
541 status = 'sent'
542 ");
543 ?>
544 <li class="sent"><a href="<?php echo esc_url(admin_url('admin.php?page=ph-settings&tab=email&section=log&status=sent' . $additional_query_string)); ?>"<?php if ( isset($_GET['status']) && $_GET['status'] == 'sent' ) { echo ' class="current"'; } ?>>Sent <span class="count">(<?php echo number_format($emails); ?>)</span></a></li>
545 </ul>
546
547 <div class="tablenav top">
548 <div class="alignleft actions bulkactions">
549 <div class="alignleft actions">
550 <input type="hidden" name="page" value="ph-settings">
551 <input type="hidden" name="tab" value="email">
552 <input type="hidden" name="section" value="log">
553 <input type="hidden" name="status" value="<?php echo ( ( isset($_GET['status']) ) ? esc_attr(ph_clean($_GET['status'])) : '' ); ?>">
554 <select name="date_from" id="dropdown_date_from">
555 <option value="<?php echo esc_attr(date("Y-m-d", strtotime("-7 days"))); ?>"<?php if ( isset($_GET['date_from']) && $_GET['date_from'] == date("Y-m-d", strtotime("-7 days")) ) { echo ' selected'; } ?>>Last 7 Days</option>
556 <option value="<?php echo esc_attr(date("Y-m-d", strtotime("-14 days"))); ?>"<?php if ( isset($_GET['date_from']) && $_GET['date_from'] == date("Y-m-d", strtotime("-14 days")) ) { echo ' selected'; } ?>>Last 14 Days</option>
557 <option value="<?php echo esc_attr(date("Y-m-d", strtotime("-30 days"))); ?>"<?php if ( !isset($_GET['date_from']) || ( isset($_GET['date_from']) && $_GET['date_from'] == date("Y-m-d", strtotime("-30 days")) ) ) { echo ' selected'; } ?>>Last 30 Days</option>
558 <option value="all"<?php if ( isset($_GET['date_from']) && $_GET['date_from'] == 'all' ) { echo ' selected'; } ?>>All Time</option>
559 </select>
560 <input type="submit" name="filter_action" id="post-query-submit" class="button" value="Filter">
561
562 <script>
563 jQuery(document).ready(function()
564 {
565 jQuery('#_wpnonce').remove();
566 jQuery('input[name=\'_wp_http_referer\']').remove();
567 jQuery('#mainform').attr('method', 'get');
568 jQuery('#mainform').attr('action', '<?php echo esc_url(admin_url('admin.php')); ?>');
569 });
570 </script>
571 </div>
572 </div>
573 </div>
574
575 <table class="ph_email_queue widefat" cellspacing="0">
576 <thead>
577 <tr>
578 <th class="date-time"><?php echo esc_html(__( 'Date/Time', 'propertyhive' )); ?></th>
579 <th class="recipient"><?php echo esc_html(__( 'Recipient', 'propertyhive' )); ?></th>
580 <th class="subject"><?php echo esc_html(__( 'Subject', 'propertyhive' )); ?></th>
581 <th class="status"><?php echo esc_html(__( 'Status', 'propertyhive' )); ?></th>
582 <th class="actions">&nbsp;</th>
583 </tr>
584 </thead>
585 <tbody>
586 <?php
587 $query = "
588 SELECT
589 email_id,
590 contact_id,
591 to_email_address,
592 subject,
593 status,
594 send_at
595 FROM " . $wpdb->prefix . "ph_email_log
596 WHERE
597 1=1 ";
598 if ( isset($_GET['status']) )
599 {
600 switch ( ph_clean($_GET['status']) )
601 {
602 case "queued": { $query .= " AND status = '' "; break; }
603 case "failed": { $query .= " AND status IN ('fail1', 'fail2') "; break; }
604 case "sent": { $query .= " AND status = 'sent' "; break; }
605 }
606 }
607 $query .= $additional_query;
608
609 $query .= " ORDER BY send_at DESC
610 LIMIT 250
611 ";
612 $emails = $wpdb->get_results( $query );
613
614 if ( is_array($emails) && !empty($emails) )
615 {
616 foreach ( $emails as $email )
617 {
618 ?>
619 <tr>
620 <td class="date-time"><?php echo esc_html(date("jS M Y H:i", strtotime($email->send_at))); ?></td>
621 <td class="recipient"><?php echo '<a href="' . esc_url(get_edit_post_link($email->contact_id)) . '">' . esc_html(get_the_title($email->contact_id)) . '</a><br>' . esc_html($email->to_email_address); ?></td>
622 <td class="subject"><?php echo esc_html($email->subject); ?></td>
623 <td class="status"><?php
624 switch ($email->status)
625 {
626 case "fail1": { echo 'First attempt failed. Will retry'; break; }
627 case "fail2": { echo 'Failed after 2 attempts'; break; }
628 case "sent": { echo 'Sent'; break; }
629 default: { echo 'Queued'; }
630 }
631 ?></td>
632 <td class="actions">
633 <a href="<?php echo esc_url(wp_nonce_url( admin_url('?view_propertyhive_email=' . $email->email_id . '&email_id=' . $email->email_id ), 'view-email' )); ?>" target="_blank" class="button">View Email</a>
634 </td>
635 </tr>
636 <?php
637 }
638 }
639 else
640 {
641 ?>
642 <tr>
643 <td colspan="5">No emails found</td>
644 </tr>
645 <?php
646 }
647 ?>
648 </tbody>
649 </table>
650 </td>
651 </tr>
652 <?php
653 }
654
655 /**
656 * Output the settings.
657 */
658 public function output() {
659 global $current_section, $hide_save_button;
660
661 if ( $current_section )
662 {
663 switch ($current_section)
664 {
665 case "enquiry-auto-responder": { $settings = $this->get_enquiry_autoresponder_settings(); break; }
666 case "match": { $settings = $this->get_property_match_settings(); break; }
667 case "booking-confirmation": { $settings = $this->get_booking_confirmation_settings(); break; }
668 case "log": { $settings = $this->get_email_queue_settings(); $hide_save_button = true; break; }
669 default: { die("Unknown setting section"); }
670 }
671 }
672 else
673 {
674 $settings = $this->get_settings();
675 }
676
677 PH_Admin_Settings::output_fields( $settings );
678 }
679
680 /**
681 * Save settings.
682 */
683 public function save()
684 {
685 global $current_section;
686
687 if ( $current_section != '' )
688 {
689 switch ($current_section)
690 {
691 case 'enquiry-auto-responder':
692 {
693 $settings = $this->get_enquiry_autoresponder_settings();
694
695 PH_Admin_Settings::save_fields( $settings );
696 break;
697 }
698 case 'match':
699 {
700 $settings = $this->get_property_match_settings();
701
702 $previous_auto_property_match = get_option( 'propertyhive_auto_property_match', '' );
703
704 PH_Admin_Settings::save_fields( $settings );
705
706 if ( isset($_POST['propertyhive_auto_property_match']) && $_POST['propertyhive_auto_property_match'] == '1' )
707 {
708 if ( $previous_auto_property_match != 'yes' )
709 {
710 // it's been activated. Stored in UTC
711 update_option( 'propertyhive_auto_property_match_enabled_date', gmdate("Y-m-d H:i:s"), FALSE);
712 }
713
714 $timestamp = wp_next_scheduled( 'propertyhive_auto_email_match' );
715 wp_unschedule_event($timestamp, 'propertyhive_auto_email_match' );
716 wp_clear_scheduled_hook('propertyhive_auto_email_match');
717
718 $recurrence = apply_filters( 'propertyhive_auto_email_match_cron_recurrence', 'daily' );
719 if ( $recurrence != 'hourly' )
720 {
721 $timestamp = strtotime( 'tomorrow +2hours' ) - ( (int)get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
722 }
723 else
724 {
725 $timestamp = strtotime( '+1 hours' );
726 }
727 wp_schedule_event(
728 apply_filters( 'propertyhive_auto_email_match_cron_timestamp', $timestamp ),
729 $recurrence,
730 'propertyhive_auto_email_match'
731 );
732 }
733 else
734 {
735 wp_clear_scheduled_hook( 'propertyhive_auto_email_match' );
736 }
737 break;
738 }
739 case 'booking-confirmation':
740 {
741 $settings = $this->get_booking_confirmation_settings();
742
743 PH_Admin_Settings::save_fields( $settings );
744 break;
745 }
746 default: { die("Unknown setting section"); }
747 }
748 }
749 else
750 {
751 PH_Admin_Settings::save_fields( $this->get_settings() );
752 }
753 }
754 }
755
756 endif;
757
758 return new PH_Settings_Emails();