ion_string); $result = apply_filters('em_booking_set_status', $result, $this); // run the filter before emails go out, in case others need to hook in first if( $result && $this->previous_status != $this->booking_status ){ //email if status has changed do_action('em_booking_status_changed', $this, array('status' => $status, 'email' => $email, 'ignore_spaces' => $ignore_spaces)); // method params passed as array if( $email ){ $func_args = func_get_args(); $email_args = !empty($func_args[3]) ? $func_args[3] : array(); $email_args = array_merge( array('email_admin'=> true, 'force_resend' => false, 'email_attendee' => true), $email_args ); if( $this->email( !empty($email_args['email_admin']), !empty($email_args['force_resend']), !empty($email_args['email_attendee'])) ){ if( $this->mails_sent > 0 ){ $this->feedback_message .= " ".__('Email Sent.','events-manager'); } }else{ //extra errors may be logged by email() in EM_Object $this->feedback_message .= ' '.__('ERROR : Email Not Sent.','events-manager').''; $this->add_error(__('ERROR : Email Not Sent.','events-manager')); } } } }else{ //errors should be logged by save() $this->feedback_message = sprintf(__('Booking could not be %s.','events-manager'), $action_string); $this->add_error(sprintf(__('Booking could not be %s.','events-manager'), $action_string)); $result = apply_filters('em_booking_set_status', false, $this); } return $result; } public function can_cancel(){ if( get_option('dbem_bookings_user_cancellation') && !in_array($this->booking_status, array(2,3)) ){ $cancellation_time = get_option('dbem_bookings_user_cancellation_time'); $can_cancel = $this->get_event()->start()->getTimestamp() > time(); // previously default was rsvp end if( !empty($cancellation_time) && $cancellation_time > 0 ){ $EM_DateTime = $this->get_event()->start()->copy()->sub('PT'.$cancellation_time.'H'); $can_cancel = time() < $EM_DateTime->getTimestamp(); }elseif( static::is_dateinterval_string($cancellation_time) && $cancellation_time[0] !== '-' ){ $EM_DateTime = $this->get_event()->start()->copy()->sub($cancellation_time); $can_cancel = time() < $EM_DateTime->getTimestamp(); } }else{ $can_cancel = false; } return apply_filters('em_booking_can_cancel', $can_cancel, $this); } /* * Bookings that are made since */ public function can_uncancel() { $has_previous_status = isset( $this->booking_meta['previous_status'] ) || defined('EM_BOOKINGS_UNCANCEL_STATUS'); $can_uncancel = get_option('dbem_bookings_user_uncancellation') && $this->validate() && $has_previous_status; return apply_filters('em_booking_can_uncancel', $can_uncancel, $this); } public static function is_dateinterval_string( $string ){ return preg_match('/^\-?P(([0-9]+[YMDW])+)?(T(([0-9]+[HMS])+))?$/', $string); } /** * Returns true if booking is reserving a space at this event, whether confirmed or not */ function is_reserved(){ $result = false; if( $this->booking_status == 0 && get_option('dbem_bookings_approval_reserved') ){ $result = true; }elseif( $this->booking_status == 0 && !get_option('dbem_bookings_approval') ){ $result = true; }elseif( $this->booking_status == 1 ){ $result = true; } return apply_filters('em_booking_is_reserved', $result, $this); } /** * Returns true if booking is associated with a non-registered user, i.e. booked as a guest 'no user mode'. * @return mixed */ function is_no_user(){ return apply_filters('em_booking_is_no_user', $this->get_person()->ID === 0, $this); } /** * Returns true if booking is either pending but not confirmed (which is assumed pending). * Pending bookings do not mean they are necessarily reserved spaces, check is_reserved() for that. */ function is_pending(){ $result = ($this->is_reserved() || $this->booking_status == 0) && $this->booking_status != 1; return apply_filters('em_booking_is_pending', $result, $this); } /** * Set RSVP status to given number. Null sets booking to unconfirmed. * * @param null|int $status * @param array $args * * @return bool */ function set_rsvp_status( $status, $args = array() ) { global $wpdb; // get status strings $action_string = static::get_rsvp_statuses( $status )->label; //if we're approving we can't approve a booking if spaces are full, so check before it's approved. $this->previous_rsvp_status = $this->booking_rsvp_status; $this->booking_rsvp_status = ( $status !== null && $status <= 2 && $status >= 0 ) ? absint($status) : null; if ( $this->booking_rsvp_status === null ) { $result = $wpdb->query($wpdb->prepare('UPDATE '.EM_BOOKINGS_TABLE.' SET booking_rsvp_status=NULL WHERE booking_id=%d', array($this->booking_id))); } else { $result = $wpdb->query($wpdb->prepare('UPDATE '.EM_BOOKINGS_TABLE.' SET booking_rsvp_status=%d WHERE booking_id=%d', array($this->booking_rsvp_status, $this->booking_id))); } if ( $result !== false ) { $this->feedback_message = esc_html__( sprintf(__("Booking RSVP status set to '%s'.",'events-manager'), $action_string) ); $result = apply_filters('em_booking_set_rsvp_status', true, $this); if( $result && $this->previous_rsvp_status != $this->booking_rsvp_status ){ // act on booking status if there's a change in rsvp do_action('em_booking_rsvp_status_changed', $this, $status, $args); // method params passed as array if( $this->booking_rsvp_status === 0 && get_option('dbem_bookings_rsvp_sync_cancel') ) { $this->cancel(); } elseif ( $this->booking_rsvp_status === 1 && get_option('dbem_bookings_rsvp_sync_confirm') ) { $this->set_status(1); } elseif( $this->previous_rsvp_status === 0 && $this->can_uncancel() ) { $this->uncancel(); } } $this->feedback_message = static::get_rsvp_statuses($status)->confirmation; } else { //errors should be logged by save() $this->feedback_message = sprintf(__('Booking could not be %s.','events-manager'), $action_string); $this->add_error(sprintf(__('Booking could not be %s.','events-manager'), $action_string)); $result = apply_filters('em_booking_set_rsvp_status', false, $this, $args); } return $result; } /** * Get RSVP Status equivalents * @param $text * @param $status * * @return int|string|null */ function get_rsvp_status( $text = false ) { if( $text ) { $status = static::get_rsvp_statuses( $this->booking_rsvp_status ); return apply_filters('em_booking_get_rsvp_status_text', $status->label, $this, array('text' => $text, 'status' => $status)); } return apply_filters('em_booking_get_rsvp_status', $this->booking_rsvp_status, $this); } /** * Sets the RSVP status of a booking to 'Maybe' (status 2), not to be confused with the actual status of the booking. * @param $args * * @return bool */ public function can_change_rsvp() { $can_change = false; $changeable_statuses = apply_filters( 'em_booking_statuses_rsvp_changeable', array(0,1,3), $this ); if ( get_option('dbem_bookings_rsvp_can_change') && in_array( $this->booking_status, $changeable_statuses) ) { if ( $this->booking_status == 3 && $this->can_uncancel() ) { $can_change = true; } else { $can_change = true; } } return apply_filters( 'can_change_rsvp', $can_change, $this ); } /** * Returns true or false if user can RSVP a certain status, null if the current status is already the one requested. * @param int|null $status * * @return mixed|null */ public function can_rsvp( $status ) { $result = false; if( get_option( 'dbem_bookings_rsvp' ) ) { // check if we're changing the RSVP or doing anew with a specific status if ( $this->booking_rsvp_status !== null && $this->can_change_rsvp() ) { $can_rsvp = true; } else { $rsvpable_booking_statuses = apply_filters( 'em_booking_rsvpable_booking_statuses', array( 0, 1 ) ); if ( $this->booking_status === 3 && get_option( 'dbem_bookings_rsvp_sync_cancel' ) && $this->can_uncancel() ) { $rsvpable_booking_statuses[] = 3; } $can_rsvp = in_array( $this->booking_status, $rsvpable_booking_statuses ); } // general RSVP possible, now go deeper if ( $can_rsvp ) { if ( $status === null ) { // unconfirm $result = $this->can_manage(); // we cannot unconfirm unless an admin } elseif ( $status === 0 ) { // cancel if ( get_option( 'dbem_bookings_rsvp_sync_cancel' ) && $this->booking_rsvp_status !== $status ) { $result = $this->can_cancel(); } else { $result = true; } } elseif ( $status === 1 ) { // confirm $result = true; } elseif ( $status === 2 ) { // maybe if ( get_option( 'dbem_bookings_rsvp_maybe' ) ) { $result = true; } } if( $result ){ $result = $this->booking_rsvp_status === $status ? null : true; } } } return apply_filters('em_booking_can_rsvp', $result, $this, $status ); } public static function get_rsvp_statuses( $status = false ) { if( empty(static::$rsvp_statuses) ) { $statuses = array( null => array( 'label' => __('Unconfirmed', 'events-manager'), 'label_action' => __('Unconfirm', 'events-manager'), 'action' => 'unconfirm', 'confirmation' => __('Your booking is now unconfirmed', 'events-manager'), ), 0 => array( 'label' => __('Not Attending', 'events-manager'), 'label_action' => sprintf( __('RSVP - %s', 'events-manager'), __('No') ), 'label_answer' => __('No'), 'confirmation' => __('You have declined your attendance.', 'events-manager'), 'action' => 'decline', ), 1 => array( 'label' => __('Attending', 'events-manager'), 'label_action' => sprintf( __('RSVP - %s', 'events-manager'), __('Yes') ), 'label_answer' => __('Yes'), 'action' => 'confirm', 'confirmation' => __('You have confirmed your attendance.', 'events-manager'), ), ); if( get_option('dbem_bookings_rsvp_sync_cancel') ) { $statuses[0] = array_merge( $statuses[0], array( 'confirmation' => __('You have declined your attendance, your booking is now cancelled.', 'events-manager'), )); } if( get_option('dbem_bookings_rsvp_maybe') ) { $statuses[2] = array( 'label' => __('Maybe Attending', 'events-manager'), 'label_action' => sprintf( __('RSVP - %s', 'events-manager'), __('Maybe', 'events-manager') ), 'label_answer' => __('Maybe', 'events-manager'), 'action' => 'maybe', 'confirmation' => __('You have not definitively confrimed your attendance.', 'events-manager'), ); } $statuses = apply_filters( 'em_booking_get_rsvp_statuses', $statuses ); foreach( $statuses as $k => $s ) $statuses[$k] = (object) $s; static::$rsvp_statuses = $statuses; } if ( $status !== false ) { return !empty(static::$rsvp_statuses[$status]) ? static::$rsvp_statuses[$status] : static::$rsvp_statuses[null]; } return static::$rsvp_statuses; } /** * Add a booking note to this booking. returns wpdb result or false if use can't manage this event. * @param string $note * @return mixed */ function add_note( $note_text ){ global $wpdb; if( $this->can_manage() ){ $this->get_notes(); $note = array('author'=>get_current_user_id(),'note'=>wp_kses_data($note_text),'timestamp'=>time()); $this->notes[] = $note; $this->feedback_message = __('Booking note successfully added.','events-manager'); return $wpdb->insert(EM_META_TABLE, array('object_id'=>$this->booking_id, 'meta_key'=>'booking-note', 'meta_value'=> serialize($note)),array('%d','%s','%s')); } return false; } function get_admin_url(){ if( get_option('dbem_edit_bookings_page') && (!is_admin() || !empty($_REQUEST['is_public'])) ){ $my_bookings_page = get_permalink(get_option('dbem_edit_bookings_page')); $bookings_link = em_add_get_params($my_bookings_page, array('event_id'=>$this->event_id, 'booking_id'=>$this->booking_id), false); }else{ if( $this->get_event()->blog_id != get_current_blog_id() ){ $bookings_link = get_admin_url($this->get_event()->blog_id, 'edit.php?post_type='.EM_POST_TYPE_EVENT."&page=events-manager-bookings&event_id=".$this->event_id."&booking_id=".$this->booking_id); }else{ $bookings_link = EM_ADMIN_URL. "&page=events-manager-bookings&event_id=".$this->event_id."&booking_id=".$this->booking_id; } } return apply_filters('em_booking_get_bookings_url', $bookings_link, $this); } function output($format, $target="html") { do_action('em_booking_output_pre', $this, $format, $target); $output_string = $format; for ($i = 0 ; $i < EM_CONDITIONAL_RECURSIONS; $i++){ preg_match_all('/\{([a-zA-Z0-9_\-,]+)\}(.+?)\{\/\1\}/s', $output_string, $conditionals); if( count($conditionals[0]) > 0 ){ //Check if the language we want exists, if not we take the first language there foreach ($conditionals[1] as $key => $condition) { $show_condition = apply_filters('em_booking_output_show_condition', false, array('format' => $format, 'target' => $target, 'condition' => $condition, 'conditionals' => $conditionals, 'key' => $key), $this ); if ($condition == 'has_rsvp_reply') { //check if there's an rsvp $show_condition = $this->booking_rsvp_status !== null; } elseif ( $condition == 'no_rsvp_reply' ) { //check if there's no rsvp $show_condition = $this->booking_rsvp_status === null; } elseif ( $condition == 'is_rsvp_reply_no' ) { //check if there's no rsvp $show_condition = $this->booking_rsvp_status === 0; } elseif ( $condition == 'is_rsvp_reply_yes' ) { //check if there's no rsvp $show_condition = $this->booking_rsvp_status === 1; } elseif ( $condition == 'is_rsvp_reply_maybe' ) { //check if there's no rsvp $show_condition = $this->booking_rsvp_status === 2; } elseif ( preg_match('/^is_rsvp_reply_([0-9]+)$/', $condition, $matches ) ) { //check if there's no rsvp $show_condition = $this->booking_rsvp_status == $matches[1]; } if( $show_condition ){ //calculate lengths to delete placeholders $placeholder_length = strlen($condition)+2; $replacement = substr($conditionals[0][$key], $placeholder_length, strlen($conditionals[0][$key])-($placeholder_length *2 +1)); $output_string = str_replace($conditionals[0][$key], apply_filters('em_booking_output_condition', $replacement, $condition, $conditionals[0][$key], $this), $output_string); } } } } preg_match_all("/(#@?_?[A-Za-z0-9_]+)({([^}]+)})?/", $output_string, $placeholders); foreach( $this->get_tickets() as $EM_Ticket){ /* @var $EM_Ticket EM_Ticket */ break; } //Get first ticket for single ticket placeholders $replaces = array(); foreach($placeholders[1] as $key => $result) { $replace = ''; $full_result = $placeholders[0][$key]; $placeholder_atts = array($result); if( !empty($placeholders[3][$key]) ) $placeholder_atts[] = $placeholders[3][$key]; switch( $result ){ case '#_BOOKINGID': $replace = $this->booking_id; break; case '#_RESPNAME' : //deprecated case '#_BOOKINGNAME': $replace = $this->get_person()->get_name(); break; case '#_RESPEMAIL' : //deprecated case '#_BOOKINGEMAIL': $replace = $this->get_person()->user_email; break; case '#_RESPPHONE' : //deprecated case '#_BOOKINGPHONE': $replace = $this->get_person()->phone; break; case '#_BOOKINGSPACES': $replace = $this->get_spaces(); break; case '#_BOOKINGDATE': $replace = ( $this->date() !== false ) ? $this->date()->i18n( em_get_date_format() ):'n/a'; break; case '#_BOOKINGTIME': $replace = ( $this->date() !== false ) ? $this->date()->i18n( em_get_hour_format() ):'n/a'; break; case '#_BOOKINGDATETIME': $replace = ( $this->date() !== false ) ? $this->date()->i18n( em_get_date_format().' '.em_get_hour_format()):'n/a'; break; case '#_BOOKINGLISTURL': $replace = em_get_my_bookings_url(); break; case '#_COMMENT' : //deprecated case '#_BOOKINGCOMMENT': $replace = $this->booking_comment; break; case '#_BOOKINGPRICEWITHOUTTAX': $replace = $this->format_price($this->get_price() - $this->get_price_taxes()); break; case '#_BOOKINGPRICETAX': $replace = $this->get_price_taxes(true); break; case '#_BOOKINGPRICEWITHTAX': case '#_BOOKINGPRICE': $replace = $this->get_price(true); break; case '#_BOOKINGTICKETNAME': $replace = $EM_Ticket->name; break; case '#_BOOKINGTICKETDESCRIPTION': $replace = $EM_Ticket->description; break; case '#_BOOKINGTICKETPRICEWITHTAX': $replace = $this->format_price( $EM_Ticket->get_price_without_tax() * (1+$this->get_tax_rate()/100) ); break; case '#_BOOKINGTICKETPRICEWITHOUTTAX': $replace = $EM_Ticket->get_price_without_tax(true); break; case '#_BOOKINGTICKETTAX': $replace = $this->format_price( $EM_Ticket->get_price_without_tax() * ($this->get_tax_rate()/100) ); break; case '#_BOOKINGTICKETPRICE': $replace = $EM_Ticket->get_price(true); break; case '#_BOOKINGTICKETS': ob_start(); em_locate_template('emails/bookingtickets.php', true, array('EM_Booking'=>$this)); $replace = ob_get_clean(); break; case '#_BOOKINGSUMMARY': ob_start(); em_locate_template('emails/bookingsummary.php', true, array('EM_Booking'=>$this)); $replace = ob_get_clean(); break; case '#_BOOKINGADMINURL': case '#_BOOKINGADMINLINK': $bookings_link = esc_url( add_query_arg('booking_id', $this->booking_id, $this->get_event()->get_bookings_url()) ); if($result == '#_BOOKINGADMINLINK'){ $replace = ''.esc_html__('Edit Booking', 'events-manager'). ''; }else{ $replace = $bookings_link; } break; case '#_BOOKINGSTATUS': case '#_BOOKING_STATUS': $replace = $this->get_status(); break; case '#_BOOKINGRSVPSTATUS': case '#_BOOKING_RSVP_STATUS': $replace = $this->get_rsvp_status( true ); break; default: $replace = $this->output_placeholder( $full_result, $placeholder_atts, $format, $target ); break; } $replaces[$full_result] = apply_filters('em_booking_output_placeholder', $replace, $this, $full_result, $target, $placeholder_atts); } //sort out replacements so that during replacements shorter placeholders don't overwrite longer varieties. krsort($replaces); foreach($replaces as $full_result => $replacement){ $output_string = str_replace($full_result, $replacement , $output_string ); } //run event output too, since this is never run from within events and will not infinitely loop $EM_Event = apply_filters('em_booking_output_event', $this->get_event(), $this); //allows us to override the booking event info if it belongs to a parent or translation $output_string = $EM_Event->output($output_string, $target); return apply_filters('em_booking_output', $output_string, $this, $format, $target); } /** * Function mainly aimed for overriding by extending classes, avoiding the need to use a filter instead. * @param string $full_result * @param array $placeholder_atts * @param string $format * @param string $target * @return string */ public function output_placeholder( $full_result, $placeholder_atts, $format, $target ){ // $placeholder = $placeholder_atts[0]; // this is the placeholder, no atts return $full_result; } public function output_intent_html(){ $input = 'get_intent_data() as $key => $value ){ $input .= ' data-'.$key.'="'. esc_attr($value) .'"'; } $input .= '>'; return apply_filters('em_booking_output_intent_html', $input, $this); } public function get_intent_data(){ return array( 'uuid' => $this->booking_uuid, 'event_id' => $this->event_id, 'spaces' => $this->get_spaces(), 'amount' => $this->get_price(), 'amount_formatted' => $this->get_price( true ), 'amount_base' => $this->get_price_base(), 'taxes' => $this->get_price_taxes(), 'currency' => $this->get_currency(), ); } /** * @param boolean $email_admin * @param boolean $force_resend * @param boolean $email_attendee * @return boolean */ function email( $email_admin = true, $force_resend = false, $email_attendee = true ){ $result = true; $this->mails_sent = 0; //Make sure event matches booking, and that booking used to be approved. if( $this->booking_status !== $this->previous_status || $force_resend ){ // before we format dates or any other language-specific placeholders, make sure we're translating the site language, not the user profile language in the admin area (e.g. if an admin is sending a booking confirmation email), assuming this isn't a ML-enabled site. if( !EM_ML::$is_ml && is_admin() && EM_ML::$wplang != get_user_locale() ) EM_ML::switch_locale(EM_ML::$wplang); do_action('em_booking_email_before_send', $this); //get event info and refresh all bookings $EM_Event = $this->get_event(); //We NEED event details here. $EM_Event->get_bookings(true); //refresh all bookings //messages can be overridden just before being sent $msg = $this->email_messages(); $filter_args = array('email_admin'=> true, 'force_resend' => $force_resend, 'email_attendee' => $email_attendee, 'msg' => $msg ); //Send user (booker) emails if( !empty($msg['user']['subject']) && $email_attendee ){ $result = $this->email_attendee( $msg, $filter_args ); } //Send admin/contact emails if this isn't the event owner or an events admin if( $email_admin && !empty($msg['admin']['subject']) ){ //emails won't be sent if admin is logged in unless they book themselves $result = $this->email_admins( $msg ); } do_action('em_booking_email_after_send', $this); if( !EM_ML::$is_ml && is_admin() ) EM_ML::restore_locale(); // restore the locale back for the rest of the site, which will happen if we switched it earlier } return apply_filters('em_booking_email', $result, $this, $email_admin, $force_resend, $email_attendee); //TODO need error checking for booking mail send } function email_attendee( $msg, $filter_args = null ){ $result = true; if( !$filter_args ){ $filter_args = array('email_admin'=> true, 'force_resend' => true, 'email_attendee' => false, 'msg' => $msg ); } $msg['user']['subject'] = $this->output($msg['user']['subject'], 'raw'); $msg['user']['body'] = $this->output($msg['user']['body'], 'email'); $attachments = array(); if( !empty($msg['user']['attachments']) && is_array($msg['user']['attachments']) ){ $attachments = $msg['user']['attachments']; } //add extra args $args = array(); if( get_option('dbem_bookings_replyto_owner') && $this->get_event()->get_contact()->user_email ){ $args['reply-to'] = $this->get_event()->get_contact()->user_email; $args['reply-to-name'] = $this->get_event()->get_contact()->display_name; } $args = apply_filters('em_booking_email_user_args', $args, $filter_args, $this); //Send to the person booking if( !$this->email_send( $msg['user']['subject'], $msg['user']['body'], $this->get_person()->user_email, $attachments, $args) ){ $result = false; }else{ $this->mails_sent++; } return $result; } function email_admins( $msg, $filter_args = null ){ $result = true; $EM_Event = $this->get_event(); //We NEED event details here. if( !$filter_args ){ $filter_args = array('email_admin'=> true, 'force_resend' => true, 'email_attendee' => false, 'msg' => $msg ); } //get admin emails that need to be notified, hook here to add extra admin emails $admin_emails = str_replace(' ','',get_option('dbem_bookings_notify_admin')); $admin_emails = apply_filters('em_booking_admin_emails', explode(',', $admin_emails), $this); //supply emails as array if( get_option('dbem_bookings_contact_email') == 1 && !empty($EM_Event->get_contact()->user_email) ){ //add event owner contact email to list of admin emails $admin_emails[] = $EM_Event->get_contact()->user_email; } foreach($admin_emails as $key => $email){ if( !is_email($email) ) unset($admin_emails[$key]); } //remove bad emails //add extra args $args = array(); if( get_option('dbem_bookings_replyto_owner_admins') && $this->get_event()->get_contact()->user_email ){ $args['reply-to'] = $this->get_event()->get_contact()->user_email; $args['reply-to-name'] = $this->get_event()->get_contact()->display_name; } $args = apply_filters('em_booking_email_admin_args', $args, $filter_args, $this); //proceed to email admins if need be if( !empty($admin_emails) ){ //Only gets sent if this is a pending booking, unless approvals are disabled. $msg['admin']['subject'] = $this->output($msg['admin']['subject'],'raw'); $msg['admin']['body'] = $this->output($msg['admin']['body'], 'email'); $attachments = array(); if( !empty($msg['admin']['attachments']) && is_array($msg['admin']['attachments']) ){ $attachments = $msg['admin']['attachments']; } //email admins if( !$this->email_send( $msg['admin']['subject'], $msg['admin']['body'], $admin_emails, $attachments, $args) && current_user_can('manage_options') ){ $this->errors[] = __('Confirmation email could not be sent to admin. Registrant should have gotten their email (only admin see this warning).','events-manager'); $result = false; }else{ $this->mails_sent++; } } return $result; } function email_messages(){ $msg = array( 'user'=> array('subject'=>'', 'body'=>'', 'attachments' => array()), 'admin'=> array('subject'=>'', 'body'=>'', 'attachments' => array())); //blank msg template //admin messages won't change whether pending or already approved switch( $this->booking_status ){ case 0: case 5: //TODO remove offline status from here and move to pro $msg['user']['subject'] = get_option('dbem_bookings_email_pending_subject'); $msg['user']['body'] = get_option('dbem_bookings_email_pending_body'); //admins should get something (if set to) $msg['admin']['subject'] = get_option('dbem_bookings_contact_email_pending_subject'); $msg['admin']['body'] = get_option('dbem_bookings_contact_email_pending_body'); break; case 1: $msg['user']['subject'] = get_option('dbem_bookings_email_confirmed_subject'); $msg['user']['body'] = get_option('dbem_bookings_email_confirmed_body'); //admins should get something (if set to) $msg['admin']['subject'] = get_option('dbem_bookings_contact_email_confirmed_subject'); $msg['admin']['body'] = get_option('dbem_bookings_contact_email_confirmed_body'); break; case 2: $msg['user']['subject'] = get_option('dbem_bookings_email_rejected_subject'); $msg['user']['body'] = get_option('dbem_bookings_email_rejected_body'); //admins should get something (if set to) $msg['admin']['subject'] = get_option('dbem_bookings_contact_email_rejected_subject'); $msg['admin']['body'] = get_option('dbem_bookings_contact_email_rejected_body'); break; case 3: $msg['user']['subject'] = get_option('dbem_bookings_email_cancelled_subject'); $msg['user']['body'] = get_option('dbem_bookings_email_cancelled_body'); //admins should get something (if set to) $msg['admin']['subject'] = get_option('dbem_bookings_contact_email_cancelled_subject'); $msg['admin']['body'] = get_option('dbem_bookings_contact_email_cancelled_body'); break; } return apply_filters('em_booking_email_messages', $msg, $this); } /** * Returns an EM_DateTime representation of when booking was made in UTC timezone. If no valid date defined, false will be returned * @param boolean $utc_timezone * @return EM_DateTime * @throws Exception */ public function date( $utc_timezone = false ){ if( empty($this->date) || !$this->date->valid ){ if( !empty($this->booking_date ) ){ $this->date = new EM_DateTime($this->booking_date, 'UTC'); }else{ //we retrn a date regardless but it's not based on a 'valid' booking date $this->date = new EM_DateTime(); $this->date->valid = false; } } //Set to UTC timezone if requested, local blog time by default if( $utc_timezone ){ $timezone = 'UTC'; }else{ //we could set this to false but this way we might avoid creating a new timezone if it's already in this one $timezone = get_option( 'timezone_string' ); if( !$timezone ) $timezone = get_option('gmt_offset'); } $this->date->setTimezone($timezone); return $this->date; } /** * Can the user manage this event? */ function can_manage( $owner_capability = false, $admin_capability = false, $user_to_check = false ){ return $this->get_event()->can_manage('manage_bookings','manage_others_bookings') || empty($this->booking_id) || !empty($this->manage_override); } /** * Returns this object in the form of an array * @return array */ function to_array($person = false){ $booking = array(); //Core Data $booking = parent::to_array(); //Person Data if($person && is_object($this->person)){ $person = $this->person->to_array(); $booking = array_merge($booking, $person); } return $booking; } function to_api( $args = array('event' => true), $version = 'v1' ){ $booking = array ( 'id' => $this->booking_id, 'event_id' => $this->event_id, 'uuid' => $this->booking_uuid, 'person_id' => $this->person_id, 'status' => $this->booking_status, 'spaces' => $this->booking_spaces, 'price' => $this->get_price(), 'tax_rate' => $this->get_tax_rate(true), // returned as decimal/percen 'taxes' => $this->booking_taxes, 'comment' => $this->booking_comment, 'meta' => $this->booking_meta, 'tickets' => array(), 'datetime' => $this->booking_date, ); // add tickets foreach ( $this->get_tickets_bookings() as $EM_Ticket_Bookings ){ $booking['tickets'][$EM_Ticket_Bookings->ticket_id] = array( 'name' => $EM_Ticket_Bookings->get_ticket()->ticket_name, 'description' => $EM_Ticket_Bookings->get_ticket()->ticket_name, 'spaces' => $EM_Ticket_Bookings->get_spaces(), 'price' => $EM_Ticket_Bookings->get_price(), 'attendees' => array(), ); foreach ( $EM_Ticket_Bookings as $EM_Ticket_Booking ){ $booking['tickets'][$EM_Ticket_Bookings->ticket_id]['attendees'][] = array( 'uuid' => $EM_Ticket_Booking->ticket_uuid, 'price' => $EM_Ticket_Booking->ticket_booking_price, 'meta' => $EM_Ticket_Booking->meta, ); } } // if event data should be sent if( !empty($args['event']) ) { $booking['event'] = $this->get_event()->to_api(); } // user $booking['person'] = array( 'guest' => false, 'email' => $this->get_person()->user_email, 'name' => $this->get_person()->get_name(), ); if( $this->get_person()->phone ){ $booking['person']['phone'] = $this->get_person()->phone; } return apply_filters('em_booking_to_api', $booking, array(), $this); } /** * Used to process values from meta table bookings_meta. Other meta table values are processed in EM_Object. * * Processing the meta for bookings is slightly different for backwards compatibility reasons. This is because of how we split subkeys version 6.4.5.1 and below, which was with an underscore. The problem with underscores is that keys can contain underscores and we don't know where to make the split. * For bookings, we consider the first word until an underscore as a key, and the rest would be considered subkeys of an array. * Future versions of EM will split keys with a pipe so there's no confusion, and compatibility is taken into account here. * * @param array $raw_meta * @return array */ function process_meta( $raw_meta ){ $processed_meta = array(); foreach( $raw_meta as $meta ){ $meta_value = maybe_unserialize($meta['meta_value']); $meta_key = $meta['meta_key']; if( preg_match('/^_([a-zA-Z\-0-9 _]+)\|([a-zA-Z\-0-9 _]+)?$/', $meta_key, $match) || preg_match('/^_([a-zA-Z\-0-9]+)_([a-zA-Z\-0-9 _]+)$/', $meta_key, $match) ){ $key = $match[1]; if( empty($processed_meta[$key]) ) $processed_meta[$key] = array(); $subkey = isset($match[2]) ? $match[2] : count($processed_meta[$key]); // allows for storing arrays without a key, such as _beverage_choice| can be stored multiple times in a row if key is not relevant if( !empty($processed_meta[$key][$subkey]) && preg_match('/\|$/', $meta_key) ){ // we create an array unsequenced array without pre-deined keys, provided the key name ends with a pipe if( !is_array($processed_meta[$key][$subkey]) ) { $processed_meta[$key][$subkey] = array($processed_meta[$key][$subkey]); } $processed_meta[$key][$subkey][] = $meta_value; }else{ $processed_meta[$key][$subkey] = $meta_value; } }else{ $processed_meta[$meta_key] = $meta_value; } } return $processed_meta; } } ?> Fietsreparatie en verkoop - Alles voor Elkaar
Menu Sluiten

Fietsreparatie en verkoop