| 1 |
<?php |
| 2 |
namespace Wdk\Elementor\Extensions; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 5 |
|
| 6 |
class AjaxHandler { |
| 7 |
/** |
| 8 |
* data array |
| 9 |
* |
| 10 |
* @var array |
| 11 |
*/ |
| 12 |
protected $data = array(); |
| 13 |
protected $WMVC = NULL; |
| 14 |
|
| 15 |
public function __construct($data = array(), $args = null) { |
| 16 |
add_action( 'eli/ajax-handler/after', array( $this, 'after' ) ); |
| 17 |
add_filter( 'eli/ajax-handler/filter_from_data', array( $this, 'filter_from_data' ) ); |
| 18 |
} |
| 19 |
|
| 20 |
public function filter_output ($filter_output = array()) { |
| 21 |
$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 |
return $filter_output; |
| 23 |
} |
| 24 |
|
| 25 |
public function filter_from_data ($form_data = array()) { |
| 26 |
if (isset($_POST['date_from']) && isset($_POST['date_to'])) { |
| 27 |
/* disable double sent to admin mail */ |
| 28 |
$form_data['settings']['disable_mail_send'] = 1; |
| 29 |
} |
| 30 |
if (isset($_POST['listing_id']) && !empty($_POST['listing_id'])) { |
| 31 |
/* disable double sent to admin mail */ |
| 32 |
// $form_data['settings']['disable_mail_send'] = 1; |
| 33 |
} |
| 34 |
return $form_data; |
| 35 |
} |
| 36 |
|
| 37 |
public function after ($form_data = array()) { |
| 38 |
$this->WMVC = &wdk_get_instance(); |
| 39 |
$this->WMVC->model('messages_m'); |
| 40 |
|
| 41 |
$message_skip = false; |
| 42 |
|
| 43 |
$email = ''; |
| 44 |
$message = ''; |
| 45 |
$post_id = ''; |
| 46 |
foreach ($_POST as $key => $value) { |
| 47 |
if (stripos($key, 'mail') !== false || filter_var($value, FILTER_VALIDATE_EMAIL)) { |
| 48 |
$email = sanitize_email($value); |
| 49 |
} |
| 50 |
if (stripos($key, 'message') !== false) { |
| 51 |
$message = sanitize_text_field($value); |
| 52 |
} |
| 53 |
if (stripos($key, 'listing_id') !== false) { |
| 54 |
$post_id = sanitize_text_field($value); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
if(function_exists('run_wdk_bookings') && is_user_logged_in()) { |
| 59 |
if(isset($_POST['date_from']) && isset($_POST['date_to']) && !empty($_POST['date_from']) && !empty($_POST['date_to'])) { |
| 60 |
$date_from = sanitize_text_field($_POST['date_from']); |
| 61 |
$date_to = sanitize_text_field($_POST['date_to']); |
| 62 |
|
| 63 |
if((bool)strtotime($date_from)) |
| 64 |
{ |
| 65 |
$date_from = date('Y-m-d H:i:s', strtotime($date_from)); |
| 66 |
} |
| 67 |
else |
| 68 |
{ |
| 69 |
return false; |
| 70 |
} |
| 71 |
|
| 72 |
if((bool)strtotime($date_to)) |
| 73 |
{ |
| 74 |
$date_to = date('Y-m-d H:i:s', strtotime($date_to)); |
| 75 |
} |
| 76 |
else |
| 77 |
{ |
| 78 |
return false; |
| 79 |
} |
| 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'); |
| 85 |
|
| 86 |
/* message data */ |
| 87 |
$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 |
|
| 97 |
if(wmvc_show_data ('pets_allowed', $_POST, false)) |
| 98 |
$note .= __('Pets', 'wpdirectorykit').': yes'.PHP_EOL; |
| 99 |
|
| 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; |
| 103 |
|
| 104 |
if(wmvc_show_data ('Phone', $_POST, false)) |
| 105 |
$note .= __('Phone', 'wpdirectorykit').': '.sanitize_text_field(wmvc_show_data ('Phone', $_POST)).PHP_EOL; |
| 106 |
|
| 107 |
if(false) |
| 108 |
foreach($_POST as $key => $value){ |
| 109 |
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; |
| 111 |
|
| 112 |
if(filter_var($value, FILTER_VALIDATE_URL ) || strpos( $value, 'http' ) !== FALSE) { |
| 113 |
$note .= str_replace('_',' ', ucfirst($key)).': <a href="'.esc_url($value).'">'.$value.'</a>'; |
| 114 |
} else { |
| 115 |
$note .= str_replace('_',' ', ucfirst($key)).': '.$value.''; |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
$data = array( |
| 120 |
'post_id' => ($post_id), |
| 121 |
'date_from' => ($date_from), |
| 122 |
'date_to' => ($date_to), |
| 123 |
'notes' => $message, |
| 124 |
'user_id' => get_current_user_id(), |
| 125 |
'price' => wmvc_show_data('price', $price), |
| 126 |
'currency_code' => wmvc_show_data('currency_code', $price), |
| 127 |
'calendar_id' => wmvc_show_data('idcalendar', $calendar), |
| 128 |
'notes' => $note, |
| 129 |
); |
| 130 |
|
| 131 |
if(wmvc_show_data('is_enable_noapprovements', $calendar, false)) |
| 132 |
$data['is_approved'] = 1; |
| 133 |
|
| 134 |
$results = $Winter_MVC_wdk_bookings->reservation_m->is_booked($post_id, $date_from, $date_to); |
| 135 |
$errors = ''; |
| 136 |
|
| 137 |
$Winter_MVC_wdk_bookings->db->where("date_from <='".$date_from."'"); |
| 138 |
$Winter_MVC_wdk_bookings->db->where("date_to >= '".$date_to."'"); |
| 139 |
$price_reservation = $Winter_MVC_wdk_bookings->price_m->get_by(array('post_id'=>$post_id), TRUE); |
| 140 |
/* manual validation */ |
| 141 |
if( !$results ){ |
| 142 |
if($date_from == $date_to) { |
| 143 |
$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 |
} |
| 145 |
|
| 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>'; |
| 148 |
} |
| 149 |
|
| 150 |
if(wmvc_show_data('сhildrens_allowed', $_POST, false) && !wmvc_show_data('is_children_acceptable', $price_reservation, false, TRUE, TRUE)) { |
| 151 |
$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 |
} |
| 153 |
|
| 154 |
if(wmvc_show_data('pets_allowed', $_POST, false) && !wmvc_show_data('is_pets_acceptable', $price_reservation, false, TRUE, TRUE)) { |
| 155 |
$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 |
} |
| 157 |
|
| 158 |
$days = array( |
| 159 |
'1'=>__('Monday', 'wpdirectorykit'), |
| 160 |
'2'=>__('Tuesday', 'wpdirectorykit'), |
| 161 |
'3'=>__('Wednesday', 'wpdirectorykit'), |
| 162 |
'4'=>__('Thursday', 'wpdirectorykit'), |
| 163 |
'5'=>__('Friday', 'wpdirectorykit'), |
| 164 |
'6'=>__('Saturday', 'wpdirectorykit'), |
| 165 |
'7'=>__('Sunday', 'wpdirectorykit'), |
| 166 |
); |
| 167 |
|
| 168 |
$day_num_from = date('N', strtotime($date_from)); |
| 169 |
$day_num_to = date('N', strtotime($date_to)); |
| 170 |
|
| 171 |
if(wmvc_show_data('changeover_day', $price_reservation, false, TRUE, TRUE) && ( |
| 172 |
wmvc_show_data('changeover_day', $price_reservation, false, TRUE, TRUE) != $day_num_from |
| 173 |
|| wmvc_show_data('changeover_day', $price_reservation, false, TRUE, TRUE) != $day_num_to |
| 174 |
) |
| 175 |
) { |
| 176 |
$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 |
} |
| 178 |
|
| 179 |
$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) { |
| 181 |
$period = ''; |
| 182 |
$min_hours = intval(wmvc_show_data('min_hours', $price_reservation, false, TRUE, TRUE)); |
| 183 |
if((int)($min_hours/24) >= 1) { |
| 184 |
$days = (int)($min_hours/24); |
| 185 |
$period .= esc_html__(sprintf(_nx( |
| 186 |
'%1$s day', |
| 187 |
'%1$s days', |
| 188 |
$days, |
| 189 |
'days', |
| 190 |
'wpdirectorykit' |
| 191 |
), $days)); |
| 192 |
|
| 193 |
$min_hours -= $days * 24; |
| 194 |
} |
| 195 |
|
| 196 |
if(!empty($min_hours)) { |
| 197 |
$period .= ' '.esc_html__(sprintf(_nx( |
| 198 |
'%1$s hour', |
| 199 |
'%1$s hours', |
| 200 |
(int)($min_hours), |
| 201 |
'hours', |
| 202 |
'wpdirectorykit' |
| 203 |
), (int)($min_hours))); |
| 204 |
} |
| 205 |
|
| 206 |
$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 |
} |
| 208 |
} |
| 209 |
|
| 210 |
if( $results ) { |
| 211 |
add_filter( 'eli/ajax-handler/filter_output', function($filter_output){ |
| 212 |
$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 |
$filter_output['no_clear_from'] = true; |
| 214 |
return $filter_output; |
| 215 |
} ); |
| 216 |
} elseif( !empty($errors) ) { |
| 217 |
add_filter( 'eli/ajax-handler/filter_output', function($filter_output) use ($errors) { |
| 218 |
$filter_output['message'] = $errors; |
| 219 |
$filter_output['no_clear_from'] = true; |
| 220 |
return $filter_output; |
| 221 |
} ); |
| 222 |
} else { |
| 223 |
$insert_id = $Winter_MVC_wdk_bookings->reservation_m->insert($data, NULL); |
| 224 |
|
| 225 |
/* auto is_enable_noapprovements enabled */ |
| 226 |
if(wmvc_show_data('is_enable_noapprovements', $calendar, false)) { |
| 227 |
/* if woo payment enabled */ |
| 228 |
if(wdk_get_option('wdk_bookings_enable_woocommerce_payments')) { |
| 229 |
global $Winter_MVC_WDK; |
| 230 |
$Winter_MVC_WDK->model('listingusers_m'); |
| 231 |
$Winter_MVC_WDK->model('listing_m'); |
| 232 |
$Winter_MVC_WDK->load_helper('listing'); |
| 233 |
|
| 234 |
$user_owner_id = NULL; |
| 235 |
$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 ); |
| 239 |
if(wmvc_show_data('user_id', $user_listing, false, TRUE, TRUE )) { |
| 240 |
$user_data_owner = get_userdata( wmvc_show_data('user_id', $user_listing, false, TRUE, TRUE ) ); |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
if(empty($user_data_owner)) { |
| 245 |
$user_data_owner = array( |
| 246 |
'display_name' => __('Administrator', 'wdk-bookings'), |
| 247 |
'user_email' => get_bloginfo('admin_email'), |
| 248 |
); |
| 249 |
} |
| 250 |
|
| 251 |
/* auto create woo item and redirect to order */ |
| 252 |
$url_pay = ''; |
| 253 |
$listing = $Winter_MVC_WDK->listing_m->get($post_id, TRUE); |
| 254 |
if(class_exists( 'WooCommerce' )) { |
| 255 |
|
| 256 |
$title = __('Reservation for', 'wpdirectorykit').' '.wdk_field_value ('post_title', $post_id).' #'.$post_id; |
| 257 |
if($user_owner_id) { |
| 258 |
$title .= ' A'.$user_owner_id; |
| 259 |
} |
| 260 |
$title .= ' '.wdk_get_date($date_from).' - '.wdk_get_date($date_to); // The product's Title |
| 261 |
|
| 262 |
$post_args = array ( |
| 263 |
'post_author' => $user_owner_id, // The user's ID |
| 264 |
'post_title' => $title, // The product's Title |
| 265 |
'post_content' => str_replace(PHP_EOL,'<br style="line-height: 0;">', $note), // The product's Title |
| 266 |
'post_type' => 'product', |
| 267 |
'post_status' => 'publish' // This could also be $data['status']; |
| 268 |
); |
| 269 |
|
| 270 |
$woo_id = wp_insert_post( $post_args ); |
| 271 |
// If the post was created okay, let's try update the WooCommerce values. |
| 272 |
if ( ! empty( $woo_id ) && function_exists( 'wc_get_product' ) ) { |
| 273 |
$product = wc_get_product( $woo_id ); |
| 274 |
$product->set_virtual(true); |
| 275 |
$product->set_sold_individually(true); |
| 276 |
$product->set_sku( 'wdk-booking-' . $woo_id ); // Generate a SKU with a prefix. (i.e. 'pre-123') |
| 277 |
$product->set_regular_price(wmvc_show_data('price', $price)); // Be sure to use the correct decimal price. |
| 278 |
$product->save(); // Save/update the WooCommerce order object. |
| 279 |
|
| 280 |
$terms = array( 'exclude-from-catalog', 'exclude-from-search' ); |
| 281 |
wp_set_object_terms( $woo_id, $terms, 'product_visibility' ); |
| 282 |
|
| 283 |
update_post_meta($woo_id, '_manage_stock', 'yes'); |
| 284 |
update_post_meta($woo_id, '_stock', 1); |
| 285 |
|
| 286 |
$wdk_attach_id = NULL; |
| 287 |
$image_ids = explode(',', trim(wdk_show_data('listing_images' , $listing, '', TRUE, TRUE), ',')); |
| 288 |
|
| 289 |
if(is_array($image_ids)) |
| 290 |
$wdk_attach_id = $image_ids[0]; |
| 291 |
|
| 292 |
set_post_thumbnail( $woo_id, $wdk_attach_id ); |
| 293 |
|
| 294 |
/* set woo product id for reservation */ |
| 295 |
$update_data = array('woocommerce_product_id'=>$woo_id); |
| 296 |
$Winter_MVC_wdk_bookings->reservation_m->insert($update_data, $insert_id); |
| 297 |
|
| 298 |
if(function_exists('wc_get_cart_url')) { |
| 299 |
$url_pay = wdk_url_suffix(wc_get_cart_url(), 'add-to-cart='.esc_attr($woo_id).'&reservation_id='.esc_attr($insert_id)); |
| 300 |
|
| 301 |
add_filter( 'eli/ajax-handler/filter_output', function($filter_output) use ($url_pay){ |
| 302 |
$filter_output['message'] = '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-success" role="alert">'.esc_html__('Reservation created, auto redirect to order page', 'wpdirectorykit').'</div>'; |
| 303 |
$filter_output['redirect'] = $url_pay; |
| 304 |
return $filter_output; |
| 305 |
} ); |
| 306 |
} |
| 307 |
} |
| 308 |
} else { |
| 309 |
|
| 310 |
} |
| 311 |
/* message */ |
| 312 |
$data_message = array(); |
| 313 |
$data_message['user'] = get_userdata(get_current_user_id()); |
| 314 |
$data_message['user_owner'] = get_userdata(get_current_user_id()); |
| 315 |
$data_message['listing'] = $listing; |
| 316 |
$data_message['user_owner'] = $user_data_owner; |
| 317 |
$data_message['pay_link'] = $url_pay; |
| 318 |
$data_message['hours_for_payment'] = false; |
| 319 |
$data_message['reservation'] = $data; |
| 320 |
$data_message['reservation_id'] = $insert_id; |
| 321 |
|
| 322 |
if(wdk_get_option(('wdk_bookings_time_for_payment'))) { |
| 323 |
$data_message['hours_for_payment'] = intval(wdk_get_option(('wdk_bookings_time_for_payment'))); |
| 324 |
|
| 325 |
/* 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")))); |
| 327 |
$Winter_MVC_wdk_bookings->reservation_m->insert($update_data, $insert_id); |
| 328 |
} |
| 329 |
|
| 330 |
wdk_mail(wdk_show_data('user_email', $data_message['user'], '' , TRUE, TRUE), __('Reservation waiting for payment', 'wpdirectorykit'), $data_message, 'reservation_user_payment_notify'); |
| 331 |
} else { |
| 332 |
/* manual pay */ |
| 333 |
global $Winter_MVC_WDK; |
| 334 |
$user_owner_id = NULL; |
| 335 |
$Winter_MVC_WDK->model('listingusers_m'); |
| 336 |
$Winter_MVC_WDK->model('listing_m'); |
| 337 |
$Winter_MVC_WDK->load_helper('listing'); |
| 338 |
|
| 339 |
$user = get_userdata( wmvc_show_data('user_id', $data) ); |
| 340 |
|
| 341 |
$user_owner_id = NULL; |
| 342 |
$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 |
} |
| 349 |
} |
| 350 |
|
| 351 |
if(empty($user_data_owner)) { |
| 352 |
$user_data_owner = array( |
| 353 |
'display_name' => __('Administrator', 'wdk-bookings'), |
| 354 |
'user_email' => get_bloginfo('admin_email'), |
| 355 |
); |
| 356 |
} |
| 357 |
|
| 358 |
/* message */ |
| 359 |
$data_message = array(); |
| 360 |
$data_message['user'] = $user; |
| 361 |
$data_message['user_owner'] = $user_data_owner; |
| 362 |
$data_message['listing'] = $Winter_MVC_WDK->listing_m->get($post_id, TRUE); |
| 363 |
$data_message['reservation'] = $data; |
| 364 |
$data_message['reservation_id'] = $insert_id; |
| 365 |
$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), |
| 370 |
); |
| 371 |
$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)); |
| 374 |
} |
| 375 |
|
| 376 |
$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 |
|
| 378 |
$ret = wdk_mail(wdk_show_data('user_email', $data_message['user_owner'], '' , TRUE, TRUE), __('New Reservation approved, please confirm as paid when you receive payment', 'wpdirectorykit'), $data_message, 'reservation_approved_owner'); |
| 379 |
|
| 380 |
if( $ret) { |
| 381 |
add_filter( 'eli/ajax-handler/filter_output', function($filter_output) { |
| 382 |
$filter_output['message'] = '<div class="elementinvader_addons_for_elementor_alert elementinvader_addons_for_elementor_alert-success" role="alert">'.esc_html__('Reservation sent, please check your email with payment details', 'wpdirectorykit').'</div>'; |
| 383 |
return $filter_output; |
| 384 |
} ); |
| 385 |
} |
| 386 |
else |
| 387 |
{ |
| 388 |
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>'; |
| 390 |
$filter_output['no_clear_from'] = true; |
| 391 |
return $filter_output; |
| 392 |
} ); |
| 393 |
} |
| 394 |
} |
| 395 |
|
| 396 |
} else { |
| 397 |
/* auto is_enable_noapprovements disabled */ |
| 398 |
global $Winter_MVC_WDK; |
| 399 |
$Winter_MVC_WDK->model('listingusers_m'); |
| 400 |
$Winter_MVC_WDK->model('listing_m'); |
| 401 |
$Winter_MVC_WDK->load_helper('listing'); |
| 402 |
|
| 403 |
$user_client = get_userdata( wmvc_show_data('user_id', $data) ); |
| 404 |
/* owner data */ |
| 405 |
$user_owner = NULL; |
| 406 |
$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 |
} |
| 414 |
} |
| 415 |
|
| 416 |
$data_listing = $Winter_MVC_WDK->listing_m->get($post_id, TRUE); |
| 417 |
|
| 418 |
/* waiting approve owner */ |
| 419 |
$data_message = array(); |
| 420 |
$data_message['user_owner'] = $user_owner; |
| 421 |
$data_message['user_client'] = $user_client; |
| 422 |
$data_message['reservation_id'] = $insert_id; |
| 423 |
$data_message['reservation'] = $data; /* reservation data */ |
| 424 |
$data_message['listing'] = $data_listing; |
| 425 |
$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), |
| 430 |
); |
| 431 |
$data_message['notes'] = $note; |
| 432 |
|
| 433 |
if(wmvc_show_data ('сhildrens_allowed', $_POST, false)) |
| 434 |
$data_message['data'][__('Childrens', 'wpdirectorykit')] = 'yes'; |
| 435 |
|
| 436 |
if(wmvc_show_data ('pets_allowed', $_POST, false)) |
| 437 |
$data_message['data'][__('Pets', 'wpdirectorykit')] = 'yes'; |
| 438 |
|
| 439 |
if(wmvc_show_data ('Guests', $_POST, false)) |
| 440 |
$data_message['data'][__('Guests', 'wpdirectorykit')] = sanitize_text_field(wmvc_show_data ('guests_number', $_POST)); |
| 441 |
|
| 442 |
if(wmvc_show_data ('Name', $_POST, false)) |
| 443 |
$data_message['data'][__('Name', 'wpdirectorykit')] = sanitize_text_field(wmvc_show_data ('Name', $_POST)); |
| 444 |
|
| 445 |
if(wmvc_show_data ('Email', $_POST, false)) |
| 446 |
$data_message['data'][__('Email', 'wpdirectorykit')] = sanitize_text_field(wmvc_show_data ('Email', $_POST)); |
| 447 |
|
| 448 |
if(wmvc_show_data ('Message', $_POST, false)) |
| 449 |
$data_message['data'][__('Message', 'wpdirectorykit')] = sanitize_text_field(wmvc_show_data ('Message', $_POST)); |
| 450 |
|
| 451 |
$ret = wdk_mail( $owner_email, __('New Reservation Waiting For Approvement', 'wpdirectorykit'), $data_message, 'reservation_waiting_for_approve_owner'); |
| 452 |
|
| 453 |
/* waiting approve to client */ |
| 454 |
$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 |
|
| 456 |
if( $ret) { |
| 457 |
add_filter( 'eli/ajax-handler/filter_output', function($filter_output){ |
| 458 |
$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 |
return $filter_output; |
| 460 |
} ); |
| 461 |
} |
| 462 |
else |
| 463 |
{ |
| 464 |
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>'; |
| 466 |
$filter_output['no_clear_from'] = true; |
| 467 |
return $filter_output; |
| 468 |
} ); |
| 469 |
} |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
} |
| 474 |
|
| 475 |
/* skip default message */ |
| 476 |
$message_skip = true; |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
if(!$message_skip) { |
| 481 |
/* message data */ |
| 482 |
if (!empty($post_id) && !empty($email)) { |
| 483 |
$data = array( |
| 484 |
'post_id' => ($post_id), |
| 485 |
'email_sender' => ($email), |
| 486 |
'message' => ($message) |
| 487 |
); |
| 488 |
|
| 489 |
$insert_idmessage = $this->WMVC->messages_m->insert($data, null); |
| 490 |
if ($insert_idmessage && isset($_POST['listing_id'])) { |
| 491 |
$data_mess= array(); |
| 492 |
|
| 493 |
foreach($_POST as $key => $value){ |
| 494 |
if($key=='element_id') continue; |
| 495 |
if(in_array($key, array('eli_id', 'eli_type','ID','filter','action','send_action_type'))) continue; |
| 496 |
|
| 497 |
if($key == 'eli_page_id'){ |
| 498 |
$value = get_permalink($value); |
| 499 |
$key = 'page_link'; |
| 500 |
} |
| 501 |
|
| 502 |
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>'; |
| 504 |
} else { |
| 505 |
$data_mess []= '<p><strong>'.str_replace('_',' ', ucfirst($key)).':</strong> '.$value.'</p>'; |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
global $Winter_MVC_WDK; |
| 510 |
$Winter_MVC_WDK->model('listingusers_m'); |
| 511 |
$Winter_MVC_WDK->model('listing_m'); |
| 512 |
$Winter_MVC_WDK->load_helper('listing'); |
| 513 |
$data_listing = $Winter_MVC_WDK->listing_m->get($post_id, TRUE); |
| 514 |
|
| 515 |
/* message for user */ |
| 516 |
if (!empty($email)) { |
| 517 |
$data_message = array(); |
| 518 |
$data_message['email_data'] = $data; |
| 519 |
$data_message['listing'] = $data; |
| 520 |
$data_message['message'] = ''; |
| 521 |
|
| 522 |
if(function_exists('run_wdk_bookings')) { |
| 523 |
if(isset($_POST['date_from']) && isset($_POST['date_to']) && !empty($_POST['date_from']) && !empty($_POST['date_to'])) { |
| 524 |
$data_message['message'] .= '<h2>'.__('Date reservation change to', 'wpdirectorykit').'</h2>'; |
| 525 |
$data_message['message'] .= '<p>'.__('Details from contact form', 'wpdirectorykit').'</p>'; |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
$data_message['message'] .= '<p>'.__('Contact message related to listing', 'wpdirectorykit').' <a href="'.esc_url(get_permalink($data_listing)).'">'.esc_html(wmvc_show_data('post_title', $data_listing, '', TRUE, TRUE)).'</a></p>'; |
| 530 |
|
| 531 |
$data_message['message'] .= implode('', $data_mess); |
| 532 |
|
| 533 |
$ret = wdk_mail($email, __('Your messages sent on', 'wpdirectorykit').' '.html_entity_decode(get_bloginfo('name')), $data_message, 'new_message'); |
| 534 |
} |
| 535 |
|
| 536 |
/* message for admin */ |
| 537 |
$data_message = array(); |
| 538 |
$data_message['email_data'] = $data; |
| 539 |
$data_message['message'] = ''; |
| 540 |
|
| 541 |
|
| 542 |
$message_title = __('New Message waiting', 'wpdirectorykit'); |
| 543 |
|
| 544 |
if(function_exists('run_wdk_bookings')) { |
| 545 |
|
| 546 |
if(isset($_POST['date_from']) && isset($_POST['date_to']) && !empty($_POST['date_from']) && !empty($_POST['date_to'])) { |
| 547 |
$data_message['message'] .= '<h2>'.__('Date reservation change to', 'wpdirectorykit').'</h2>'; |
| 548 |
$data_message['message'] .= '<p>'.__('Details from contact form', 'wpdirectorykit').'</p>'; |
| 549 |
|
| 550 |
$message_title = __('Contact message related to reservation on page', 'wpdirectorykit').' '.get_bloginfo('name'); |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
$data_message['message'] .= '<p>'.__('Contact message related to listing', 'wpdirectorykit').' <a href="'.esc_url(get_permalink($data_listing)).'">'.esc_html(wmvc_show_data('post_title', $data_listing, '', TRUE, TRUE)).'</a></p>'; |
| 555 |
$data_message['message'] .= implode('', $data_mess); |
| 556 |
|
| 557 |
/* owner data */ |
| 558 |
$user_owner = NULL; |
| 559 |
$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 |
} |
| 567 |
} |
| 568 |
|
| 569 |
$ret = wdk_mail($owner_email, $message_title, $data_message, 'new_message'); |
| 570 |
if( $ret) { |
| 571 |
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>'; |
| 573 |
return $filter_output; |
| 574 |
} ); |
| 575 |
add_filter( 'eli/ajax-handler/filter_from_data', function ($form_data = array()) { |
| 576 |
/* disable double sent to admin mail */ |
| 577 |
$form_data['settings']['disable_mail_send'] = 1; |
| 578 |
return $form_data; |
| 579 |
} |
| 580 |
); |
| 581 |
} |
| 582 |
else |
| 583 |
{ |
| 584 |
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>'; |
| 586 |
$filter_output['no_clear_from'] = true; |
| 587 |
return $filter_output; |
| 588 |
} ); |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
} |
| 595 |
} |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
} |
| 600 |
|
| 601 |
} |
| 602 |
|