Exemplo n.º 1
3
/**
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_record_activity_booking_save($result, $EM_Booking)
{
    if ($result) {
        $rejected_statuses = array(0, 2, 3);
        //these statuses apply to rejected/cancelled bookings
        $user = $EM_Booking->person;
        $member_slug = function_exists('bp_get_members_root_slug') ? bp_get_members_root_slug() : BP_MEMBERS_SLUG;
        $member_link = trailingslashit(bp_get_root_domain()) . $member_slug . '/' . $user->user_login;
        $user_link = "<a href='" . $member_link . "/'>" . $user->display_name . "</a>";
        $event_link = $EM_Booking->get_event()->output('#_EVENTLINK');
        $status = $EM_Booking->booking_status;
        $EM_Event = $EM_Booking->get_event();
        if (empty($EM_Event->group_id)) {
            if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
                $action = sprintf(__('%s is attending %s.', 'dbem'), $user_link, $event_link);
            } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && in_array($status, $rejected_statuses)) {
                $action = sprintf(__('%s will not be attending %s anymore.', 'dbem'), $user_link, $event_link);
            }
        } else {
            $group = new BP_Groups_Group($EM_Event->group_id);
            $group_link = '<a href="' . bp_get_group_permalink($group) . '">' . bp_get_group_name($group) . '</a>';
            if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
                $action = sprintf(__('%s is attending %s of the group %s.', 'dbem'), $user_link, $event_link, $group_link);
            } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && in_array($status, $rejected_statuses)) {
                $action = sprintf(__('%s will not be attending %s of group %s anymore.', 'dbem'), $user_link, $event_link, $group_link);
            }
        }
        if (!empty($action)) {
            bp_em_record_activity(array('user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => 'new_booking', 'item_id' => $EM_Event->event_id, 'secondary_item_id' => $EM_Booking->booking_id, 'hide_sitewide' => $EM_Event->event_private));
            //group activity
            if (!empty($EM_Event->group_id)) {
                //tis a group event
                bp_em_record_activity(array('component' => 'groups', 'item_id' => $EM_Event->group_id, 'user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => 'new_booking', 'secondary_item_id' => $EM_Booking->booking_id, 'hide_sitewide' => $EM_Event->event_private));
            }
        }
    }
    return $result;
}
Exemplo n.º 2
0
/**
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_record_activity_booking_save($result, $EM_Booking)
{
    if ($result) {
        $user = $EM_Booking->person;
        $user_link = "<a href='" . get_bloginfo('wpurl') . '/' . BP_MEMBERS_SLUG . '/' . $user->user_login . "/'>" . $user->display_name . "</a>";
        $event_link = $EM_Booking->get_event()->output('#_EVENTLINK');
        $status = $EM_Booking->status;
        if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
            $action = sprintf(__('%s is attending %s.', 'dbem'), $user_link, $event_link);
        } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && ($status > 1 || empty($status) || !get_option('dbem_bookings_approval') && $status != 1)) {
            $action = sprintf(__('%s will not be attending %s anymore.', 'dbem'), $user_link, $event_link);
        }
        $EM_Event = $EM_Booking->get_event();
        if (!empty($EM_Event->group_id)) {
            $group = new BP_Groups_Group($EM_Event->group_id);
            $group_link = '<a href="' . bp_get_group_permalink($group) . '">' . bp_get_group_name($group) . '</a>';
            if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
                $action = sprintf(__('%s is attending %s of the group %s.', 'dbem'), $user_link, $event_link, $group_link);
            } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && ($status > 1 || empty($status) || !get_option('dbem_bookings_approval') && $status != 1)) {
                $action = sprintf(__('%s will not be attending %s of group %s anymore.', 'dbem'), $user_link, $event_link, $group_link);
            }
        }
        if (!empty($action)) {
            bp_em_record_activity(array('user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => 'new_booking', 'item_id' => $EM_Event->id, 'secondary_item_id' => $EM_Booking->id));
            //group activity
            if (!empty($EM_Event->group_id)) {
                //tis a group event
                bp_em_record_activity(array('component' => 'groups', 'item_id' => $EM_Event->group_id, 'user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => 'new_booking', 'secondary_item_id' => $EM_Booking->id));
            }
        }
    }
    return $result;
}
 /**
  * Hooks into the em_booking_email_messages filter to modify email templates if the relevant custom email template exists for the event or gateway if events don't exist
  * @param array $msg
  * @param EM_Booking $EM_Booking contains event information used to retrieve custom email templates
  */
 public static function em_booking_email_messages($msg, $EM_Booking)
 {
     //get the event object and custom emails array
     $EM_Event = $EM_Booking->get_event();
     $custom_emails = self::get_event_emails($EM_Event);
     $users_to_check = $gateway_users = array();
     if (get_option('dbem_custom_emails_events')) {
         $users_to_check = array('admin' => 'admin', 'user' => 'user');
     }
     //firstly, check if we're using a gateway, and if there's an email to send for that gateway
     if (!empty($EM_Booking->booking_meta['gateway']) && get_option('dbem_custom_emails_gateways') && $EM_Booking->get_price() > 0) {
         $gateway = $EM_Booking->booking_meta['gateway'];
         $gateway_users = array($gateway . '-admin' => 'admin', $gateway . '-user' => 'user');
         $gateway_emails = maybe_unserialize(get_option('em_' . $EM_Booking->booking_meta['gateway'] . "_emails"));
         $users_to_check = array_merge($users_to_check, $gateway_users);
     }
     //set both admin and user email messages according to settings in custom emails
     foreach ($users_to_check as $user => $email_type) {
         if (!empty($custom_emails[$user][$EM_Booking->booking_status]) && $custom_emails[$user][$EM_Booking->booking_status]['status'] == 1) {
             //override default email with custom email
             $msg[$email_type]['subject'] = $custom_emails[$user][$EM_Booking->booking_status]['subject'];
             $msg[$email_type]['body'] = $custom_emails[$user][$EM_Booking->booking_status]['message'];
         } elseif (!empty($custom_emails[$user][$EM_Booking->booking_status]) && $custom_emails[$user][$EM_Booking->booking_status]['status'] == 2) {
             //disable the email entirely
             $msg[$email_type]['subject'] = $msg[$user]['body'] = '';
         } elseif (!empty($EM_Booking->booking_meta['gateway']) && array_key_exists($user, $gateway_users) && !empty($gateway_emails[$user][$EM_Booking->booking_status]['status'])) {
             //we requested the default for this gateway, so check if there's a overriden default for this gateway
             if ($gateway_emails[$user][$EM_Booking->booking_status]['status'] == 1) {
                 //override default gateway email with custom email
                 $msg[$email_type]['subject'] = $gateway_emails[$user][$EM_Booking->booking_status]['subject'];
                 $msg[$email_type]['body'] = $gateway_emails[$user][$EM_Booking->booking_status]['message'];
             } elseif ($gateway_emails[$user][$EM_Booking->booking_status]['status'] == 2) {
                 //disable the gateway email entirely
                 $msg[$email_type]['subject'] = $msg[$email_type]['body'] = '';
             }
         }
     }
     return $msg;
 }
Exemplo n.º 4
0
 /**
  * Add a booking into this event (or add spaces if person already booked this). We assume at this point that the booking has already been validated usin $EM_Booking->validate()
  * @param EM_Booking $EM_Booking
  * @return boolean
  */
 function add($EM_Booking)
 {
     global $wpdb, $EM_Mailer;
     //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);
     }
     return apply_filters('em_bookings_add', false, $EM_Booking);
 }
Exemplo n.º 5
0
 /**
  * Creates an EM_Tickets instance, 
  * @param EM_Event $event
  * @return null
  */
 function EM_Tickets($object = false)
 {
     global $wpdb;
     if (is_object($object) && get_class($object) == "EM_Event") {
         //Creates a blank tickets object if needed
         $this->event = $object;
         $sql = "SELECT * FROM " . EM_TICKETS_TABLE . " WHERE event_id ='{$this->event->id}'";
         $tickets = $wpdb->get_results($sql, ARRAY_A);
         foreach ($tickets as $ticket) {
             $EM_Ticket = new EM_Ticket($ticket);
             $EM_Ticket->event = $this->event;
             $this->tickets[] = $EM_Ticket;
         }
     } elseif (is_object($object) && get_class($object) == "EM_Booking") {
         $this->booking = $object;
         $this->event = $this->booking->get_event();
         $sql = "SELECT * FROM " . EM_TICKETS_TABLE . " t LEFT JOIN " . EM_TICKETS_BOOKINGS_TABLE . " bt ON bt.ticket_id=t.ticket_id  WHERE booking_id ='{$this->booking->id}'";
         $tickets = $wpdb->get_results($sql, ARRAY_A);
         foreach ($tickets as $ticket) {
             $EM_Ticket = new EM_Ticket($ticket);
             $EM_Ticket->event = $this->event;
             $this->tickets[] = $EM_Ticket;
         }
     } elseif (is_array($object)) {
         if (is_object(current($object)) && get_class(current($object)) == 'EM_Ticket') {
             $this->tickets = $object;
         } else {
             foreach ($object as $ticket) {
                 $EM_Ticket = new EM_Ticket($ticket);
                 $EM_Ticket->event = $this->event;
                 $this->tickets[] = $EM_Ticket;
             }
         }
     }
     do_action('em_tickets', $this, $object);
 }
Exemplo n.º 6
0
/**
 * Catch booking saves and add a BP notification.
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_add_booking_notification($result, $EM_Booking)
{
    global $bp;
    if (get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
        $action = 'pending_booking';
    } elseif ($EM_Booking->get_status() == 1 || get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
        $action = 'confirmed_booking';
    } elseif ($EM_Booking->get_status() == 3) {
        $action = 'cancelled_booking';
    }
    if (!empty($action) && !(get_option('dbem_bookings_registration_disable') && get_option('dbem_bookings_registration_user') == $EM_Booking->get_event()->get_contact()->ID)) {
        bp_notifications_add_notification(array('item_id' => $EM_Booking->booking_id, 'secondary_item_id' => $EM_Booking->event_id, 'user_id' => $EM_Booking->get_event()->get_contact()->ID, 'component_name' => 'events', 'component_action' => $action));
    }
    return $result;
}
Exemplo n.º 7
0
/**
 * Catch booking saves and add a BP notification.
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_add_booking_notification($result, $EM_Booking)
{
    global $bp;
    if (get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
        $action = 'pending_booking';
    } elseif ($EM_Booking->get_status() == 1 || get_option('dbem_bookings_approval') && $EM_Booking->get_status() == 0) {
        $action = 'confirmed_booking';
    } elseif ($EM_Booking->get_status() == 3) {
        $action = 'cancelled_booking';
    }
    if (!empty($action)) {
        bp_core_add_notification($EM_Booking->booking_id, $EM_Booking->get_event()->get_contact()->ID, 'events', $action);
    }
    return $result;
}
 /**
  * Retreive the authorize_aim vars needed to send to the gateway to proceed with payment
  * @param EM_Booking $EM_Booking
  */
 function authorize_and_capture($EM_Booking)
 {
     global $EM_Notices;
     $sale = $this->get_api();
     //Get transaction ID for authorization/capture
     $sale->amount = $amount = $EM_Booking->get_price(false, false, true);
     $sale->exp_date = $_REQUEST['x_exp_date_month'] . '/' . $_REQUEST['x_exp_date_year'];
     $sale->card_num = $_REQUEST['x_card_num'];
     $sale->card_code = $_REQUEST['x_card_code'];
     //Email Info
     $sale->email_customer = get_option('em_' . $this->gateway . '_email_customer', 0) ? '1' : '0';
     //for later
     $sale->header_email_receipt = get_option('em_' . $this->gateway . '_header_email_receipt');
     $sale->footer_email_receipt = get_option('em_' . $this->gateway . '_footer_email_receipt');
     //Order Info
     $sale->invoice_num = $EM_Booking->booking_id;
     $sale->description = preg_replace('/[^a-zA-Z0-9\\s]/i', "", $EM_Booking->get_event()->event_name);
     //clean event name
     //Customer Info
     $sale->email = $EM_Booking->get_person()->user_email;
     $sale->customer_ip = $_SERVER['REMOTE_ADDR'];
     $sale->cust_id = get_option('dbem_bookings_registration_disable') ? 'booking-' . $EM_Booking->booking_id : 'user-' . $EM_Booking->get_person()->ID;
     //Address Info
     $names = explode(' ', $EM_Booking->get_person()->get_name());
     if (!empty($names[0])) {
         $sale->first_name = array_shift($names);
     }
     if (implode(' ', $names) != '') {
         $sale->last_name = implode(' ', $names);
     }
     //address slightly special address field
     $address = '';
     if (EM_Gateways::get_customer_field('address', $EM_Booking) != '') {
         $address = EM_Gateways::get_customer_field('address', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('address_2', $EM_Booking) != '') {
         $address .= ', ' . EM_Gateways::get_customer_field('address_2', $EM_Booking);
     }
     if (!empty($address)) {
         $sale->address = substr($address, 0, 60);
     }
     //cut off at 60 characters
     if (EM_Gateways::get_customer_field('city', $EM_Booking) != '') {
         $sale->city = EM_Gateways::get_customer_field('city', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('state', $EM_Booking) != '') {
         $sale->state = EM_Gateways::get_customer_field('state', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('zip', $EM_Booking) != '') {
         $sale->zip = EM_Gateways::get_customer_field('zip', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('country', $EM_Booking) != '') {
         $countries = em_get_countries();
         $sale->country = $countries[EM_Gateways::get_customer_field('country', $EM_Booking)];
     }
     if (EM_Gateways::get_customer_field('phone', $EM_Booking) != '') {
         $sale->phone = EM_Gateways::get_customer_field('phone', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('fax', $EM_Booking) != '') {
         $sale->fax = EM_Gateways::get_customer_field('fax', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('company', $EM_Booking) != '') {
         $sale->company = EM_Gateways::get_customer_field('company', $EM_Booking);
     }
     //Itemized Billing
     $tax_enabled = get_option('dbem_bookings_tax') > 0 ? 'Y' : 'N';
     foreach ($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking) {
         $price = round($EM_Ticket_Booking->get_price() / $EM_Ticket_Booking->get_spaces(), 2);
         if ($price > 0) {
             $ticket_name = substr($EM_Ticket_Booking->get_ticket()->ticket_name, 0, 31);
             $sale->addLineItem($EM_Ticket_Booking->get_ticket()->ticket_id, $ticket_name, $EM_Ticket_Booking->get_ticket()->ticket_description, $EM_Ticket_Booking->get_spaces(), $price, $tax_enabled);
         }
     }
     if ($tax_enabled == 'Y') {
         $sale->tax = number_format($EM_Booking->get_price_taxes(), 2);
     }
     //Add discounts to itemized billing
     $discount = $EM_Booking->get_price_discounts_amount('pre') + $EM_Booking->get_price_discounts_amount('post');
     if ($discount > 0) {
         $sale->addLineItem(0, __('Discount', 'em-pro'), '', 1, $discount, 'N');
     }
     //Get Payment
     $sale = apply_filters('em_gateawy_authorize_aim_sale_var', $sale, $EM_Booking, $this);
     $response = $sale->authorizeAndCapture();
     //Handle result
     $result = $response->approved == true;
     if ($result) {
         $EM_Booking->booking_meta[$this->gateway] = array('txn_id' => $response->transaction_id, 'amount' => $amount);
         $this->record_transaction($EM_Booking, $amount, 'USD', date('Y-m-d H:i:s', current_time('timestamp')), $response->transaction_id, 'Completed', '');
     } else {
         $EM_Booking->add_error($response->response_reason_text);
     }
     //Return transaction_id or false
     return apply_filters('em_gateway_authorize_aim_authorize', $result, $EM_Booking, $this);
 }
Exemplo n.º 9
0
 /**
  * @param EM_Booking $EM_Booking
  * @return mixed
  */
 function get_booking_actions($EM_Booking)
 {
     $booking_actions = array();
     $url = $EM_Booking->get_event()->get_bookings_url();
     switch ($EM_Booking->booking_status) {
         case 0:
             //pending
             if (get_option('dbem_bookings_approval')) {
                 $booking_actions = array('approve' => '<a class="em-bookings-approve" href="' . em_add_get_params($url, array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'reject' => '<a class="em-bookings-reject" href="' . em_add_get_params($url, array('action' => 'bookings_reject', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Reject', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
                 break;
             }
             //if approvals are off, treat as a 1
         //if approvals are off, treat as a 1
         case 1:
             //approved
             $booking_actions = array('unapprove' => '<a class="em-bookings-unapprove" href="' . em_add_get_params($url, array('action' => 'bookings_unapprove', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Unapprove', 'dbem') . '</a>', 'reject' => '<a class="em-bookings-reject" href="' . em_add_get_params($url, array('action' => 'bookings_reject', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Reject', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
             break;
         case 2:
             //rejected
             $booking_actions = array('approve' => '<a class="em-bookings-approve" href="' . em_add_get_params($url, array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
             break;
         case 3:
             //cancelled
         //cancelled
         case 4:
             //awaiting online payment - similar to pending but always needs approval in EM Free
         //awaiting online payment - similar to pending but always needs approval in EM Free
         case 5:
             //awaiting payment - similar to pending but always needs approval in EM Free
             $booking_actions = array('approve' => '<a class="em-bookings-approve" href="' . em_add_get_params($url, array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
             break;
     }
     if (!get_option('dbem_bookings_approval')) {
         unset($booking_actions['unapprove']);
     }
     $booking_actions = apply_filters('em_bookings_table_booking_actions_' . $EM_Booking->booking_status, $booking_actions, $EM_Booking);
     return apply_filters('em_bookings_table_cols_col_action', $booking_actions, $EM_Booking);
 }
 function email($email_admin = true, $force_resend = false, $email_attendee = true)
 {
     if (get_option('dbem_multiple_bookings_contact_email')) {
         //we also email individual booking emails to the individual event owners
         foreach ($this->get_bookings() as $EM_Booking) {
             $EM_Booking->email($email_admin, $force_resend, false);
         }
     }
     return parent::email($email_admin, $force_resend);
 }
Exemplo n.º 11
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;
        }
    }
}
 /**
  * Hooks into the em_booking_save filter and checks whether a partial or full payment has been submitted
  * @param boolean $result
  * @param EM_Booking $EM_Booking
  */
 function em_booking_save($result, $EM_Booking)
 {
     if ($result && !empty($_REQUEST['manual_booking']) && wp_verify_nonce($_REQUEST['manual_booking'], 'em_manual_booking_' . $_REQUEST['event_id'])) {
         remove_filter('em_booking_set_status', array(&$this, 'em_booking_set_status'), 1, 2);
         if (!empty($_REQUEST['payment_full'])) {
             $price = !empty($_REQUEST['payment_amount']) && is_numeric($_REQUEST['payment_amount']) ? $_REQUEST['payment_amount'] : $EM_Booking->get_price(false, false, true);
             $this->record_transaction($EM_Booking, $price, get_option('dbem_bookings_currency'), current_time('mysql'), '', 'Completed', __('Manual booking.', 'em-pro'));
             $EM_Booking->set_status(1, false);
         } elseif (!empty($_REQUEST['payment_amount']) && is_numeric($_REQUEST['payment_amount'])) {
             $this->record_transaction($EM_Booking, $_REQUEST['payment_amount'], get_option('dbem_bookings_currency'), current_time('mysql'), '', 'Completed', __('Manual booking.', 'em-pro'));
             if ($_REQUEST['payment_amount'] >= $EM_Booking->get_price(false, false, true)) {
                 $EM_Booking->set_status(1, false);
             }
         }
         add_filter('em_booking_set_status', array(&$this, 'em_booking_set_status'), 1, 2);
         $add_txt = '<a href=\\"' . wp_get_referer() . '\\">' . __('Add another booking', 'em-pro') . '</a>';
         add_filter('em_action_booking_add', create_function('$feedback', '$feedback["message"] = $feedback["message"] . "<p>' . $add_txt . '</p>"; return $feedback;'));
     }
     return $result;
 }
 /**
  * @param EM_Booking $EM_Booking
  * @return mixed
  */
 function get_booking_actions($EM_Booking)
 {
     $booking_actions = array();
     $url = $EM_Booking->get_event()->get_bookings_url();
     switch ($EM_Booking->booking_status) {
         case 0:
             if (get_option('dbem_bookings_approval')) {
                 $booking_actions = array('approve' => '<a class="em-bookings-approve" href="' . em_add_get_params($url, array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'reject' => '<a class="em-bookings-reject" href="' . em_add_get_params($url, array('action' => 'bookings_reject', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Reject', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
                 break;
             }
             //if approvals are off, treat as a 1
         //if approvals are off, treat as a 1
         case 1:
             $booking_actions = array('unapprove' => '<a class="em-bookings-unapprove" href="' . em_add_get_params($url, array('action' => 'bookings_unapprove', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Unapprove', 'dbem') . '</a>', 'reject' => '<a class="em-bookings-reject" href="' . em_add_get_params($url, array('action' => 'bookings_reject', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Reject', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
             break;
         case 2:
             $booking_actions = array('approve' => '<a class="em-bookings-approve" href="' . em_add_get_params($url, array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
             break;
         case 3:
             $booking_actions = array('approve' => '<a class="em-bookings-approve" href="' . em_add_get_params($url, array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
             break;
         case 4:
             $booking_actions = apply_filters('em_bookings_table_booking_actions_4', array('delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>'), $EM_Booking);
             break;
         case 5:
             $booking_actions = apply_filters('em_bookings_table_booking_actions_5', array('delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($url, array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>'), $EM_Booking);
             break;
         default:
             $booking_actions = apply_filters('em_bookings_table_booking_actions_' . $EM_Booking->booking_status, array(), $EM_Booking);
             break;
     }
     if (!get_option('dbem_bookings_approval')) {
         unset($booking_actions['unapprove']);
     }
     return apply_filters('em_bookings_table_cols_col_action', $booking_actions, $EM_Booking);
 }
Exemplo n.º 14
0
 /**
  * @param string $replace
  * @param EM_Booking $EM_Booking
  * @param string $full_result
  * @return string
  */
 function placeholders($replace, $EM_Booking, $full_result)
 {
     if (empty($replace) || $replace == $full_result) {
         $user = $EM_Booking->get_person();
         $EM_Form = self::get_form($EM_Booking->event_id, $EM_Booking);
         if ($full_result == '#_BOOKINGFORMCUSTOMREG{user_name}' || $full_result == '#_BOOKINGFORMCUSTOM{user_name}') {
             //special user_name case
             if (!is_user_logged_in()) {
                 $replace = $EM_Booking->get_person()->get_name();
             } else {
                 $replace = $user->get_name();
             }
         } elseif ($full_result == '#_BOOKINGFORMCUSTOMFIELDS') {
             $replace = '';
             foreach ($EM_Form->form_fields as $field) {
                 if ($field['type'] != 'html') {
                     $replace .= "\r\n" . $field['label'] . ': ';
                     if (!empty($user->{$field}['fieldid'])) {
                         //user profile is freshest, using this
                         $replace .= $user->{$field}['fieldid'];
                     } elseif (!empty($EM_Booking->booking_meta['registration'][$field['fieldid']])) {
                         //reg fields only exist as reg fields
                         $replace .= $EM_Form->get_formatted_value($field, $EM_Booking->booking_meta['registration'][$field['fieldid']]);
                     } elseif (!empty($EM_Booking->booking_meta['booking'][$field['fieldid']])) {
                         //match for custom field value
                         $replace .= $EM_Form->get_formatted_value($field, $EM_Booking->booking_meta['booking'][$field['fieldid']]);
                     }
                 }
             }
         } else {
             foreach ($EM_Form->form_fields as $field) {
                 if ($full_result == '#_BOOKINGFORMCUSTOM{' . $field['fieldid'] . '}' || $full_result == '#_BOOKINGFORMCUSTOMREG{' . $field['fieldid'] . '}') {
                     $replace = '';
                     if (!empty($user->{$field}['fieldid'])) {
                         //user profile is freshest, using this
                         $replace = $user->{$field}['fieldid'];
                     } elseif (!empty($EM_Booking->booking_meta['registration'][$field['fieldid']])) {
                         //reg fields only exist as reg fields
                         $replace = $EM_Form->get_formatted_value($field, $EM_Booking->booking_meta['registration'][$field['fieldid']]);
                     } elseif (!empty($EM_Booking->booking_meta['booking'][$field['fieldid']])) {
                         //match for custom field value
                         $replace = $EM_Form->get_formatted_value($field, $EM_Booking->booking_meta['booking'][$field['fieldid']]);
                     }
                 }
             }
         }
     }
     return $replace;
     //no need for a filter, use the em_booking_email_placeholders filter
 }
Exemplo n.º 15
0
 /**
  * Retreive the paypal vars needed to send to the gatway to proceed with payment
  * @param EM_Booking $EM_Booking
  */
 function get_paypal_vars($EM_Booking)
 {
     global $wp_rewrite, $EM_Notices;
     $notify_url = $this->get_payment_return_url();
     $paypal_vars = array('business' => get_option('em_' . $this->gateway . "_email"), 'cmd' => '_cart', 'upload' => 1, 'currency_code' => get_option('dbem_bookings_currency', 'USD'), 'notify_url' => $notify_url, 'custom' => $EM_Booking->booking_id . ':' . $EM_Booking->event_id, 'charset' => 'UTF-8', 'bn' => 'NetWebLogic_SP');
     if (get_option('em_' . $this->gateway . "_lc")) {
         $paypal_vars['lc'] = get_option('em_' . $this->gateway . "_lc");
     }
     //address fields`and name/email fields to prefill on checkout page (if available)
     $paypal_vars['email'] = $EM_Booking->get_person()->user_email;
     $paypal_vars['first_name'] = $EM_Booking->get_person()->first_name;
     $paypal_vars['last_name'] = $EM_Booking->get_person()->last_name;
     if (EM_Gateways::get_customer_field('address', $EM_Booking) != '') {
         $paypal_vars['address1'] = EM_Gateways::get_customer_field('address', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('address_2', $EM_Booking) != '') {
         $paypal_vars['address2'] = EM_Gateways::get_customer_field('address_2', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('city', $EM_Booking) != '') {
         $paypal_vars['city'] = EM_Gateways::get_customer_field('city', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('state', $EM_Booking) != '') {
         $paypal_vars['state'] = EM_Gateways::get_customer_field('state', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('zip', $EM_Booking) != '') {
         $paypal_vars['zip'] = EM_Gateways::get_customer_field('zip', $EM_Booking);
     }
     if (EM_Gateways::get_customer_field('country', $EM_Booking) != '') {
         $paypal_vars['country'] = EM_Gateways::get_customer_field('country', $EM_Booking);
     }
     //tax is added regardless of whether included in ticket price, otherwise we can't calculate post/pre tax discounts
     if ($EM_Booking->get_price_taxes() > 0 && !get_option('em_' . $this->gateway . "_inc_tax")) {
         $paypal_vars['tax_cart'] = round($EM_Booking->get_price_taxes(), 2);
     }
     if (get_option('em_' . $this->gateway . "_return") != "") {
         $paypal_vars['return'] = get_option('em_' . $this->gateway . "_return");
     }
     if (get_option('em_' . $this->gateway . "_cancel_return") != "") {
         $paypal_vars['cancel_return'] = get_option('em_' . $this->gateway . "_cancel_return");
     }
     if (get_option('em_' . $this->gateway . "_format_logo") !== false) {
         $paypal_vars['cpp_logo_image'] = get_option('em_' . $this->gateway . "_format_logo");
     }
     if (get_option('em_' . $this->gateway . "_border_color") !== false) {
         $paypal_vars['cpp_cart_border_color'] = get_option('em_' . $this->gateway . "_format_border");
     }
     $count = 1;
     foreach ($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking) {
         /* @var $EM_Ticket_Booking EM_Ticket_Booking */
         //divide price by spaces for per-ticket price
         //we divide this way rather than by $EM_Ticket because that can be changed by user in future, yet $EM_Ticket_Booking will change if booking itself is saved.
         if (!get_option('em_' . $this->gateway . "_inc_tax")) {
             $price = $EM_Ticket_Booking->get_price() / $EM_Ticket_Booking->get_spaces();
         } else {
             $price = $EM_Ticket_Booking->get_price_with_taxes() / $EM_Ticket_Booking->get_spaces();
         }
         if ($price > 0) {
             $paypal_vars['item_name_' . $count] = wp_kses_data($EM_Ticket_Booking->get_ticket()->name);
             $paypal_vars['quantity_' . $count] = $EM_Ticket_Booking->get_spaces();
             $paypal_vars['amount_' . $count] = round($price, 2);
             $count++;
         }
     }
     //calculate discounts, if any:
     $discount = $EM_Booking->get_price_discounts_amount('pre') + $EM_Booking->get_price_discounts_amount('post');
     if ($discount > 0) {
         $paypal_vars['discount_amount_cart'] = $discount;
     }
     return apply_filters('em_gateway_paypal_get_paypal_vars', $paypal_vars, $EM_Booking, $this);
 }
Exemplo n.º 16
0
/**
 * @param boolean $result
 * @param EM_Booking $EM_Booking
 * @return boolean
 */
function bp_em_record_activity_booking_save($result, $EM_Booking)
{
    /* @todo this isn't good at detecting status changes. */
    if (!empty($EM_Booking->event_id) && $result) {
        $action_type = 'new_booking';
        if (!empty($EM_Booking->last_bp_activity) && $EM_Booking->last_bp_activity == $action_type) {
            return $result;
        }
        //prevent duplicates
        $EM_Booking->last_bp_activity = $action_type;
        $rejected_statuses = array(0, 2, 3);
        //these statuses apply to rejected/cancelled bookings
        $user = $EM_Booking->get_person();
        $member_link = bp_core_get_user_domain($user->ID);
        $user_link = "<a href='" . $member_link . "/'>" . $user->display_name . "</a>";
        $event_link = $EM_Booking->get_event()->output('#_EVENTLINK');
        $status = $EM_Booking->booking_status;
        $EM_Event = $EM_Booking->get_event();
        if (empty($EM_Event->group_id)) {
            if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
                $action = sprintf(__('%s is attending %s.', 'events-manager'), $user_link, $event_link);
            } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && in_array($status, $rejected_statuses)) {
                $action = sprintf(__('%s will not be attending %s anymore.', 'events-manager'), $user_link, $event_link);
                //$action_type = 'cancelled_booking';
            }
        } else {
            $group = new BP_Groups_Group($EM_Event->group_id);
            $group_link = '<a href="' . bp_get_group_permalink($group) . '">' . bp_get_group_name($group) . '</a>';
            if ($status == 1 || !get_option('dbem_bookings_approval') && $status < 2) {
                $action = sprintf(__('%s is attending %s of the group %s.', 'events-manager'), $user_link, $event_link, $group_link);
            } elseif (($EM_Booking->previous_status == 1 || !get_option('dbem_bookings_approval') && $EM_Booking->previous_status < 2) && in_array($status, $rejected_statuses)) {
                $action = sprintf(__('%s will not be attending %s of group %s anymore.', 'events-manager'), $user_link, $event_link, $group_link);
                //$action_type = 'cancelled_booking';
            }
        }
        if (!empty($action)) {
            if (empty($EM_Event->group_id)) {
                bp_em_record_activity(array('user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => $action_type, 'item_id' => $EM_Event->event_id, 'secondary_item_id' => $EM_Booking->booking_id, 'hide_sitewide' => $EM_Event->event_private));
            } else {
                //tis a group event
                bp_em_record_activity(array('component' => 'groups', 'user_id' => $EM_Booking->person->ID, 'action' => $action, 'primary_link' => $EM_Event->output('#_EVENTURL'), 'type' => $action_type, 'item_id' => $EM_Event->group_id, 'secondary_item_id' => $EM_Booking->booking_id, 'hide_sitewide' => $EM_Event->event_private));
            }
        }
    }
    return $result;
}
Exemplo n.º 17
0
 /**
  * @param string $replace
  * @param EM_Booking $EM_Booking
  * @param string $full_result
  * @return string
  */
 public static function placeholders($replace, $EM_Booking, $full_result)
 {
     if (empty($replace) || $replace == $full_result) {
         $user = $EM_Booking->get_person();
         $EM_Form = self::get_form($EM_Booking->event_id);
         if ($full_result == '#_BOOKINGATTENDEES') {
             $replace = '';
             ob_start();
             emp_locate_template('placeholders/bookingattendees.php', true, array('EM_Booking' => $EM_Booking));
             $replace = ob_get_clean();
         }
     }
     return $replace;
     //no need for a filter, use the em_booking_email_placeholders filter
 }
Exemplo n.º 18
0
 /**
  * @param boolean $result
  * @param EM_Booking $EM_Booking
  * @return boolean
  */
 public static function em_booking_get_post($result, $EM_Booking)
 {
     if (!empty($_REQUEST['coupon_code'])) {
         $EM_Coupon = EM_Coupons::event_get_coupon($_REQUEST['coupon_code'], $EM_Booking->get_event());
         if ($EM_Coupon === false && !empty($EM_Booking->booking_id)) {
             //if a previously saved booking, account for the fact it may not work
             $EM_Coupon = new EM_Coupon($EM_Booking->booking_meta['coupon']);
         }
         if ($EM_Coupon !== false) {
             $EM_Booking->booking_meta['coupon'] = $EM_Coupon->to_array();
             //we add an clean a coupon array here for the first time
             $EM_Booking->calculate_price();
             //refresh price
         } else {
             $EM_Booking->booking_meta['coupon'] = array('coupon_code' => $_REQUEST['coupon_code']);
             //will not validate later
         }
     }
     return apply_filters('em_coupons_em_booking_get_post', $result, $EM_Booking);
 }
 /**
  * Retreive the paypal pro vars needed to send to the gateway to proceed with payment
  * @param EM_Booking $EM_Booking
  */
 function processStripe($EM_Booking)
 {
     global $EM_Notices;
     if (empty($_POST['stripe_card_num'])) {
         $EM_Booking->add_error(__('Please enter credit card number', 'em-pro') . '"');
         return false;
     }
     if (empty($_POST['stripe_exp_date_month'])) {
         $EM_Booking->add_error(__('Please select expire month', 'em-pro') . '"');
         return false;
     }
     if (empty($_POST['stripe_exp_date_year'])) {
         $EM_Booking->add_error(__('Please select expire year', 'em-pro') . '"');
         return false;
     }
     if (empty($_POST['stripe_card_code'])) {
         $EM_Booking->add_error(__('Please enter CVV number', 'em-pro') . '"');
         return false;
     }
     if ($this->debug == 'yes') {
         // Send request to paypal
         EM_Pro::log(sprintf(__('Payment Processing Start here', 'emp_stripe')));
     }
     // Get the credit card details submitted by the form
     include "lib/Stripe.php";
     if ($this->debug == 'yes') {
         EM_Pro::log(sprintf(__('Payment Processing start after include library', 'emp_stripe')));
     }
     Stripe::setApiKey($this->SecretKey);
     if ($this->debug == 'yes') {
         EM_Pro::log(sprintf(__('Set Secret Key', 'emp_stripe')));
     }
     try {
         $amount = $EM_Booking->get_price(false, false, true);
         if ($this->debug == 'yes') {
             EM_Pro::log(sprintf(__('Credit Card token create', 'emp_stripe')));
         }
         $token_id = Stripe_Token::create(array("card" => array("number" => $_POST['stripe_card_num'], "exp_month" => $_POST['stripe_exp_date_month'], "exp_year" => $_POST['stripe_exp_date_year'], "cvc" => $_POST['stripe_card_code'])));
         if ($this->debug == 'yes') {
             EM_Pro::log(sprintf(__('Token genreated ID : %s', 'emp_stripe'), print_r($token_id->id, true)));
         }
         //Email Info
         $email_customer = get_option('em_' . $this->gateway . '_header_email_customer', 0) ? '1' : '0';
         //for later
         $header_email_receipt = get_option('em_' . $this->gateway . '_header_email_receipt');
         $footer_email_receipt = get_option('em_' . $this->gateway . '_footer_email_receipt');
         //Order Info
         $booking_id = $EM_Booking->booking_id;
         $booking_description = preg_replace('/[^a-zA-Z0-9\\s]/i', "", $EM_Booking->get_event()->event_name);
         //clean event name
         $charge = Stripe_Charge::create(array("amount" => $amount * 100, "currency" => get_option('dbem_bookings_currency', 'USD'), "card" => $token_id->id, "metadata" => array("order_id" => $booking_id), "description" => $booking_description));
         if ($this->debug == 'yes') {
             EM_Pro::log(sprintf(__('Return Response from Stripe: %s', 'emp_stripe'), print_r($charge, true)));
         }
         if ($token_id->id != '') {
             if ($charge->paid == true) {
                 if ($this->debug == 'yes') {
                     EM_Pro::log(sprintf(__('Payment Received...', 'emp_stripe')));
                 }
                 $EM_Booking->booking_meta[$this->gateway] = array('txn_id' => $charge->id, 'amount' => $amount);
                 $this->record_transaction($EM_Booking, $amount, get_option('dbem_bookings_currency', 'USD'), date('Y-m-d H:i:s', current_time('timestamp')), $charge->id, 'Completed', '');
                 $result = true;
             } else {
                 if ($this->debug == 'yes') {
                     EM_Pro::log(sprintf(__('Stripe payment failed. Payment declined.', 'emp_stripe')));
                 }
                 $EM_Booking->add_error('Stripe payment failed. Payment declined.');
                 $result = false;
             }
         } else {
             if ($this->debug == 'yes') {
                 EM_Pro::log(sprintf(__('Stripe payment failed. Payment declined. Please Check your Admin settings', 'emp_stripe')));
             }
             $EM_Booking->add_error('Stripe payment failed. Payment declined. Please Check your Admin settings');
         }
         //Return transaction_id or false
         return apply_filters('em_gateway_stripe_capture', $result, $EM_Booking, $this);
     } catch (Exception $e) {
         $EM_Booking->add_error(__('Connection error:', 'em-pro') . ': "' . $e->getMessage() . '"');
         return false;
     }
 }
 /**
  * Adds relevant actions to booking shown in the bookings table
  * @param EM_Booking $EM_Booking
  */
 function bookings_table_actions($actions, $EM_Booking)
 {
     return array('approve' => '<a class="em-bookings-approve em-bookings-approve-offline" href="' . em_add_get_params($_SERVER['REQUEST_URI'], array('action' => 'bookings_approve', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Approve', 'dbem') . '</a>', 'delete' => '<span class="trash"><a class="em-bookings-delete" href="' . em_add_get_params($_SERVER['REQUEST_URI'], array('action' => 'bookings_delete', 'booking_id' => $EM_Booking->booking_id)) . '">' . __('Delete', 'dbem') . '</a></span>', 'edit' => '<a class="em-bookings-edit" href="' . em_add_get_params($EM_Booking->get_event()->get_bookings_url(), array('booking_id' => $EM_Booking->booking_id, 'em_ajax' => null, 'em_obj' => null)) . '">' . __('Edit/View', 'dbem') . '</a>');
 }
Exemplo n.º 21
0
 /**
  * Triggered by the em_booking_add_yourgateway action, modifies the booking status if the event isn't free and also adds a filter to modify user feedback returned.
  * @param EM_Event $EM_Event
  * @param EM_Booking $EM_Booking
  * @param boolean $post_validation
  */
 function booking_add($EM_Event, $EM_Booking, $post_validation = false)
 {
     global $wpdb, $wp_rewrite, $EM_Notices;
     add_filter('em_action_booking_add', array(&$this, 'booking_form_feedback'), 1, 2);
     //modify the payment return
     add_filter('em_action_emp_checkout', array(&$this, 'booking_form_feedback'), 1, 2);
     //modify the payment return
     if ($EM_Booking->get_price() > 0) {
         $EM_Booking->booking_status = $this->status;
         //status 4 = awaiting online payment
     }
 }
 /**
  * @param string $replace
  * @param EM_Booking $EM_Booking
  * @param string $full_result
  * @return string
  */
 function placeholders($replace, $EM_Booking, $full_result)
 {
     if (empty($replace) || $replace == $full_result) {
         $user = $EM_Booking->get_person();
         $EM_Form = self::get_form($EM_Booking->event_id);
         if ($full_result == '#_BOOKINGFORMAttendee') {
             $replace = '';
             foreach ($EM_Form->form_fields as $field) {
                 $replace .= "\r\n" . $field['label'] . ': ';
                 if (!empty($user->{$field}['fieldid'])) {
                     //user profile is freshest, using this
                     $replace .= $user->{$field}['fieldid'];
                 } elseif (!empty($EM_Booking->booking_meta['registration'][$field['fieldid']])) {
                     //reg fields only exist as reg fields
                     if (!is_array($EM_Booking->booking_meta['registration'][$field['fieldid']])) {
                         $replace .= $EM_Booking->booking_meta['registration'][$field['fieldid']];
                     } else {
                         $replace .= implode(', ', $EM_Booking->booking_meta['registration'][$field['fieldid']]);
                     }
                 } elseif (!empty($EM_Booking->booking_meta['booking'][$field['fieldid']])) {
                     //match for custom field value
                     if (!is_array($EM_Booking->booking_meta['booking'][$field['fieldid']])) {
                         $replace .= $EM_Booking->booking_meta['booking'][$field['fieldid']];
                     } else {
                         $replace .= implode(', ', $EM_Booking->booking_meta['booking'][$field['fieldid']]);
                     }
                 }
             }
         }
     }
     return $replace;
     //no need for a filter, use the em_booking_email_placeholders filter
 }
Exemplo n.º 23
0
function em_ajax_actions()
{
    //TODO Clean this up.... use a uniformed way of calling EM Ajax actions
    if (!empty($_REQUEST['em_ajax']) || !empty($_REQUEST['em_ajax_action'])) {
        if (isset($_REQUEST['dbem_ajax_action']) && $_REQUEST['dbem_ajax_action'] == 'booking_data') {
            if (isset($_REQUEST['id'])) {
                $EM_Event = new EM_Event($_REQUEST['id']);
                echo "[{bookedSeats:" . $EM_Event->get_bookings()->get_booked_seats() . ", availableSeats:" . $EM_Event->get_bookings()->get_available_seats() . "}]";
            }
            die;
        }
        if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'get_location') {
            if (isset($_REQUEST['id'])) {
                $EM_Location = new EM_Location($_REQUEST['id']);
                $location_array = $EM_Location->to_array();
                $location_array['location_balloon'] = $EM_Location->output(get_option('dbem_location_baloon_format'));
                echo EM_Object::json_encode($location_array);
            }
            die;
        }
        if (isset($_REQUEST['query']) && $_REQUEST['query'] == 'GlobalMapData') {
            $locations = EM_Locations::get($_REQUEST);
            $json_locations = array();
            foreach ($locations as $location_key => $location) {
                $json_locations[$location_key] = $location->to_array();
                $json_locations[$location_key]['location_balloon'] = $location->output(get_option('dbem_map_text_format'));
            }
            echo EM_Object::json_encode($json_locations);
            die;
        }
        if (isset($_REQUEST['ajaxCalendar']) && $_REQUEST['ajaxCalendar']) {
            //FIXME if long events enabled originally, this won't show up on ajax call
            echo EM_Calendar::output($_REQUEST);
            die;
        }
        //EM Ajax requests require this flag.
        if (is_admin()) {
            //Admin operations
            //Booking Actions
            global $EM_Booking;
            if (!empty($_REQUEST['bookings']) || is_object($EM_Booking)) {
                if (is_object($EM_Booking)) {
                    $_REQUEST['bookings'] = $EM_Booking;
                    //small hack to prevent unecessary db reads
                }
                $EM_Bookings = new EM_Bookings();
                //Empty, not bound to event.
                if ($_REQUEST['action'] == 'bookings_approve') {
                    $EM_Bookings->approve($_REQUEST['bookings']);
                    echo $EM_Bookings->feedback_message;
                    die;
                } elseif ($_REQUEST['action'] == 'bookings_reject') {
                    $EM_Bookings->reject($_REQUEST['bookings']);
                    echo $EM_Bookings->feedback_message;
                    die;
                } elseif ($_REQUEST['action'] == 'bookings_unapprove') {
                    $EM_Bookings->unapprove($_REQUEST['bookings']);
                    echo $EM_Bookings->feedback_message;
                    die;
                } elseif ($_REQUEST['action'] == 'bookings_delete') {
                    //Just do it here, since we may be deleting bookings of different events.
                    $result = false;
                    if (EM_Object::array_is_numeric($_REQUEST['bookings'])) {
                        $results = array();
                        foreach ($_REQUEST['bookings'] as $booking_id) {
                            $EM_Booking = new EM_Booking($booking_id);
                            $results[] = $EM_Booking->delete();
                        }
                        $result = !in_array(false, $results);
                    } elseif (is_numeric($_REQUEST['bookings'])) {
                        $EM_Booking = new EM_Booking($_REQUEST['bookings']);
                        $result = $EM_Booking->delete();
                    } elseif (is_object($EM_Booking)) {
                        $result = $EM_Booking->delete();
                    }
                    if ($result) {
                        echo __('Booking Deleted', 'dbem');
                    } else {
                        echo '<span style="color:red">' . __('Booking deletion unsuccessful', 'dbem') . '</span>';
                    }
                    die;
                }
            }
            //Specific Oject Ajax
            if (!empty($_REQUEST['em_obj'])) {
                switch ($_REQUEST['em_obj']) {
                    case 'em_bookings_events_table':
                    case 'em_bookings_pending_table':
                    case 'em_bookings_confirmed_table':
                        call_user_func($_REQUEST['em_obj']);
                        break;
                }
                die;
            }
        }
    }
}
Exemplo n.º 24
0
 /**
  * Get bookings that match the array of arguments passed.
  * @return array 
  * @static
  */
 function get($args = array(), $count = false)
 {
     global $wpdb, $current_user;
     $bookings_table = EM_BOOKINGS_TABLE;
     $events_table = EM_EVENTS_TABLE;
     $locations_table = EM_LOCATIONS_TABLE;
     //Quick version, we can accept an array of IDs, which is easy to retrieve
     if (self::array_is_numeric($args)) {
         //Array of numbers, assume they are event IDs to retreive
         //We can just get all the events here and return them
         $sql = "\r\n\t\t\t\tSELECT * FROM {$bookings_table} b \r\n\t\t\t\tLEFT JOIN {$events_table} e ON e.event_id=b.event_id \r\n\t\t\t\tWHERE booking_id" . implode(" OR booking_id=", $args);
         $results = $wpdb->get_results(apply_filters('em_bookings_get_sql', $sql), ARRAY_A);
         $bookings = array();
         foreach ($results as $result) {
             $bookings[] = new EM_Booking($result);
         }
         return $bookings;
         //We return all the bookings matched as an EM_Booking array.
     }
     //We assume it's either an empty array or array of search arguments to merge with defaults
     $args = self::get_default_search($args);
     $limit = $args['limit'] && is_numeric($args['limit']) ? "LIMIT {$args['limit']}" : '';
     $offset = $limit != "" && is_numeric($args['offset']) ? "OFFSET {$args['offset']}" : '';
     //Get the default conditions
     $conditions = self::build_sql_conditions($args);
     //Put it all together
     $where = count($conditions) > 0 ? " WHERE " . implode(" AND ", $conditions) : '';
     //Get ordering instructions
     $EM_Booking = new EM_Booking();
     $accepted_fields = $EM_Booking->get_fields(true);
     $orderby = self::build_sql_orderby($args, $accepted_fields);
     //Now, build orderby sql
     $orderby_sql = count($orderby) > 0 ? 'ORDER BY ' . implode(', ', $orderby) : '';
     //Selector
     $selectors = $count ? 'COUNT(*)' : '*';
     //Create the SQL statement and execute
     $sql = "\r\n\t\t\tSELECT {$selectors} FROM {$bookings_table} \r\n\t\t\tLEFT JOIN {$events_table} ON {$events_table}.event_id={$bookings_table}.event_id \r\n\t\t\tLEFT JOIN {$locations_table} ON {$locations_table}.location_id={$events_table}.location_id\r\n\t\t\t{$where}\r\n\t\t\t{$orderby_sql}\r\n\t\t\t{$limit} {$offset}\r\n\t\t";
     //If we're only counting results, return the number of results
     if ($count) {
         return apply_filters('em_bookings_get_count', $wpdb->get_var($sql), $args);
     }
     $results = $wpdb->get_results(apply_filters('em_events_get_sql', $sql, $args), ARRAY_A);
     //If we want results directly in an array, why not have a shortcut here?
     if ($args['array'] == true) {
         return $results;
     }
     //Make returned results EM_Booking objects
     $results = is_array($results) ? $results : array();
     $bookings = array();
     foreach ($results as $booking) {
         $bookings[] = new EM_Booking($booking);
     }
     $EM_Bookings = new EM_Bookings($bookings);
     return apply_filters('em_bookings_get', $EM_Bookings);
 }
Exemplo n.º 25
0
/**
 * Performs actions on init. This works for both ajax and normal requests, the return results depends if an em_ajax flag is passed via POST or GET.
 */
function em_init_actions()
{
    global $wpdb, $EM_Notices, $EM_Event;
    //NOTE - No EM objects are globalized at this point, as we're hitting early init mode.
    //TODO Clean this up.... use a uniformed way of calling EM Ajax actions
    if (!empty($_REQUEST['em_ajax']) || !empty($_REQUEST['em_ajax_action'])) {
        if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'get_location') {
            if (isset($_REQUEST['id'])) {
                $EM_Location = new EM_Location($_REQUEST['id']);
                $location_array = $EM_Location->to_array();
                $location_array['location_balloon'] = $EM_Location->output(get_option('dbem_location_baloon_format'));
                echo EM_Object::json_encode($location_array);
            }
            die;
        }
        if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'delete_ticket') {
            if (isset($_REQUEST['id'])) {
                $EM_Ticket = new EM_Ticket($_REQUEST['id']);
                $result = $EM_Ticket->delete();
                if ($result) {
                    $result = array('result' => true);
                } else {
                    $result = array('result' => false, 'error' => $EM_Ticket->feedback_message);
                }
            } else {
                $result = array('result' => false, 'error' => __('No ticket id provided', 'dbem'));
            }
            echo EM_Object::json_encode($result);
            die;
        }
        if (isset($_REQUEST['query']) && $_REQUEST['query'] == 'GlobalMapData') {
            $EM_Locations = EM_Locations::get($_REQUEST);
            $json_locations = array();
            foreach ($EM_Locations as $location_key => $EM_Location) {
                $json_locations[$location_key] = $EM_Location->to_array();
                $json_locations[$location_key]['location_balloon'] = $EM_Location->output(get_option('dbem_map_text_format'));
            }
            echo EM_Object::json_encode($json_locations);
            die;
        }
        if (isset($_REQUEST['ajaxCalendar']) && $_REQUEST['ajaxCalendar']) {
            //FIXME if long events enabled originally, this won't show up on ajax call
            echo EM_Calendar::output($_REQUEST);
            die;
        }
    }
    //Event Actions
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 5) == 'event') {
        //Load the event object, with saved event if requested
        if (!empty($_REQUEST['event_id'])) {
            $EM_Event = new EM_Event($_REQUEST['event_id']);
        } else {
            $EM_Event = new EM_Event();
        }
        if ($_REQUEST['action'] == 'event_save' && current_user_can('edit_events')) {
            //Check Nonces
            if (is_admin()) {
                if (!wp_verify_nonce($_REQUEST['_wpnonce'] && 'event_save')) {
                    check_admin_referer('trigger_error');
                }
            } else {
                if (!wp_verify_nonce($_REQUEST['_wpnonce'] && 'event_save')) {
                    exit('Trying to perform an illegal action.');
                }
            }
            //Grab and validate submitted data
            if ($EM_Event->get_post() && $EM_Event->save()) {
                //EM_Event gets the event if submitted via POST and validates it (safer than to depend on JS)
                $EM_Notices->add_confirm($EM_Event->feedback_message);
                if (is_admin()) {
                    $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : '';
                    $scope = !empty($_REQUEST['scope']) ? $_REQUEST['scope'] : '';
                    //wp_redirect( get_bloginfo('wpurl').'/wp-admin/admin.php?page=events-manager&pno='.$page.'&scope='.$scope.'&message='.urlencode($EM_Event->feedback_message));
                } else {
                    $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer();
                    wp_redirect($redirect);
                }
                $events_result = true;
            } else {
                $EM_Notices->add_error($EM_Event->get_errors());
                $events_result = false;
            }
        }
        if ($_REQUEST['action'] == 'event_duplicate') {
            global $EZSQL_ERROR;
            $EM_Event = $EM_Event->duplicate();
            if ($EM_Event === false) {
                $EM_Notices->add_error($EM_Event->errors, true);
            } else {
                if ($EM_Event->id == $_REQUEST['event_id']) {
                    $EM_Notices->add_confirm($EM_Event->feedback_message . " " . sprintf(__('You are now viewing the duplicated %s.', 'dbem'), __('event', 'dbem')), true);
                } else {
                    $EM_Notices->add_confirm($EM_Event->feedback_message, true);
                }
            }
        }
        if ($_REQUEST['action'] == 'event_delete') {
            //DELETE action
            $selectedEvents = !empty($_REQUEST['events']) ? $_REQUEST['events'] : '';
            if (EM_Object::array_is_numeric($selectedEvents)) {
                $events_result = EM_Events::delete($selectedEvents);
            } elseif (is_object($EM_Event)) {
                $events_result = $EM_Event->delete();
            }
            $plural = count($selectedEvents) > 1 ? __('Events', 'dbem') : __('Event', 'dbem');
            if ($events_result) {
                $message = is_object($EM_Event) ? $EM_Event->feedback_message : sprintf(__('%s successfully deleted.', 'dbem'), $plural);
                $EM_Notices->add_confirm($message);
            } else {
                $message = is_object($EM_Event) ? $EM_Event->errors : sprintf(__('%s could not be deleted.', 'dbem'), $plural);
                $EM_Notices->add_confirm($message);
            }
        } elseif ($_REQUEST['action'] == 'event_approve') {
            //Approve Action
            $events_result = $EM_Event->approve();
            if ($events_result) {
                $EM_Notices->add_confirm($EM_Event->feedback_message);
            } else {
                $EM_Notices->add_error($EM_Event->errors);
            }
        }
        //AJAX Exit
        if (isset($events_result) && !empty($_REQUEST['em_ajax'])) {
            if ($events_result) {
                $return = array('result' => true, 'message' => $EM_Event->feedback_message);
            } else {
                $return = array('result' => false, 'message' => $EM_Event->feedback_message, 'errors' => $EM_Event->errors);
            }
        }
    }
    //Location Actions
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 8) == 'location') {
        global $EM_Location, $EM_Notices;
        //Load the location object, with saved event if requested
        if (!empty($_REQUEST['location_id'])) {
            $EM_Location = new EM_Location($_REQUEST['location_id']);
        } else {
            $EM_Location = new EM_Location();
        }
        if ($_REQUEST['action'] == 'location_save' && current_user_can('edit_locations')) {
            //Check Nonces
            em_verify_nonce('location_save');
            //Grab and validate submitted data
            if ($EM_Location->get_post() && $EM_Location->save()) {
                //EM_location gets the location if submitted via POST and validates it (safer than to depend on JS)
                $EM_Notices->add_confirm($EM_Location->feedback_message);
                $result = true;
            } else {
                $EM_Notices->add_error($EM_Location->get_errors());
                $result = false;
            }
        } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "location_delete") {
            //delete location
            //get object or objects
            if (!empty($_REQUEST['locations']) || !empty($_REQUEST['location_id'])) {
                $args = !empty($_REQUEST['locations']) ? $_REQUEST['locations'] : $_REQUEST['location_id'];
                $locations = EM_Locations::get($args);
                foreach ($locations as $location) {
                    if (!$location->delete()) {
                        $EM_Notices->add_error($location->get_errors());
                        $errors = true;
                    }
                }
                if (empty($errors)) {
                    $result = true;
                    $location_term = count($locations) > 1 ? __('Locations', 'dbem') : __('Location', 'dbem');
                    $EM_Notices->add_confirm(sprintf(__('%s successfully deleted', 'dbem'), $location_term));
                } else {
                    $result = false;
                }
            }
        }
        if (isset($result) && $result && !empty($_REQUEST['em_ajax'])) {
            $return = array('result' => true, 'message' => $EM_Location->feedback_message);
            echo EM_Object::json_encode($return);
            die;
        } elseif (isset($result) && !$result && !empty($_REQUEST['em_ajax'])) {
            $return = array('result' => false, 'message' => $EM_Location->feedback_message, 'errors' => $EM_Notices->get_errors());
            echo EM_Object::json_encode($return);
            die;
        }
    }
    //Category Actions
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 8) == 'category') {
        global $EM_Category, $EM_Notices;
        //Load the category object, with saved event if requested
        if (!empty($_REQUEST['category_id'])) {
            $EM_Category = new EM_Category($_REQUEST['category_id']);
        } else {
            $EM_Category = new EM_Category();
        }
        if ($_REQUEST['action'] == 'category_save' && current_user_can('edit_categories')) {
            //Check Nonces
            em_verify_nonce('category_save');
            //Grab and validate submitted data
            if ($EM_Category->get_post() && $EM_Category->save()) {
                //EM_Category gets the category if submitted via POST and validates it (safer than to depend on JS)
                $EM_Notices->add_confirm($EM_Category->feedback_message);
                $result = true;
            } else {
                $EM_Notices->add_error($EM_Category->get_errors());
                $result = false;
            }
        } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "category_delete") {
            //delete category
            //get object or objects
            if (!empty($_REQUEST['categories']) || !empty($_REQUEST['category_id'])) {
                $args = !empty($_REQUEST['categories']) ? $_REQUEST['categories'] : $_REQUEST['category_id'];
                $categories = EM_Categories::get($args);
                foreach ($categories as $category) {
                    if (!$category->delete()) {
                        $EM_Notices->add_error($category->get_errors());
                        $errors = true;
                    }
                }
                if (empty($errors)) {
                    $result = true;
                    $category_term = count($categories) > 1 ? __('EM_Categories', 'dbem') : __('Category', 'dbem');
                    $EM_Notices->add_confirm(sprintf(__('%s successfully deleted', 'dbem'), $category_term));
                } else {
                    $result = false;
                }
            }
        }
        if (isset($result) && $result && !empty($_REQUEST['em_ajax'])) {
            $return = array('result' => true, 'message' => $EM_Category->feedback_message);
            echo EM_Object::json_encode($return);
            die;
        } elseif (isset($result) && !$result && !empty($_REQUEST['em_ajax'])) {
            $return = array('result' => false, 'message' => $EM_Category->feedback_message, 'errors' => $EM_Notices->get_errors());
            echo EM_Object::json_encode($return);
            die;
        }
    }
    //Booking Actions
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 7) == 'booking' && (is_user_logged_in() || $_REQUEST['action'] == 'booking_add' && get_option('dbem_bookings_anonymous'))) {
        global $EM_Event, $EM_Booking, $EM_Person;
        //Load the event object, with saved event if requested
        $EM_Event = !empty($_REQUEST['event_id']) ? new EM_Event($_REQUEST['event_id']) : new EM_Event();
        //Load the booking object, with saved booking if requested
        $EM_Booking = !empty($_REQUEST['booking_id']) ? new EM_Booking($_REQUEST['booking_id']) : new EM_Booking();
        $allowed_actions = array('bookings_approve' => 'approve', 'bookings_reject' => 'reject', 'bookings_unapprove' => 'unapprove', 'bookings_delete' => 'delete');
        $result = false;
        if ($_REQUEST['action'] == 'booking_add') {
            //ADD/EDIT Booking
            em_verify_nonce('booking_add');
            do_action('em_booking_add', $EM_Event, $EM_Booking);
            if ($EM_Booking->get_post()) {
                //Does this user need to be registered first?
                $registration = true;
                //TODO do some ticket validation before registering the user
                if ($_REQUEST['register_user'] && get_option('dbem_bookings_anonymous')) {
                    //find random username - less options for user, less things go wrong
                    $username_root = explode('@', $_REQUEST['user_email']);
                    $username_rand = $username_root[0] . rand(1, 1000);
                    while (username_exists($username_root[0] . rand(1, 1000))) {
                        $username_rand = $username_root[0] . rand(1, 1000);
                    }
                    $id = em_register_new_user($username_rand, $_REQUEST['user_email'], $_REQUEST['user_name'], $_REQUEST['user_phone']);
                    if (is_numeric($id)) {
                        $EM_Person = new EM_Person($id);
                        $EM_Booking->person_id = $id;
                        $EM_Notices->add_confirm(__('A new user account has been created for you. Please check your email for access details.', 'dbem'));
                    } else {
                        $registration = false;
                        if (is_object($id) && get_class($id) == 'WP_Error') {
                            /* @var $id WP_Error */
                            if ($id->get_error_code() == 'email_exists') {
                                $EM_Notices->add_error(__('This email already exists in our system, please log in to register to proceed with your booking.', 'dbem'));
                            } else {
                                $EM_Notices->add_error($id->get_error_messages());
                            }
                        } else {
                            $EM_Notices->add_error(__('There was a problem creating a user account, please contact a website administrator.', 'dbem'));
                        }
                    }
                }
                if ($EM_Event->get_bookings()->add($EM_Booking) && $registration) {
                    $result = true;
                    $EM_Notices->add_confirm($EM_Event->get_bookings()->feedback_message);
                } else {
                    ob_start();
                    echo "<pre>";
                    print_r($id);
                    echo "</pre>";
                    $EM_Booking->feedback_message = ob_get_clean();
                    $EM_Notices->add_error($EM_Event->get_bookings()->get_errors());
                }
            } else {
                $result = false;
                $EM_Notices->add_error($EM_Booking->get_errors());
            }
        } elseif ($_REQUEST['action'] == 'booking_add_one' && is_object($EM_Event) && is_user_logged_in()) {
            //ADD/EDIT Booking
            em_verify_nonce('booking_add_one');
            $EM_Booking = new EM_Booking(array('person_id' => get_current_user_id(), 'event_id' => $EM_Event->id));
            //new booking
            //get first ticket in this event and book one place there.
            $EM_Ticket = $EM_Event->get_bookings()->get_tickets()->get_first();
            $EM_Ticket_Booking = new EM_Ticket_Booking(array('ticket_id' => $EM_Ticket->id, 'ticket_booking_spaces' => 1));
            $EM_Booking->get_tickets_bookings();
            $EM_Booking->tickets_bookings->tickets_bookings[] = $EM_Ticket_Booking;
            //Now save booking
            if ($EM_Event->get_bookings()->add($EM_Booking)) {
                $EM_Booking = $booking;
                $result = true;
                $EM_Notices->add_confirm($EM_Event->get_bookings()->feedback_message);
            } else {
                $EM_Notices->add_error($EM_Event->get_bookings()->get_errors());
            }
        } elseif ($_REQUEST['action'] == 'booking_cancel') {
            //Cancel Booking
            em_verify_nonce('booking_cancel');
            if ($EM_Booking->can_manage() || $EM_Booking->person->ID == get_current_user_id()) {
                if ($EM_Booking->cancel()) {
                    $result = true;
                    if (!defined('DOING_AJAX')) {
                        if ($EM_Booking->person->ID == get_current_user_id()) {
                            $EM_Notices->add_confirm(sprintf(__('Booking %s', 'dbem'), __('Cancelled', 'dbem')), true);
                        } else {
                            $EM_Notices->add_confirm($EM_Booking->feedback_message, true);
                        }
                        wp_redirect($_SERVER['HTTP_REFERER']);
                        exit;
                    }
                } else {
                    $EM_Notices->add_error($EM_Booking->get_errors());
                }
            } else {
                $EM_Notices->add_error(__('You must log in to cancel your booking.', 'dbem'));
            }
        } elseif (array_key_exists($_REQUEST['action'], $allowed_actions) && $EM_Event->can_manage('manage_bookings', 'manage_others_bookings')) {
            //Event Admin only actions
            $action = $allowed_actions[$_REQUEST['action']];
            //Just do it here, since we may be deleting bookings of different events.
            if (!empty($_REQUEST['bookings']) && EM_Object::array_is_numeric($_REQUEST['bookings'])) {
                $results = array();
                foreach ($_REQUEST['bookings'] as $booking_id) {
                    $EM_Booking = new EM_Booking($booking_id);
                    $result = $EM_Booking->{$action}();
                    $results[] = $result;
                    if (!in_array(false, $results) && !$result) {
                        $feedback = $EM_Booking->feedback_message;
                    }
                }
                $result = !in_array(false, $results);
            } elseif (is_object($EM_Booking)) {
                $result = $EM_Booking->{$action}();
                $feedback = $EM_Booking->feedback_message;
            }
            //FIXME not adhereing to object's feedback or error message, like other bits in this file.
            //TODO multiple deletion won't work in ajax
            if (isset($result) && !empty($_REQUEST['em_ajax'])) {
                if ($result) {
                    echo $feedback;
                } else {
                    echo '<span style="color:red">' . $feedback . '</span>';
                }
                die;
            }
        }
        if ($result && defined('DOING_AJAX')) {
            $return = array('result' => true, 'message' => $EM_Booking->feedback_message);
            echo EM_Object::json_encode($return);
            die;
        } elseif (!$result && defined('DOING_AJAX')) {
            $return = array('result' => false, 'message' => $EM_Booking->feedback_message, 'errors' => $EM_Notices->get_errors());
            echo EM_Object::json_encode($return);
            die;
        }
    } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'booking_add' && !is_user_logged_in() && !get_option('dbem_bookings_anonymous')) {
        $EM_Notices->add_error(__('You must log in before you make a booking.', 'dbem'));
        if (!$result && defined('DOING_AJAX')) {
            $return = array('result' => false, 'message' => $EM_Booking->feedback_message, 'errors' => $EM_Notices->get_errors());
            echo EM_Object::json_encode($return);
        }
        die;
    }
    //AJAX call for searches
    if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 6) == 'search') {
        if ($_REQUEST['action'] == 'search_states' && wp_verify_nonce($_REQUEST['_wpnonce'], 'search_states')) {
            if (!empty($_REQUEST['country'])) {
                $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_state AS value, location_country AS country, CONCAT(location_state, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_state IS NOT NULL AND location_state != '' AND location_country=%s", $_REQUEST['country']));
            } elseif (!empty($_REQUEST['region'])) {
                $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_state AS value, location_country AS country, CONCAT(location_state, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_state IS NOT NULL AND location_state != '' AND location_region=%s", $_REQUEST['region']));
            } else {
                $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_state AS value, location_country AS country, CONCAT(location_state, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE, $_REQUEST['country'] . "WHERE  location_state IS NOT NULL AND location_state != ''"));
            }
            if ($_REQUEST['return_html']) {
                //quick shortcut for quick html form manipulation
                ob_start();
                ?>
				<option value=''><?php 
                _e('All States', 'dbem');
                ?>
</option>
				<?php 
                foreach ($results as $result) {
                    echo "<option>{$result->value}</option>";
                }
                $return = ob_get_clean();
                echo apply_filters('em_ajax_search_states', $return);
                exit;
            } else {
                echo EM_Object::json_encode($results);
                exit;
            }
        }
        if ($_REQUEST['action'] == 'search_regions' && wp_verify_nonce($_REQUEST['_wpnonce'], 'search_regions')) {
            if (!empty($_REQUEST['country'])) {
                $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_region AS value, location_country AS country, CONCAT(location_region, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_region IS NOT NULL AND location_region != '' AND location_country=%s", $_REQUEST['country']));
            } else {
                $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_region AS value, location_country AS country, CONCAT(location_region, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_region IS NOT NULL AND location_region != ''", $_REQUEST['country']));
            }
            if ($_REQUEST['return_html']) {
                //quick shortcut for quick html form manipulation
                ob_start();
                ?>
				<option value=''><?php 
                _e('All Regions', 'dbem');
                ?>
</option>
				<?php 
                foreach ($results as $result) {
                    echo "<option>{$result->value}</option>";
                }
                $return = ob_get_clean();
                echo apply_filters('em_ajax_search_regions', $return);
                exit;
            } else {
                echo EM_Object::json_encode($results);
                exit;
            }
        } elseif ($_REQUEST['action'] == 'search_events' && wp_verify_nonce($_POST['_wpnonce'], 'search_events') && get_option('dbem_events_page_search')) {
            $args = EM_Events::get_post_search();
            ob_start();
            em_locate_template('templates/events-list.php', true, array('args' => $args));
            //if successful, this template overrides the settings and defaults, including search
            echo apply_filters('em_ajax_search_events', ob_get_clean(), $args);
            exit;
        }
    }
    //EM Ajax requests require this flag.
    if (is_admin() && is_user_logged_in()) {
        //Admin operations
        //Specific Oject Ajax
        if (!empty($_REQUEST['em_obj'])) {
            switch ($_REQUEST['em_obj']) {
                case 'em_bookings_events_table':
                case 'em_bookings_pending_table':
                case 'em_bookings_confirmed_table':
                    call_user_func($_REQUEST['em_obj']);
                    break;
            }
            die;
        }
    }
}
Exemplo n.º 26
0
/**
 * Decides whether to register a user based on a certain booking that is to be added
 * @param EM_Booking $EM_Booking 
 */
function em_booking_add_registration($EM_Booking)
{
    global $EM_Notices;
    //Does this user need to be registered first?
    $registration = true;
    if ((!is_user_logged_in() && get_option('dbem_bookings_anonymous') || EM_Bookings::is_registration_forced()) && !get_option('dbem_bookings_registration_disable')) {
        //find random username - less options for user, less things go wrong
        $username_root = explode('@', wp_kses_data($_REQUEST['user_email']));
        $username_root = $username_rand = sanitize_user($username_root[0], true);
        while (username_exists($username_rand)) {
            $username_rand = $username_root . rand(1, 1000);
        }
        $_REQUEST['dbem_phone'] = !empty($_REQUEST['dbem_phone']) ? wp_kses_data($_REQUEST['dbem_phone']) : '';
        //fix to prevent warnings
        $_REQUEST['user_name'] = !empty($_REQUEST['user_name']) ? wp_kses_data($_REQUEST['user_name']) : '';
        //fix to prevent warnings
        $user_data = array('user_login' => $username_rand, 'user_email' => $_REQUEST['user_email'], 'user_name' => $_REQUEST['user_name'], 'dbem_phone' => $_REQUEST['dbem_phone']);
        $id = em_register_new_user($user_data);
        if (is_numeric($id)) {
            $EM_Person = new EM_Person($id);
            $EM_Booking->person_id = $id;
            $feedback = get_option('dbem_booking_feedback_new_user');
            $EM_Notices->add_confirm($feedback);
            add_action('em_bookings_added', 'em_new_user_notification');
        } else {
            $registration = false;
            if (is_object($id) && get_class($id) == 'WP_Error') {
                /* @var $id WP_Error */
                if ($id->get_error_code() == 'email_exists') {
                    $EM_Notices->add_error(get_option('dbem_booking_feedback_email_exists'));
                } else {
                    $EM_Notices->add_error($id->get_error_messages());
                }
            } else {
                $EM_Notices->add_error(get_option('dbem_booking_feedback_reg_error'));
            }
        }
    } elseif ((!is_user_logged_in() || EM_Bookings::is_registration_forced()) && get_option('dbem_bookings_registration_disable')) {
        //Validate name, phone and email
        if ($EM_Booking->get_person_post()) {
            //Save default person to booking
            $EM_Booking->person_id = get_option('dbem_bookings_registration_user');
        } else {
            $registration = false;
        }
    } elseif (!is_user_logged_in()) {
        $registration = false;
        $EM_Notices->add_error(get_option('dbem_booking_feedback_log_in'));
    } elseif (empty($EM_Booking->person_id)) {
        //user must be logged in, so we make this person the current user id
        $EM_Booking->person_id = get_current_user_id();
    }
    return apply_filters('em_booking_add_registration_result', $registration, $EM_Booking, $EM_Notices);
}
	/**
	* attempt to process payment
	* @param EM_Booking $EM_Booking
	* @return boolean
	*/
	public function processPayment($EM_Booking){
		// process the payment
		$isLiveSite = !(get_option('em_' . EM_EWAY_GATEWAY . '_mode') == 'sandbox');
		if (!$isLiveSite && get_option('em_' . EM_EWAY_GATEWAY . '_test_force')) {
			$customerID = EWAY_PAYMENTS_TEST_CUSTOMER;
		}
		else {
			$customerID = get_option('em_' . EM_EWAY_GATEWAY . '_cust_id');
		}

		if (get_option('em_' . EM_EWAY_GATEWAY . '_stored')) {
			$eway = new EwayPaymentsStoredPayment($customerID, $isLiveSite);
		}
		else {
			$eway = new EwayPaymentsPayment($customerID, $isLiveSite);
		}

		$eway->invoiceDescription			= $EM_Booking->get_event()->event_name;
		//~ $eway->invoiceDescription		= $EM_Booking->output('#_BOOKINGTICKETDESCRIPTION');
		$eway->invoiceReference				= $EM_Booking->booking_id;						// customer invoice reference
		$eway->transactionNumber			= $EM_Booking->booking_id;						// transaction reference
		$eway->cardHoldersName				= self::getPostValue('x_card_name');
		$eway->cardNumber					= strtr(self::getPostValue('x_card_num'), array(' ' => '', '-' => ''));
		$eway->cardExpiryMonth				= self::getPostValue('x_exp_date_month');
		$eway->cardExpiryYear				= self::getPostValue('x_exp_date_year');
		$eway->cardVerificationNumber		= self::getPostValue('x_card_code');
		$eway->emailAddress					= $EM_Booking->get_person()->user_email;
		$eway->postcode						= self::getPostValue('zip');

		// for Beagle (free) security
		if (get_option('em_' . EM_EWAY_GATEWAY . '_beagle')) {
			$eway->customerCountryCode		= EM_Gateways::get_customer_field('country', $EM_Booking);
		}

		// attempt to split name into parts, and hope to not offend anyone!
		$names = explode(' ', $EM_Booking->get_person()->get_name());
		if (!empty($names[0])) {
			$eway->firstName				= array_shift($names);		// remove first name from array
		}
		$eway->lastName						= trim(implode(' ', $names));

		// use cardholder name for last name if no customer name entered
		if (empty($eway->firstName) && empty($eway->lastName)) {
			$eway->lastName = $eway->cardHoldersName;
		}

		// aggregate street, city, state, country into a single string
		$parts = array (
			EM_Gateways::get_customer_field('address', $EM_Booking),
			EM_Gateways::get_customer_field('address_2', $EM_Booking),
			EM_Gateways::get_customer_field('city', $EM_Booking),
			EM_Gateways::get_customer_field('state', $EM_Booking),
			self::getCountryName(EM_Gateways::get_customer_field('country', $EM_Booking)),
		);
		$eway->address						= implode(', ', array_filter($parts, 'strlen'));

		// if live, pass through amount exactly, but if using test site, round up to whole dollars or eWAY will fail
		$amount = $EM_Booking->get_price(false, false, true);
		$amount = apply_filters('em_eway_amount', $amount, $EM_Booking);
		$eway->amount						= $isLiveSite ? $amount : ceil($amount);

		// allow plugins/themes to modify invoice description and reference, and set option fields
		$eway->invoiceDescription			= apply_filters('em_eway_invoice_desc', $eway->invoiceDescription, $EM_Booking);
		$eway->invoiceReference				= apply_filters('em_eway_invoice_ref', $eway->invoiceReference, $EM_Booking);
		$eway->option1						= apply_filters('em_eway_option1', '', $EM_Booking);
		$eway->option2						= apply_filters('em_eway_option2', '', $EM_Booking);
		$eway->option3						= apply_filters('em_eway_option3', '', $EM_Booking);

		// Get Payment
		try {
			$result = false;
			$response = $eway->processPayment();

			if ($response->status) {
				// transaction was successful, so record transaction number and continue
				$EM_Booking->booking_meta[EM_EWAY_GATEWAY] = array(
					'txn_id'	=> $response->transactionNumber,
					'authcode'	=> $response->authCode,
					'amount'	=> $response->amount,
				);

				$notes = array();
				if (!empty($response->authCode)) {
					$notes[] = 'Authcode: ' . $response->authCode;
				}
				if (!empty($response->beagleScore)) {
					$notes[] = 'Beagle score: ' . $response->beagleScore;
				}
				$note = implode("\n", $notes);

				$status = get_option('em_' . EM_EWAY_GATEWAY . '_stored') ? 'Pending' : 'Completed';
				$this->record_transaction($EM_Booking, $response->amount, 'AUD', date('Y-m-d H:i:s', current_time('timestamp')), $response->transactionNumber, $status, $note);
				$result = true;
			}
			else {
				// transaction was unsuccessful, so record the error
				$EM_Booking->add_error($response->error);
			}
		}
		catch (Exception $e) {
			// an exception occured, so record the error
			$EM_Booking->add_error($e->getMessage());
			return;
		}

		// Return status
		return apply_filters('em_gateway_eway_authorize', $result, $EM_Booking, $this);
	}