get_bookings()->add_from_post();
if($result){
$return = array('result'=>true, 'message'=>$EM_Event->get_bookings()->feedback_message);
}else{
$return = array('result'=>false, 'message'=>implode('
', $EM_Event->get_bookings()->errors));
}
echo EM_Object::json_encode($return);
exit();
}else{
$return = array('result'=>false, 'message'=>'');
echo EM_Object::json_encode($return);
exit();
}
}
/**
* Check if there's any actions to take for bookings
* @return null
*/
function actions() {
global $wpdb;
global $EM_Event, $EM_Person;
if( @get_class($EM_Event) == 'EM_Event' ){
//ADD/EDIT Booking
if (isset($_POST['action']) && $_POST['action'] == 'add_booking') {
check_admin_referer( 'em_add_booking', '_wpnonce_em_add_booking' );
$EM_Event->get_bookings()->add_from_post();
}
//CANCEL Booking
if (isset($_POST['action']) && $_POST['action'] == 'cancel_booking') {
self::cancel_booking();
}
}
}
/**
* Handles booking cancellations on the front end. makes a few extra checks.
*/
function cancel_booking(){
global $EM_Event;
if( is_user_logged_in() ){
$canceled = 0;
foreach($EM_Event->get_bookings()->bookings as $EM_Booking){
if($EM_Booking->person->ID == $EM_Person->ID ){
$EM_Booking->cancel();
$canceled++;
}
}
if($canceled > 0){
self::$em_form_messages_booking_cancel['success'] = __('Booking cancelled', 'dbem');
}
}else{
self::$em_form_messages_booking_cancel['error'] = __('You must log in to cancel your booking.', 'dbem');
}
}
/**
* Returns the booking form for the front-end, displayed when using placeholder #_ADDBOOKINGFORM
* @return string
*/
function create() {
global $em_form_messages_booking_add, $EM_Event;
$booked_places_options = array();
for ( $i = 1; $i <= 10; $i++ ) {
$booking_spaces = (!empty($_POST['booking_spaces']) && $_POST['booking_spaces'] == $i) ? 'selected="selected"':'';
array_push($booked_places_options, "");
}
ob_start();
?>
Please log in to manage your bookings.