| @@ -28,9 +28,9 @@ | ||
| 28 | 28 | - 'modification' |
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | 31 | |
| 32 | -require_once( WPBC_PLUGIN_DIR . '/core/any/api-emails.php' ); // API | |
| 32 | +require_once WPBC_PLUGIN_DIR . '/core/any/api-emails.php'; // API | |
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | // <editor-fold defaultstate="collapsed" desc=" Import Old Data " > |
| @@ -545,14 +545,14 @@ | ||
| 545 | 545 | |
| 546 | 546 | $tabs[ 'email' ] = array( |
| 547 | 547 | 'title' => __( 'Emails', 'booking') // Title of TAB |
| 548 | 548 | , 'page_title'=> __( 'Emails Settings', 'booking') // Title of Page |
| 549 | - , 'hint' => __( 'Emails Settings', 'booking') // Hint | |
| 549 | + , 'hint' => __( 'Set up automatic email notifications for different booking actions.', 'booking') // Hint | |
| 550 | 550 | //, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link |
| 551 | 551 | //, 'position' => '' // 'left' || 'right' || '' |
| 552 | 552 | //, 'css_classes'=> '' // CSS class(es) |
| 553 | 553 | //, 'icon' => '' // Icon - link to the real PNG img |
| 554 | - , 'font_icon' => 'wpbc_icn_mail_outline' // CSS definition of forn Icon | |
| 554 | + , 'font_icon' => 'wpbc-bi-envelope-at 0wpbc_icn_mail_outline' // CSS definition of forn Icon | |
| 555 | 555 | //, 'default' => false // Is this tab activated by default or not: true || false. |
| 556 | 556 | //, 'disabled' => false // Is this tab disbaled: true || false. |
| 557 | 557 | //, 'hided' => false // Is this tab hided: true || false. |
| 558 | 558 | , 'subtabs' => array() |
| @@ -565,20 +565,20 @@ | ||
| 565 | 565 | |
| 566 | 566 | $subtabs['new-admin'] = array( |
| 567 | 567 | 'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 568 | 568 | , 'title' => __('New Booking' ,'booking') . ' (' . __('admin' ,'booking') . ')' // Title of TAB |
| 569 | - , 'page_title' => __('Emails Settings', 'booking') // Title of Page | |
| 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 | |
| 570 | 571 | , 'link' => '' // link |
| 571 | 572 | , 'position' => '' // 'left' || 'right' || '' |
| 572 | 573 | , 'css_classes' => '' // CSS class(es) |
| 573 | 574 | //, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img |
| 574 | 575 | //, 'font_icon' => 'wpbc_icn_mail_outline' // CSS definition of Font Icon |
| 575 | - , 'header_font_icon' => 'wpbc_icn_mail_outline' // CSS definition of Font Icon // FixIn: 9.6.1.4. | |
| 576 | - , 'default' => true // Is this sub tab activated by default or not: true || false. | |
| 576 | + , 'default' => true // Is this sub tab activated by default or not: true || false. | |
| 577 | 577 | , 'disabled' => false // Is this sub tab deactivated: true || false. |
| 578 | 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 | 579 | , 'content' => 'content' // Function to load as conten of this TAB |
| 580 | - , 'is_use_left_navigation' => true | |
| 580 | + , 'font_icon' => 'wpbc-bi-envelope-paper 0wpbc_icn_mark_email_unread' | |
| 581 | 581 | , 'show_checked_icon' => true |
| 582 | 582 | , 'checked_data' => WPBC_EMAIL_NEW_ADMIN_PREFIX . WPBC_EMAIL_NEW_ADMIN_ID // This is where we get content |
| 583 | 583 | //, 'hint' => array( 'title' => __('Customization of email template, which is sending to Admin after new booking' ,'booking') , 'position' => 'right' ) |
| 584 | 584 | ); |
| @@ -879,9 +879,14 @@ | ||
| 879 | 879 | // FixIn: 8.7.2.5. |
| 880 | 880 | $replace[ 'check_in_only_date' ] = $my_check_in_onlydate; |
| 881 | 881 | $replace[ 'check_out_only_date' ] = $my_check_out_onlydate; |
| 882 | 882 | $replace[ 'check_out_plus1day'] = $my_check_out_plus1day; // FixIn: 6.0.1.11. |
| 883 | - $replace[ 'dates_count' ] = count( $my_dates4emeil_check_in_out ); | |
| 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 | + | |
| 884 | 889 | $replace['cost'] = $booking_cost; |
| 885 | 890 | $replace['cost_digits_only'] = $booking_cost_digits_only; |
| 886 | 891 | $replace[ 'siteurl' ] = htmlspecialchars_decode( '<a href="' . esc_url( home_url() ) . '">' . home_url() . '</a>' ); |
| 887 | 892 | $replace[ 'resource_title'] = wpbc_lang( $bk_title ); |
| @@ -907,9 +912,9 @@ | ||
| 907 | 912 | |
| 908 | 913 | // Links /////////////////////////////////////////////////////////////////// |
| 909 | 914 | $replace[ 'moderatelink' ] = htmlspecialchars_decode( |
| 910 | 915 | // '<a href="' . |
| 911 | - esc_url( wpbc_get_bookings_url() . '&view_mode=vm_listing&tab=actions&wh_booking_id=' . $booking_id ) | |
| 916 | + esc_url( wpbc_get_bookings_url() . '&tab=vm_booking_listing&wh_booking_id=' . $booking_id ) | |
| 912 | 917 | // . '">' . esc_html__('here', 'booking') . '</a>' |
| 913 | 918 | ); |
| 914 | 919 | |
| 915 | 920 | if ( function_exists( 'wpbc_get_url_click2approve' ) ) { |
| @@ -1033,43 +1038,165 @@ | ||
| 1033 | 1038 | |
| 1034 | 1039 | $mail_api->set_replace( $replace ); |
| 1035 | 1040 | $mail_api->fields_values['from_name'] = $mail_api->replace_shortcodes( $mail_api->fields_values['from_name'] ); // FixIn: 7.0.1.29. |
| 1036 | 1041 | |
| 1037 | - if ( ( strpos( $mail_api->fields_values['to'], ',') === false ) && ( strpos( $mail_api->fields_values['to'], ';') === false ) ) { | |
| 1038 | - | |
| 1039 | - $valid_email = sanitize_email( $mail_api->fields_values['to'] ); | |
| 1040 | - if ( ! empty( $valid_email ) ) | |
| 1041 | - $to = trim( wp_specialchars_decode( esc_html( stripslashes( $mail_api->fields_values['to_name'] ) ), ENT_QUOTES ) ) | |
| 1042 | - . ' <' . $valid_email . '> '; | |
| 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 | + // ------------------------------------------------------------------------------------------------------------- | |
| 1043 | 1141 | } else { |
| 1044 | - | |
| 1045 | - // Comma separated several emails - validate all these emails in Email API class | |
| 1046 | - $to_array = $mail_api->fields_values['to']; | |
| 1047 | - | |
| 1048 | - $to_array = str_replace(';', ',', $to_array); | |
| 1049 | - if ( !is_array( $to_array ) ) $to_array = explode( ',', $to_array ); | |
| 1050 | 1142 | |
| 1051 | - $to_name = str_replace(';', ',', $mail_api->fields_values['to_name']); | |
| 1052 | - if ( !is_array( $to_name ) ) $to_name = explode( ',', $to_name ); | |
| 1143 | + if ( strpos( $mail_api->fields_values['to'], ',' ) === false ) { | |
| 1053 | 1144 | |
| 1054 | - $to = array(); | |
| 1055 | - foreach ( $to_array as $to_ind => $to_email) { | |
| 1056 | - | |
| 1057 | - $to_name_str = $to_name[ ( count( $to_name ) - 1 ) ]; | |
| 1058 | - | |
| 1059 | - if ( isset( $to_name[ $to_ind ] ) ) | |
| 1060 | - $to_name_str = $to_name[ $to_ind ]; | |
| 1145 | + $valid_email = sanitize_email( $mail_api->fields_values['to'] ); | |
| 1061 | 1146 | |
| 1062 | - $valid_email = sanitize_email( $to_email ); | |
| 1063 | - if ( ! empty( $valid_email ) ) | |
| 1064 | - $to[] = trim( wp_specialchars_decode( esc_html( stripslashes( $to_name_str ) ), ENT_QUOTES ) ) . ' <' . $valid_email . '> '; | |
| 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 ); | |
| 1065 | 1194 | } |
| 1066 | - $to = implode(',', $to); | |
| 1067 | - | |
| 1068 | - } | |
| 1069 | 1195 | |
| 1070 | - if ( wpbc_is_not_blank_email( $to, $replace['content'] ) ) { | |
| 1071 | - $email_result = $mail_api->send( $to , $replace ); | |
| 1196 | + if ( wpbc_is_not_blank_email( $to, $replace['content'] ) ) { | |
| 1197 | + $email_result = $mail_api->send( $to, $replace ); | |
| 1198 | + } | |
| 1072 | 1199 | } |
| 1073 | 1200 | |
| 1074 | 1201 | make_bk_action( 'wpbc_mu_set_environment_for_user', $previous_active_user ); // MU |
| 1075 | 1202 | |