/** * Processes the btb_checkout_overview shortcode. * * Based on the set style it calls a sub function to render the output. * * @param array $atts The shortcode attributes. See class description for explanation. */ public static function btb_checkout_overview_func($atts) { if (isset($_GET['booking']) && isset($_GET['btbnonce']) && !isset($_POST['btb_checkout_nonce'])) { if (!wp_verify_nonce($_GET['btbnonce'], 'btb_direct_booking_nonce')) { return; } $master_instance = get_option('btb_instance_type', 'master') == 'master'; if ($master_instance) { $booking = btb_get_booking($_GET['booking'], OBJECT, 'display'); } else { $booking = btb_get_booking_from_api($_GET['booking'], OBJECT, 'display'); } if (!$booking) { return; } if ($booking->post_type !== "btb_booking") { return; } if ($master_instance) { $time = btb_get_time($booking->booked_time, OBJECT, 'display'); } else { $time = btb_get_time_from_api($booking->booked_time, OBJECT, 'display'); } if (!$time) { return; } if ($time->post_type !== "btb_time") { return; } if ($master_instance) { $event = btb_get_event($time->event, OBJECT, 'display'); } else { $event = btb_get_event_from_api($time->event, OBJECT, 'display'); } if (!$event) { return; } if ($event->post_type !== "btb_event") { return; } $a = shortcode_atts(array('headline' => ''), $atts); switch (get_option('btb_style', 'custom')) { case 'avada': return self::btb_checkout_overview_avada($a, $booking, $time, $event); case 'bootstrap3': return self::btb_checkout_overview_bs3($a, $booking, $time, $event); default: return self::btb_checkout_overview_default($a, $booking, $time, $event); } } }
/** * Sends e-mails to customer and wordpress owner. * * @param BTB_Booking &$booking The booking object to send mails for. * @return int 1 if successfull, 0 if mail to owner failed, -1 if mail to customer failed, -2 if both mails failed */ private static function send_mails(&$booking) { $notifyemail = get_option('btb_notify_to', ''); // email address of the site owne to notify about new bookings $fromemail = get_option('btb_confirm_from', ''); // email address used as from address when sending booking to customer if (empty($notifyemail) && empty($fromemail)) { return -2; } $tags = array('{{salutation}}', '{{title}}', '{{first_name}}', '{{last_name}}', '{{company}}', '{{address}}', '{{address2}}', '{{zip}}', '{{city}}', '{{country}}', '{{mail}}', '{{phone}}', '{{notes}}', '{{event_name}}', '{{event_url}}', '{{event_start_date}}', '{{event_end_date}}', '{{event_start_time}}', '{{event_end_time}}', '{{slots}}', '{{single_price}}', '{{total_price}}', '{{booking_code}}', '{{booking_time}}'); if (get_option('btb_instance_type', 'master') == 'master') { $event = btb_get_event($booking->booked_event); $time = btb_get_time($booking->booked_time); } else { $event = btb_get_event_from_api($booking->booked_event, OBJECT, 'display'); $time = btb_get_time_from_api($booking->booked_time, OBJECT, 'display'); } date_default_timezone_set(get_option('timezone_string', 'UTC')); $replacements = array($booking->title == "mr" ? sprintf(__('Dear Mr. %s %s', 'bt-booking'), $booking->first_name, $booking->last_name) : sprintf(__('Dear Mrs. %s %s', 'bt-booking'), $booking->first_name, $booking->last_name), $booking->title == "mr" ? __('Mr.', 'bt-booking', 'bt-booking') : __('Mrs.', 'bt-booking'), $booking->first_name, $booking->last_name, $booking->company ? $booking->company : '', $booking->address, $booking->address2, $booking->zip, $booking->city, BTBookingCountries::get_country_by_code($booking->country), $booking->email, $booking->phone, $booking->notes, $event->name, btb_get_description_page($event, true), date_i18n(_x('m/d/Y', 'Event date shown in e-mails', 'bt-booking'), $time->start), date_i18n(_x('m/d/Y', 'Event date shown in e-mails', 'bt-booking'), $time->end), $time->date_only ? '' : date_i18n(_x('h:iA', 'Event time shown in e-mails', 'bt-booking'), $time->start), $time->date_only ? '' : date_i18n(_x('h:iA', 'Event time shown in e-mails', 'bt-booking'), $time->end), $booking->booked_slots, get_option('btb_currency', '€') . ' ' . number_format_i18n($booking->price, 2), get_option('btb_currency', '€') . ' ' . number_format_i18n($booking->price * $booking->booked_slots, 2), $booking->code, date_i18n(_x('m/d/Y h:iA', 'Booking time shown in e-mails', 'bt-booking'), $booking->booking_time)); $ret = 1; if (!empty($notifyemail) && !empty($fromemail)) { if (!self::send_mail_to_owner($tags, $replacements, $notifyemail, $fromemail, $booking)) { $ret = 0; } } else { $ret = 0; } if (!empty($fromemail)) { if (!self::send_mail_to_customer($tags, $replacements, $booking, $fromemail)) { $ret = $ret - 2; } } else { $ret = $ret - 2; } return $ret; }
/** * Processes the btb_direct_booking shortcode. * * If the booking process is started, it takes the POST data and creates a new booking post item * for further processing. * * @param array $atts See class description for explanation. */ public static function direct_booking_func($atts) { date_default_timezone_set(get_option('timezone_string', 'UTC')); $master_instance = get_option('btb_instance_type', 'master') == 'master'; if (!empty($_POST)) { if (!wp_verify_nonce($_POST['btb_direct_booking_nonce'], 'btb_direct_booking_data')) { return; } if (!isset($_POST['btb_booking_event_id']) || !isset($_POST['btb_booking_amount']) || !isset($_POST['btb_booking_time'])) { return; } $event_id = intval($_POST['btb_booking_event_id']); $time_id = intval($_POST['btb_booking_time']); $amount = intval($_POST['btb_booking_amount']); if ($master_instance) { $free_slots = btb_get_time_free_slots($time_id); } else { $time = btb_get_time_from_api($time_id, OBJECT, 'display'); $event = btb_get_event_from_api($event_id, OBJECT, 'display'); $free_slots = $time->free_slots; } if ($free_slots >= $amount) { if ($master_instance) { $timeprice = floatval(get_post_meta($time_id, 'btb_price', true)); $eventprice = floatval(get_post_meta($event_id, 'btb_price', true)); } else { $timeprice = floatval($time->price); $eventprice = floatval($event->price); } $price = $timeprice ? $timeprice : $eventprice; if ($master_instance) { $new_booking = btb_create_booking($event_id, $time_id, array('btb_slots' => $amount, 'btb_booking_time' => time(), 'btb_price' => $price)); } else { $new_booking = btb_create_booking_via_api($time_id, array('btb_slots' => $amount, 'btb_booking_time' => time(), 'btb_price' => $price)); } if ($new_booking) { $nonce = wp_create_nonce('btb_direct_booking_nonce'); echo printf('<script>window.location.href = "%s?booking=%u&btbnonce=%s";</script>', get_permalink(get_option('btb_checkout_page')), $new_booking, $nonce); } } else { if (abs($free_slots - $amount) < $amount && abs($free_slots - $amount) > 0) { return '<p>' . esc_html__('There are not enough free slots for your selection.', 'bt-booking') . '</p>'; } else { return '<p>' . esc_html__('This is now booked out.', 'bt-booking') . '</p>'; } } } $a = shortcode_atts(array('id' => '', 'style' => get_option('btb_style', 'default'), 'headline' => get_option('btb_shortcode_headline', __('Booking', 'bt-booking')), 'button_class' => get_option('btb_shortcode_buttonclass', ''), 'button_text' => get_option('btb_shortcode_buttontext', __('Book', 'bt-booking')), 'select_class' => get_option('btb_shortcode_timeselectorclass', ''), 'select_label' => get_option('btb_shortcode_timeselectortext', __('Dates', 'bt-booking')), 'select_layout' => get_option('btb_shortcode_timeselectorlayout', 'dropdown'), 'amount_input_class' => get_option('btb_shortcode_amount_class', ''), 'amount_input_type' => 'number', 'amount_input_surrounding' => get_option('btb_shortcode_amount_surrounding', ''), 'amount_input_label' => get_option('btb_shortcode_amount_label', __('People', 'bt-booking')), 'ind_req_label' => get_option('btb_shortcode_ind_req_label', __('Individual request', 'bt-booking')), 'ind_req_force' => get_option('btb_shortcode_force_ind_req', 0)), $atts); if (empty($a['id'])) { $current_post_type = get_post_type(); if ($current_post_type == 'btb_event') { $a['id'] = get_the_ID(); } elseif ($current_post_type == 'page') { $a['id'] = btb_get_event_id_by_desc_page(get_the_ID()); } } if (empty($a['id'])) { return "<p>No ID given.</p>"; } if ($master_instance) { $event = btb_get_event(intval($a['id']), OBJECT, 'display'); } else { $event = btb_get_event_from_api(intval($a['id']), OBJECT, 'display'); } if (!$event) { return '<p>' . esc_html__('Under the specified ID no event has been found.', 'bt-booking') . '</p>'; } if ($event->post_type !== "btb_event") { return '<p>' . esc_html__('The content with the specified ID ist not an event.', 'bt-booking') . '</p>'; } // requesting the event times from the database if ($master_instance) { $times = btb_get_times($event->ID, 'display', true); // calculate the free slots for each time if (!empty($times)) { foreach ($times as $key => $time) { $time->calc_slots(); } } } else { $times = btb_get_times_from_api($event->ID, 'display', true); } $venue = null; // apply the filter to generate the booking box output $out = apply_filters('btb_create_direct_booking_box', '', $event, $times, $venue, $a); // check if we should generate schema.org output, but only if PHP JSON extension is available. if (get_option('btb_struct_data_enabled', 0) == 1 && extension_loaded("json")) { if (empty($event->struct_data_type)) { $event->struct_data_type = get_option('btb_struct_data_default_type', 'event'); } if (!$venue && $event->struct_data_type == 'event') { $venue = btb_get_venue($event->venue); } $out = apply_filters('btb_create_event_schema_org', $out, $event, $times, $venue); } return $out; }