| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version 1.0 |
| 4 |
* @package Content |
| 5 |
* @category Menu |
| 6 |
* @author wpdevelop |
| 7 |
* |
| 8 |
* @web-site https://wpbookingcalendar.com/ |
| 9 |
* @email info@wpbookingcalendar.com |
| 10 |
* |
| 11 |
* @modified 2015-04-09 |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 15 |
|
| 16 |
|
| 17 |
if ( ! defined( 'WPBC_EMAIL_DELETED_PREFIX' ) ) define( 'WPBC_EMAIL_DELETED_PREFIX', 'booking_email_' ); // Its defined in api-emails.php file & its same for all emails, here its used only for easy coding... |
| 18 |
|
| 19 |
if ( ! defined( 'WPBC_EMAIL_DELETED_ID' ) ) define( 'WPBC_EMAIL_DELETED_ID', 'deleted' ); /* Define Name of Email Template. |
| 20 |
Note. Prefix "booking_email_" defined in api-emails.php file. |
| 21 |
Full name of option is - "booking_email_deleted" |
| 22 |
Other email templates names: |
| 23 |
- 'new_admin' |
| 24 |
- 'new_visitor' |
| 25 |
- 'approved' |
| 26 |
- 'deny' -- pending, trash, deleted |
| 27 |
- 'payment_request' |
| 28 |
- 'modification' |
| 29 |
*/ |
| 30 |
|
| 31 |
|
| 32 |
require_once( WPBC_PLUGIN_DIR . '/core/any/api-emails.php' ); // API |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
// <editor-fold defaultstate="collapsed" desc=" Import Old Data " > |
| 37 |
|
| 38 |
function wpbc_import6_is_old_email_deleted_exist() { |
| 39 |
|
| 40 |
$is_old_data_exist = get_bk_option( 'booking_email_deny_content' ); |
| 41 |
|
| 42 |
if ( ! empty( $is_old_data_exist ) ) // Check if Old data exist |
| 43 |
return true; |
| 44 |
else |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
function wpbc_import6_get_old_email_deleted_data() { |
| 49 |
|
| 50 |
$default_values = array(); |
| 51 |
if ( wpbc_import6_is_old_email_deleted_exist() ) { |
| 52 |
|
| 53 |
$default_values['enabled'] = get_bk_option( 'booking_is_email_deny_adress' ); |
| 54 |
$default_values['copy_to_admin'] = get_bk_option( 'booking_is_email_deny_send_copy_to_admin' ); //Parse it to Name and Email |
| 55 |
$default_values['from'] = get_bk_option( 'booking_email_deny_adress' ); //Parse it to Name and Email, relpace [visitoremail] |
| 56 |
$default_values['subject'] = get_bk_option( 'booking_email_deny_subject' ); |
| 57 |
$default_values['content'] = get_bk_option( 'booking_email_deny_content' ); |
| 58 |
|
| 59 |
} |
| 60 |
return $default_values; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
function wpbc_import6_is_new_email_deleted_exist() { |
| 65 |
|
| 66 |
$is_data_exist = get_bk_option( WPBC_EMAIL_DELETED_PREFIX . WPBC_EMAIL_DELETED_ID ); // ''booking_email_' - defined in api-emails.php file. |
| 67 |
|
| 68 |
if ( ! empty( $is_data_exist ) ) // Check if data exist |
| 69 |
return true; |
| 70 |
else |
| 71 |
return false; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
function wpbc_import6_email__deleted__get_fields_array_for_activation() { |
| 76 |
|
| 77 |
|
| 78 |
if ( ! wpbc_import6_is_new_email_deleted_exist() ) { // New Email Template NOT exist |
| 79 |
|
| 80 |
// Import |
| 81 |
$old_data = wpbc_import6_get_old_email_deleted_data(); |
| 82 |
if ( ! empty( $old_data ) ) { // Get Old data |
| 83 |
|
| 84 |
/* |
| 85 |
$old_data = [ |
| 86 |
[enabled] => On |
| 87 |
[to] => "Booking system" <beta@wpbookingcalendar.com> |
| 88 |
[from] => [visitoremail] |
| 89 |
[subject] => New booking |
| 90 |
[content] => You need to approve a new booking [bookingtype] for: [dates]<br/><br/> Person detail information:<br/> [content]<br/><br/> Currently a new booking is waiting for approval. Please visit the moderation panel [moderatelink]<br/><br/>Thank you, Beta<br/>[siteurl] |
| 91 |
] |
| 92 |
wpbc_get_email_parts() >>> return [ |
| 93 |
[email] => beta@wpbookingcalendar.com |
| 94 |
[title] => Booking system |
| 95 |
[original] => "Booking system" |
| 96 |
[original_to_show] => "Booking system" <beta@wpbookingcalendar.com> |
| 97 |
] |
| 98 |
*/ |
| 99 |
|
| 100 |
// Make transform - emails |
| 101 |
// $email_to = wpbc_get_email_parts( $old_data['to'] ); |
| 102 |
$email_from = wpbc_get_email_parts( $old_data['from'] ); |
| 103 |
|
| 104 |
// $old_data['to'] = $email_to['email']; // 'beta@wpbookingcalendar.com' // booking_email_reservation_adress |
| 105 |
// $old_data['to_name'] = $email_to['title']; // 'Booking system' // booking_email_reservation_adress |
| 106 |
/* Description of Code. |
| 107 |
* Here we replacing any shortcodes, like [visitoremail] to get_option( 'admin_email' ) |
| 108 |
* because we are setting in header "Reply-To" visitor emil from the booking form - its exist by hook for this email template at the wpbc-emails.php file |
| 109 |
* |
| 110 |
* Here we need to use for field "From" email with DNS same as DNS in the website. In most cases its have to be the get_option( 'admin_email' ) |
| 111 |
* |
| 112 |
* After parsing with wpbc_get_email_parts, if we was have [visitoremail] in this field, then $email_from['email'] will be empty. So we check it and set admin email. |
| 113 |
* |
| 114 |
*/ |
| 115 |
$old_data['from'] = ( empty( $email_from['email'] ) ? get_option( 'admin_email' ) /*$email_from['original']*/ : $email_from['email'] ); // [visitoremail] | email@server.com // booking_email_reservation_from_adress |
| 116 |
$old_data['from_name'] = $email_from['title']; // [visitoremail] | 'Booking System' | '' // booking_email_reservation_from_adress |
| 117 |
|
| 118 |
// $old_data['subject'] = html_entity_decode( $old_data['subject'] ); |
| 119 |
// $old_data['content'] = html_entity_decode( $old_data['content'] ); |
| 120 |
} |
| 121 |
|
| 122 |
// Default |
| 123 |
$init_fields_values = $old_data; |
| 124 |
$mail_api = new WPBC_Emails_API_Deleted( WPBC_EMAIL_DELETED_ID , $init_fields_values ); |
| 125 |
|
| 126 |
$default_fields_in_settings = $mail_api->get_default_values() ; // Get default fields values, from settings - defined in function init_settings_fields {class WPBC_Emails_API_Deleted} |
| 127 |
|
| 128 |
$fields_values = wp_parse_args( $old_data, $default_fields_in_settings ); |
| 129 |
|
| 130 |
return array( WPBC_EMAIL_DELETED_PREFIX . WPBC_EMAIL_DELETED_ID => $fields_values ); |
| 131 |
|
| 132 |
/* |
| 133 |
Array ( |
| 134 |
[booking_email_deleted] => Array |
| 135 |
( |
| 136 |
[enabled] => On |
| 137 |
[to] => beta@wpbookingcalendar.com |
| 138 |
[to_name] => Booking system |
| 139 |
[from] => admin@wpbookingcalendar.com |
| 140 |
[from_name] => |
| 141 |
[subject] => New booking |
| 142 |
[content] => You need to approve a new booking [bookingtype] for: [dates]... |
| 143 |
[header_content] => |
| 144 |
[footer_content] => |
| 145 |
[template_file] => plain |
| 146 |
[base_color] => #557da1 |
| 147 |
[background_color] => #f5f5f5 |
| 148 |
[body_color] => #fdfdfd |
| 149 |
[text_color] => #505050 |
| 150 |
[email_content_type] => html |
| 151 |
) |
| 152 |
) |
| 153 |
|
| 154 |
// $mail_api->save_to_db( $fields_values ); |
| 155 |
|
| 156 |
*/ |
| 157 |
|
| 158 |
} else { // New Email Template is Exist - return empty array(), its will make loading of data from DB, during activation Mail API class. |
| 159 |
return array( WPBC_EMAIL_DELETED_PREFIX . WPBC_EMAIL_DELETED_ID => array() ); |
| 160 |
} |
| 161 |
} |
| 162 |
// </editor-fold> |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
/** Email F i e l d s */ |
| 167 |
class WPBC_Emails_API_Deleted extends WPBC_Emails_API { // O v e r r i d i n g "WPBC_Emails_API" ClASS |
| 168 |
|
| 169 |
|
| 170 |
/** Overrided functions - define Email Fields & Values */ |
| 171 |
public function init_settings_fields() { |
| 172 |
|
| 173 |
$this->fields = array(); |
| 174 |
|
| 175 |
$this->fields['enabled'] = array( |
| 176 |
'type' => 'checkbox', |
| 177 |
'default' => 'On', |
| 178 |
'title' => __( 'Enable / Disable', 'booking' ), |
| 179 |
'label' => __( 'Enable this email notification', 'booking' ), |
| 180 |
'description' => '', |
| 181 |
'group' => 'general' |
| 182 |
); |
| 183 |
|
| 184 |
$this->fields['copy_to_admin'] = array( |
| 185 |
'type' => 'checkbox' |
| 186 |
, 'default' => 'Off' |
| 187 |
, 'title' => __('Copy(ies)', 'booking') //FixIn: 8.1.2.17.1 |
| 188 |
, 'label' => __('Enable / disable sending email(s) to additional addresses', 'booking') . ' (admin@; sales@; others@)' //FixIn: 8.1.2.17.1 |
| 189 |
, 'description' => '' |
| 190 |
, 'group' => 'general' |
| 191 |
|
| 192 |
); |
| 193 |
|
| 194 |
// FixIn: 8.1.2.17. |
| 195 |
$this->fields['to_html_prefix'] = array( |
| 196 |
'type' => 'pure_html' |
| 197 |
, 'group' => 'general' |
| 198 |
, 'html' => '<tr valign="top" class="wpbc_tr_copy_to_admin_to"> |
| 199 |
<th scope="row"> |
| 200 |
<label class="wpbc-form-email" for="' |
| 201 |
. esc_attr( 'approved_to' ) |
| 202 |
. '">' . wp_kses_post( __('To' ,'booking') ) . ' (' . strtolower( __('Copy(ies)', 'booking') ). ')' //FixIn: 8.1.2.17.1 |
| 203 |
. '</label> |
| 204 |
</th> |
| 205 |
<td><fieldset style="float:left;width:50%;margin-right:5%;">' |
| 206 |
); |
| 207 |
$this->fields['to'] = array( |
| 208 |
'type' => 'text' // We are using here 'text' and not 'email', for ability to save several comma seperated emails. |
| 209 |
, 'default' => get_option( 'admin_email' ) |
| 210 |
//, 'placeholder' => '' |
| 211 |
, 'title' => '' |
| 212 |
, 'description' => __('Email Address', 'booking') . '. ' . __('Required', 'booking') . '. ' |
| 213 |
. __('You can put multiple emails separated by', 'booking') . ' <code>;</code>' //FixIn: 8.1.2.17.1 |
| 214 |
, 'description_tag' => '' |
| 215 |
, 'css' => 'width:100%' |
| 216 |
, 'group' => 'general' |
| 217 |
, 'tr_class' => '' |
| 218 |
, 'only_field' => true |
| 219 |
, 'validate_as' => array( ) |
| 220 |
); |
| 221 |
$this->fields['to_html_middle'] = array( |
| 222 |
'type' => 'pure_html' |
| 223 |
, 'group' => 'general' |
| 224 |
, 'html' => '</fieldset><fieldset style="float:left;width:45%;">' |
| 225 |
); |
| 226 |
$this->fields['to_name'] = array( |
| 227 |
'type' => 'text' |
| 228 |
, 'default' => 'Booking system' |
| 229 |
//, 'placeholder' => '' |
| 230 |
, 'title' => '' |
| 231 |
, 'description' => __('Title', 'booking') . ' (' . __('optional', 'booking') . ').' //. ' ' . __('If empty then title defined as WordPress', 'booking') |
| 232 |
, 'description_tag' => '' |
| 233 |
, 'css' => 'width:100%' |
| 234 |
, 'group' => 'general' |
| 235 |
, 'tr_class' => '' |
| 236 |
, 'only_field' => true |
| 237 |
); |
| 238 |
$this->fields['to_html_sufix'] = array( |
| 239 |
'type' => 'pure_html' |
| 240 |
, 'group' => 'general' |
| 241 |
, 'html' => ' </fieldset> |
| 242 |
</td> |
| 243 |
</tr>' |
| 244 |
); |
| 245 |
|
| 246 |
$this->fields['to_hr'] = array( 'type' => 'hr' ); |
| 247 |
/**/ |
| 248 |
//FixIn: 8.1.2.17 - END |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
$this->fields['from_html_prefix'] = array( |
| 253 |
'type' => 'pure_html' |
| 254 |
, 'group' => 'general' |
| 255 |
, 'html' => '<tr valign="top"> |
| 256 |
<th scope="row"> |
| 257 |
<label class="wpbc-form-email" for="' |
| 258 |
. esc_attr( 'deleted_from' ) |
| 259 |
. '">' . wp_kses_post( __('From' ,'booking') ) |
| 260 |
. '</label> |
| 261 |
</th> |
| 262 |
<td><fieldset style="float:left;width:50%;margin-right:5%;">' |
| 263 |
); |
| 264 |
$this->fields['from'] = array( |
| 265 |
'type' => 'email' // Its can be only 1 email, so check it as Email field. |
| 266 |
, 'default' => get_option( 'admin_email' ) |
| 267 |
//, 'placeholder' => '' |
| 268 |
, 'title' => '' |
| 269 |
, 'description' => __('Email Address', 'booking') . '. ' . __('Required', 'booking') . '.' |
| 270 |
, 'description_tag' => '' |
| 271 |
, 'css' => 'width:100%' |
| 272 |
, 'group' => 'general' |
| 273 |
, 'tr_class' => '' |
| 274 |
, 'only_field' => true |
| 275 |
, 'validate_as' => array( 'required' ) |
| 276 |
); |
| 277 |
$this->fields['from_html_middle'] = array( |
| 278 |
'type' => 'pure_html' |
| 279 |
, 'group' => 'general' |
| 280 |
, 'html' => '</fieldset><fieldset style="float:left;width:45%;">' |
| 281 |
); |
| 282 |
$this->fields['from_name'] = array( |
| 283 |
'type' => 'text' |
| 284 |
, 'default' => 'Booking system' |
| 285 |
//, 'placeholder' => '' |
| 286 |
, 'title' => '' |
| 287 |
, 'description' => __('Title', 'booking') . ' (' . __('optional', 'booking') . ').' //. ' ' . __('If empty then title defined as WordPress', 'booking') |
| 288 |
, 'description_tag' => '' |
| 289 |
, 'css' => 'width:100%' |
| 290 |
, 'group' => 'general' |
| 291 |
, 'tr_class' => '' |
| 292 |
, 'only_field' => true |
| 293 |
); |
| 294 |
$this->fields['from_html_sufix'] = array( |
| 295 |
'type' => 'pure_html' |
| 296 |
, 'group' => 'general' |
| 297 |
, 'html' => ' </fieldset> |
| 298 |
</td> |
| 299 |
</tr>' |
| 300 |
); |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
$this->fields['subject_before'] = array( |
| 307 |
'type' => 'pure_html' |
| 308 |
, 'group' => 'general_content' |
| 309 |
, 'html' => '<tr><td colspan="2">' |
| 310 |
.'<div style="margin: 0 0 15px;font-weight: 600;">' |
| 311 |
.'<label class="wpbc-form-email-subject" for="' . WPBC_EMAIL_DELETED_ID . '_subject">' . |
| 312 |
__( 'Subject', 'booking' ) |
| 313 |
. '</label></div>' |
| 314 |
); |
| 315 |
$this->fields['subject'] = array( |
| 316 |
'type' => 'text' |
| 317 |
, 'default' => __( 'Your booking has been declined', 'booking' ) |
| 318 |
//, 'placeholder' => '' |
| 319 |
, 'title' => __('Subject', 'booking') |
| 320 |
, 'description' => '' |
| 321 |
, 'description_tag' => '' |
| 322 |
, 'css' => 'width:100%;font-size:16px;line-height:34px;font-weight:600;' |
| 323 |
, 'group' => 'general_content' |
| 324 |
, 'tr_class' => '' |
| 325 |
, 'validate_as' => array( 'required' ) |
| 326 |
, 'only_field' => true |
| 327 |
); |
| 328 |
$this->fields['subject_after'] = array( 'type' => 'pure_html', 'group' => 'general_content', |
| 329 |
'html' => '<p style="text-align: right;font-size:12px;">' |
| 330 |
/* translators: 1: ... */ |
| 331 |
. sprintf( __( 'Type your email %1$ssubject%2$s for the booking confirmation message.', 'booking' ),'<b>','</b>') . ' ' . __('Required', 'booking') |
| 332 |
. '.</p>' . '</td></tr>' ); |
| 333 |
|
| 334 |
$blg_title = get_option( 'blogname' ); |
| 335 |
$blg_title = str_replace( array( '"', "'" ), '', $blg_title ); |
| 336 |
|
| 337 |
/* translators: 1: ... */ |
| 338 |
$email_content = sprintf( __( 'Your booking %1$s for: %2$s has been canceled. %3$sThank you, %4$s', 'booking' ), '[bookingtype]', '[dates]', '<br/>[denyreason]<br/><br/>[content]<br/><br/>', $blg_title . '<br/>[siteurl]' ); |
| 339 |
|
| 340 |
$this->fields['content_before'] = array( |
| 341 |
'type' => 'pure_html', |
| 342 |
'group' => 'general_content', |
| 343 |
'html' => '<tr><td colspan="2" style="padding-bottom:0;">' |
| 344 |
. '<div style="margin: 0;font-weight: 600;">' |
| 345 |
. '<label class="wpbc-form-email-content" for="' . WPBC_EMAIL_DELETED_ID . '_content">' . |
| 346 |
__( 'Content', 'booking' ) |
| 347 |
. '</label></div>' |
| 348 |
); |
| 349 |
$this->fields['content'] = array( |
| 350 |
'type' => 'wp_textarea' |
| 351 |
, 'default' => $email_content |
| 352 |
//, 'placeholder' => '' |
| 353 |
, 'title' => __('Content', 'booking') |
| 354 |
, 'description' => ''//__('Type your email message content. ', 'booking') |
| 355 |
, 'description_tag' => '' |
| 356 |
, 'css' => '' |
| 357 |
, 'group' => 'general_content' |
| 358 |
, 'tr_class' => '' |
| 359 |
, 'rows' => 17 |
| 360 |
, 'show_in_2_cols' => true |
| 361 |
, 'only_field' => true |
| 362 |
); |
| 363 |
$this->fields['content_after'] = array( 'type' => 'pure_html', 'group' => 'general_content', 'html' => '</td></tr>' ); |
| 364 |
// $this->fields['content'] = htmlspecialchars( $this->fields['content'] );// Convert > to > |
| 365 |
// $this->fields['content'] = html_entity_decode( $this->fields['content'] );// Convert > to > |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
//////////////////////////////////////////////////////////////////// |
| 370 |
// Style |
| 371 |
//////////////////////////////////////////////////////////////////// |
| 372 |
|
| 373 |
|
| 374 |
$this->fields['header_content'] = array( |
| 375 |
'type' => 'textarea' |
| 376 |
, 'default' => '' |
| 377 |
, 'title' => __('Email Heading', 'booking') |
| 378 |
, 'description' => __('Enter main heading contained within the email notification.', 'booking') |
| 379 |
//, 'placeholder' => '' |
| 380 |
, 'rows' => 2 |
| 381 |
, 'css' => "width:100%;" |
| 382 |
, 'group' => 'parts' |
| 383 |
); |
| 384 |
$this->fields['footer_content'] = array( |
| 385 |
'type' => 'textarea' |
| 386 |
, 'default' => '' |
| 387 |
, 'title' => __('Email Footer Text', 'booking') |
| 388 |
, 'description' => __('Enter text contained within footer of the email notification', 'booking') |
| 389 |
//, 'placeholder' => '' |
| 390 |
, 'rows' => 2 |
| 391 |
, 'css' => 'width:100%;' |
| 392 |
, 'group' => 'parts' |
| 393 |
); |
| 394 |
|
| 395 |
$this->fields['template_file'] = array( |
| 396 |
'type' => 'select' |
| 397 |
, 'default' => 'plain' |
| 398 |
, 'title' => __('Email template', 'booking') |
| 399 |
, 'description' => __('Choose email template.', 'booking') |
| 400 |
, 'description_tag' => 'span' |
| 401 |
, 'css' => '' |
| 402 |
, 'options' => array( |
| 403 |
'plain' => __('Plain (without styles)', 'booking') |
| 404 |
, 'standard' => __('Standard 1 column', 'booking') |
| 405 |
) |
| 406 |
, 'group' => 'style' |
| 407 |
); |
| 408 |
|
| 409 |
$this->fields['template_file_help'] = array( |
| 410 |
'type' => 'help' |
| 411 |
/* translators: 1: ... */ |
| 412 |
, 'value' => array( sprintf( __( 'You can override this email template in this folder %s', 'booking') |
| 413 |
, '<code>' . realpath( dirname(__FILE__) . '/../any/emails_tpl/' ) . '</code>' ) |
| 414 |
) |
| 415 |
, 'cols' => 2 |
| 416 |
, 'group' => 'style' |
| 417 |
); |
| 418 |
|
| 419 |
$this->fields['base_color'] = array( |
| 420 |
'type' => 'color' |
| 421 |
, 'default' => '#557da1' |
| 422 |
, 'title' => __('Base Color', 'booking') |
| 423 |
, 'description' => __('The base color for email templates.', 'booking') |
| 424 |
. ' ' . __('Default color', 'booking') .': <code>#557da1</code>.' |
| 425 |
, 'group' => 'style' |
| 426 |
, 'tr_class' => 'template_colors' |
| 427 |
); |
| 428 |
$this->fields['background_color'] = array( |
| 429 |
'type' => 'color' |
| 430 |
, 'default' => '#f5f5f5' |
| 431 |
, 'title' => __('Background Color', 'booking') |
| 432 |
, 'description' => __('The background color for email templates.', 'booking') |
| 433 |
. ' ' . __('Default color', 'booking') .': <code>#f5f5f5</code>.' |
| 434 |
, 'group' => 'style' |
| 435 |
, 'tr_class' => 'template_colors' |
| 436 |
); |
| 437 |
$this->fields['body_color'] = array( |
| 438 |
'type' => 'color' |
| 439 |
, 'default' => '#fdfdfd' |
| 440 |
, 'title' => __('Email Body Background Color', 'booking') |
| 441 |
, 'description' => __('The main body background color for email templates.', 'booking') |
| 442 |
. ' ' . __('Default color', 'booking') .': <code>#fdfdfd</code>.' |
| 443 |
, 'group' => 'style' |
| 444 |
, 'tr_class' => 'template_colors' |
| 445 |
); |
| 446 |
$this->fields['text_color'] = array( |
| 447 |
'type' => 'color' |
| 448 |
, 'default' => '#505050' |
| 449 |
, 'title' => __('Email Body Text Colour', 'booking') |
| 450 |
, 'description' => __('The main body text color for email templates.', 'booking') |
| 451 |
. ' ' . __('Default color', 'booking') .': <code>#505050</code>.' |
| 452 |
, 'group' => 'style' |
| 453 |
, 'tr_class' => 'template_colors' |
| 454 |
); |
| 455 |
|
| 456 |
|
| 457 |
//////////////////////////////////////////////////////////////////// |
| 458 |
// Email format: Plain, HTML, MultiPart |
| 459 |
//////////////////////////////////////////////////////////////////// |
| 460 |
|
| 461 |
|
| 462 |
$this->fields['email_content_type'] = array( |
| 463 |
'type' => 'select' |
| 464 |
, 'default' => 'plain' |
| 465 |
, 'title' => __('Email format', 'booking') |
| 466 |
, 'description' => __('Choose which format of email to send.', 'booking') |
| 467 |
, 'description_tag' => 'p' |
| 468 |
, 'css' => 'width:100%;' |
| 469 |
, 'options' => array( |
| 470 |
'plain' => __('Plain text', 'booking') |
| 471 |
// , 'html' => __('HTML', 'booking') |
| 472 |
// , 'multipart' => __('Multipart', 'booking') |
| 473 |
) |
| 474 |
, 'group' => 'email_content_type' |
| 475 |
); |
| 476 |
if ( class_exists( 'DOMDocument' ) ) { |
| 477 |
$this->fields['email_content_type']['options']['html'] = __('HTML', 'booking'); |
| 478 |
$this->fields['email_content_type']['options']['multipart'] = __('Multipart', 'booking'); |
| 479 |
|
| 480 |
$this->fields['email_content_type']['default'] = 'html'; |
| 481 |
} |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
//////////////////////////////////////////////////////////////////// |
| 486 |
// Help |
| 487 |
//////////////////////////////////////////////////////////////////// |
| 488 |
|
| 489 |
$this->fields['content_help'] = array( |
| 490 |
'type' => 'help' |
| 491 |
, 'value' => array() |
| 492 |
, 'cols' => 2 |
| 493 |
, 'group' => 'help' |
| 494 |
, 'css' => 'padding-right: 10px !important;max-height: 598px;overflow: auto;' |
| 495 |
, 'only_field' => true |
| 496 |
); |
| 497 |
|
| 498 |
$skip_shortcodes = array( |
| 499 |
// 'denyreason' |
| 500 |
'moderatelink' |
| 501 |
, 'paymentreason' |
| 502 |
, 'visitorbookingediturl' |
| 503 |
//, 'visitorbookingslisting' //FixIn: 8.1.3.5.1 |
| 504 |
, 'visitorbookingcancelurl' |
| 505 |
, 'visitorbookingpayurl' |
| 506 |
, 'add_to_google_cal_button' // FixIn: 9.6.3.8. |
| 507 |
); |
| 508 |
/* translators: 1: ... */ |
| 509 |
$email_example = sprintf( __( 'For example: "You have a new reservation %1$s on the following date(s): %2$s Contact information: %3$s You can approve or cancel this booking at: %4$s Thank you, Reservation service."', 'booking' ),'','[dates]<br/><br/>','<br/> [content]<br/><br/>', htmlentities( ' <a href="[moderatelink]">'.__('here' ,'booking').'</a> ') . '<br/><br/> '); |
| 510 |
|
| 511 |
$help_fields = wpbc_get_email_help_shortcodes( $skip_shortcodes, $email_example ); |
| 512 |
|
| 513 |
foreach ( $help_fields as $help_fields_key => $help_fields_value ) { |
| 514 |
$this->fields['content_help']['value'][] = $help_fields_value; |
| 515 |
} |
| 516 |
|
| 517 |
} |
| 518 |
|
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
/** Settings Emails P a g e */ |
| 524 |
class WPBC_Settings_Page_Email_Deleted extends WPBC_Page_Structure { |
| 525 |
|
| 526 |
public $email_settings_api = false; |
| 527 |
|
| 528 |
|
| 529 |
/** |
| 530 |
* Define interface for Email API |
| 531 |
* |
| 532 |
* @param string $selected_email_name - name of Email template |
| 533 |
* @param array $init_fields_values - array of init form fields data |
| 534 |
* @return object Email API |
| 535 |
*/ |
| 536 |
public function mail_api( $selected_email_name ='', $init_fields_values = array() ){ |
| 537 |
|
| 538 |
if ( $this->email_settings_api === false ) { |
| 539 |
$this->email_settings_api = new WPBC_Emails_API_Deleted( $selected_email_name , $init_fields_values ); |
| 540 |
} |
| 541 |
|
| 542 |
return $this->email_settings_api; |
| 543 |
} |
| 544 |
|
| 545 |
|
| 546 |
public function in_page() { // P a g e t a g |
| 547 |
return 'wpbc-settings'; |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
public function tabs() { // T a b s A r r a y |
| 552 |
|
| 553 |
$tabs = array(); |
| 554 |
|
| 555 |
// $tabs[ 'email' ] = array( |
| 556 |
// 'title' => __( 'Emails', 'booking') // Title of TAB |
| 557 |
// , 'page_title'=> __( 'Emails Settings', 'booking') // Title of Page |
| 558 |
// , 'hint' => __( 'Emails Settings', 'booking') // Hint |
| 559 |
// //, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link |
| 560 |
// //, 'position' => '' // 'left' || 'right' || '' |
| 561 |
// //, 'css_classes'=> '' // CSS class(es) |
| 562 |
// //, 'icon' => '' // Icon - link to the real PNG img |
| 563 |
// , 'font_icon' => 'wpbc_icn_mail_outline' // CSS definition of forn Icon |
| 564 |
// //, 'default' => false // Is this tab activated by default or not: true || false. |
| 565 |
// //, 'disabled' => false // Is this tab disbaled: true || false. |
| 566 |
// //, 'hided' => false // Is this tab hided: true || false. |
| 567 |
// , 'subtabs' => array() |
| 568 |
// ); |
| 569 |
|
| 570 |
$subtabs = array(); |
| 571 |
|
| 572 |
|
| 573 |
$is_data_exist = get_bk_option( WPBC_EMAIL_NEW_ADMIN_PREFIX . WPBC_EMAIL_DELETED_ID ); |
| 574 |
if ( ( ! empty( $is_data_exist ) ) && ( isset( $is_data_exist['copy_to_admin'] ) ) && ( $is_data_exist['copy_to_admin'] == 'On' ) ) |
| 575 |
$sufix = '<sup> 2</sup>'; |
| 576 |
else |
| 577 |
$sufix = ''; |
| 578 |
|
| 579 |
|
| 580 |
$subtabs['deleted'] = array( |
| 581 |
'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 582 |
, 'title' => '<span>' . esc_html__( 'Deleted', 'booking' ) . $sufix . '</span>' // Title of TAB |
| 583 |
, 'page_title' => __('Emails Settings', 'booking') // Title of Page |
| 584 |
, 'hint' => __('Customization of email template, which is sent to Visitor after Cancellation of booking' ,'booking') //FixIn: 8.1.2.17.1 |
| 585 |
, 'link' => '' // link |
| 586 |
, 'position' => '' // 'left' || 'right' || '' |
| 587 |
, 'css_classes' => '' // CSS class(es) |
| 588 |
//, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img |
| 589 |
//, 'font_icon' => 'wpbc_icn_mail_outline' // CSS definition of Font Icon |
| 590 |
, 'header_font_icon' => 'wpbc_icn_mail_outline' // CSS definition of Font Icon // FixIn: 9.6.1.4. |
| 591 |
, 'default' => false // Is this sub tab activated by default or not: true || false. |
| 592 |
, 'disabled' => false // Is this sub tab deactivated: true || false. |
| 593 |
, 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' ) |
| 594 |
, 'content' => 'content' // Function to load as conten of this TAB |
| 595 |
, 'is_use_left_navigation' => true |
| 596 |
, 'show_checked_icon' => true |
| 597 |
, 'checked_data' => WPBC_EMAIL_NEW_ADMIN_PREFIX . WPBC_EMAIL_DELETED_ID // This is where we get content |
| 598 |
); |
| 599 |
|
| 600 |
$tabs[ 'email' ]['subtabs'] = $subtabs; |
| 601 |
|
| 602 |
return $tabs; |
| 603 |
} |
| 604 |
|
| 605 |
|
| 606 |
/** Show Content of Settings page */ |
| 607 |
public function content() { |
| 608 |
$this->css(); |
| 609 |
|
| 610 |
// ------------------------------------------------------------------------------------------------------------- |
| 611 |
// Checking |
| 612 |
// ------------------------------------------------------------------------------------------------------------- |
| 613 |
do_action( 'wpbc_hook_settings_page_header', 'emails_settings'); // Define Notices Section and show some static messages, if needed |
| 614 |
|
| 615 |
if ( ! wpbc_is_mu_user_can_be_here('activated_user') ) return false; // Check if MU user activated, otherwise show Warning message. |
| 616 |
// if ( ! wpbc_is_mu_user_can_be_here('only_super_admin') ) return false; // User is not Super admin, so exit. Basically its was already checked at the bottom of the PHP file, just in case. |
| 617 |
|
| 618 |
|
| 619 |
// ------------------------------------------------------------------------------------------------------------- |
| 620 |
// S u b m i t Main Form |
| 621 |
// ------------------------------------------------------------------------------------------------------------- |
| 622 |
$submit_form_name = 'wpbc_emails_template'; // Define form name |
| 623 |
// $this->maybe_update(); // It is run from parent CLASS before showing this content on Actual Selected by user Page |
| 624 |
|
| 625 |
|
| 626 |
//////////////////////////////////////////////////////////////////////// |
| 627 |
// JavaScript: Tooltips, Popover, Datepick (js & css) |
| 628 |
//////////////////////////////////////////////////////////////////////// |
| 629 |
|
| 630 |
echo '<span class="wpdevelop">'; |
| 631 |
|
| 632 |
wpbc_js_for_bookings_page(); |
| 633 |
|
| 634 |
echo '</span>'; |
| 635 |
|
| 636 |
|
| 637 |
//////////////////////////////////////////////////////////////////////// |
| 638 |
// Content |
| 639 |
//////////////////////////////////////////////////////////////////////// |
| 640 |
?> |
| 641 |
<div class="clear"></div> |
| 642 |
|
| 643 |
<span class="metabox-holder"> |
| 644 |
|
| 645 |
<form name="<?php echo esc_attr( $submit_form_name ); ?>" id="<?php echo esc_attr( $submit_form_name ); ?>" action="" method="post" autocomplete="off"> |
| 646 |
<?php |
| 647 |
// N o n c e field, and key for checking S u b m i t |
| 648 |
wp_nonce_field( 'wpbc_settings_page_' . $submit_form_name ); |
| 649 |
?><input type="hidden" name="is_form_sbmitted_<?php echo esc_attr( $submit_form_name ); ?>" id="is_form_sbmitted_<?php echo esc_attr( $submit_form_name ); ?>" value="1" /> |
| 650 |
|
| 651 |
<div class="clear"></div> |
| 652 |
<?php |
| 653 |
|
| 654 |
wpbc_email_troubleshooting_help_notice(); |
| 655 |
|
| 656 |
?> |
| 657 |
<div class="metabox-holder"> |
| 658 |
<?php |
| 659 |
wpbc_open_meta_box_section( $submit_form_name . 'general', __('Email is sent to Visitor after Deleting of booking.', 'booking') ); //FixIn: 8.1.2.17.1 |
| 660 |
|
| 661 |
$this->mail_api()->show( 'general' ); |
| 662 |
|
| 663 |
wpbc_close_meta_box_section(); |
| 664 |
?> |
| 665 |
<div class="wpbc_settings_row wpbc_settings_row_left" > |
| 666 |
<?php |
| 667 |
wpbc_open_meta_box_section( $submit_form_name . 'general_content', __('Email Content', 'booking') ); //FixIn: 8.1.2.17.1 |
| 668 |
|
| 669 |
$this->mail_api()->show( 'general_content' ); |
| 670 |
|
| 671 |
wpbc_close_meta_box_section(); |
| 672 |
?> |
| 673 |
</div> |
| 674 |
|
| 675 |
<div class="wpbc_settings_row wpbc_settings_row_right"> |
| 676 |
<?php |
| 677 |
wpbc_open_meta_box_section( $submit_form_name . 'help', __('Help', 'booking') ); |
| 678 |
|
| 679 |
$this->mail_api()->show( 'help' ); |
| 680 |
|
| 681 |
wpbc_close_meta_box_section(); |
| 682 |
?> |
| 683 |
</div> |
| 684 |
<div class="clear"></div> |
| 685 |
<?php |
| 686 |
wpbc_open_meta_box_section( $submit_form_name . 'email_content_type', __('Email Type', 'booking') . ' / ' . __('Email Styles', 'booking') ); |
| 687 |
|
| 688 |
$this->mail_api()->show( 'email_content_type' ); |
| 689 |
|
| 690 |
$this->mail_api()->show( 'style' ); |
| 691 |
|
| 692 |
wpbc_close_meta_box_section(); |
| 693 |
|
| 694 |
wpbc_open_meta_box_section( $submit_form_name . 'parts' , __('Header / Footer', 'booking') ); |
| 695 |
|
| 696 |
$this->mail_api()->show( 'parts' ); |
| 697 |
|
| 698 |
wpbc_close_meta_box_section(); |
| 699 |
?> |
| 700 |
</div> |
| 701 |
<input type="submit" value="<?php echo esc_attr( __( 'Save Changes', 'booking' ) ); ?>" class="button button-primary" /> |
| 702 |
</form> |
| 703 |
</span> |
| 704 |
<?php |
| 705 |
|
| 706 |
$this->enqueue_js(); |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
/** |
| 711 |
* This function called from PARENT CLASS for actual selected tab. Firstly it load data and then Maybe Save changes. |
| 712 |
* @return void |
| 713 |
*/ |
| 714 |
public function maybe_update() { |
| 715 |
|
| 716 |
// ------------------------------------------------------------------------------------------------------------- |
| 717 |
// Load Data |
| 718 |
// ------------------------------------------------------------------------------------------------------------- |
| 719 |
|
| 720 |
/* Check if New Email Template Exist or NOT |
| 721 |
* Exist - return empty array in format: array( OPTION_NAME => array() ) |
| 722 |
* It will load DATA from DB, during creation mail_api CLASS |
| 723 |
* during initial activation of the API its try to get option from DB |
| 724 |
* We need to define this API before checking POST, to know all available fields |
| 725 |
* Define Email Name & define field values from DB, if not exist, then default values. |
| 726 |
* Not Exist - import Old Data from DB |
| 727 |
* or get "default" data from settings and return array with this data |
| 728 |
* This data its initial parameters for definition fields in mail_api CLASS |
| 729 |
* |
| 730 |
*/ |
| 731 |
|
| 732 |
$init_fields_values = wpbc_import6_email__deleted__get_fields_array_for_activation(); |
| 733 |
|
| 734 |
// Get Value of first element - array of default or imported OLD data, because need only array of values without key - name of options for wp_options table |
| 735 |
$init_fields_values_temp = array_values( $init_fields_values ); // FixIn: 7.0.1.32. |
| 736 |
$init_fields_values = array_shift( $init_fields_values_temp ); |
| 737 |
|
| 738 |
|
| 739 |
$this->mail_api( WPBC_EMAIL_DELETED_ID, $init_fields_values ); |
| 740 |
|
| 741 |
|
| 742 |
// ------------------------------------------------------------------------------------------------------------- |
| 743 |
// Maybe Update Data |
| 744 |
// ------------------------------------------------------------------------------------------------------------- |
| 745 |
|
| 746 |
// Define form name. |
| 747 |
$submit_form_name = 'wpbc_emails_template'; |
| 748 |
|
| 749 |
$this->mail_api()->validated_form_id = $submit_form_name; // Define ID of Form for ability to validate fields before submit. |
| 750 |
|
| 751 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 752 |
if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) { |
| 753 |
|
| 754 |
// Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. } |
| 755 |
$nonce_gen_time = check_admin_referer( 'wpbc_settings_page_' . $submit_form_name ); // Its stop show anything on submiting, if its not refear to the original page |
| 756 |
|
| 757 |
// Save Changes |
| 758 |
$this->update(); |
| 759 |
} |
| 760 |
} |
| 761 |
|
| 762 |
|
| 763 |
/** Update Email template to DB */ |
| 764 |
public function update() { |
| 765 |
|
| 766 |
// Get Validated Email fields |
| 767 |
$validated_fields = $this->mail_api()->validate_post(); |
| 768 |
|
| 769 |
$this->mail_api()->save_to_db( $validated_fields ); |
| 770 |
|
| 771 |
wpbc_show_message ( __('Settings saved.', 'booking'), 5 ); // Show Save message |
| 772 |
} |
| 773 |
|
| 774 |
// <editor-fold defaultstate="collapsed" desc=" CSS & JS " > |
| 775 |
|
| 776 |
/** CSS for this page */ |
| 777 |
private function css() { |
| 778 |
?> |
| 779 |
<style type="text/css"> |
| 780 |
.wpbc-help-message { |
| 781 |
border:none; |
| 782 |
margin:0 !important; |
| 783 |
padding:0 !important; |
| 784 |
} |
| 785 |
|
| 786 |
@media (max-width: 399px) { |
| 787 |
} |
| 788 |
</style> |
| 789 |
<?php |
| 790 |
} |
| 791 |
|
| 792 |
|
| 793 |
/** |
| 794 |
* Add Custon JavaScript - for some specific settings options |
| 795 |
* Executed After post content, after initial definition of settings, and possible definition after POST request. |
| 796 |
* |
| 797 |
* @param type $menu_slug |
| 798 |
* |
| 799 |
*/ |
| 800 |
private function enqueue_js(){ |
| 801 |
|
| 802 |
$js_script = ''; |
| 803 |
//Show or hide colors section in settings page depend form selected email template. |
| 804 |
$js_script .= " jQuery('select[name=\"deleted_template_file\"]').on( 'change', function(){ |
| 805 |
if ( jQuery('select[name=\"deleted_template_file\"] option:selected').val() == 'plain' ) { |
| 806 |
jQuery('.template_colors').hide(); |
| 807 |
} else { |
| 808 |
jQuery('.template_colors').show(); |
| 809 |
} |
| 810 |
} ); "; |
| 811 |
$js_script .= "\n"; //New Line |
| 812 |
$js_script .= " if ( jQuery('select[name=\"deleted_template_file\"] option:selected').val() == 'plain' ) { |
| 813 |
jQuery('.template_colors').hide(); |
| 814 |
} "; |
| 815 |
|
| 816 |
// Show Warning messages if Title (optional) is empty - title of email will be "WordPress |
| 817 |
$js_script .= " jQuery(document).ready(function(){ "; |
| 818 |
$js_script .= " if ( jQuery('#deleted_to_name').val() == '' ) {"; |
| 819 |
$js_script .= " jQuery('#deleted_to_name').parent().append('<div class=\'updated\' style=\'border-left-color:#ffb900;padding:5px 10px;\'>". esc_js(__('If empty then title defined as WordPress', 'booking' ))."</div>')"; |
| 820 |
$js_script .= " }"; |
| 821 |
$js_script .= " if ( jQuery('#deleted_from_name').val() == '' ) {"; |
| 822 |
$js_script .= " jQuery('#deleted_from_name').parent().append('<div class=\'updated\' style=\'border-left-color:#ffb900;padding:5px 10px;\'>". esc_js(__('If empty then title defined as WordPress', 'booking' ))."</div>')"; |
| 823 |
$js_script .= " }"; |
| 824 |
$js_script .= " }); "; |
| 825 |
|
| 826 |
// FixIn: 8.1.2.17. |
| 827 |
$js_script .= " jQuery('#deleted_copy_to_admin').on( 'change', function(){ "; |
| 828 |
$js_script .= " if ( jQuery('#deleted_copy_to_admin').is(':checked') ) {"; |
| 829 |
$js_script .= " jQuery('.wpbc_tr_copy_to_admin_to').show();"; |
| 830 |
$js_script .= " } else { "; |
| 831 |
$js_script .= " jQuery('.wpbc_tr_copy_to_admin_to').hide();"; |
| 832 |
$js_script .= " } "; |
| 833 |
$js_script .= " }); "; |
| 834 |
$js_script .= " jQuery(document).ready(function(){ "; |
| 835 |
$js_script .= " if ( jQuery('#deleted_copy_to_admin').is(':checked') ) {"; |
| 836 |
$js_script .= " jQuery('.wpbc_tr_copy_to_admin_to').show();"; |
| 837 |
$js_script .= " } else { "; |
| 838 |
$js_script .= " jQuery('.wpbc_tr_copy_to_admin_to').hide();"; |
| 839 |
$js_script .= " } "; |
| 840 |
$js_script .= " }); "; |
| 841 |
//FixIn: 8.1.2.17 - END |
| 842 |
|
| 843 |
// Eneque JS to the footer of the page |
| 844 |
wpbc_enqueue_js( $js_script ); |
| 845 |
} |
| 846 |
|
| 847 |
// </editor-fold> |
| 848 |
} |
| 849 |
add_action('wpbc_menu_created', array( new WPBC_Settings_Page_Email_Deleted() , '__construct') ); // Executed after creation of Menu |
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
// <editor-fold defaultstate="collapsed" desc=" Emails Sending" > |
| 854 |
|
| 855 |
/** |
| 856 |
* Get ShortCodes to Replace |
| 857 |
* |
| 858 |
* @param int $booking_id - ID of booking |
| 859 |
* @param int $bktype - booking resource type |
| 860 |
* @param string $formdata - booking form data content |
| 861 |
*/ |
| 862 |
function wpbc__get_replace_shortcodes__email_deleted( $booking_id, $bktype, $formdata ) { |
| 863 |
|
| 864 |
$replace = array(); |
| 865 |
|
| 866 |
// Resources /////////////////////////////////////////////////////////////// |
| 867 |
$bk_title = wpbc_get_resource_title( $bktype ); |
| 868 |
$parent_resource_title = wpbc_get_parent_resource_title( $bktype ); // FixIn: 10.9.2.4. |
| 869 |
|
| 870 |
// Dates /////////////////////////////////////////////////////////////////// |
| 871 |
$my_dates4emeil = wpbc_db__get_sql_dates__in_booking__as_str( $booking_id ); |
| 872 |
|
| 873 |
$my_dates_4_send = ( 'short' === get_bk_option( 'booking_date_view_type' ) ) |
| 874 |
? wpbc_get_dates_short_format( $my_dates4emeil ) |
| 875 |
: wpbc_get_dates_comma_string_localized( $my_dates4emeil ); |
| 876 |
$my_dates4emeil_check_in_out = explode( ',', $my_dates4emeil ); |
| 877 |
|
| 878 |
$my_check_in_date = wpbc_get_dates_comma_string_localized( $my_dates4emeil_check_in_out[0] ); |
| 879 |
$my_check_out_date = wpbc_get_dates_comma_string_localized( $my_dates4emeil_check_in_out[ count( $my_dates4emeil_check_in_out ) - 1 ] ); |
| 880 |
$my_check_in_onlydate = wpbc_get_dates_comma_string_localized( wpbc_datetime_localized( gmdate( 'Y-m-d 00:00:00', strtotime( $my_dates4emeil_check_in_out[0] ) ), 'Y-m-d 00:00:00' ) ); // FixIn: 8.7.2.5. |
| 881 |
$my_check_out_onlydate = wpbc_get_dates_comma_string_localized( wpbc_datetime_localized( gmdate( 'Y-m-d 00:00:00', strtotime( $my_dates4emeil_check_in_out[ count( $my_dates4emeil_check_in_out ) - 1 ] ) ), 'Y-m-d 00:00:00' ) ); |
| 882 |
$my_check_out_plus1day = wpbc_get_dates_comma_string_localized( wpbc_datetime_localized( gmdate( 'Y-m-d H:i:s', strtotime( $my_dates4emeil_check_in_out[ count( $my_dates4emeil_check_in_out ) - 1 ] . " +1 day" ) ), 'Y-m-d H:i:s' ) ); // FixIn: 6.0.1.11. |
| 883 |
|
| 884 |
// FixIn: 10.1.5.6. |
| 885 |
$dates_only_arr = wpbc_get_only_dates__from_dates_ymd_his_csv__as_arr( $my_dates4emeil ); // -> '2023-10-09, 2023-10-09' |
| 886 |
$dates_only_str = implode( ',', $dates_only_arr ); |
| 887 |
$dates_only_str_formatted = ( 'short' === get_bk_option( 'booking_date_view_type' ) ) |
| 888 |
? wpbc_get_dates_short_format( $dates_only_str ) |
| 889 |
: wpbc_get_dates_comma_string_localized( $dates_only_str ); |
| 890 |
|
| 891 |
// Cost //////////////////////////////////////////////////////////////////// |
| 892 |
$booking_cost_digits_only = apply_bk_filter( 'get_booking_cost_from_db', '', $booking_id ); // FixIn: 9.2.3.1. |
| 893 |
$booking_cost = wpbc_get_cost_with_currency_for_user( $booking_cost_digits_only ); |
| 894 |
// Other /////////////////////////////////////////////////////////////////// |
| 895 |
$replace[ 'booking_id' ] = $booking_id; |
| 896 |
$replace[ 'id' ] = $replace[ 'booking_id' ]; |
| 897 |
$replace[ 'dates' ] = $my_dates_4_send; |
| 898 |
$replace[ 'only_dates' ] = $dates_only_str_formatted; |
| 899 |
$replace[ 'dates_only' ] = $dates_only_str_formatted; |
| 900 |
$replace[ 'check_in_date' ] = $my_check_in_date; |
| 901 |
$replace[ 'check_out_date' ] = $my_check_out_date; |
| 902 |
// FixIn: 8.7.2.5. |
| 903 |
$replace[ 'check_in_only_date' ] = $my_check_in_onlydate; |
| 904 |
$replace[ 'check_out_only_date' ] = $my_check_out_onlydate; |
| 905 |
|
| 906 |
$replace[ 'check_out_plus1day'] = $my_check_out_plus1day; // FixIn: 6.0.1.11. |
| 907 |
$replace[ 'dates_count' ] = count( $my_dates4emeil_check_in_out ); |
| 908 |
$replace['cost'] = $booking_cost; |
| 909 |
$replace['cost_digits_only'] = $booking_cost_digits_only; |
| 910 |
$replace[ 'siteurl' ] = htmlspecialchars_decode( '<a href="' . esc_url( home_url() ) . '">' . home_url() . '</a>' ); |
| 911 |
$replace[ 'resource_title'] = wpbc_lang( $bk_title ); |
| 912 |
$replace[ 'parent_resource_title'] = wpbc_lang( $parent_resource_title ); // FixIn: 10.9.2.4. |
| 913 |
$replace[ 'bookingtype' ] = $replace[ 'resource_title']; |
| 914 |
$replace[ 'remote_ip' ] = wpbc_get_user_ip(); //FixIn:7.1.2.4 // The IP address from which the user is viewing the current page. |
| 915 |
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 916 |
$replace[ 'user_agent' ] = ( ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ) : '' ); // Contents of the User-Agent: header from the current request, if there is one. |
| 917 |
$server_http_referer_uri = ( ( isset( $_SERVER['HTTP_REFERER'] ) ) ? sanitize_text_field( $_SERVER['HTTP_REFERER'] ) : '' ); /* phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash */ /* FixIn: sanitize_unslash */ |
| 918 |
$replace['request_url'] = $server_http_referer_uri; // The address of the page (if any) where action was occured. Because we are sending it in Ajax request, we need to use the REFERER HTTP |
| 919 |
$replace[ 'current_date' ] = date_i18n( get_bk_option( 'booking_date_format' ) ); |
| 920 |
$replace[ 'current_time' ] = date_i18n( get_bk_option( 'booking_time_format' ) ); |
| 921 |
|
| 922 |
// Form Fields ///////////////////////////////////////////////////////////// |
| 923 |
$booking_form_show_array = wpbc__legacy__get_form_content_arr( $formdata, $bktype, '', $replace ); // We use here $replace array, becaise in "Content of booking filds data" form can be shortcodes from above definition |
| 924 |
|
| 925 |
foreach ( $booking_form_show_array['_all_fields_'] as $shortcode_name => $shortcode_value ) { |
| 926 |
|
| 927 |
if ( ! isset( $replace[ $shortcode_name ] ) ) |
| 928 |
$replace[ $shortcode_name ] = $shortcode_value; |
| 929 |
} |
| 930 |
$replace[ 'content' ] = $booking_form_show_array['content']; |
| 931 |
|
| 932 |
// Links /////////////////////////////////////////////////////////////////// |
| 933 |
$replace[ 'moderatelink' ] = htmlspecialchars_decode( |
| 934 |
// '<a href="' . |
| 935 |
esc_url( wpbc_get_bookings_url() . '&view_mode=vm_listing&tab=actions&wh_booking_id=' . $booking_id ) |
| 936 |
// . '">' . esc_html__('here', 'booking') . '</a>' |
| 937 |
); |
| 938 |
$replace[ 'visitorbookingediturl' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingediturl]', $booking_id ); |
| 939 |
$replace[ 'visitorbookingslisting' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingslisting]', $booking_id ); //FixIn: 8.1.3.5.1 |
| 940 |
$replace[ 'visitorbookingcancelurl' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingcancelurl]', $booking_id ); |
| 941 |
$replace[ 'visitorbookingpayurl' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingpayurl]', $booking_id ); |
| 942 |
$replace[ 'bookinghash' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[bookinghash]', $booking_id ); |
| 943 |
|
| 944 |
// ----------------------------------------------------------------------------------------------------------------- |
| 945 |
// Get additional replace paramaters to the email shortcodes |
| 946 |
$replace = apply_filters( 'wpbc_replace_params_for_booking', $replace, $booking_id, $bktype, $formdata ); // FixIn: 8.0.1.7. |
| 947 |
|
| 948 |
|
| 949 |
return $replace; |
| 950 |
|
| 951 |
|
| 952 |
} |
| 953 |
|
| 954 |
|
| 955 |
/** |
| 956 |
* Send email |
| 957 |
* |
| 958 |
* @param type $booking_id - ID of booking |
| 959 |
* @param type $bktype - type |
| 960 |
* @param type $formdata - booking form data |
| 961 |
*/ |
| 962 |
|
| 963 |
function wpbc_send_email_deleted( $deleted_id_str, $is_send_emeils, $deletedreason = '' ) { |
| 964 |
|
| 965 |
global $wpdb; |
| 966 |
$sql = "SELECT * FROM {$wpdb->prefix}booking as bk WHERE bk.booking_id IN ({$deleted_id_str})"; |
| 967 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared |
| 968 |
$result = $wpdb->get_results( $sql ); |
| 969 |
|
| 970 |
foreach ( $result as $res ) { |
| 971 |
|
| 972 |
$booking_id = $res->booking_id; |
| 973 |
$bktype = $res->booking_type; |
| 974 |
$formdata = $res->form; |
| 975 |
|
| 976 |
$previous_active_user = apply_bk_filter( 'wpbc_mu_set_environment_for_owner_of_resource', -1, $bktype ); // MU |
| 977 |
|
| 978 |
//////////////////////////////////////////////////////////////////////// |
| 979 |
// Load Data |
| 980 |
//////////////////////////////////////////////////////////////////////// |
| 981 |
|
| 982 |
/* Check if New Email Template Exist or NOT |
| 983 |
* Exist - return empty array in format: array( OPTION_NAME => array() ) |
| 984 |
* Its will load DATA from DB, during creattion mail_api CLASS |
| 985 |
* during initial activation of the API its try to get option from DB |
| 986 |
* We need to define this API before checking POST, to know all available fields |
| 987 |
* Define Email Name & define field values from DB, if not exist, then default values. |
| 988 |
* Not Exist - import Old Data from DB |
| 989 |
* or get "default" data from settings and return array with this data |
| 990 |
* This data its initial parameters for definition fields in mail_api CLASS |
| 991 |
* |
| 992 |
*/ |
| 993 |
|
| 994 |
$init_fields_values = wpbc_import6_email__deleted__get_fields_array_for_activation(); |
| 995 |
|
| 996 |
// Get Value of first element - array of default or imported OLD data, because need only array of values without key - name of options for wp_options table |
| 997 |
$init_fields_values_temp = array_values( $init_fields_values ); // FixIn: 7.0.1.32. |
| 998 |
$init_fields_values = array_shift( $init_fields_values_temp ); |
| 999 |
|
| 1000 |
|
| 1001 |
$mail_api = new WPBC_Emails_API_Deleted( WPBC_EMAIL_DELETED_ID, $init_fields_values ); |
| 1002 |
|
| 1003 |
//////////////////////////////////////////////////////////////////////////// |
| 1004 |
|
| 1005 |
if ( $mail_api->fields_values['enabled'] == 'Off' ) return false; // Email template deactivated - exit. |
| 1006 |
|
| 1007 |
|
| 1008 |
$replace = wpbc__get_replace_shortcodes__email_deleted( $booking_id, $bktype, $formdata ); |
| 1009 |
$replace[ 'denyreason' ] = $deletedreason; // FixIn: 7.0.1.1. |
| 1010 |
|
| 1011 |
// Replace shortcodes with custom URL parameter, like: 'visitorbookingediturl', 'visitorbookingcancelurl', 'visitorbookingpayurl' |
| 1012 |
foreach ( array( 'visitorbookingediturl', 'visitorbookingcancelurl', 'visitorbookingpayurl' , 'visitorbookingslisting' ) as $url_shortcode ) { //FixIn: 7.0.1.8 //FixIn: 8.1.3.5.1 |
| 1013 |
|
| 1014 |
// Loop to search if we are having several such shortcodes in our $mail_api->fields_values['content'] (For example, if we have several languges ). |
| 1015 |
$pos = 0; //FixIn: 7.0.1.52 |
| 1016 |
do { |
| 1017 |
$shortcode_params = wpbc_get_params_of_shortcode_in_string( $url_shortcode, $mail_api->fields_values['content'] , $pos ); |
| 1018 |
|
| 1019 |
if ( ( ! empty( $shortcode_params ) ) && ( isset( $shortcode_params['url'] ) ) ){ |
| 1020 |
|
| 1021 |
$pos = $shortcode_params['end']; |
| 1022 |
|
| 1023 |
$exist_replace = substr( $mail_api->fields_values['content'], $shortcode_params['start'], ( $shortcode_params['end'] - $shortcode_params['start'] ) ); |
| 1024 |
|
| 1025 |
$new_replace = $url_shortcode . wp_rand(1000,9000); |
| 1026 |
|
| 1027 |
$pos = $shortcode_params['start'] + strlen( $new_replace ); //FixIn: 9.7.3.5.1 |
| 1028 |
$mail_api->fields_values['content'] = str_replace( $exist_replace, $new_replace ,$mail_api->fields_values['content'] ); |
| 1029 |
|
| 1030 |
$replace[ $new_replace ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '['.$exist_replace.']', $booking_id ); |
| 1031 |
} else if ( // FixIn: 8.1.1.8. |
| 1032 |
( ! empty( $shortcode_params ) ) |
| 1033 |
&& ( isset( $shortcode_params['end'] ) ) |
| 1034 |
&& ( $shortcode_params['end'] < strlen( $mail_api->fields_values['content'] ) ) |
| 1035 |
) { |
| 1036 |
$pos = $shortcode_params['end']; |
| 1037 |
} else { |
| 1038 |
$shortcode_params = false; //FixIn: 7.0.1.58 |
| 1039 |
} |
| 1040 |
|
| 1041 |
} while ( ! empty( $shortcode_params ) ); // FixIn: 7.0.1.52. |
| 1042 |
|
| 1043 |
} |
| 1044 |
|
| 1045 |
$mail_api->set_replace( $replace ); |
| 1046 |
$mail_api->fields_values['from_name'] = $mail_api->replace_shortcodes( $mail_api->fields_values['from_name'] ); // FixIn: 7.0.1.29. |
| 1047 |
|
| 1048 |
|
| 1049 |
$to = ( isset( $replace['email'] ) ) ? $replace['email'] : ''; // Get To field |
| 1050 |
|
| 1051 |
if ( ! empty( $replace['email'] ) ) { |
| 1052 |
$to = wpbc_email_prepand_person_name( $replace['email'], $replace ); |
| 1053 |
} |
| 1054 |
|
| 1055 |
$to = wpbc_check_for_several_emails_in_form( $to, $formdata, $bktype ); // FixIn: 6.0.1.9. |
| 1056 |
|
| 1057 |
$to = str_replace( ';', ',', $to ); |
| 1058 |
|
| 1059 |
|
| 1060 |
if ( wpbc_is_not_blank_email( $to, $replace['content'] ) ) { |
| 1061 |
$email_result = $mail_api->send( $to, $replace ); |
| 1062 |
} |
| 1063 |
|
| 1064 |
make_bk_action( 'wpbc_mu_set_environment_for_user', $previous_active_user ); // MU |
| 1065 |
} |
| 1066 |
|
| 1067 |
$email_result = ( isset( $email_result ) ) ? $email_result : false; |
| 1068 |
return $email_result; |
| 1069 |
} |
| 1070 |
|
| 1071 |
// </editor-fold> |
| 1072 |
|