| @@ -9,14 +9,29 @@ | ||
| 9 | 9 | * |
| 10 | 10 | * @var array |
| 11 | 11 | */ |
| 12 | 12 | protected $data = array(); |
| 13 | + public $_translate_strings = array(); | |
| 13 | 14 | protected $WMVC = NULL; |
| 14 | 15 | |
| 16 | + | |
| 17 | + public function helper_transalte_strings($data = array(), $args = null) { | |
| 18 | + | |
| 19 | + $this->_translate_strings = array( | |
| 20 | + __('Guests number', 'wpdirectorykit'), | |
| 21 | + __('Listing link', 'wpdirectorykit'), | |
| 22 | + __('Name', 'wpdirectorykit'), | |
| 23 | + __('Date from', 'wpdirectorykit'), | |
| 24 | + __('Date to', 'wpdirectorykit'), | |
| 25 | + ); | |
| 26 | + } | |
| 27 | + | |
| 15 | 28 | public function __construct($data = array(), $args = null) { |
| 29 | + add_action( 'init', array( $this, 'helper_transalte_strings' ) ); | |
| 16 | 30 | add_action( 'eli/ajax-handler/after', array( $this, 'after' ) ); |
| 17 | 31 | add_filter( 'eli/ajax-handler/filter_from_data', array( $this, 'filter_from_data' ) ); |
| 18 | 32 | } |
| 33 | + | |
| 19 | 34 | |
| 20 | 35 | public function filter_output ($filter_output = array()) { |
| 21 | 36 | $filter_output['message'] = '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-primary" role="alert">The form was sent successfully.</div>'; |
| 22 | 37 | return $filter_output; |
| @@ -28,14 +43,15 @@ | ||
| 28 | 43 | $form_data['settings']['disable_mail_send'] = 1; |
| 29 | 44 | } |
| 30 | 45 | if (isset($_POST['listing_id']) && !empty($_POST['listing_id'])) { |
| 31 | 46 | /* disable double sent to admin mail */ |
| 32 | - // $form_data['settings']['disable_mail_send'] = 1; | |
| 47 | + $form_data['settings']['disable_mail_send'] = 1; | |
| 33 | 48 | } |
| 34 | 49 | return $form_data; |
| 35 | 50 | } |
| 36 | 51 | |
| 37 | 52 | public function after ($form_data = array()) { |
| 53 | + | |
| 38 | 54 | $this->WMVC = &wdk_get_instance(); |
| 39 | 55 | $this->WMVC->model('messages_m'); |
| 40 | 56 | |
| 41 | 57 | $message_skip = false; |
| @@ -42,8 +58,9 @@ | ||
| 42 | 58 | |
| 43 | 59 | $email = ''; |
| 44 | 60 | $message = ''; |
| 45 | 61 | $post_id = ''; |
| 62 | + $wdk_widget = ''; | |
| 46 | 63 | foreach ($_POST as $key => $value) { |
| 47 | 64 | if (stripos($key, 'mail') !== false || filter_var($value, FILTER_VALIDATE_EMAIL)) { |
| 48 | 65 | $email = sanitize_email($value); |
| 49 | 66 | } |
| @@ -49,21 +66,39 @@ | ||
| 49 | 66 | } |
| 50 | 67 | if (stripos($key, 'message') !== false) { |
| 51 | 68 | $message = sanitize_text_field($value); |
| 52 | 69 | } |
| 70 | + if (stripos($key, 'wdk_widget') !== false) { | |
| 71 | + $wdk_widget = sanitize_text_field($value); | |
| 72 | + } | |
| 53 | 73 | if (stripos($key, 'listing_id') !== false) { |
| 54 | - $post_id = sanitize_text_field($value); | |
| 74 | + $post_id = (int)sanitize_text_field($value); | |
| 55 | 75 | } |
| 56 | 76 | } |
| 57 | - | |
| 58 | - if(function_exists('run_wdk_bookings') && is_user_logged_in()) { | |
| 77 | + | |
| 78 | + if(function_exists('run_wdk_bookings') && ( | |
| 79 | + is_user_logged_in() || | |
| 80 | + $wdk_widget == 'wdk-booking-quick-submission' || | |
| 81 | + wdk_get_option('wdk_booking_disable_for_not_login') || | |
| 82 | + (!wdk_get_option('wdk_booking_disable_for_not_login') && wdk_get_option('wdk_bookings_enable_woocommerce_payments')) | |
| 83 | + ) | |
| 84 | + ) { | |
| 59 | 85 | if(isset($_POST['date_from']) && isset($_POST['date_to']) && !empty($_POST['date_from']) && !empty($_POST['date_to'])) { |
| 60 | 86 | $date_from = sanitize_text_field($_POST['date_from']); |
| 61 | 87 | $date_to = sanitize_text_field($_POST['date_to']); |
| 88 | + $errors = ''; | |
| 89 | + | |
| 90 | + global $Winter_MVC_wdk_bookings; | |
| 91 | + $Winter_MVC_wdk_bookings->model('reservation_m'); | |
| 92 | + $Winter_MVC_wdk_bookings->model('calendar_m'); | |
| 93 | + $Winter_MVC_wdk_bookings->model('price_m'); | |
| 94 | + | |
| 95 | + $calendar = $Winter_MVC_wdk_bookings->calendar_m->get_by(array('post_id'=>$post_id), TRUE); // date_package_expire package_id | |
| 62 | 96 | |
| 63 | - if((bool)strtotime($date_from)) | |
| 97 | + | |
| 98 | + if(wdk_is_date($date_from)) | |
| 64 | 99 | { |
| 65 | - $date_from = date('Y-m-d H:i:s', strtotime($date_from)); | |
| 100 | + $date_from = wdk_normalize_date_db($date_from, 'Y-m-d H:i:s', (!wmvc_show_data('is_hour_enabled', $calendar,false)) ? 'Y-m-d': 'Y-m-d H:i:s'); | |
| 66 | 101 | } |
| 67 | 102 | else |
| 68 | 103 | { |
| 69 | 104 | return false; |
| @@ -68,55 +103,154 @@ | ||
| 68 | 103 | { |
| 69 | 104 | return false; |
| 70 | 105 | } |
| 71 | 106 | |
| 72 | - if((bool)strtotime($date_to)) | |
| 107 | + if(wdk_is_date($date_to)) | |
| 73 | 108 | { |
| 74 | - $date_to = date('Y-m-d H:i:s', strtotime($date_to)); | |
| 109 | + $date_to = wdk_normalize_date_db($date_to, 'Y-m-d H:i:s', (!wmvc_show_data('is_hour_enabled', $calendar,false)) ? 'Y-m-d': 'Y-m-d H:i:s'); | |
| 75 | 110 | } |
| 76 | 111 | else |
| 77 | 112 | { |
| 78 | 113 | return false; |
| 79 | 114 | } |
| 80 | - | |
| 81 | - global $Winter_MVC_wdk_bookings; | |
| 82 | - $Winter_MVC_wdk_bookings->model('reservation_m'); | |
| 83 | - $Winter_MVC_wdk_bookings->model('calendar_m'); | |
| 84 | - $Winter_MVC_wdk_bookings->model('price_m'); | |
| 115 | + | |
| 85 | 116 | |
| 86 | 117 | /* message data */ |
| 118 | + | |
| 119 | + | |
| 87 | 120 | $price = $Winter_MVC_wdk_bookings->reservation_m->calculate_price($post_id, $date_from, $date_to); |
| 88 | - $calendar = $Winter_MVC_wdk_bookings->calendar_m->get_by(array('post_id'=>$post_id), TRUE); // date_package_expire package_id | |
| 89 | - | |
| 90 | - $note = ''; | |
| 91 | - if(wmvc_show_data ('Guests', $_POST, false)) | |
| 92 | - $note .= __('Guests', 'wpdirectorykit').': '.sanitize_text_field(wmvc_show_data('guests_number', $_POST)).PHP_EOL; | |
| 93 | - | |
| 94 | - if(wmvc_show_data ('сhildrens_allowed', $_POST, false)) | |
| 95 | - $note .= __('Childrens', 'wpdirectorykit').': yes'.PHP_EOL; | |
| 96 | 121 | |
| 122 | + $calendar_fees = array(); | |
| 123 | + if($calendar && !empty($calendar->json_data_fees)) | |
| 124 | + $calendar_fees = json_decode($calendar->json_data_fees ); | |
| 125 | + | |
| 126 | + if($price) { | |
| 127 | + $guests_number = intval(wmvc_show_data('guests_number_adults', $_POST, 0)) + intval(wmvc_show_data('guests_number_childs', $_POST, 0)); | |
| 128 | + $nights = (int)abs(strtotime($date_to) - strtotime($date_from))/(60*60*24); | |
| 129 | + foreach ($calendar_fees as $fee) { | |
| 130 | + if(!wmvc_show_data('is_activated', $fee, false,TRUE,TRUE)) continue; | |
| 131 | + if(is_intval(wmvc_show_data('value', $fee,'',TRUE,TRUE))) { | |
| 132 | + $field = wdk_generate_slug(strtolower(esc_html(wmvc_show_data('title', $fee,'-',TRUE,TRUE)))); | |
| 133 | + if(!wmvc_show_data('is_required', $fee, false,TRUE,TRUE) && !isset($_POST['fee_'.$field])) { | |
| 134 | + | |
| 135 | + } else { | |
| 136 | + if(wmvc_show_data('calculation_base', $fee,'',TRUE,TRUE) == 'per_night') { | |
| 137 | + $price['price'] += intval(wmvc_show_data('value', $fee,'',TRUE,TRUE)) * $nights; | |
| 138 | + } else if(wmvc_show_data('calculation_base', $fee,'',TRUE,TRUE) == 'per_person') { | |
| 139 | + $price['price'] += intval(wmvc_show_data('value', $fee,'',TRUE,TRUE)) * $guests_number; | |
| 140 | + } else { | |
| 141 | + $price['price'] += intval(wmvc_show_data('value', $fee,'',TRUE,TRUE)); | |
| 142 | + } | |
| 143 | + } | |
| 144 | + } | |
| 145 | + } | |
| 146 | + } | |
| 147 | + | |
| 148 | + $note = '<br>'; | |
| 149 | + if(empty($calendar->is_guests_disabled)){ | |
| 150 | + if(wmvc_show_data ('guests_number_adults', $_POST, false)) | |
| 151 | + $note .= '<b>'.__('Guests Adult', 'wpdirectorykit').':</b> '.sanitize_text_field(wmvc_show_data('guests_number_adults', $_POST)).'<br>'.PHP_EOL; | |
| 152 | + if(wmvc_show_data ('guests_number_childs', $_POST, false)) | |
| 153 | + $note .= '<b>'.__('Guests Childs', 'wpdirectorykit').':</b> '.sanitize_text_field(wmvc_show_data('guests_number_childs', $_POST)).'<br>'.PHP_EOL; | |
| 154 | + } | |
| 155 | + | |
| 156 | + if(wmvc_show_data ('сhildrens_allowed', $_POST, false) || intval(wmvc_show_data ('guests_number_childs', $_POST, false)) > 0) | |
| 157 | + $note .= '<b>'.__('Childrens', 'wpdirectorykit').':</b> yes'.'<br>'.PHP_EOL; | |
| 158 | + | |
| 97 | 159 | if(wmvc_show_data ('pets_allowed', $_POST, false)) |
| 98 | - $note .= __('Pets', 'wpdirectorykit').': yes'.PHP_EOL; | |
| 160 | + $note .= '<b>'.__('Pets', 'wpdirectorykit').':</b> yes'.'<br>'.PHP_EOL; | |
| 99 | 161 | |
| 100 | - $note .= __('Name', 'wpdirectorykit').': '.sanitize_text_field(wmvc_show_data ('Name', $_POST)).PHP_EOL; | |
| 101 | - $note .= __('Email', 'wpdirectorykit').': '.sanitize_text_field(wmvc_show_data ('Email', $_POST)).PHP_EOL; | |
| 102 | - $note .= __('Message', 'wpdirectorykit').': '.sanitize_text_field(wmvc_show_data ('Message', $_POST)).PHP_EOL; | |
| 162 | + if(wmvc_show_data ('Name', $_POST, false)) | |
| 163 | + $note .= '<b>'.__('Name', 'wpdirectorykit').':</b> '.sanitize_text_field(wmvc_show_data ('Name', $_POST)).'<br>'.PHP_EOL; | |
| 103 | 164 | |
| 165 | + if(wmvc_show_data ('Email', $_POST, false)) | |
| 166 | + $note .= '<b>'.__('Email', 'wpdirectorykit').':</b> '.sanitize_text_field(wmvc_show_data ('Email', $_POST)).'<br>'.PHP_EOL; | |
| 167 | + | |
| 168 | + if(wmvc_show_data ('Message', $_POST, false)) | |
| 169 | + $note .= '<b>'.__('Message', 'wpdirectorykit').':</b> '.sanitize_text_field(wmvc_show_data ('Message', $_POST)).'<br>'.PHP_EOL; | |
| 170 | + | |
| 104 | 171 | if(wmvc_show_data ('Phone', $_POST, false)) |
| 105 | - $note .= __('Phone', 'wpdirectorykit').': '.sanitize_text_field(wmvc_show_data ('Phone', $_POST)).PHP_EOL; | |
| 172 | + $note .= '<b>'.__('Phone', 'wpdirectorykit').':</b> '.sanitize_text_field(wmvc_show_data ('Phone', $_POST)).'<br>'.PHP_EOL; | |
| 106 | 173 | |
| 107 | - if(false) | |
| 108 | - foreach($_POST as $key => $value){ | |
| 174 | + if(true) | |
| 175 | + foreach($_POST as $key => $value) { | |
| 109 | 176 | if($key=='element_id') continue; |
| 110 | - if(in_array($key, array('eli_page_id','eli_id', 'eli_type','ID','filter','action','send_action_type','Phone','Message','Email','Name','pets_allowed','сhildrens_allowed','Guests'))) continue; | |
| 177 | + if(in_array($key, array('eli_page_id', 'g-recaptcha-response','eli_id', 'eli_type','ID','filter','action','send_action_type','Phone','Message','Email','Name','pets_allowed','сhildrens_allowed','guests_number','guests_number_childs','guests_number_adults'))) continue; | |
| 178 | + if(in_array($key, array('listing_link','date_from','date_to','listing_id','wdk_widget', 'function','page','eli_nonce','eli_token','_wp_http_referer'))) continue; | |
| 111 | 179 | |
| 112 | 180 | if(filter_var($value, FILTER_VALIDATE_URL ) || strpos( $value, 'http' ) !== FALSE) { |
| 113 | - $note .= str_replace('_',' ', ucfirst($key)).': <a href="'.esc_url($value).'">'.$value.'</a>'; | |
| 181 | + // Dynamic field values are registered in the translation catalog separately. | |
| 182 | +// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText | |
| 183 | + $note .= '<b> '.__(str_replace('_',' ', ucfirst($key)), 'wpdirectorykit').':</b> <a href="'.esc_url($value).'">'.$value.'</a><br>'; | |
| 114 | 184 | } else { |
| 115 | - $note .= str_replace('_',' ', ucfirst($key)).': '.$value.''; | |
| 185 | + // Dynamic field values are registered in the translation catalog separately. | |
| 186 | +// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText | |
| 187 | + $note .= '<b> '.__(str_replace('_',' ', ucfirst($key)), 'wpdirectorykit').':</b> '.$value.'<br>'; | |
| 116 | 188 | } |
| 117 | 189 | } |
| 118 | 190 | |
| 191 | + | |
| 192 | + if( !is_user_logged_in()) { | |
| 193 | + | |
| 194 | + if( | |
| 195 | + $wdk_widget == 'wdk-booking-quick-submission' || | |
| 196 | + (!wdk_get_option('wdk_booking_disable_for_not_login') && wdk_get_option('wdk_bookings_enable_woocommerce_payments')) | |
| 197 | + ) { | |
| 198 | + | |
| 199 | + /* if not disable for not login users, try create user */ | |
| 200 | + $userlogin = $email; | |
| 201 | + $username = ''; | |
| 202 | + $email_address = $email; | |
| 203 | + $password = wp_generate_password(); | |
| 204 | + | |
| 205 | + if(wmvc_show_data('name', $_POST, false)) | |
| 206 | + $username = sanitize_text_field(wmvc_show_data('name', $_POST, false)); | |
| 207 | + | |
| 208 | + $user_id = wp_create_user( $userlogin, $password, $email_address ); | |
| 209 | + | |
| 210 | + if(is_intval($user_id)) { | |
| 211 | + // Set the nickname | |
| 212 | + wp_update_user( | |
| 213 | + array( | |
| 214 | + 'ID' => $user_id, | |
| 215 | + 'nickname' => $email_address | |
| 216 | + ) | |
| 217 | + ); | |
| 218 | + | |
| 219 | + $user = new \WP_User( $user_id ); | |
| 220 | + $user->set_role('wdk_visitor'); | |
| 221 | + | |
| 222 | + wp_update_user( array ('ID' => $user_id, 'display_name' => esc_html( $username ) ) ); | |
| 223 | + | |
| 224 | + $userdata = get_userdata($user_id); | |
| 225 | + | |
| 226 | + $subject = __('New user on our website!', 'wpdirectorykit'); | |
| 227 | + $data_message = array(); | |
| 228 | + $data_message['login'] = $userlogin; | |
| 229 | + $data_message['password'] = $password; | |
| 230 | + $data_message['user'] = $userdata; | |
| 231 | + $data_message['data'] = ''; | |
| 232 | + | |
| 233 | + update_user_meta( $user_id, 'first_name', $username); | |
| 234 | + | |
| 235 | + wdk_mail($email_address, $subject, $data_message, 'new_user_auto_created'); | |
| 236 | + | |
| 237 | + /* auto login */ | |
| 238 | + wp_set_current_user($user_id, $userdata->user_login ); | |
| 239 | + wp_set_auth_cookie($user_id); | |
| 240 | + | |
| 241 | + } elseif($user = get_user_by( 'email', $email_address)) { | |
| 242 | + $user_id = $user->ID; | |
| 243 | + /* translators: 1: User email address. */ | |
| 244 | + $errors .= '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.wdk_sprintf(__( 'For Booking required login, user with email %1$s already exists, please first try login', 'wpdirectorykit' ), $email_address).' <a href="'.wdk_login_url().'" target="_blank" style="text-decoration: underline;">'.esc_html__('here', 'wpdirectorykit').'</a></div>'; | |
| 245 | + } else { | |
| 246 | + $errors .= '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('For Booking please login', 'wpdirectorykit').' <a href="'.wdk_login_url().'" target="_blank" style="text-decoration: underline;">'.esc_html__('here', 'wpdirectorykit').'</div>'; | |
| 247 | + } | |
| 248 | + } else { | |
| 249 | + $errors .= '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('For Booking please login', 'wpdirectorykit').' <a href="'.wdk_login_url().'" target="_blank" style="text-decoration: underline;">'.esc_html__('here', 'wpdirectorykit').'</div>'; | |
| 250 | + } | |
| 251 | + } | |
| 252 | + | |
| 119 | 253 | $data = array( |
| 120 | 254 | 'post_id' => ($post_id), |
| 121 | 255 | 'date_from' => ($date_from), |
| 122 | 256 | 'date_to' => ($date_to), |
| @@ -122,9 +256,9 @@ | ||
| 122 | 256 | 'date_to' => ($date_to), |
| 123 | 257 | 'notes' => $message, |
| 124 | 258 | 'user_id' => get_current_user_id(), |
| 125 | 259 | 'price' => wmvc_show_data('price', $price), |
| 126 | - 'currency_code' => wmvc_show_data('currency_code', $price), | |
| 260 | + 'currency_code' => wdk_booking_currency_symbol(), | |
| 127 | 261 | 'calendar_id' => wmvc_show_data('idcalendar', $calendar), |
| 128 | 262 | 'notes' => $note, |
| 129 | 263 | ); |
| 130 | 264 | |
| @@ -131,9 +265,9 @@ | ||
| 131 | 265 | if(wmvc_show_data('is_enable_noapprovements', $calendar, false)) |
| 132 | 266 | $data['is_approved'] = 1; |
| 133 | 267 | |
| 134 | 268 | $results = $Winter_MVC_wdk_bookings->reservation_m->is_booked($post_id, $date_from, $date_to); |
| 135 | - $errors = ''; | |
| 269 | + | |
| 136 | 270 | |
| 137 | 271 | $Winter_MVC_wdk_bookings->db->where("date_from <='".$date_from."'"); |
| 138 | 272 | $Winter_MVC_wdk_bookings->db->where("date_to >= '".$date_to."'"); |
| 139 | 273 | $price_reservation = $Winter_MVC_wdk_bookings->price_m->get_by(array('post_id'=>$post_id), TRUE); |
| @@ -142,17 +276,20 @@ | ||
| 142 | 276 | if($date_from == $date_to) { |
| 143 | 277 | $errors .= '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('Please set different dates', 'wpdirectorykit').'</div>'; |
| 144 | 278 | } |
| 145 | 279 | |
| 146 | - if(!empty(wmvc_show_data('guests', $price_reservation, 0, TRUE, TRUE)) && wmvc_show_data('guests_number', $_POST, 0) > wmvc_show_data('guests', $price_reservation, 0, TRUE, TRUE)) { | |
| 147 | - $errors .= '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('Possible max', 'wpdirectorykit').' '.esc_html(wmvc_show_data('guests', $price_reservation, 0, TRUE, TRUE)).' '.esc_html__('guest(s)', 'wpdirectorykit').'</div>'; | |
| 280 | + if(empty($calendar->is_guests_disabled)){ | |
| 281 | + $guests_number = intval(wmvc_show_data('guests_number_adults', $_POST, 0)) + intval(wmvc_show_data('guests_number_childs', $_POST, 0)); | |
| 282 | + if(!empty(wmvc_show_data('guests', $calendar, 0, TRUE, TRUE)) && $guests_number > wmvc_show_data('guests', $calendar, 0, TRUE, TRUE)) { | |
| 283 | + $errors .= '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('Possible max', 'wpdirectorykit').' '.esc_html(wmvc_show_data('guests', $calendar, 0, TRUE, TRUE)).' '.esc_html__('guest(s)', 'wpdirectorykit').'</div>'; | |
| 284 | + } | |
| 148 | 285 | } |
| 149 | 286 | |
| 150 | - if(wmvc_show_data('сhildrens_allowed', $_POST, false) && !wmvc_show_data('is_children_acceptable', $price_reservation, false, TRUE, TRUE)) { | |
| 287 | + if((wmvc_show_data('сhildrens_allowed', $_POST, false) || wmvc_show_data('guests_number_childs', $_POST, 0) > 0) && !wmvc_show_data('is_children_acceptable', $calendar, false, TRUE, TRUE)) { | |
| 151 | 288 | $errors .= '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('Only without children\'s', 'wpdirectorykit').'</div>'; |
| 152 | 289 | } |
| 153 | 290 | |
| 154 | - if(wmvc_show_data('pets_allowed', $_POST, false) && !wmvc_show_data('is_pets_acceptable', $price_reservation, false, TRUE, TRUE)) { | |
| 291 | + if(wmvc_show_data('pets_allowed', $_POST, false) && !wmvc_show_data('is_pets_acceptable', $calendar, false, TRUE, TRUE)) { | |
| 155 | 292 | $errors .= '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('Only without pet\'s', 'wpdirectorykit').'</div>'; |
| 156 | 293 | } |
| 157 | 294 | |
| 158 | 295 | $days = array( |
| @@ -164,10 +301,10 @@ | ||
| 164 | 301 | '6'=>__('Saturday', 'wpdirectorykit'), |
| 165 | 302 | '7'=>__('Sunday', 'wpdirectorykit'), |
| 166 | 303 | ); |
| 167 | 304 | |
| 168 | - $day_num_from = date('N', strtotime($date_from)); | |
| 169 | - $day_num_to = date('N', strtotime($date_to)); | |
| 305 | + $day_num_from = gmdate('N', strtotime($date_from)); | |
| 306 | + $day_num_to = gmdate('N', strtotime($date_to)); | |
| 170 | 307 | |
| 171 | 308 | if(wmvc_show_data('changeover_day', $price_reservation, false, TRUE, TRUE) && ( |
| 172 | 309 | wmvc_show_data('changeover_day', $price_reservation, false, TRUE, TRUE) != $day_num_from |
| 173 | 310 | || wmvc_show_data('changeover_day', $price_reservation, false, TRUE, TRUE) != $day_num_to |
| @@ -176,14 +313,17 @@ | ||
| 176 | 313 | $errors .= '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('Changeover day is', 'wpdirectorykit').' '.esc_html($days[wmvc_show_data('changeover_day', $price_reservation, false, TRUE, TRUE)]).'</div>'; |
| 177 | 314 | } |
| 178 | 315 | |
| 179 | 316 | $hours_reservation = abs(strtotime($date_to) - strtotime($date_from))/(60*60); |
| 180 | - if(wmvc_show_data('min_hours', $price_reservation, false, TRUE, TRUE) && wmvc_show_data('min_hours', $price_reservation, false, TRUE, TRUE) >= $hours_reservation) { | |
| 317 | + | |
| 318 | + if(wmvc_show_data('min_hours', $price_reservation, false, TRUE, TRUE) && wmvc_show_data('min_hours', $price_reservation, false, TRUE, TRUE) > $hours_reservation) { | |
| 181 | 319 | $period = ''; |
| 182 | 320 | $min_hours = intval(wmvc_show_data('min_hours', $price_reservation, false, TRUE, TRUE)); |
| 183 | 321 | if((int)($min_hours/24) >= 1) { |
| 184 | 322 | $days = (int)($min_hours/24); |
| 185 | - $period .= esc_html__(sprintf(_nx( | |
| 323 | + $period .= esc_html(sprintf( | |
| 324 | + /* translators: 1: Number of days. */ | |
| 325 | + _nx( | |
| 186 | 326 | '%1$s day', |
| 187 | 327 | '%1$s days', |
| 188 | 328 | $days, |
| 189 | 329 | 'days', |
| @@ -193,9 +333,11 @@ | ||
| 193 | 333 | $min_hours -= $days * 24; |
| 194 | 334 | } |
| 195 | 335 | |
| 196 | 336 | if(!empty($min_hours)) { |
| 197 | - $period .= ' '.esc_html__(sprintf(_nx( | |
| 337 | + $period .= ' '.esc_html(sprintf( | |
| 338 | + /* translators: 1: Number of hours. */ | |
| 339 | + _nx( | |
| 198 | 340 | '%1$s hour', |
| 199 | 341 | '%1$s hours', |
| 200 | 342 | (int)($min_hours), |
| 201 | 343 | 'hours', |
| @@ -204,8 +346,41 @@ | ||
| 204 | 346 | } |
| 205 | 347 | |
| 206 | 348 | $errors .= '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('Min', 'wpdirectorykit').' '.esc_html($period).'</div>'; |
| 207 | 349 | } |
| 350 | + | |
| 351 | + if(wmvc_show_data('max_hours', $price_reservation, false, TRUE, TRUE) && wmvc_show_data('max_hours', $price_reservation, false, TRUE, TRUE) < $hours_reservation) { | |
| 352 | + $period = ''; | |
| 353 | + $max_hours = intval(wmvc_show_data('max_hours', $price_reservation, false, TRUE, TRUE)); | |
| 354 | + if((int)($max_hours/24) >= 1) { | |
| 355 | + $days = (int)($max_hours/24); | |
| 356 | + $period .= esc_html(sprintf( | |
| 357 | + /* translators: 1: Number of days. */ | |
| 358 | + _nx( | |
| 359 | + '%1$s day', | |
| 360 | + '%1$s days', | |
| 361 | + $days, | |
| 362 | + 'days', | |
| 363 | + 'wpdirectorykit' | |
| 364 | + ), $days)); | |
| 365 | + | |
| 366 | + $max_hours -= $days * 24; | |
| 367 | + } | |
| 368 | + | |
| 369 | + if(!empty($max_hours)) { | |
| 370 | + $period .= ' '.esc_html(sprintf( | |
| 371 | + /* translators: 1: Number of hours. */ | |
| 372 | + _nx( | |
| 373 | + '%1$s hour', | |
| 374 | + '%1$s hours', | |
| 375 | + (int)($max_hours), | |
| 376 | + 'hours', | |
| 377 | + 'wpdirectorykit' | |
| 378 | + ), (int)($max_hours))); | |
| 379 | + } | |
| 380 | + | |
| 381 | + $errors .= '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('Max', 'wpdirectorykit').' '.esc_html($period).'</div>'; | |
| 382 | + } | |
| 208 | 383 | } |
| 209 | 384 | |
| 210 | 385 | if( $results ) { |
| 211 | 386 | add_filter( 'eli/ajax-handler/filter_output', function($filter_output){ |
| @@ -210,17 +385,24 @@ | ||
| 210 | 385 | if( $results ) { |
| 211 | 386 | add_filter( 'eli/ajax-handler/filter_output', function($filter_output){ |
| 212 | 387 | $filter_output['message'] = '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('Date not available', 'wpdirectorykit').'</div>'; |
| 213 | 388 | $filter_output['no_clear_from'] = true; |
| 389 | + $filter_output['success'] = false; | |
| 214 | 390 | return $filter_output; |
| 215 | 391 | } ); |
| 216 | 392 | } elseif( !empty($errors) ) { |
| 217 | 393 | add_filter( 'eli/ajax-handler/filter_output', function($filter_output) use ($errors) { |
| 218 | 394 | $filter_output['message'] = $errors; |
| 395 | + $filter_output['success'] = false; | |
| 219 | 396 | $filter_output['no_clear_from'] = true; |
| 220 | 397 | return $filter_output; |
| 221 | 398 | } ); |
| 222 | 399 | } else { |
| 400 | + | |
| 401 | + if(wmvc_show_data('is_hour_enabled', $calendar, false) && !empty($data['date_from']) && !empty($data['date_to'])) { | |
| 402 | + $data['date_from'] = gmdate('Y-m-d 00:00:00', strtotime($data['date_from'])); | |
| 403 | + $data['date_to'] = gmdate('Y-m-d 00:00:00', strtotime($data['date_to'])); | |
| 404 | + } | |
| 223 | 405 | $insert_id = $Winter_MVC_wdk_bookings->reservation_m->insert($data, NULL); |
| 224 | 406 | |
| 225 | 407 | /* auto is_enable_noapprovements enabled */ |
| 226 | 408 | if(wmvc_show_data('is_enable_noapprovements', $calendar, false)) { |
| @@ -229,14 +411,14 @@ | ||
| 229 | 411 | global $Winter_MVC_WDK; |
| 230 | 412 | $Winter_MVC_WDK->model('listingusers_m'); |
| 231 | 413 | $Winter_MVC_WDK->model('listing_m'); |
| 232 | 414 | $Winter_MVC_WDK->load_helper('listing'); |
| 233 | - | |
| 415 | + $listing = $Winter_MVC_WDK->listing_m->get($post_id, TRUE); | |
| 234 | 416 | $user_owner_id = NULL; |
| 235 | 417 | $user_data_owner = NULL; |
| 236 | - $user_listing = $Winter_MVC_WDK->listingusers_m->get($post_id, TRUE); | |
| 237 | - if($user_listing) { | |
| 238 | - $user_owner_id = wmvc_show_data('user_id', $user_listing, '', TRUE, TRUE ); | |
| 418 | + | |
| 419 | + if( wmvc_show_data('user_id_editor', $listing, '', TRUE, TRUE )) { | |
| 420 | + $user_owner_id = wmvc_show_data('user_id_editor', $listing, '', TRUE, TRUE ); | |
| 239 | 421 | if(wmvc_show_data('user_id', $user_listing, false, TRUE, TRUE )) { |
| 240 | 422 | $user_data_owner = get_userdata( wmvc_show_data('user_id', $user_listing, false, TRUE, TRUE ) ); |
| 241 | 423 | } |
| 242 | 424 | } |
| @@ -242,9 +424,9 @@ | ||
| 242 | 424 | } |
| 243 | 425 | |
| 244 | 426 | if(empty($user_data_owner)) { |
| 245 | 427 | $user_data_owner = array( |
| 246 | - 'display_name' => __('Administrator', 'wdk-bookings'), | |
| 428 | + 'display_name' => __('Administrator', 'wpdirectorykit'), | |
| 247 | 429 | 'user_email' => get_bloginfo('admin_email'), |
| 248 | 430 | ); |
| 249 | 431 | } |
| 250 | 432 | |
| @@ -249,9 +431,9 @@ | ||
| 249 | 431 | } |
| 250 | 432 | |
| 251 | 433 | /* auto create woo item and redirect to order */ |
| 252 | 434 | $url_pay = ''; |
| 253 | - $listing = $Winter_MVC_WDK->listing_m->get($post_id, TRUE); | |
| 435 | + | |
| 254 | 436 | if(class_exists( 'WooCommerce' )) { |
| 255 | 437 | |
| 256 | 438 | $title = __('Reservation for', 'wpdirectorykit').' '.wdk_field_value ('post_title', $post_id).' #'.$post_id; |
| 257 | 439 | if($user_owner_id) { |
| @@ -320,11 +502,11 @@ | ||
| 320 | 502 | $data_message['reservation_id'] = $insert_id; |
| 321 | 503 | |
| 322 | 504 | if(wdk_get_option(('wdk_bookings_time_for_payment'))) { |
| 323 | 505 | $data_message['hours_for_payment'] = intval(wdk_get_option(('wdk_bookings_time_for_payment'))); |
| 324 | - | |
| 506 | + | |
| 325 | 507 | /* set date_expire for reservation */ |
| 326 | - $update_data = array('date_expire'=>esc_sql(date("Y-m-d H:i:s", strtotime("+".intval(wdk_get_option(('wdk_bookings_time_for_payment')))." hours")))); | |
| 508 | + $update_data = array('date_expire'=>esc_sql(gmdate("Y-m-d H:i:s", strtotime("+".intval(wdk_get_option(('wdk_bookings_time_for_payment')))." hours")))); | |
| 327 | 509 | $Winter_MVC_wdk_bookings->reservation_m->insert($update_data, $insert_id); |
| 328 | 510 | } |
| 329 | 511 | |
| 330 | 512 | wdk_mail(wdk_show_data('user_email', $data_message['user'], '' , TRUE, TRUE), __('Reservation waiting for payment', 'wpdirectorykit'), $data_message, 'reservation_user_payment_notify'); |
| @@ -334,24 +516,21 @@ | ||
| 334 | 516 | $user_owner_id = NULL; |
| 335 | 517 | $Winter_MVC_WDK->model('listingusers_m'); |
| 336 | 518 | $Winter_MVC_WDK->model('listing_m'); |
| 337 | 519 | $Winter_MVC_WDK->load_helper('listing'); |
| 338 | - | |
| 520 | + $listing = $Winter_MVC_WDK->listing_m->get($post_id, TRUE); | |
| 339 | 521 | $user = get_userdata( wmvc_show_data('user_id', $data) ); |
| 340 | 522 | |
| 341 | 523 | $user_owner_id = NULL; |
| 342 | 524 | $user_data_owner = NULL; |
| 343 | - $user_listing = $Winter_MVC_WDK->listingusers_m->get($post_id, TRUE); | |
| 344 | - if($user_listing) { | |
| 345 | - $user_owner_id = wmvc_show_data('user_id', $user_listing, '', TRUE, TRUE ); | |
| 346 | - if(wmvc_show_data('user_id', $user_listing, false, TRUE, TRUE )) { | |
| 347 | - $user_data_owner = get_userdata( wmvc_show_data('user_id', $user_listing, false, TRUE, TRUE ) ); | |
| 348 | - } | |
| 525 | + if(wmvc_show_data('user_id_editor', $listing, '', TRUE, TRUE )) { | |
| 526 | + $user_owner_id = wmvc_show_data('user_id_editor', $listing, '', TRUE, TRUE ); | |
| 527 | + $user_data_owner = get_userdata( wmvc_show_data('user_id_editor', $listing, false, TRUE, TRUE ) ); | |
| 349 | 528 | } |
| 350 | 529 | |
| 351 | 530 | if(empty($user_data_owner)) { |
| 352 | 531 | $user_data_owner = array( |
| 353 | - 'display_name' => __('Administrator', 'wdk-bookings'), | |
| 532 | + 'display_name' => __('Administrator', 'wpdirectorykit'), | |
| 354 | 533 | 'user_email' => get_bloginfo('admin_email'), |
| 355 | 534 | ); |
| 356 | 535 | } |
| 357 | 536 | |
| @@ -358,20 +537,42 @@ | ||
| 358 | 537 | /* message */ |
| 359 | 538 | $data_message = array(); |
| 360 | 539 | $data_message['user'] = $user; |
| 361 | 540 | $data_message['user_owner'] = $user_data_owner; |
| 362 | - $data_message['listing'] = $Winter_MVC_WDK->listing_m->get($post_id, TRUE); | |
| 541 | + $data_message['listing'] = $listing; | |
| 363 | 542 | $data_message['reservation'] = $data; |
| 364 | 543 | $data_message['reservation_id'] = $insert_id; |
| 365 | 544 | $data_message['data'] = array( |
| 366 | - __('Reservation ID', 'wdk-bookings')=> $insert_id, | |
| 367 | - __('Date From', 'wpdirectorykit')=> str_replace(' 00:00:00','', $date_from), | |
| 368 | - __('Date To', 'wpdirectorykit')=> str_replace(' 00:00:00','', $date_to), | |
| 369 | - __('Price', 'wpdirectorykit')=> wmvc_show_data('price', $price).wmvc_show_data('currency_code', $price), | |
| 545 | + __('Reservation ID', 'wpdirectorykit')=> $insert_id, | |
| 546 | + __('Date From', 'wpdirectorykit')=> wdk_get_date($date_from), | |
| 547 | + __('Date To', 'wpdirectorykit')=> wdk_get_date($date_to), | |
| 548 | + __('Nights', 'wpdirectorykit')=> wdk_calculate_nights(wdk_get_date($date_from), wdk_get_date($date_to)), | |
| 370 | 549 | ); |
| 550 | + | |
| 551 | + $nights = (int)abs(strtotime($date_to) - strtotime($date_from))/(60*60*24); | |
| 552 | + $guests_number = intval(wmvc_show_data('guests_number_adults', $_POST, 0)) + intval(wmvc_show_data('guests_number_childs', $_POST, 0)); | |
| 553 | + foreach ($calendar_fees as $fee) { | |
| 554 | + if(!wmvc_show_data('is_activated', $fee, false,TRUE,TRUE)) continue; | |
| 555 | + | |
| 556 | + $field = wdk_generate_slug(strtolower(esc_html(wmvc_show_data('title', $fee,'-',TRUE,TRUE)))); | |
| 557 | + if(!wmvc_show_data('is_required', $fee, false,TRUE,TRUE) && !isset($_POST['fee_'.$field])) { | |
| 558 | + | |
| 559 | + } else { | |
| 560 | + if(wmvc_show_data('calculation_base', $fee,'',TRUE,TRUE) == 'per_night') { | |
| 561 | + $data_message['data'][__('Price', 'wpdirectorykit').' '.wmvc_show_data('title', $fee, '-', TRUE, TRUE)] = intval(wmvc_show_data('value', $fee,'',TRUE,TRUE)) * $nights; | |
| 562 | + } else if(wmvc_show_data('calculation_base', $fee,'',TRUE,TRUE) == 'per_person') { | |
| 563 | + $data_message['data'][__('Price', 'wpdirectorykit').' '.wmvc_show_data('title', $fee, '-', TRUE, TRUE)] = intval(wmvc_show_data('value', $fee,'',TRUE,TRUE)) * $guests_number; | |
| 564 | + } else { | |
| 565 | + $data_message['data'][__('Price', 'wpdirectorykit').' '.wmvc_show_data('title', $fee, '-', TRUE, TRUE)] = intval(wmvc_show_data('value', $fee,'',TRUE,TRUE)); | |
| 566 | + } | |
| 567 | + } | |
| 568 | + } | |
| 569 | + | |
| 570 | + $data_message['data'][__('Total Price', 'wpdirectorykit')] = wmvc_show_data('price', $price).wdk_booking_currency_symbol(); | |
| 571 | + | |
| 371 | 572 | $data_message['notes'] = $note; |
| 372 | - if(wmvc_show_data('payment_info', $price_reservation, false, TRUE, TRUE)) { | |
| 373 | - $data_message['data'][__('Payment info', 'wdk-bookings')] = str_replace(PHP_EOL,'<br style="line-height: 0;">', wmvc_show_data('payment_info', $price_reservation, false, TRUE, TRUE)); | |
| 573 | + if(wmvc_show_data('payment_info', $calendar, false, TRUE, TRUE)) { | |
| 574 | + $data_message['data'][__('Payment info', 'wpdirectorykit')] = str_replace(PHP_EOL,'<br style="line-height: 0;">', wmvc_show_data('payment_info', $calendar, false, TRUE, TRUE)); | |
| 374 | 575 | } |
| 375 | 576 | |
| 376 | 577 | $ret = wdk_mail(wdk_show_data('user_email', $data_message['user'], '' , TRUE, TRUE), __('Reservation approved, waiting for payment', 'wpdirectorykit'), $data_message, 'reservation_approved_visitor'); |
| 377 | 578 | |
| @@ -385,9 +586,14 @@ | ||
| 385 | 586 | } |
| 386 | 587 | else |
| 387 | 588 | { |
| 388 | 589 | add_filter( 'eli/ajax-handler/filter_output', function($filter_output) { |
| 389 | - $filter_output['message'] = '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('Server can\'t send emails, please use SMTP mail configuration.', 'wpdirectorykit').'</div>'; | |
| 590 | + $filter_output['message'] = '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'. sprintf( | |
| 591 | + /* translators: 1: Tag with link open, 2: close link tag. */ | |
| 592 | + esc_html__('Server can\'t send emails, please use SMTP mail configuration. Check %1$sGuide%2$s', 'wpdirectorykit'), | |
| 593 | + '<a href="https://wpdirectorykit.com/e-mail-sending-issues-smtp-mail-configuration/" target="_blank" style="text-decoration: underline">', | |
| 594 | + '</a>' | |
| 595 | + ).'</div>'; | |
| 390 | 596 | $filter_output['no_clear_from'] = true; |
| 391 | 597 | return $filter_output; |
| 392 | 598 | } ); |
| 393 | 599 | } |
| @@ -399,23 +605,20 @@ | ||
| 399 | 605 | $Winter_MVC_WDK->model('listingusers_m'); |
| 400 | 606 | $Winter_MVC_WDK->model('listing_m'); |
| 401 | 607 | $Winter_MVC_WDK->load_helper('listing'); |
| 402 | 608 | |
| 609 | + $data_listing = $Winter_MVC_WDK->listing_m->get($post_id, TRUE); | |
| 403 | 610 | $user_client = get_userdata( wmvc_show_data('user_id', $data) ); |
| 404 | 611 | /* owner data */ |
| 405 | 612 | $user_owner = NULL; |
| 406 | 613 | $owner_email = get_bloginfo('admin_email'); |
| 407 | - $user_listing = $Winter_MVC_WDK->listingusers_m->get($post_id, TRUE); | |
| 408 | - if($user_listing) { | |
| 409 | - if(wmvc_show_data('user_id', $user_listing, false, TRUE, TRUE )) { | |
| 410 | - $user_owner = get_userdata( wmvc_show_data('user_id', $user_listing, false, TRUE, TRUE ) ); | |
| 411 | - if($user_owner) | |
| 412 | - $owner_email = $user_owner->user_email; | |
| 413 | - } | |
| 614 | + | |
| 615 | + if(wmvc_show_data('user_id_editor', $data_listing, false, TRUE, TRUE )) { | |
| 616 | + $user_owner = get_userdata( wmvc_show_data('user_id_editor', $data_listing, false, TRUE, TRUE ) ); | |
| 617 | + if($user_owner) | |
| 618 | + $owner_email = $user_owner->user_email; | |
| 414 | 619 | } |
| 415 | 620 | |
| 416 | - $data_listing = $Winter_MVC_WDK->listing_m->get($post_id, TRUE); | |
| 417 | - | |
| 418 | 621 | /* waiting approve owner */ |
| 419 | 622 | $data_message = array(); |
| 420 | 623 | $data_message['user_owner'] = $user_owner; |
| 421 | 624 | $data_message['user_client'] = $user_client; |
| @@ -422,13 +625,34 @@ | ||
| 422 | 625 | $data_message['reservation_id'] = $insert_id; |
| 423 | 626 | $data_message['reservation'] = $data; /* reservation data */ |
| 424 | 627 | $data_message['listing'] = $data_listing; |
| 425 | 628 | $data_message['data'] = array( |
| 426 | - __('Reservation ID', 'wdk-bookings')=> $insert_id, | |
| 427 | - __('Date From', 'wpdirectorykit')=> str_replace(' 00:00:00','', $date_from), | |
| 428 | - __('Date To', 'wpdirectorykit')=> str_replace(' 00:00:00','', $date_to), | |
| 429 | - __('Price', 'wpdirectorykit')=> wmvc_show_data('price', $price).wmvc_show_data('currency_code', $price), | |
| 629 | + __('Reservation ID', 'wpdirectorykit')=> $insert_id, | |
| 630 | + __('Date From', 'wpdirectorykit')=> wdk_get_date($date_from), | |
| 631 | + __('Date To', 'wpdirectorykit')=> wdk_get_date($date_to), | |
| 632 | + __('Nights', 'wpdirectorykit')=> wdk_calculate_nights(wdk_get_date($date_from), wdk_get_date($date_to)), | |
| 430 | 633 | ); |
| 634 | + $nights = (int)abs(strtotime($date_to) - strtotime($date_from))/(60*60*24); | |
| 635 | + $guests_number = intval(wmvc_show_data('guests_number_adults', $_POST, 0)) + intval(wmvc_show_data('guests_number_childs', $_POST, 0)); | |
| 636 | + foreach ($calendar_fees as $fee) { | |
| 637 | + if(!wmvc_show_data('is_activated', $fee, false,TRUE,TRUE)) continue; | |
| 638 | + | |
| 639 | + $field = wdk_generate_slug(strtolower(esc_html(wmvc_show_data('title', $fee,'-',TRUE,TRUE)))); | |
| 640 | + if(!wmvc_show_data('is_required', $fee, false,TRUE,TRUE) && !isset($_POST['fee_'.$field])) { | |
| 641 | + | |
| 642 | + } else { | |
| 643 | + if(wmvc_show_data('calculation_base', $fee,'',TRUE,TRUE) == 'per_night') { | |
| 644 | + $data_message['data'][__('Price', 'wpdirectorykit').' '.wmvc_show_data('title', $fee, '-', TRUE, TRUE)] = intval(wmvc_show_data('value', $fee,'',TRUE,TRUE)) * $nights; | |
| 645 | + } else if(wmvc_show_data('calculation_base', $fee,'',TRUE,TRUE) == 'per_person') { | |
| 646 | + $data_message['data'][__('Price', 'wpdirectorykit').' '.wmvc_show_data('title', $fee, '-', TRUE, TRUE)] = intval(wmvc_show_data('value', $fee,'',TRUE,TRUE)) * $guests_number; | |
| 647 | + } else { | |
| 648 | + $data_message['data'][__('Price', 'wpdirectorykit').' '.wmvc_show_data('title', $fee, '-', TRUE, TRUE)] = intval(wmvc_show_data('value', $fee,'',TRUE,TRUE)); | |
| 649 | + } | |
| 650 | + } | |
| 651 | + } | |
| 652 | + | |
| 653 | + $data_message['data'][__('Total Price', 'wpdirectorykit')] = wmvc_show_data('price', $price).wdk_booking_currency_symbol(); | |
| 654 | + | |
| 431 | 655 | $data_message['notes'] = $note; |
| 432 | 656 | |
| 433 | 657 | if(wmvc_show_data ('сhildrens_allowed', $_POST, false)) |
| 434 | 658 | $data_message['data'][__('Childrens', 'wpdirectorykit')] = 'yes'; |
| @@ -435,11 +659,15 @@ | ||
| 435 | 659 | |
| 436 | 660 | if(wmvc_show_data ('pets_allowed', $_POST, false)) |
| 437 | 661 | $data_message['data'][__('Pets', 'wpdirectorykit')] = 'yes'; |
| 438 | 662 | |
| 439 | - if(wmvc_show_data ('Guests', $_POST, false)) | |
| 440 | - $data_message['data'][__('Guests', 'wpdirectorykit')] = sanitize_text_field(wmvc_show_data ('guests_number', $_POST)); | |
| 441 | - | |
| 663 | + if(empty($calendar->is_guests_disabled)){ | |
| 664 | + if(wmvc_show_data ('guests_number_adults', $_POST, false)) | |
| 665 | + $data_message['data'][__('Guests Adult', 'wpdirectorykit')] = sanitize_text_field(wmvc_show_data ('guests_number_adults', $_POST)); | |
| 666 | + if(wmvc_show_data ('guests_number_childs', $_POST, false)) | |
| 667 | + $data_message['data'][__('Guests Childs', 'wpdirectorykit')] = sanitize_text_field(wmvc_show_data ('guests_number_childs', $_POST)); | |
| 668 | + } | |
| 669 | + | |
| 442 | 670 | if(wmvc_show_data ('Name', $_POST, false)) |
| 443 | 671 | $data_message['data'][__('Name', 'wpdirectorykit')] = sanitize_text_field(wmvc_show_data ('Name', $_POST)); |
| 444 | 672 | |
| 445 | 673 | if(wmvc_show_data ('Email', $_POST, false)) |
| @@ -451,9 +679,9 @@ | ||
| 451 | 679 | $ret = wdk_mail( $owner_email, __('New Reservation Waiting For Approvement', 'wpdirectorykit'), $data_message, 'reservation_waiting_for_approve_owner'); |
| 452 | 680 | |
| 453 | 681 | /* waiting approve to client */ |
| 454 | 682 | $ret = wdk_mail(wdk_show_data('user_email', $user_client, '' , TRUE, TRUE), __('Your reservation waiting approvement by owner', 'wpdirectorykit'), $data_message, 'reservation_waiting_for_approve_visitor'); |
| 455 | - | |
| 683 | + | |
| 456 | 684 | if( $ret) { |
| 457 | 685 | add_filter( 'eli/ajax-handler/filter_output', function($filter_output){ |
| 458 | 686 | $filter_output['message'] = '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-success" role="alert">'.esc_html__('Thanks on reservation, after owner approvement you will receive details for payment', 'wpdirectorykit').'</div>'; |
| 459 | 687 | return $filter_output; |
| @@ -461,9 +689,14 @@ | ||
| 461 | 689 | } |
| 462 | 690 | else |
| 463 | 691 | { |
| 464 | 692 | add_filter( 'eli/ajax-handler/filter_output', function($filter_output) { |
| 465 | - $filter_output['message'] = '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('Server can\'t send emails, please use SMTP mail configuration.', 'wpdirectorykit').'</div>'; | |
| 693 | + $filter_output['message'] = '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'. sprintf( | |
| 694 | + /* translators: 1: Tag with link open, 2: close link tag. */ | |
| 695 | + esc_html__('Server can\'t send emails, please use SMTP mail configuration. Check %1$sGuide%2$s', 'wpdirectorykit'), | |
| 696 | + '<a href="https://wpdirectorykit.com/e-mail-sending-issues-smtp-mail-configuration/" target="_blank" style="text-decoration: underline">', | |
| 697 | + '</a>' | |
| 698 | + ).'</div>'; | |
| 466 | 699 | $filter_output['no_clear_from'] = true; |
| 467 | 700 | return $filter_output; |
| 468 | 701 | } ); |
| 469 | 702 | } |
| @@ -482,9 +715,11 @@ | ||
| 482 | 715 | if (!empty($post_id) && !empty($email)) { |
| 483 | 716 | $data = array( |
| 484 | 717 | 'post_id' => ($post_id), |
| 485 | 718 | 'email_sender' => ($email), |
| 486 | - 'message' => ($message) | |
| 719 | + 'message' => ($message), | |
| 720 | + 'json_object' => json_encode($_POST), | |
| 721 | + 'user_id_sender' => get_current_user_id() | |
| 487 | 722 | ); |
| 488 | 723 | |
| 489 | 724 | $insert_idmessage = $this->WMVC->messages_m->insert($data, null); |
| 490 | 725 | if ($insert_idmessage && isset($_POST['listing_id'])) { |
| @@ -491,19 +726,20 @@ | ||
| 491 | 726 | $data_mess= array(); |
| 492 | 727 | |
| 493 | 728 | foreach($_POST as $key => $value){ |
| 494 | 729 | if($key=='element_id') continue; |
| 495 | - if(in_array($key, array('eli_id', 'eli_type','ID','filter','action','send_action_type'))) continue; | |
| 730 | + if(in_array($key, array('eli_id','eli_page_id', 'eli_type','ID','filter','action','send_action_type', 'page_link', 'g-recaptcha-response','eli_nonce','eli_token','_wp_http_referer'))) continue; | |
| 496 | 731 | |
| 497 | - if($key == 'eli_page_id'){ | |
| 498 | - $value = get_permalink($value); | |
| 499 | - $key = 'page_link'; | |
| 500 | - } | |
| 501 | - | |
| 732 | + if(empty($value)) continue; | |
| 733 | + | |
| 502 | 734 | if(filter_var($value, FILTER_VALIDATE_URL ) || strpos( $value, 'http' ) !== FALSE) { |
| 503 | - $data_mess []= '<p><strong>'.str_replace('_',' ', ucfirst($key)).':</strong> <a href="'.esc_url($value).'">'.$value.'</a></p>'; | |
| 735 | + // Dynamic field values are registered in the translation catalog separately. | |
| 736 | +// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText | |
| 737 | + $data_mess []= '<p><strong>'.__(str_replace('_',' ', ucfirst($key)), 'wpdirectorykit').':</strong> <a href="'.esc_url($value).'">'.$value.'</a></p>'; | |
| 504 | 738 | } else { |
| 505 | - $data_mess []= '<p><strong>'.str_replace('_',' ', ucfirst($key)).':</strong> '.$value.'</p>'; | |
| 739 | + // Dynamic field values are registered in the translation catalog separately. | |
| 740 | +// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText | |
| 741 | + $data_mess []= '<p><strong>'.__(str_replace('_',' ', ucfirst($key)), 'wpdirectorykit').':</strong> '.$value.'</p>'; | |
| 506 | 742 | } |
| 507 | 743 | } |
| 508 | 744 | |
| 509 | 745 | global $Winter_MVC_WDK; |
| @@ -511,8 +747,14 @@ | ||
| 511 | 747 | $Winter_MVC_WDK->model('listing_m'); |
| 512 | 748 | $Winter_MVC_WDK->load_helper('listing'); |
| 513 | 749 | $data_listing = $Winter_MVC_WDK->listing_m->get($post_id, TRUE); |
| 514 | 750 | |
| 751 | + if(function_exists('run_wdk_bookings')) { | |
| 752 | + if(isset($_POST['date_from']) && isset($_POST['date_to']) && !empty($_POST['date_from']) && !empty($_POST['date_to'])) { | |
| 753 | + $data_mess []= '<p><strong>'.__('Nights', 'wpdirectorykit').':</strong> '.wdk_calculate_nights(wdk_get_date($_POST['date_from']), wdk_get_date($_POST['date_to'])).'</p>'; | |
| 754 | + } | |
| 755 | + } | |
| 756 | + | |
| 515 | 757 | /* message for user */ |
| 516 | 758 | if (!empty($email)) { |
| 517 | 759 | $data_message = array(); |
| 518 | 760 | $data_message['email_data'] = $data; |
| @@ -538,9 +780,9 @@ | ||
| 538 | 780 | $data_message['email_data'] = $data; |
| 539 | 781 | $data_message['message'] = ''; |
| 540 | 782 | |
| 541 | 783 | |
| 542 | - $message_title = __('New Message waiting', 'wpdirectorykit'); | |
| 784 | + $message_title = __('New Message', 'wpdirectorykit'); | |
| 543 | 785 | |
| 544 | 786 | if(function_exists('run_wdk_bookings')) { |
| 545 | 787 | |
| 546 | 788 | if(isset($_POST['date_from']) && isset($_POST['date_to']) && !empty($_POST['date_from']) && !empty($_POST['date_to'])) { |
| @@ -545,9 +787,9 @@ | ||
| 545 | 787 | |
| 546 | 788 | if(isset($_POST['date_from']) && isset($_POST['date_to']) && !empty($_POST['date_from']) && !empty($_POST['date_to'])) { |
| 547 | 789 | $data_message['message'] .= '<h2>'.__('Date reservation change to', 'wpdirectorykit').'</h2>'; |
| 548 | 790 | $data_message['message'] .= '<p>'.__('Details from contact form', 'wpdirectorykit').'</p>'; |
| 549 | - | |
| 791 | + | |
| 550 | 792 | $message_title = __('Contact message related to reservation on page', 'wpdirectorykit').' '.get_bloginfo('name'); |
| 551 | 793 | } |
| 552 | 794 | } |
| 553 | 795 | |
| @@ -556,21 +798,19 @@ | ||
| 556 | 798 | |
| 557 | 799 | /* owner data */ |
| 558 | 800 | $user_owner = NULL; |
| 559 | 801 | $owner_email = get_bloginfo('admin_email'); |
| 560 | - $user_listing = $Winter_MVC_WDK->listingusers_m->get(intval($_POST['listing_id']), TRUE); | |
| 561 | - if($user_listing) { | |
| 562 | - if(wmvc_show_data('user_id', $user_listing, false, TRUE, TRUE )) { | |
| 563 | - $user_owner = get_userdata( wmvc_show_data('user_id', $user_listing, false, TRUE, TRUE ) ); | |
| 564 | - if($user_owner) | |
| 565 | - $owner_email = $user_owner->user_email; | |
| 566 | - } | |
| 802 | + if(wmvc_show_data('user_id_editor', $data_listing, false, TRUE, TRUE )) { | |
| 803 | + $user_owner = get_userdata( wmvc_show_data('user_id_editor', $data_listing, false, TRUE, TRUE ) ); | |
| 804 | + if($user_owner) | |
| 805 | + $owner_email = $user_owner->user_email; | |
| 567 | 806 | } |
| 568 | 807 | |
| 569 | - $ret = wdk_mail($owner_email, $message_title, $data_message, 'new_message'); | |
| 808 | + $ret = wdk_mail($owner_email, $message_title, $data_message, 'new_message', '', NULL, $email); | |
| 809 | + | |
| 570 | 810 | if( $ret) { |
| 571 | 811 | add_filter( 'eli/ajax-handler/filter_output', function($filter_output){ |
| 572 | - $filter_output['message'] = '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-success" role="alert">'.esc_html__('Thanks on message', 'wpdirectorykit').'</div>'; | |
| 812 | + $filter_output['message'] = '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-success" role="alert">'.esc_html__('Thanks for the message.', 'wpdirectorykit').'</div>'; | |
| 573 | 813 | return $filter_output; |
| 574 | 814 | } ); |
| 575 | 815 | add_filter( 'eli/ajax-handler/filter_from_data', function ($form_data = array()) { |
| 576 | 816 | /* disable double sent to admin mail */ |
| @@ -581,9 +821,19 @@ | ||
| 581 | 821 | } |
| 582 | 822 | else |
| 583 | 823 | { |
| 584 | 824 | add_filter( 'eli/ajax-handler/filter_output', function($filter_output) { |
| 585 | - $filter_output['message'] = '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'.esc_html__('Server can\'t send emails, please use SMTP mail configuration.', 'wpdirectorykit').'</div>'; | |
| 825 | + $filter_output['message'] = '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-danger" role="alert">'. | |
| 826 | + sprintf( | |
| 827 | + /* translators: 1: Tag with link open, 2: close link tag. */ | |
| 828 | + esc_html__('Server can\'t send emails, please use SMTP mail configuration. Check %1$sGuide%2$s', 'wpdirectorykit'), | |
| 829 | + '<a href="https://wpdirectorykit.com/e-mail-sending-issues-smtp-mail-configuration/" target="_blank" style="text-decoration: underline">', | |
| 830 | + '</a>' | |
| 831 | + ) | |
| 832 | + .'</div>'; | |
| 833 | + | |
| 834 | + | |
| 835 | + $filter_output['success'] = false; | |
| 586 | 836 | $filter_output['no_clear_from'] = true; |
| 587 | 837 | return $filter_output; |
| 588 | 838 | } ); |
| 589 | 839 | } |