Beispiel #1
0
 /**
  * Add a booking into this event (or add spaces if person already booked this), checking that there's enough space for the event
  * @param EM_Booking $EM_Booking
  * @return boolean
  */
 function add($EM_Booking)
 {
     global $wpdb, $EM_Mailer;
     if ($this->get_available_spaces() >= $EM_Booking->get_spaces(true)) {
         //Save the booking
         $email = false;
         //set status depending on approval settings
         if (empty($EM_Booking->booking_status)) {
             //if status is not set, give 1 or 0 depending on approval settings
             $EM_Booking->booking_status = get_option('dbem_bookings_approval') ? 0 : 1;
         }
         $result = $EM_Booking->save(false);
         if ($result) {
             //Success
             do_action('em_bookings_added', $EM_Booking);
             $this->bookings[] = $EM_Booking;
             $email = $EM_Booking->email();
             if (get_option('dbem_bookings_approval') == 1 && $EM_Booking->booking_status == 0) {
                 $this->feedback_message = get_option('dbem_booking_feedback_pending');
             } else {
                 $this->feedback_message = get_option('dbem_booking_feedback');
             }
             if (!$email) {
                 $EM_Booking->email_not_sent = true;
                 $this->feedback_message .= ' ' . get_option('dbem_booking_feedback_nomail');
                 if (current_user_can('activate_plugins')) {
                     if (count($EM_Booking->get_errors()) > 0) {
                         $this->feedback_message .= '<br/><strong>Errors:</strong> (only admins see this message)<br/><ul><li>' . implode('</li><li>', $EM_Booking->get_errors()) . '</li></ul>';
                     } else {
                         $this->feedback_message .= '<br/><strong>No errors returned by mailer</strong> (only admins see this message)';
                     }
                 }
             }
             return apply_filters('em_bookings_add', true, $EM_Booking);
         } else {
             //Failure
             $this->errors[] = "<strong>" . get_option('dbem_booking_feedback_error') . "</strong><br />" . implode('<br />', $EM_Booking->errors);
         }
     } else {
         $this->add_error(get_option('dbem_booking_feedback_full'));
     }
     return apply_filters('em_bookings_add', false, $EM_Booking);
 }
Beispiel #2
0
 /**
  * Add a booking into this event (or add spaces if person already booked this), checking that there's enough space for the event
  * @param EM_Booking $EM_Booking
  * @return boolean
  */
 function add($EM_Booking)
 {
     global $wpdb, $EM_Mailer;
     if ($this->get_available_spaces() >= $EM_Booking->get_spaces(true)) {
         //Save the booking
         $email = false;
         if (!get_option('dbem_bookings_approval') && $EM_Booking->status < 2) {
             $EM_Booking->status = 1;
         }
         $result = $EM_Booking->save(false);
         if ($result) {
             //Success
             $this->bookings[] = $EM_Booking;
             $email = $EM_Booking->email();
             if (get_option('dbem_bookings_approval') == 1 && $EM_Booking->status == 0) {
                 $this->feedback_message = __('Booking successful, pending confirmation (you will also receive an email once confirmed).', 'dbem');
             } else {
                 $this->feedback_message = __('Booking successful.', 'dbem');
             }
             if (!$email) {
                 $this->feedback_message .= ' ' . __('However, there were some problems whilst sending confirmation emails to you and/or the event contact person. You may want to contact them directly and letting them know of this error.', 'dbem');
                 if (current_user_can('activate_plugins')) {
                     if (count($EM_Booking->get_errors()) > 0) {
                         $this->feedback_message .= '<br/><strong>Errors:</strong> (only admins see this message)<br/><ul><li>' . implode('</li><li>', $EM_Booking->get_errors()) . '</li></ul>';
                     } else {
                         $this->feedback_message .= '<br/><strong>No errors returned by mailer</strong> (only admins see this message)';
                     }
                 }
             }
             return true;
         } else {
             //Failure
             $this->errors[] = "<strong>" . __('Booking could not be created', 'dbem') . ":</strong><br />" . implode('<br />', $EM_Booking->errors);
         }
     } else {
         $this->add_error(__('Booking cannot be made, not enough spaces available!', 'dbem'));
     }
     return false;
 }
Beispiel #3
0
/**
 * Check if there's any admin-related actions to take for bookings. All actions are caught here.
 * @return null
 */
function em_admin_actions_bookings()
{
    global $dbem_form_add_message;
    global $dbem_form_delete_message;
    global $wpdb, $EM_Booking, $EM_Event;
    if (current_user_can(EM_MIN_CAPABILITY) && is_object($EM_Booking) && !empty($_REQUEST['action'])) {
        if ($_REQUEST['action'] == 'bookings_delete') {
            //Delete
            if (isset($_POST['booking_id'])) {
                $EM_Booking = new EM_Booking($_POST['booking_id']);
                $EM_Booking->delete();
            }
        } elseif ($_REQUEST['action'] == 'bookings_edit') {
            //Edit Booking
            $validation = $EM_Booking->get_post();
            if ($validation) {
                //EM_Event gets the event if submitted via POST and validates it (safer than to depend on JS)
                //Save
                if ($EM_Booking->save()) {
                    function em_booking_save_notification()
                    {
                        global $EM_Booking;
                        ?>
<div class="updated"><p><strong><?php 
                        echo $EM_Booking->feedback_message;
                        ?>
</strong></p></div><?php 
                    }
                } else {
                    function em_booking_save_notification()
                    {
                        global $EM_Booking;
                        ?>
<div class="error"><p><strong><?php 
                        echo $EM_Booking->feedback_message;
                        ?>
</strong></p></div><?php 
                    }
                }
            } else {
                //TODO make errors clearer when saving person
                function em_booking_save_notification()
                {
                    global $EM_Booking;
                    ?>
<div class="error"><p><strong><?php 
                    echo $EM_Booking->feedback_message;
                    ?>
</strong></p></div><?php 
                }
            }
            add_action('admin_notices', 'em_booking_save_notification');
        } elseif ($_REQUEST['action'] == 'bookings_approve' || $_REQUEST['action'] == 'bookings_reject' || $_REQUEST['action'] == 'bookings_unapprove') {
            //Booking Approvals
            $status_array = array('bookings_unapprove' => 0, 'bookings_approve' => 1, 'bookings_reject' => 2, 'bookings_cancel' => 3);
            if ($EM_Booking->set_status($status_array[$_REQUEST['action']])) {
                function em_booking_save_notification()
                {
                    global $EM_Booking;
                    ?>
<div class="updated"><p><strong><?php 
                    echo $EM_Booking->feedback_message;
                    ?>
</strong></p></div><?php 
                }
            } else {
                function em_booking_save_notification()
                {
                    global $EM_Booking;
                    ?>
<div class="error"><p><strong><?php 
                    echo $EM_Booking->feedback_message;
                    ?>
</strong></p></div><?php 
                }
            }
            add_action('admin_notices', 'em_booking_save_notification');
        } elseif ($_REQUEST['action'] == 'bookings_add_note') {
            $EM_Booking->add_note($_REQUEST['booking_note']);
            function em_booking_save_notification()
            {
                global $EM_Booking;
                ?>
<div class="updated"><p><strong><?php 
                echo $EM_Booking->feedback_message;
                ?>
</strong></p></div><?php 
            }
            add_action('admin_notices', 'em_booking_save_notification');
        }
    } elseif (current_user_can(EM_MIN_CAPABILITY) && is_object($EM_Event) && !empty($_REQUEST['action'])) {
        if ($_REQUEST['action'] == 'export_csv') {
            $EM_Event->get_bookings()->export_csv();
            exit;
        }
    }
}