/** * Check if there's any actions to take for bookings * @return null */ function em_actions_bookings() { global $dbem_form_messages_booking_delete, $dbem_form_messages_booking_add; global $wpdb; global $EM_Event; if (@get_class($EM_Event) == 'EM_Event') { //ADD/EDIT Booking if (isset($_POST['eventAction']) && $_POST['eventAction'] == 'add_booking') { //$EM_Event->get_bookings(); if ($EM_Event->get_bookings()->add(new EM_Booking($_POST))) { $dbem_form_messages_booking_add['success'] = $EM_Event->get_bookings()->feedback_message; } else { $dbem_form_messages_booking_add['error'] = implode('<br />', $EM_Event->get_bookings()->errors); } } //DELETE Booking if (isset($_POST['eventAction']) && $_POST['eventAction'] == 'delete_booking') { $EM_Person = new EM_Person(); if ($EM_Person->get(array('person_name' => $_POST['person_name'], 'person_email' => $_POST['person_email']))) { $deleted = 0; foreach ($EM_Event->get_bookings()->bookings as $EM_Booking) { if ($EM_Booking->person->id == $EM_Person->id) { $EM_Booking->cancel(); $deleted++; } } } if ($deleted > 0) { $dbem_form_messages_booking_delete['success'] = __('Booking deleted', 'dbem'); } else { $dbem_form_messages_booking_delete['error'] = __('There are no bookings associated to this name and e-mail', 'dbem'); } } } }