| 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_NEW_ADMIN_PREFIX' ) ) define( 'WPBC_EMAIL_NEW_ADMIN_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_NEW_ADMIN_ID' ) ) define( 'WPBC_EMAIL_NEW_ADMIN_ID', 'new_admin' ); /* Define Name of Email Template. |
| 20 |
Note. Prefix "booking_email_" defined in api-emails.php file. |
| 21 |
Full name of option is - "booking_email_new_admin" |
| 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_new_admin_exist() { |
| 39 |
|
| 40 |
$is_old_data_exist = get_bk_option( 'booking_email_reservation_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_new_admin_data() { |
| 49 |
|
| 50 |
$default_values = array(); |
| 51 |
if ( wpbc_import6_is_old_email_new_admin_exist() ) { |
| 52 |
$default_values['enabled'] = get_bk_option( 'booking_is_email_reservation_adress' ); |
| 53 |
$default_values['to'] = get_bk_option( 'booking_email_reservation_adress' ); //Parse it to Name and Email |
| 54 |
$default_values['from'] = get_bk_option( 'booking_email_reservation_from_adress' ); //Parse it to Name and Email, relpace [visitoremail] |
| 55 |
$default_values['subject'] = get_bk_option( 'booking_email_reservation_subject' ); |
| 56 |
$default_values['content'] = get_bk_option( 'booking_email_reservation_content' ); |
| 57 |
} |
| 58 |
return $default_values; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
function wpbc_import6_is_new_email_new_admin_exist() { |
| 63 |
|
| 64 |
$is_data_exist = get_bk_option( WPBC_EMAIL_NEW_ADMIN_PREFIX . WPBC_EMAIL_NEW_ADMIN_ID ); // ''booking_email_' - defined in api-emails.php file. |
| 65 |
|
| 66 |
if ( ! empty( $is_data_exist ) ) // Check if data exist |
| 67 |
return true; |
| 68 |
else |
| 69 |
return false; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
function wpbc_import6_email__new_admin__get_fields_array_for_activation() { |
| 74 |
|
| 75 |
|
| 76 |
if ( ! wpbc_import6_is_new_email_new_admin_exist() ) { // New Email Template NOT exist |
| 77 |
|
| 78 |
// Import |
| 79 |
$old_data = wpbc_import6_get_old_email_new_admin_data(); |
| 80 |
|
| 81 |
if ( ! empty( $old_data ) ) { // Get Old data |
| 82 |
|
| 83 |
/* |
| 84 |
$old_data = [ |
| 85 |
[enabled] => On |
| 86 |
[to] => "Booking system" <beta@wpbookingcalendar.com> |
| 87 |
[from] => [visitoremail] |
| 88 |
[subject] => New booking |
| 89 |
[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] |
| 90 |
] |
| 91 |
wpbc_get_email_parts() >>> return [ |
| 92 |
[email] => beta@wpbookingcalendar.com |
| 93 |
[title] => Booking system |
| 94 |
[original] => "Booking system" |
| 95 |
[original_to_show] => "Booking system" <beta@wpbookingcalendar.com> |
| 96 |
] |
| 97 |
*/ |
| 98 |
|
| 99 |
// Make transform - emails |
| 100 |
$email_to = wpbc_get_email_parts( $old_data['to'] ); |
| 101 |
$email_from = wpbc_get_email_parts( $old_data['from'] ); |
| 102 |
|
| 103 |
$old_data['to'] = $email_to['email']; // 'beta@wpbookingcalendar.com' // booking_email_reservation_adress |
| 104 |
$old_data['to_name'] = $email_to['title']; // 'Booking system' // booking_email_reservation_adress |
| 105 |
/* Description of Code. |
| 106 |
* Here we replacing any shortcodes, like [visitoremail] to get_option( 'admin_email' ) |
| 107 |
* 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 |
| 108 |
* |
| 109 |
* 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' ) |
| 110 |
* |
| 111 |
* 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. |
| 112 |
* |
| 113 |
*/ |
| 114 |
$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 |
| 115 |
$old_data['from_name'] = $email_from['title']; // [visitoremail] | 'Booking System' | '' // booking_email_reservation_from_adress |
| 116 |
|
| 117 |
// $old_data['subject'] = html_entity_decode( $old_data['subject'] ); |
| 118 |
// $old_data['content'] = html_entity_decode( $old_data['content'] ); |
| 119 |
} |
| 120 |
|
| 121 |
// Default |
| 122 |
$init_fields_values = $old_data; |
| 123 |
$mail_api = new WPBC_Emails_API_NewAdmin( WPBC_EMAIL_NEW_ADMIN_ID , $init_fields_values ); |
| 124 |
|
| 125 |
$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_NewAdmin} |
| 126 |
|
| 127 |
$fields_values = wp_parse_args( $old_data, $default_fields_in_settings ); |
| 128 |
|
| 129 |
return array( WPBC_EMAIL_NEW_ADMIN_PREFIX . WPBC_EMAIL_NEW_ADMIN_ID => $fields_values ); |
| 130 |
|
| 131 |
/* |
| 132 |
Array ( |
| 133 |
[booking_email_new_admin] => Array |
| 134 |
( |
| 135 |
[enabled] => On |
| 136 |
[to] => beta@wpbookingcalendar.com |
| 137 |
[to_name] => Booking system |
| 138 |
[from] => admin@wpbookingcalendar.com |
| 139 |
[from_name] => |
| 140 |
[subject] => New booking |
| 141 |
[content] => You need to approve a new booking [bookingtype] for: [dates]... |
| 142 |
[header_content] => |
| 143 |
[footer_content] => |
| 144 |
[template_file] => plain |
| 145 |
[base_color] => #557da1 |
| 146 |
[background_color] => #f5f5f5 |
| 147 |
[body_color] => #fdfdfd |
| 148 |
[text_color] => #505050 |
| 149 |
[email_content_type] => html |
| 150 |
) |
| 151 |
) |
| 152 |
|
| 153 |
// $mail_api->save_to_db( $fields_values ); |
| 154 |
|
| 155 |
*/ |
| 156 |
|
| 157 |
} else { // New Email Template is Exist - return empty array(), its will make loading of data from DB, during activation Mail API class. |
| 158 |
return array( WPBC_EMAIL_NEW_ADMIN_PREFIX . WPBC_EMAIL_NEW_ADMIN_ID => array() ); |
| 159 |
} |
| 160 |
} |
| 161 |
// </editor-fold> |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
/** Email F i e l d s */ |
| 166 |
class WPBC_Emails_API_NewAdmin extends WPBC_Emails_API { // O v e r r i d i n g "WPBC_Emails_API" ClASS |
| 167 |
|
| 168 |
/** Overrided functions - define Email Fields & Values */ |
| 169 |
public function init_settings_fields() { |
| 170 |
|
| 171 |
$this->fields = array(); |
| 172 |
|
| 173 |
$this->fields['enabled'] = array( |
| 174 |
'type' => 'checkbox' |
| 175 |
, 'default' => 'On' |
| 176 |
, 'title' => __('Enable / Disable', 'booking') |
| 177 |
, 'label' => __('Enable this email notification', 'booking') |
| 178 |
, 'description' => '' |
| 179 |
, 'group' => 'general' |
| 180 |
|
| 181 |
); |
| 182 |
|
| 183 |
$this->fields['to_html_prefix'] = array( |
| 184 |
'type' => 'pure_html' |
| 185 |
, 'group' => 'general' |
| 186 |
, 'html' => '<tr valign="top"> |
| 187 |
<th scope="row"> |
| 188 |
<label class="wpbc-form-email" for="' |
| 189 |
. esc_attr( 'new_admin_to' ) |
| 190 |
. '">' . wp_kses_post( __('To' ,'booking') ) |
| 191 |
. '</label> |
| 192 |
</th> |
| 193 |
<td><fieldset style="float:left;width:50%;margin-right:5%;">' |
| 194 |
); |
| 195 |
$this->fields['to'] = array( |
| 196 |
'type' => 'text' // We are using here 'text' and not 'email', for ability to save several comma seperated emails. |
| 197 |
, 'default' => get_option( 'admin_email' ) |
| 198 |
//, 'placeholder' => '' |
| 199 |
, 'title' => '' |
| 200 |
, 'description' => __('Email Address', 'booking') . '. ' . __('Required', 'booking') . '.' |
| 201 |
, 'description_tag' => '' |
| 202 |
, 'css' => 'width:100%' |
| 203 |
, 'group' => 'general' |
| 204 |
, 'tr_class' => '' |
| 205 |
, 'only_field' => true |
| 206 |
, 'validate_as' => array( 'required' ) |
| 207 |
); |
| 208 |
$this->fields['to_html_middle'] = array( |
| 209 |
'type' => 'pure_html' |
| 210 |
, 'group' => 'general' |
| 211 |
, 'html' => '</fieldset><fieldset style="float:left;width:45%;">' |
| 212 |
); |
| 213 |
$this->fields['to_name'] = array( |
| 214 |
'type' => 'text' |
| 215 |
, 'default' => 'Booking system' |
| 216 |
//, 'placeholder' => '' |
| 217 |
, 'title' => '' |
| 218 |
, 'description' => __('Title', 'booking') . ' (' . __('optional', 'booking') . ').' //. ' ' . __('If empty then title defined as WordPress', 'booking') |
| 219 |
, 'description_tag' => '' |
| 220 |
, 'css' => 'width:100%' |
| 221 |
, 'group' => 'general' |
| 222 |
, 'tr_class' => '' |
| 223 |
, 'only_field' => true |
| 224 |
); |
| 225 |
$this->fields['to_html_sufix'] = array( |
| 226 |
'type' => 'pure_html' |
| 227 |
, 'group' => 'general' |
| 228 |
, 'html' => ' </fieldset> |
| 229 |
</td> |
| 230 |
</tr>' |
| 231 |
); |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
$this->fields['from_html_prefix'] = array( |
| 236 |
'type' => 'pure_html' |
| 237 |
, 'group' => 'general' |
| 238 |
, 'html' => '<tr valign="top"> |
| 239 |
<th scope="row"> |
| 240 |
<label class="wpbc-form-email" for="' |
| 241 |
. esc_attr( 'new_admin_from' ) |
| 242 |
. '">' . wp_kses_post( __('From' ,'booking') ) |
| 243 |
. '</label> |
| 244 |
</th> |
| 245 |
<td><fieldset style="float:left;width:50%;margin-right:5%;">' |
| 246 |
); |
| 247 |
$this->fields['from'] = array( |
| 248 |
'type' => 'email' // Its can be only 1 email, so check it as Email field. |
| 249 |
, 'default' => get_option( 'admin_email' ) |
| 250 |
//, 'placeholder' => '' |
| 251 |
, 'title' => '' |
| 252 |
, 'description' => __('Email Address', 'booking') . '. ' . __('Required', 'booking') . '.' |
| 253 |
, 'description_tag' => '' |
| 254 |
, 'css' => 'width:100%' |
| 255 |
, 'group' => 'general' |
| 256 |
, 'tr_class' => '' |
| 257 |
, 'only_field' => true |
| 258 |
, 'validate_as' => array( 'required' ) |
| 259 |
); |
| 260 |
$this->fields['from_html_middle'] = array( |
| 261 |
'type' => 'pure_html' |
| 262 |
, 'group' => 'general' |
| 263 |
, 'html' => '</fieldset><fieldset style="float:left;width:45%;">' |
| 264 |
); |
| 265 |
$this->fields['from_name'] = array( |
| 266 |
'type' => 'text' |
| 267 |
, 'default' => 'Booking system' |
| 268 |
//, 'placeholder' => '' |
| 269 |
, 'title' => '' |
| 270 |
, 'description' => __('Title', 'booking') . ' (' . __('optional', 'booking') . ').' //. ' ' . __('If empty then title defined as WordPress', 'booking') |
| 271 |
, 'description_tag' => '' |
| 272 |
, 'css' => 'width:100%' |
| 273 |
, 'group' => 'general' |
| 274 |
, 'tr_class' => '' |
| 275 |
, 'only_field' => true |
| 276 |
); |
| 277 |
$this->fields['from_html_sufix'] = array( |
| 278 |
'type' => 'pure_html' |
| 279 |
, 'group' => 'general' |
| 280 |
, 'html' => ' </fieldset> |
| 281 |
</td> |
| 282 |
</tr>' |
| 283 |
); |
| 284 |
// FixIn: 9.7.3.17. |
| 285 |
$this->fields['enable_replyto'] = array( |
| 286 |
'type' => 'checkbox' |
| 287 |
, 'default' => 'Off' |
| 288 |
, 'title' => __( 'Enable Reply-To', 'booking' ) |
| 289 |
, 'label' => __( 'Enable Reply-To visitor email', 'booking' ) |
| 290 |
, 'description' => '' |
| 291 |
, 'group' => 'general' |
| 292 |
|
| 293 |
); |
| 294 |
$this->fields['subject_before'] = array( |
| 295 |
'type' => 'pure_html' |
| 296 |
, 'group' => 'general_content' |
| 297 |
, 'html' => '<tr><td colspan="2">' |
| 298 |
.'<div style="margin: 0 0 15px;font-weight: 600;">' |
| 299 |
.'<label class="wpbc-form-email-subject" for="' . WPBC_EMAIL_NEW_ADMIN_ID . '_subject">' . |
| 300 |
__( 'Subject', 'booking' ) |
| 301 |
. '</label></div>' |
| 302 |
); |
| 303 |
$this->fields['subject'] = array( |
| 304 |
'type' => 'text' |
| 305 |
, 'default' => __( 'New booking', 'booking' ) |
| 306 |
//, 'placeholder' => '' |
| 307 |
, 'title' => __('Subject', 'booking') |
| 308 |
, 'description' => '' |
| 309 |
, 'description_tag' => '' |
| 310 |
, 'css' => 'width:100%;font-size:16px;line-height:34px;font-weight:600;' |
| 311 |
, 'group' => 'general_content' |
| 312 |
, 'tr_class' => '' |
| 313 |
, 'validate_as' => array( 'required' ) |
| 314 |
, 'only_field' => true |
| 315 |
); |
| 316 |
$this->fields['subject_after'] = array( 'type' => 'pure_html', 'group' => 'general_content', |
| 317 |
'html' => '<p style="text-align: right;font-size:12px;">' |
| 318 |
/* translators: 1: ... */ |
| 319 |
. sprintf( __( 'Type your email %1$ssubject%2$s for the booking confirmation message.', 'booking' ), '<b>', '</b>' ) . ' ' . __( 'Required', 'booking' ) |
| 320 |
. '.</p>' . '</td></tr>' ); |
| 321 |
|
| 322 |
$this->fields['content_before'] = array( |
| 323 |
'type' => 'pure_html', |
| 324 |
'group' => 'general_content', |
| 325 |
'html' => '<tr><td colspan="2" style="padding-bottom:0;">' |
| 326 |
. '<div style="margin: 0;font-weight: 600;">' |
| 327 |
. '<label class="wpbc-form-email-content" for="' . WPBC_EMAIL_NEW_ADMIN_ID . '_content">' . |
| 328 |
__( 'Content', 'booking' ) |
| 329 |
. '</label></div>' |
| 330 |
); |
| 331 |
$blg_title = get_option( 'blogname' ); |
| 332 |
$blg_title = str_replace( array( '"', "'" ), '', $blg_title ); |
| 333 |
$this->fields['content'] = array( |
| 334 |
'type' => 'wp_textarea' |
| 335 |
/* translators: 1: ... */ |
| 336 |
, 'default' => sprintf( __( 'You need to approve a new booking %1$s for: %2$s Person detail information:%3$s Currently a new booking is waiting for approval. Please visit the moderation panel%4$sThank you, %5$s', 'booking' ), '[bookingtype]', '[dates]<br/><br/>', '<br/> [content]<br/><br/>', ' [moderatelink]<br/><br/>', $blg_title . '<br/>[siteurl]' ) |
| 337 |
//, 'placeholder' => '' |
| 338 |
, 'title' => __('Content', 'booking') |
| 339 |
, 'description' => ''//__('Type your email message content. ', 'booking') |
| 340 |
, 'description_tag' => '' |
| 341 |
, 'css' => '' |
| 342 |
, 'group' => 'general_content' |
| 343 |
, 'tr_class' => '' |
| 344 |
, 'rows' => 17 |
| 345 |
, 'show_in_2_cols' => true |
| 346 |
, 'only_field' => true |
| 347 |
); |
| 348 |
$this->fields['content_after'] = array( 'type' => 'pure_html', 'group' => 'general_content', 'html' => '</td></tr>' ); |
| 349 |
|
| 350 |
// $this->fields['content'] = htmlspecialchars( $this->fields['content'] );// Convert > to > |
| 351 |
// $this->fields['content'] = html_entity_decode( $this->fields['content'] );// Convert > to > |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
//////////////////////////////////////////////////////////////////// |
| 356 |
// Style |
| 357 |
//////////////////////////////////////////////////////////////////// |
| 358 |
|
| 359 |
|
| 360 |
$this->fields['header_content'] = array( |
| 361 |
'type' => 'textarea' |
| 362 |
, 'default' => '' |
| 363 |
, 'title' => __('Email Heading', 'booking') |
| 364 |
, 'description' => __('Enter main heading contained within the email notification.', 'booking') |
| 365 |
//, 'placeholder' => '' |
| 366 |
, 'rows' => 2 |
| 367 |
, 'css' => "width:100%;" |
| 368 |
, 'group' => 'parts' |
| 369 |
); |
| 370 |
$this->fields['footer_content'] = array( |
| 371 |
'type' => 'textarea' |
| 372 |
, 'default' => '' |
| 373 |
, 'title' => __('Email Footer Text', 'booking') |
| 374 |
, 'description' => __('Enter text contained within footer of the email notification', 'booking') |
| 375 |
//, 'placeholder' => '' |
| 376 |
, 'rows' => 2 |
| 377 |
, 'css' => 'width:100%;' |
| 378 |
, 'group' => 'parts' |
| 379 |
); |
| 380 |
|
| 381 |
$this->fields['template_file'] = array( |
| 382 |
'type' => 'select' |
| 383 |
, 'default' => 'plain' |
| 384 |
, 'title' => __('Email template', 'booking') |
| 385 |
, 'description' => __('Choose email template.', 'booking') |
| 386 |
, 'description_tag' => 'span' |
| 387 |
, 'css' => '' |
| 388 |
, 'options' => array( |
| 389 |
'plain' => __('Plain (without styles)', 'booking') |
| 390 |
, 'standard' => __('Standard 1 column', 'booking') |
| 391 |
) |
| 392 |
, 'group' => 'style' |
| 393 |
); |
| 394 |
|
| 395 |
$this->fields['template_file_help'] = array( |
| 396 |
'type' => 'help' |
| 397 |
/* translators: 1: ... */ |
| 398 |
, 'value' => array( sprintf( __( 'You can override this email template in this folder %s', 'booking') |
| 399 |
, '<code>' . realpath( dirname(__FILE__) . '/../any/emails_tpl/' ) . '</code>' ) |
| 400 |
) |
| 401 |
, 'cols' => 2 |
| 402 |
, 'group' => 'style' |
| 403 |
); |
| 404 |
|
| 405 |
$this->fields['base_color'] = array( |
| 406 |
'type' => 'color' |
| 407 |
, 'default' => '#557da1' |
| 408 |
, 'title' => __('Base Color', 'booking') |
| 409 |
, 'description' => __('The base color for email templates.', 'booking') |
| 410 |
. ' ' . __('Default color', 'booking') .': <code>#557da1</code>.' |
| 411 |
, 'group' => 'style' |
| 412 |
, 'tr_class' => 'template_colors' |
| 413 |
); |
| 414 |
$this->fields['background_color'] = array( |
| 415 |
'type' => 'color' |
| 416 |
, 'default' => '#f5f5f5' |
| 417 |
, 'title' => __('Background Color', 'booking') |
| 418 |
, 'description' => __('The background color for email templates.', 'booking') |
| 419 |
. ' ' . __('Default color', 'booking') .': <code>#f5f5f5</code>.' |
| 420 |
, 'group' => 'style' |
| 421 |
, 'tr_class' => 'template_colors' |
| 422 |
); |
| 423 |
$this->fields['body_color'] = array( |
| 424 |
'type' => 'color' |
| 425 |
, 'default' => '#fdfdfd' |
| 426 |
, 'title' => __('Email Body Background Color', 'booking') |
| 427 |
, 'description' => __('The main body background color for email templates.', 'booking') |
| 428 |
. ' ' . __('Default color', 'booking') .': <code>#fdfdfd</code>.' |
| 429 |
, 'group' => 'style' |
| 430 |
, 'tr_class' => 'template_colors' |
| 431 |
); |
| 432 |
$this->fields['text_color'] = array( |
| 433 |
'type' => 'color' |
| 434 |
, 'default' => '#505050' |
| 435 |
, 'title' => __('Email Body Text Colour', 'booking') |
| 436 |
, 'description' => __('The main body text color for email templates.', 'booking') |
| 437 |
. ' ' . __('Default color', 'booking') .': <code>#505050</code>.' |
| 438 |
, 'group' => 'style' |
| 439 |
, 'tr_class' => 'template_colors' |
| 440 |
); |
| 441 |
|
| 442 |
|
| 443 |
//////////////////////////////////////////////////////////////////// |
| 444 |
// Email format: Plain, HTML, MultiPart |
| 445 |
//////////////////////////////////////////////////////////////////// |
| 446 |
|
| 447 |
|
| 448 |
$this->fields['email_content_type'] = array( |
| 449 |
'type' => 'select' |
| 450 |
, 'default' => 'plain' |
| 451 |
, 'title' => __('Email format', 'booking') |
| 452 |
, 'description' => __('Choose which format of email to send.', 'booking') |
| 453 |
, 'description_tag' => 'p' |
| 454 |
, 'css' => 'width:100%;' |
| 455 |
, 'options' => array( |
| 456 |
'plain' => __('Plain text', 'booking') |
| 457 |
// , 'html' => __('HTML', 'booking') |
| 458 |
// , 'multipart' => __('Multipart', 'booking') |
| 459 |
) |
| 460 |
, 'group' => 'email_content_type' |
| 461 |
); |
| 462 |
if ( class_exists( 'DOMDocument' ) ) { |
| 463 |
$this->fields['email_content_type']['options']['html'] = __('HTML', 'booking'); |
| 464 |
$this->fields['email_content_type']['options']['multipart'] = __('Multipart', 'booking'); |
| 465 |
|
| 466 |
$this->fields['email_content_type']['default'] = 'html'; |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
//////////////////////////////////////////////////////////////////// |
| 472 |
// Help |
| 473 |
//////////////////////////////////////////////////////////////////// |
| 474 |
|
| 475 |
$this->fields['content_help'] = array( |
| 476 |
'type' => 'help' |
| 477 |
, 'value' => array() |
| 478 |
, 'cols' => 2 |
| 479 |
, 'group' => 'help' |
| 480 |
, 'css' => 'padding-right: 10px !important;max-height: 598px;overflow: auto;' |
| 481 |
, 'only_field' => true |
| 482 |
); |
| 483 |
|
| 484 |
$skip_shortcodes = array( |
| 485 |
'denyreason' |
| 486 |
, 'paymentreason' |
| 487 |
, 'visitorbookingediturl' |
| 488 |
, 'visitorbookingslisting' //FixIn: 8.1.3.5.1 |
| 489 |
, 'visitorbookingcancelurl' |
| 490 |
, 'visitorbookingpayurl' |
| 491 |
); |
| 492 |
/* translators: 1: ... */ |
| 493 |
$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/> '); |
| 494 |
|
| 495 |
$help_fields = wpbc_get_email_help_shortcodes( $skip_shortcodes, $email_example ); |
| 496 |
|
| 497 |
foreach ( $help_fields as $help_fields_key => $help_fields_value ) { |
| 498 |
$this->fields['content_help']['value'][] = $help_fields_value; |
| 499 |
} |
| 500 |
|
| 501 |
} |
| 502 |
|
| 503 |
} |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
/** Settings Emails P a g e */ |
| 508 |
class WPBC_Settings_Page_Email_NewAdmin extends WPBC_Page_Structure { |
| 509 |
|
| 510 |
public $email_settings_api = false; |
| 511 |
|
| 512 |
|
| 513 |
/** |
| 514 |
* Define interface for Email API |
| 515 |
* |
| 516 |
* @param string $selected_email_name - name of Email template |
| 517 |
* @param array $init_fields_values - array of init form fields data |
| 518 |
* @return object Email API |
| 519 |
*/ |
| 520 |
public function mail_api( $selected_email_name ='', $init_fields_values = array() ){ |
| 521 |
|
| 522 |
if ( $this->email_settings_api === false ) { |
| 523 |
$this->email_settings_api = new WPBC_Emails_API_NewAdmin( $selected_email_name , $init_fields_values ); |
| 524 |
} |
| 525 |
|
| 526 |
return $this->email_settings_api; |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
public function in_page() { // P a g e t a g |
| 531 |
// if ( |
| 532 |
// ( ! wpbc_is_mu_user_can_be_here( 'only_super_admin' ) ) |
| 533 |
// && ( ! wpbc_is_current_user_have_this_role('contributor') ) |
| 534 |
// ){ // If this User not "super admin", then do not load this page at all |
| 535 |
// return (string) wp_rand(100000, 1000000); |
| 536 |
// } |
| 537 |
|
| 538 |
return 'wpbc-settings'; |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
public function tabs() { // T a b s A r r a y |
| 543 |
|
| 544 |
$tabs = array(); |
| 545 |
|
| 546 |
$tabs[ 'email' ] = array( |
| 547 |
'title' => __( 'Emails', 'booking') // Title of TAB |
| 548 |
, 'page_title'=> __( 'Emails Settings', 'booking') // Title of Page |
| 549 |
, 'hint' => __( 'Set up automatic email notifications for different booking actions.', 'booking') // Hint |
| 550 |
//, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link |
| 551 |
//, 'position' => '' // 'left' || 'right' || '' |
| 552 |
//, 'css_classes'=> '' // CSS class(es) |
| 553 |
//, 'icon' => '' // Icon - link to the real PNG img |
| 554 |
, 'font_icon' => 'wpbc-bi-envelope-at 0wpbc_icn_mail_outline' // CSS definition of forn Icon |
| 555 |
//, 'default' => false // Is this tab activated by default or not: true || false. |
| 556 |
//, 'disabled' => false // Is this tab disbaled: true || false. |
| 557 |
//, 'hided' => false // Is this tab hided: true || false. |
| 558 |
, 'subtabs' => array() |
| 559 |
); |
| 560 |
|
| 561 |
$subtabs = array(); |
| 562 |
|
| 563 |
|
| 564 |
$is_data_exist = get_bk_option( WPBC_EMAIL_NEW_ADMIN_PREFIX . WPBC_EMAIL_NEW_ADMIN_ID ); // ''booking_email_' - defined in api-emails.php file. |
| 565 |
|
| 566 |
$subtabs['new-admin'] = array( |
| 567 |
'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 568 |
, 'title' => __('New Booking' ,'booking') . ' (' . __('admin' ,'booking') . ')' // Title of TAB |
| 569 |
, 'page_title' => __('Emails Settings', 'booking') . ' - <span>' . esc_html( __('New Booking' ,'booking') . ' - ' . ucfirst( __('admin' ,'booking') ) ) . '</span>' // Title of Page. |
| 570 |
, 'hint' => __( 'Set up automatic email notification about new booking for Administrator', 'booking') // Hint |
| 571 |
, 'link' => '' // link |
| 572 |
, 'position' => '' // 'left' || 'right' || '' |
| 573 |
, 'css_classes' => '' // CSS class(es) |
| 574 |
//, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img |
| 575 |
//, 'font_icon' => 'wpbc_icn_mail_outline' // CSS definition of Font Icon |
| 576 |
, 'default' => true // Is this sub tab activated by default or not: true || false. |
| 577 |
, 'disabled' => false // Is this sub tab deactivated: true || false. |
| 578 |
, 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' ) |
| 579 |
, 'content' => 'content' // Function to load as conten of this TAB |
| 580 |
, 'font_icon' => 'wpbc-bi-envelope-paper 0wpbc_icn_mark_email_unread' |
| 581 |
, 'show_checked_icon' => true |
| 582 |
, 'checked_data' => WPBC_EMAIL_NEW_ADMIN_PREFIX . WPBC_EMAIL_NEW_ADMIN_ID // This is where we get content |
| 583 |
//, 'hint' => array( 'title' => __('Customization of email template, which is sending to Admin after new booking' ,'booking') , 'position' => 'right' ) |
| 584 |
); |
| 585 |
|
| 586 |
$tabs[ 'email' ]['subtabs'] = $subtabs; |
| 587 |
|
| 588 |
return $tabs; |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
/** Show Content of Settings page */ |
| 593 |
public function content() { |
| 594 |
$this->css(); |
| 595 |
|
| 596 |
// ------------------------------------------------------------------------------------------------------------- |
| 597 |
// Checking |
| 598 |
// ------------------------------------------------------------------------------------------------------------- |
| 599 |
do_action( 'wpbc_hook_settings_page_header', 'emails_settings'); // Define Notices Section and show some static messages, if needed |
| 600 |
|
| 601 |
if ( ! wpbc_is_mu_user_can_be_here('activated_user') ) return false; // Check if MU user activated, otherwise show Warning message. |
| 602 |
// 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. |
| 603 |
|
| 604 |
|
| 605 |
// ------------------------------------------------------------------------------------------------------------- |
| 606 |
// S u b m i t Main Form |
| 607 |
// ------------------------------------------------------------------------------------------------------------- |
| 608 |
$submit_form_name = 'wpbc_emails_template'; // Define form name |
| 609 |
// $this->maybe_update(); // It is run from parent CLASS before showing this content on Actual Selected by user Page |
| 610 |
|
| 611 |
|
| 612 |
//////////////////////////////////////////////////////////////////////// |
| 613 |
// JavaScript: Tooltips, Popover, Datepick (js & css) |
| 614 |
//////////////////////////////////////////////////////////////////////// |
| 615 |
|
| 616 |
echo '<span class="wpdevelop">'; |
| 617 |
|
| 618 |
wpbc_js_for_bookings_page(); |
| 619 |
|
| 620 |
echo '</span>'; |
| 621 |
|
| 622 |
|
| 623 |
//////////////////////////////////////////////////////////////////////// |
| 624 |
// Content |
| 625 |
//////////////////////////////////////////////////////////////////////// |
| 626 |
?> |
| 627 |
<div class="clear"></div> |
| 628 |
|
| 629 |
<span class="metabox-holder"> |
| 630 |
|
| 631 |
<form name="<?php echo esc_attr( $submit_form_name ); ?>" id="<?php echo esc_attr( $submit_form_name ); ?>" action="" method="post" autocomplete="off"> |
| 632 |
<?php |
| 633 |
// N o n c e field, and key for checking S u b m i t |
| 634 |
wp_nonce_field( 'wpbc_settings_page_' . $submit_form_name ); |
| 635 |
?><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" /> |
| 636 |
|
| 637 |
<div class="clear"></div> |
| 638 |
<?php |
| 639 |
|
| 640 |
wpbc_email_troubleshooting_help_notice(); |
| 641 |
|
| 642 |
?> |
| 643 |
<div class="metabox-holder"> |
| 644 |
<?php |
| 645 |
wpbc_open_meta_box_section( $submit_form_name . 'general', __('Email is sending to Admin after creation of booking.', 'booking') ); //FixIn: 8.1.2.17.1 |
| 646 |
|
| 647 |
$this->mail_api()->show( 'general' ); |
| 648 |
|
| 649 |
wpbc_close_meta_box_section(); |
| 650 |
?> |
| 651 |
<div class="wpbc_settings_row wpbc_settings_row_left" > |
| 652 |
<?php |
| 653 |
wpbc_open_meta_box_section( $submit_form_name . 'general_content', __('Email Content', 'booking') ); //FixIn: 8.1.2.17.1 |
| 654 |
|
| 655 |
$this->mail_api()->show( 'general_content' ); |
| 656 |
|
| 657 |
wpbc_close_meta_box_section(); |
| 658 |
?> |
| 659 |
</div> |
| 660 |
|
| 661 |
<div class="wpbc_settings_row wpbc_settings_row_right"> |
| 662 |
<?php |
| 663 |
wpbc_open_meta_box_section( $submit_form_name . 'help', __('Help', 'booking') ); |
| 664 |
|
| 665 |
$this->mail_api()->show( 'help' ); |
| 666 |
|
| 667 |
wpbc_close_meta_box_section(); |
| 668 |
?> |
| 669 |
</div> |
| 670 |
<div class="clear"></div> |
| 671 |
<?php |
| 672 |
wpbc_open_meta_box_section( $submit_form_name . 'email_content_type', __('Email Type', 'booking') . ' / ' . __('Email Styles', 'booking') ); |
| 673 |
|
| 674 |
$this->mail_api()->show( 'email_content_type' ); |
| 675 |
|
| 676 |
$this->mail_api()->show( 'style' ); |
| 677 |
|
| 678 |
wpbc_close_meta_box_section(); |
| 679 |
|
| 680 |
wpbc_open_meta_box_section( $submit_form_name . 'parts' , __('Header / Footer', 'booking') ); |
| 681 |
|
| 682 |
$this->mail_api()->show( 'parts' ); |
| 683 |
|
| 684 |
wpbc_close_meta_box_section(); |
| 685 |
?> |
| 686 |
</div> |
| 687 |
<input type="submit" value="<?php echo esc_attr( __( 'Save Changes', 'booking' ) ); ?>" class="button button-primary" /> |
| 688 |
</form> |
| 689 |
</span> |
| 690 |
<?php |
| 691 |
|
| 692 |
$this->enqueue_js(); |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
/** |
| 697 |
* This function called from PARENT CLASS for actual selected tab. Firstly it load data and then Maybe Save changes. |
| 698 |
* @return void |
| 699 |
*/ |
| 700 |
public function maybe_update() { |
| 701 |
|
| 702 |
// ------------------------------------------------------------------------------------------------------------- |
| 703 |
// Load Data |
| 704 |
// ------------------------------------------------------------------------------------------------------------- |
| 705 |
|
| 706 |
/* Check if New Email Template Exist or NOT |
| 707 |
* Exist - return empty array in format: array( OPTION_NAME => array() ) |
| 708 |
* It will load DATA from DB, during creation mail_api CLASS |
| 709 |
* during initial activation of the API its try to get option from DB |
| 710 |
* We need to define this API before checking POST, to know all available fields |
| 711 |
* Define Email Name & define field values from DB, if not exist, then default values. |
| 712 |
* Not Exist - import Old Data from DB |
| 713 |
* or get "default" data from settings and return array with this data |
| 714 |
* This data its initial parameters for definition fields in mail_api CLASS |
| 715 |
* |
| 716 |
*/ |
| 717 |
|
| 718 |
$init_fields_values = wpbc_import6_email__new_admin__get_fields_array_for_activation(); |
| 719 |
|
| 720 |
// 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 |
| 721 |
$init_fields_values_temp = array_values( $init_fields_values ); // FixIn: 7.0.1.32. |
| 722 |
$init_fields_values = array_shift( $init_fields_values_temp ); |
| 723 |
|
| 724 |
|
| 725 |
$this->mail_api( WPBC_EMAIL_NEW_ADMIN_ID, $init_fields_values ); |
| 726 |
|
| 727 |
// ------------------------------------------------------------------------------------------------------------- |
| 728 |
// Maybe Update Data |
| 729 |
// ------------------------------------------------------------------------------------------------------------- |
| 730 |
|
| 731 |
$submit_form_name = 'wpbc_emails_template'; // Define form name |
| 732 |
|
| 733 |
$this->mail_api()->validated_form_id = $submit_form_name; // Define ID of Form for ability to validate fields before submit. |
| 734 |
|
| 735 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 736 |
if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) { |
| 737 |
|
| 738 |
// Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. } |
| 739 |
$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 |
| 740 |
|
| 741 |
// Save Changes |
| 742 |
$this->update(); |
| 743 |
} |
| 744 |
} |
| 745 |
|
| 746 |
|
| 747 |
/** Update Email template to DB */ |
| 748 |
public function update() { |
| 749 |
|
| 750 |
// Get Validated Email fields |
| 751 |
$validated_fields = $this->mail_api()->validate_post(); |
| 752 |
|
| 753 |
$this->mail_api()->save_to_db( $validated_fields ); |
| 754 |
|
| 755 |
wpbc_show_message ( __('Settings saved.', 'booking'), 5 ); // Show Save message |
| 756 |
} |
| 757 |
|
| 758 |
// <editor-fold defaultstate="collapsed" desc=" CSS & JS " > |
| 759 |
|
| 760 |
/** CSS for this page */ |
| 761 |
private function css() { |
| 762 |
?> |
| 763 |
<style type="text/css"> |
| 764 |
.wpbc-help-message { |
| 765 |
border:none; |
| 766 |
margin:0 !important; |
| 767 |
padding:0 !important; |
| 768 |
} |
| 769 |
|
| 770 |
@media (max-width: 399px) { |
| 771 |
} |
| 772 |
</style> |
| 773 |
<?php |
| 774 |
} |
| 775 |
|
| 776 |
|
| 777 |
/** |
| 778 |
* Add Custon JavaScript - for some specific settings options |
| 779 |
* Executed After post content, after initial definition of settings, and possible definition after POST request. |
| 780 |
* |
| 781 |
* @param type $menu_slug |
| 782 |
* |
| 783 |
*/ |
| 784 |
private function enqueue_js(){ // $page_tag, $active_page_tab, $active_page_subtab ) { |
| 785 |
$js_script = ''; |
| 786 |
//Show or hide colors section in settings page depend form selected email template. |
| 787 |
$js_script .= " jQuery('select[name=\"new_admin_template_file\"]').on( 'change', function(){ |
| 788 |
if ( jQuery('select[name=\"new_admin_template_file\"] option:selected').val() == 'plain' ) { |
| 789 |
jQuery('.template_colors').hide(); |
| 790 |
} else { |
| 791 |
jQuery('.template_colors').show(); |
| 792 |
} |
| 793 |
} ); "; |
| 794 |
$js_script .= "\n"; //New Line |
| 795 |
$js_script .= " if ( jQuery('select[name=\"new_admin_template_file\"] option:selected').val() == 'plain' ) { |
| 796 |
jQuery('.template_colors').hide(); |
| 797 |
} "; |
| 798 |
|
| 799 |
// Show Warning messages if Title (optional) is empty - title of email will be "WordPress |
| 800 |
$js_script .= " jQuery(document).ready(function(){ "; |
| 801 |
$js_script .= " if ( jQuery('#new_admin_to_name').val() == '' ) {"; |
| 802 |
$js_script .= " jQuery('#new_admin_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>')"; |
| 803 |
$js_script .= " }"; |
| 804 |
$js_script .= " if ( jQuery('#new_admin_from_name').val() == '' ) {"; |
| 805 |
$js_script .= " jQuery('#new_admin_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>')"; |
| 806 |
$js_script .= " }"; |
| 807 |
$js_script .= " }); "; |
| 808 |
|
| 809 |
// Eneque JS to the footer of the page |
| 810 |
wpbc_enqueue_js( $js_script ); |
| 811 |
} |
| 812 |
|
| 813 |
// </editor-fold> |
| 814 |
} |
| 815 |
add_action('wpbc_menu_created', array( new WPBC_Settings_Page_Email_NewAdmin() , '__construct') ); // Executed after creation of Menu |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
// <editor-fold defaultstate="collapsed" desc=" Emails Sending After New Booking " > |
| 820 |
|
| 821 |
/** |
| 822 |
* Get ShortCodes to Replace |
| 823 |
* |
| 824 |
* @param int $booking_id - ID of booking |
| 825 |
* @param int $bktype - booking resource type |
| 826 |
* @param string $formdata - booking form data content |
| 827 |
*/ |
| 828 |
function wpbc__get_replace_shortcodes__email_new_admin( $booking_id, $bktype, $formdata ) { |
| 829 |
|
| 830 |
$replace = array(); |
| 831 |
|
| 832 |
// Resources /////////////////////////////////////////////////////////////// |
| 833 |
$bk_title = wpbc_get_resource_title( $bktype ); |
| 834 |
$parent_resource_title = wpbc_get_parent_resource_title( $bktype ); // FixIn: 10.9.2.4. |
| 835 |
|
| 836 |
// FixIn: 9.6.3.10. |
| 837 |
if ( class_exists( 'wpdev_bk_biz_l' ) ) { |
| 838 |
$booking_data_arr = wpbc_api_get_booking_by_id( $booking_id ); |
| 839 |
|
| 840 |
$child_resource_id = (int) $booking_data_arr['booking_type']; |
| 841 |
|
| 842 |
$bk_title = wpbc_get_resource_title( $child_resource_id ); |
| 843 |
} |
| 844 |
|
| 845 |
// Dates /////////////////////////////////////////////////////////////////// |
| 846 |
$my_dates4emeil = wpbc_db__get_sql_dates__in_booking__as_str( $booking_id ); |
| 847 |
|
| 848 |
$my_dates_4_send = ( 'short' === get_bk_option( 'booking_date_view_type' ) ) |
| 849 |
? wpbc_get_dates_short_format( $my_dates4emeil ) |
| 850 |
: wpbc_get_dates_comma_string_localized( $my_dates4emeil ); |
| 851 |
$my_dates4emeil_check_in_out = explode( ',', $my_dates4emeil ); |
| 852 |
|
| 853 |
$my_check_in_date = wpbc_get_dates_comma_string_localized( $my_dates4emeil_check_in_out[0] ); |
| 854 |
$my_check_out_date = wpbc_get_dates_comma_string_localized( $my_dates4emeil_check_in_out[ count( $my_dates4emeil_check_in_out ) - 1 ] ); |
| 855 |
$my_check_in_onlydate_ymd = wpbc_date_localized( gmdate( 'Y-m-d 00:00:00', strtotime( $my_dates4emeil_check_in_out[0] ) ), 'Y-m-d' ); // FixIn: 8.7.2.5. |
| 856 |
$my_check_out_onlydate_ymd = wpbc_date_localized( gmdate( 'Y-m-d 00:00:00', strtotime( $my_dates4emeil_check_in_out[ count( $my_dates4emeil_check_in_out ) - 1 ] ) ), 'Y-m-d' ); |
| 857 |
$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. |
| 858 |
$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' ) ); |
| 859 |
$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' ) ); |
| 860 |
|
| 861 |
// FixIn: 10.1.5.6. |
| 862 |
$dates_only_arr = wpbc_get_only_dates__from_dates_ymd_his_csv__as_arr( $my_dates4emeil ); // -> '2023-10-09, 2023-10-09' |
| 863 |
$dates_only_str = implode( ',', $dates_only_arr ); |
| 864 |
$dates_only_str_formatted = ( 'short' === get_bk_option( 'booking_date_view_type' ) ) |
| 865 |
? wpbc_get_dates_short_format( $dates_only_str ) |
| 866 |
: wpbc_get_dates_comma_string_localized( $dates_only_str ); |
| 867 |
|
| 868 |
// Cost //////////////////////////////////////////////////////////////////// |
| 869 |
$booking_cost_digits_only = apply_bk_filter( 'get_booking_cost_from_db', '', $booking_id ); // FixIn: 9.2.3.1. |
| 870 |
$booking_cost = wpbc_get_cost_with_currency_for_user( $booking_cost_digits_only ); |
| 871 |
// Other /////////////////////////////////////////////////////////////////// |
| 872 |
$replace[ 'booking_id' ] = $booking_id; |
| 873 |
$replace[ 'id' ] = $replace[ 'booking_id' ]; |
| 874 |
$replace[ 'dates' ] = $my_dates_4_send; |
| 875 |
$replace[ 'only_dates' ] = $dates_only_str_formatted; |
| 876 |
$replace[ 'dates_only' ] = $dates_only_str_formatted; |
| 877 |
$replace[ 'check_in_date' ] = $my_check_in_date; |
| 878 |
$replace[ 'check_out_date' ] = $my_check_out_date; |
| 879 |
// FixIn: 8.7.2.5. |
| 880 |
$replace[ 'check_in_only_date' ] = $my_check_in_onlydate; |
| 881 |
$replace[ 'check_out_only_date' ] = $my_check_out_onlydate; |
| 882 |
$replace[ 'check_out_plus1day'] = $my_check_out_plus1day; // FixIn: 6.0.1.11. |
| 883 |
|
| 884 |
$replace['dates_count'] = count( $my_dates4emeil_check_in_out ); |
| 885 |
$replace['days_count'] = intval( $replace['dates_count'] ); // FixIn: 10.15.1.3. |
| 886 |
$replace['nights_count'] = ( $replace['days_count'] > 1 ) ? intval( $replace['days_count'] - 1 ) : 1; |
| 887 |
$replace['days_count_plus1day'] = intval( $replace['days_count'] + 1 ); |
| 888 |
|
| 889 |
$replace['cost'] = $booking_cost; |
| 890 |
$replace['cost_digits_only'] = $booking_cost_digits_only; |
| 891 |
$replace[ 'siteurl' ] = htmlspecialchars_decode( '<a href="' . esc_url( home_url() ) . '">' . home_url() . '</a>' ); |
| 892 |
$replace[ 'resource_title'] = wpbc_lang( $bk_title ); |
| 893 |
$replace[ 'parent_resource_title'] = wpbc_lang( $parent_resource_title ); // FixIn: 10.9.2.4. |
| 894 |
$replace[ 'bookingtype' ] = $replace[ 'resource_title']; |
| 895 |
$replace[ 'remote_ip' ] = wpbc_get_user_ip(); //FixIn:7.1.2.4 // The IP address from which the user is viewing the current page. |
| 896 |
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 897 |
$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. |
| 898 |
$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 */ |
| 899 |
$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 |
| 900 |
$replace[ 'current_date' ] = date_i18n( get_bk_option( 'booking_date_format' ) ); |
| 901 |
$replace[ 'current_time' ] = date_i18n( get_bk_option( 'booking_time_format' ) ); |
| 902 |
|
| 903 |
// Form Fields ///////////////////////////////////////////////////////////// |
| 904 |
$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 |
| 905 |
|
| 906 |
foreach ( $booking_form_show_array['_all_fields_'] as $shortcode_name => $shortcode_value ) { |
| 907 |
|
| 908 |
if ( ! isset( $replace[ $shortcode_name ] ) ) |
| 909 |
$replace[ $shortcode_name ] = $shortcode_value; |
| 910 |
} |
| 911 |
$replace[ 'content' ] = $booking_form_show_array['content']; |
| 912 |
|
| 913 |
// Links /////////////////////////////////////////////////////////////////// |
| 914 |
$replace[ 'moderatelink' ] = htmlspecialchars_decode( |
| 915 |
// '<a href="' . |
| 916 |
esc_url( wpbc_get_bookings_url() . '&tab=vm_booking_listing&wh_booking_id=' . $booking_id ) |
| 917 |
// . '">' . esc_html__('here', 'booking') . '</a>' |
| 918 |
); |
| 919 |
|
| 920 |
if ( function_exists( 'wpbc_get_url_click2approve' ) ) { |
| 921 |
$replace['click2approve'] = wpbc_get_url_click2approve( $booking_id ); // FixIn: 8.4.7.25. |
| 922 |
$replace['click2decline'] = wpbc_get_url_click2decline( $booking_id ); // FixIn: 8.4.7.25. |
| 923 |
$replace['click2trash'] = wpbc_get_url_click2trash( $booking_id ); // FixIn: 8.4.7.25. |
| 924 |
} |
| 925 |
|
| 926 |
$replace[ 'visitorbookingediturl' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingediturl]', $booking_id ); |
| 927 |
$replace[ 'visitorbookingslisting' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingslisting]', $booking_id ); //FixIn: 8.1.3.5.1 |
| 928 |
$replace[ 'visitorbookingcancelurl' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingcancelurl]', $booking_id ); |
| 929 |
$replace[ 'visitorbookingpayurl' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[visitorbookingpayurl]', $booking_id ); |
| 930 |
$replace[ 'bookinghash' ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '[bookinghash]', $booking_id ); |
| 931 |
|
| 932 |
|
| 933 |
// FixIn: 7.1.2.5. |
| 934 |
// $booking_data = array( 'form_data' => $booking_form_show_array ); |
| 935 |
// $booking_data[ 'dates_short' ] = array( $my_dates4emeil_check_in_out[ 0 ], '-', $my_dates4emeil_check_in_out[ count( $my_dates4emeil_check_in_out ) - 1 ] ); |
| 936 |
// $replace[ 'add_to_google_cal_url' ] = htmlspecialchars_decode( esc_url( |
| 937 |
// wpbc_btn_add_booking_to_google_calendar( $booking_data , array( 'is_only_url' => true ), false ) |
| 938 |
// ) ); |
| 939 |
// FixIn: 9.6.3.8. |
| 940 |
$google_calendar_link = wpbc_booking_do_action__get_google_calendar_link( array( |
| 941 |
'form_data' => $booking_form_show_array['_all_fields_'], |
| 942 |
'form_show' => $booking_form_show_array['content'], //wp_strip_all_tags( $parsed_form_show ), |
| 943 |
'dates_short' => array( |
| 944 |
$my_dates4emeil_check_in_out[0] |
| 945 |
, '-' |
| 946 |
, $my_dates4emeil_check_in_out[ count( $my_dates4emeil_check_in_out ) - 1 ] |
| 947 |
) |
| 948 |
) ); |
| 949 |
$replace['add_to_google_cal_url'] = htmlspecialchars_decode( esc_url( $google_calendar_link ) ); |
| 950 |
$replace['add_to_google_cal_button'] = '<a href="' . esc_attr( $replace['add_to_google_cal_url'] ) . '" target="_blank" rel="nofollow">' . esc_attr__( 'Add to Google Calendar', 'booking' ) . '</a>'; |
| 951 |
|
| 952 |
|
| 953 |
// Get additional replace paramaters to the email shortcodes |
| 954 |
$replace = apply_filters( 'wpbc_replace_params_for_booking', $replace, $booking_id, $bktype, $formdata ); // FixIn: 8.0.1.7. |
| 955 |
|
| 956 |
// ----------------------------------------------------------------------------------------------------------------- |
| 957 |
return $replace; |
| 958 |
|
| 959 |
|
| 960 |
} |
| 961 |
|
| 962 |
|
| 963 |
/** |
| 964 |
* Send email about New Booking to Admin |
| 965 |
* |
| 966 |
* @param type $booking_id - ID of booking |
| 967 |
* @param type $bktype - type |
| 968 |
* @param type $formdata - booking form data |
| 969 |
*/ |
| 970 |
function wpbc_send_email_new_admin( $booking_id, $bktype, $formdata ) { // function wpbc_send_email_new() - Old |
| 971 |
|
| 972 |
$previous_active_user = apply_bk_filter( 'wpbc_mu_set_environment_for_owner_of_resource', -1, $bktype ); // MU |
| 973 |
|
| 974 |
//////////////////////////////////////////////////////////////////////// |
| 975 |
// Load Data |
| 976 |
//////////////////////////////////////////////////////////////////////// |
| 977 |
|
| 978 |
/* Check if New Email Template Exist or NOT |
| 979 |
* Exist - return empty array in format: array( OPTION_NAME => array() ) |
| 980 |
* Its will load DATA from DB, during creattion mail_api CLASS |
| 981 |
* during initial activation of the API its try to get option from DB |
| 982 |
* We need to define this API before checking POST, to know all available fields |
| 983 |
* Define Email Name & define field values from DB, if not exist, then default values. |
| 984 |
* Not Exist - import Old Data from DB |
| 985 |
* or get "default" data from settings and return array with this data |
| 986 |
* This data its initial parameters for definition fields in mail_api CLASS |
| 987 |
* |
| 988 |
*/ |
| 989 |
|
| 990 |
$init_fields_values = wpbc_import6_email__new_admin__get_fields_array_for_activation(); |
| 991 |
|
| 992 |
// 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 |
| 993 |
$init_fields_values_temp = array_values( $init_fields_values ); // FixIn: 7.0.1.32. |
| 994 |
$init_fields_values = array_shift( $init_fields_values_temp ); |
| 995 |
|
| 996 |
|
| 997 |
$mail_api = new WPBC_Emails_API_NewAdmin( WPBC_EMAIL_NEW_ADMIN_ID, $init_fields_values ); |
| 998 |
|
| 999 |
// ----------------------------------------------------------------------------------------------------------------- |
| 1000 |
if ( $mail_api->fields_values['enabled'] == 'Off' ) return false; // Email template deactivated - exit. |
| 1001 |
|
| 1002 |
|
| 1003 |
$replace = wpbc__get_replace_shortcodes__email_new_admin( $booking_id, $bktype, $formdata ); |
| 1004 |
|
| 1005 |
// Replace shortcodes with custom URL parameter, like: 'visitorbookingediturl', 'visitorbookingcancelurl', 'visitorbookingpayurl' |
| 1006 |
foreach ( array( 'visitorbookingediturl', 'visitorbookingcancelurl', 'visitorbookingpayurl' , 'visitorbookingslisting' ) as $url_shortcode ) { //FixIn: 7.0.1.8 //FixIn: 8.1.3.5.1 |
| 1007 |
|
| 1008 |
// Loop to search if we are having several such shortcodes in our $mail_api->fields_values['content'] (For example, if we have several languges ). |
| 1009 |
$pos = 0; //FixIn: 7.0.1.52 |
| 1010 |
do { |
| 1011 |
$shortcode_params = wpbc_get_params_of_shortcode_in_string( $url_shortcode, $mail_api->fields_values['content'] , $pos ); |
| 1012 |
|
| 1013 |
if ( ( ! empty( $shortcode_params ) ) && ( isset( $shortcode_params['url'] ) ) ){ |
| 1014 |
|
| 1015 |
$pos = $shortcode_params['end']; |
| 1016 |
|
| 1017 |
$exist_replace = substr( $mail_api->fields_values['content'], $shortcode_params['start'], ( $shortcode_params['end'] - $shortcode_params['start'] ) ); |
| 1018 |
|
| 1019 |
$new_replace = $url_shortcode . wp_rand(1000,9000); |
| 1020 |
|
| 1021 |
$pos = $shortcode_params['start'] + strlen( $new_replace ); //FixIn: 9.7.3.5.1 |
| 1022 |
$mail_api->fields_values['content'] = str_replace( $exist_replace, $new_replace ,$mail_api->fields_values['content'] ); |
| 1023 |
|
| 1024 |
$replace[ $new_replace ] = apply_bk_filter( 'wpdev_booking_set_booking_edit_link_at_email', '['.$exist_replace.']', $booking_id ); |
| 1025 |
} else if ( // FixIn: 8.1.1.8. |
| 1026 |
( ! empty( $shortcode_params ) ) |
| 1027 |
&& ( isset( $shortcode_params['end'] ) ) |
| 1028 |
&& ( $shortcode_params['end'] < strlen( $mail_api->fields_values['content'] ) ) |
| 1029 |
) { |
| 1030 |
$pos = $shortcode_params['end']; |
| 1031 |
} else { |
| 1032 |
$shortcode_params = false; //FixIn: 7.0.1.58 |
| 1033 |
} |
| 1034 |
|
| 1035 |
} while ( ! empty( $shortcode_params ) ); // FixIn: 7.0.1.52. |
| 1036 |
|
| 1037 |
} |
| 1038 |
|
| 1039 |
$mail_api->set_replace( $replace ); |
| 1040 |
$mail_api->fields_values['from_name'] = $mail_api->replace_shortcodes( $mail_api->fields_values['from_name'] ); // FixIn: 7.0.1.29. |
| 1041 |
|
| 1042 |
$email_result = false; |
| 1043 |
|
| 1044 |
// ------------------------------------------------------------------------------------------------------------- |
| 1045 |
// Case #1. Semicolon => send SEPARATE emails. |
| 1046 |
// Example: |
| 1047 |
// to = admin1@example.com;admin2@example.com |
| 1048 |
// to_name = Admin One;Admin Two |
| 1049 |
// |
| 1050 |
// Also supported: |
| 1051 |
// to = admin1@example.com,sales@example.com;support@example.com |
| 1052 |
// to_name = Admin One,Sales Team;Support Team |
| 1053 |
// => first email sent to 2 recipients, second email sent separately. |
| 1054 |
// ------------------------------------------------------------------------------------------------------------- |
| 1055 |
if ( strpos( $mail_api->fields_values['to'], ';' ) !== false ) { |
| 1056 |
|
| 1057 |
$to_groups = explode( ';', $mail_api->fields_values['to'] ); |
| 1058 |
$to_name_groups = explode( ';', $mail_api->fields_values['to_name'] ); |
| 1059 |
|
| 1060 |
$email_result = true; |
| 1061 |
$sent_emails = 0; |
| 1062 |
|
| 1063 |
foreach ( $to_groups as $group_ind => $to_group ) { |
| 1064 |
|
| 1065 |
$to_group = trim( $to_group ); |
| 1066 |
if ( '' === $to_group ) { |
| 1067 |
continue; |
| 1068 |
} |
| 1069 |
|
| 1070 |
$to_name_group = ''; |
| 1071 |
if ( ! empty( $to_name_groups ) ) { |
| 1072 |
$to_name_group = $to_name_groups[ count( $to_name_groups ) - 1 ]; |
| 1073 |
if ( isset( $to_name_groups[ $group_ind ] ) ) { |
| 1074 |
$to_name_group = $to_name_groups[ $group_ind ]; |
| 1075 |
} |
| 1076 |
} |
| 1077 |
|
| 1078 |
// One recipient in this group. |
| 1079 |
if ( strpos( $to_group, ',' ) === false ) { |
| 1080 |
|
| 1081 |
$valid_email = sanitize_email( $to_group ); |
| 1082 |
|
| 1083 |
if ( empty( $valid_email ) ) { |
| 1084 |
continue; |
| 1085 |
} |
| 1086 |
|
| 1087 |
$to = trim( |
| 1088 |
wp_specialchars_decode( |
| 1089 |
esc_html( stripslashes( $to_name_group ) ), |
| 1090 |
ENT_QUOTES |
| 1091 |
) |
| 1092 |
) . ' <' . $valid_email . '> '; |
| 1093 |
|
| 1094 |
// Several recipients in this group => send one email to this comma-separated group. |
| 1095 |
} else { |
| 1096 |
|
| 1097 |
$to_array = explode( ',', $to_group ); |
| 1098 |
$to_name = explode( ',', $to_name_group ); |
| 1099 |
|
| 1100 |
$to = array(); |
| 1101 |
|
| 1102 |
foreach ( $to_array as $to_ind => $to_email ) { |
| 1103 |
|
| 1104 |
$to_name_str = ''; |
| 1105 |
if ( ! empty( $to_name ) ) { |
| 1106 |
$to_name_str = $to_name[ count( $to_name ) - 1 ]; |
| 1107 |
if ( isset( $to_name[ $to_ind ] ) ) { |
| 1108 |
$to_name_str = $to_name[ $to_ind ]; |
| 1109 |
} |
| 1110 |
} |
| 1111 |
|
| 1112 |
$valid_email = sanitize_email( $to_email ); |
| 1113 |
if ( ! empty( $valid_email ) ) { |
| 1114 |
$to[] = trim( |
| 1115 |
wp_specialchars_decode( |
| 1116 |
esc_html( stripslashes( $to_name_str ) ), |
| 1117 |
ENT_QUOTES |
| 1118 |
) |
| 1119 |
) . ' <' . $valid_email . '> '; |
| 1120 |
} |
| 1121 |
} |
| 1122 |
|
| 1123 |
$to = implode( ',', $to ); |
| 1124 |
} |
| 1125 |
|
| 1126 |
if ( wpbc_is_not_blank_email( $to, $replace['content'] ) ) { |
| 1127 |
$single_result = $mail_api->send( $to, $replace ); |
| 1128 |
$email_result = ( $email_result && (bool) $single_result ); |
| 1129 |
$sent_emails++; |
| 1130 |
} |
| 1131 |
} |
| 1132 |
|
| 1133 |
if ( 0 === $sent_emails ) { |
| 1134 |
$email_result = false; |
| 1135 |
} |
| 1136 |
|
| 1137 |
// ------------------------------------------------------------------------------------------------------------- |
| 1138 |
// Case #2. No semicolon => keep old behavior. |
| 1139 |
// Single email OR one email to several comma-separated recipients. |
| 1140 |
// ------------------------------------------------------------------------------------------------------------- |
| 1141 |
} else { |
| 1142 |
|
| 1143 |
if ( strpos( $mail_api->fields_values['to'], ',' ) === false ) { |
| 1144 |
|
| 1145 |
$valid_email = sanitize_email( $mail_api->fields_values['to'] ); |
| 1146 |
|
| 1147 |
if ( ! empty( $valid_email ) ) { |
| 1148 |
$to = trim( |
| 1149 |
wp_specialchars_decode( |
| 1150 |
esc_html( stripslashes( $mail_api->fields_values['to_name'] ) ), |
| 1151 |
ENT_QUOTES |
| 1152 |
) |
| 1153 |
) . ' <' . $valid_email . '> '; |
| 1154 |
} else { |
| 1155 |
$to = ''; |
| 1156 |
} |
| 1157 |
|
| 1158 |
} else { |
| 1159 |
|
| 1160 |
$to_array = $mail_api->fields_values['to']; |
| 1161 |
if ( ! is_array( $to_array ) ) { |
| 1162 |
$to_array = explode( ',', $to_array ); |
| 1163 |
} |
| 1164 |
|
| 1165 |
$to_name = $mail_api->fields_values['to_name']; |
| 1166 |
if ( ! is_array( $to_name ) ) { |
| 1167 |
$to_name = explode( ',', $to_name ); |
| 1168 |
} |
| 1169 |
|
| 1170 |
$to = array(); |
| 1171 |
|
| 1172 |
foreach ( $to_array as $to_ind => $to_email ) { |
| 1173 |
|
| 1174 |
$to_name_str = ''; |
| 1175 |
if ( ! empty( $to_name ) ) { |
| 1176 |
$to_name_str = $to_name[ count( $to_name ) - 1 ]; |
| 1177 |
if ( isset( $to_name[ $to_ind ] ) ) { |
| 1178 |
$to_name_str = $to_name[ $to_ind ]; |
| 1179 |
} |
| 1180 |
} |
| 1181 |
|
| 1182 |
$valid_email = sanitize_email( $to_email ); |
| 1183 |
if ( ! empty( $valid_email ) ) { |
| 1184 |
$to[] = trim( |
| 1185 |
wp_specialchars_decode( |
| 1186 |
esc_html( stripslashes( $to_name_str ) ), |
| 1187 |
ENT_QUOTES |
| 1188 |
) |
| 1189 |
) . ' <' . $valid_email . '> '; |
| 1190 |
} |
| 1191 |
} |
| 1192 |
|
| 1193 |
$to = implode( ',', $to ); |
| 1194 |
} |
| 1195 |
|
| 1196 |
if ( wpbc_is_not_blank_email( $to, $replace['content'] ) ) { |
| 1197 |
$email_result = $mail_api->send( $to, $replace ); |
| 1198 |
} |
| 1199 |
} |
| 1200 |
|
| 1201 |
make_bk_action( 'wpbc_mu_set_environment_for_user', $previous_active_user ); // MU |
| 1202 |
|
| 1203 |
$email_result = ( isset( $email_result ) ) ? $email_result : false; |
| 1204 |
return $email_result; |
| 1205 |
} |
| 1206 |
|
| 1207 |
// </editor-fold> |