Exemplo n.º 1
0
function eme_multipayment_form($payment_id, $form_result_message = "")
{
    $ret_string = "<div id='eme-rsvp-message'>";
    if (!empty($form_result_message)) {
        $ret_string .= "<div class='eme-rsvp-message'>{$form_result_message}</div>";
    }
    $ret_string .= "</div>";
    $booking_ids = eme_get_payment_booking_ids($payment_id);
    if (!$booking_ids) {
        return $ret_string;
    }
    $bookings = eme_get_bookings($booking_ids);
    $total_price = eme_bookings_total_booking_price($bookings);
    // we take the currency of the first event in the series
    $event = eme_get_event_by_booking_id($booking_ids[0]);
    $booking = eme_get_booking($booking_ids[0]);
    $cur = $event['currency'];
    $eme_multipayment_form_header_format = get_option('eme_multipayment_form_header_format');
    if (!empty($eme_multipayment_form_header_format)) {
        $result = eme_replace_placeholders($eme_multipayment_form_header_format, $event, "html", 0);
        $result = eme_replace_booking_placeholders($result, $event, $booking);
        $ret_string .= "<div id='eme-payment-formtext' class='eme-payment-formtext'>";
        $ret_string .= $result;
        $ret_string .= "</div>";
    } else {
        $ret_string .= "<div id='eme-payment-handling' class='eme-payment-handling'>" . __('Payment handling', 'eme') . "</div>";
        $ret_string .= "<div id='eme-payment-price-info' class='eme-payment-price-info'>" . sprintf(__("The booking price in %s is: %01.2f", 'eme'), $cur, $total_price) . "</div>";
    }
    $ret_string .= "<div id='eme-payment-form' class='eme-payment-form'>";
    $payment = eme_get_payment($payment_id);
    if ($event['use_paypal']) {
        $ret_string .= eme_paypal_form($event, $payment, $total_price, $booking['lang'], 1);
    }
    if ($event['use_2co']) {
        $ret_string .= eme_2co_form($event, $payment, $total_price, $booking['lang'], 1);
    }
    if ($event['use_webmoney']) {
        $ret_string .= eme_webmoney_form($event, $payment, $total_price, $booking['lang'], 1);
    }
    if ($event['use_fdgg']) {
        $ret_string .= eme_fdgg_form($event, $payment, $total_price, $booking['lang'], 1);
    }
    if ($event['use_mollie']) {
        $ret_string .= eme_mollie_form($event, $payment, $total_price, $booking['lang'], 1);
    }
    if ($event['use_sagepay']) {
        $ret_string .= eme_sagepay_form($event, $payment, $total_price, $booking['lang'], 1);
    }
    if ($event['event_properties']['use_worldpay']) {
        $ret_string .= eme_worldpay_form($event, $payment, $total_price, $booking['lang'], 1);
    }
    $ret_string .= "</div>";
    $eme_multipayment_form_footer_format = get_option('eme_multipayment_form_footer_format');
    if (!empty($eme_multipayment_form_footer_format)) {
        $result = eme_replace_placeholders($eme_multipayment_form_footer_format, $event, "html", 0);
        $result = eme_replace_booking_placeholders($result, $event, $booking);
        $ret_string .= "<div id='eme-payment-formtext' class='eme-payment-formtext'>";
        $ret_string .= $result;
        $ret_string .= "</div>";
    }
    return $ret_string;
}
Exemplo n.º 2
0
function eme_replace_booking_placeholders($format, $event, $booking, $is_multibooking = 0, $target = "html", $lang = '')
{
    $deprecated = get_option('eme_deprecated');
    preg_match_all("/#(ESC)?_?[A-Za-z0-9_]+(\\{[A-Za-z0-9_]+\\})?/", $format, $placeholders);
    $person = eme_get_person($booking['person_id']);
    $current_userid = get_current_user_id();
    $answers = eme_get_answers($booking['booking_id']);
    $payment_id = eme_get_booking_payment_id($booking['booking_id']);
    $payment = eme_get_payment($payment_id);
    $booking_ids = array();
    $bookings = array();
    if ($payment_id) {
        $booking_ids = eme_get_payment_booking_ids($payment_id);
        $bookings = eme_get_bookings($booking_ids);
    }
    usort($placeholders[0], 'sort_stringlenth');
    foreach ($placeholders[0] as $result) {
        $replacement = '';
        $found = 1;
        $need_escape = 0;
        $orig_result = $result;
        if (strstr($result, '#ESC')) {
            $result = str_replace("#ESC", "#", $result);
            $need_escape = 1;
        }
        if (preg_match('/#_RESPID/', $result)) {
            $replacement = $person['person_id'];
            $replacement = eme_sanitize_html($replacement);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_RESP(NAME|LASTNAME|FIRSTNAME|ZIP|CITY|STATE|COUNTRY|ADDRESS1|ADDRESS2|PHONE|EMAIL)/', $result)) {
            $field = preg_replace("/#_RESP/", "", $result);
            $field = strtolower($field);
            if ($field == "name") {
                $field = "lastname";
            }
            $replacement = $person[$field];
            $replacement = eme_sanitize_html($replacement);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_(RESPCOMMENT|COMMENT)/', $result)) {
            $replacement = $booking['booking_comment'];
            $replacement = eme_sanitize_html($replacement);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif ($deprecated && preg_match('/#_RESPSPACES(\\d+)/', $result, $matches) || preg_match('/#_RESPSPACES\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]) - 1;
            if (eme_is_multi($booking['booking_price'])) {
                $seats = eme_convert_multi2array($booking['booking_seats_mp']);
                if (array_key_exists($field_id, $seats)) {
                    $replacement = $seats[$field_id];
                }
            }
        } elseif (preg_match('/#_TOTALPRICE$/', $result)) {
            $price = eme_get_total_booking_price($event, $booking);
            $replacement = sprintf("%01.2f", $price);
        } elseif (preg_match('/#_BOOKINGPRICEPERSEAT$/', $result)) {
            $price = eme_get_seat_booking_price($event, $booking);
            $replacement = sprintf("%01.2f", $price);
        } elseif (preg_match('/#_BOOKINGPRICEPERSEAT\\{(\\d+)\\}/', $result, $matches)) {
            // total price to pay per price if multiprice
            $total_prices = eme_get_seat_booking_multiprice($event, $booking);
            $field_id = intval($matches[1]) - 1;
            if (array_key_exists($field_id, $total_prices)) {
                $price = $total_prices[$field_id];
                $replacement = sprintf("%01.2f", $price);
            }
        } elseif (preg_match('/#_TOTALPRICE\\{(\\d+)\\}/', $result, $matches)) {
            // total price to pay per price if multiprice
            $total_prices = eme_get_total_booking_multiprice($event, $booking);
            $field_id = intval($matches[1]) - 1;
            if (array_key_exists($field_id, $total_prices)) {
                $price = $total_prices[$field_id];
                $replacement = sprintf("%01.2f", $price);
            }
        } elseif ($deprecated && preg_match('/#_TOTALPRICE(\\d+)/', $result, $matches)) {
            // total price to pay per price if multiprice
            $total_prices = eme_get_total_booking_multiprice($event, $booking);
            $field_id = intval($matches[1]) - 1;
            if (array_key_exists($field_id, $total_prices)) {
                $price = $total_prices[$field_id];
                $replacement = sprintf("%01.2f", $price);
            }
        } elseif (preg_match('/#_CHARGE\\{(.+)\\}$/', $result, $matches)) {
            $price = eme_get_total_booking_price($event, $booking);
            $replacement = eme_payment_provider_extra_charge($price, $matches[1]);
        } elseif (preg_match('/#_RESPSPACES$/', $result)) {
            $replacement = eme_get_multitotal($booking['booking_seats']);
        } elseif (preg_match('/#_BOOKINGCREATIONDATE/', $result)) {
            $replacement = eme_localised_date($booking['creation_date']);
        } elseif (preg_match('/#_BOOKINGMODIFDATE/', $result)) {
            $replacement = eme_localised_date($booking['modif_date']);
        } elseif (preg_match('/#_BOOKINGCREATIONTIME/', $result)) {
            $replacement = eme_localised_time($booking['creation_date']);
        } elseif (preg_match('/#_BOOKINGMODIFTIME/', $result)) {
            $replacement = eme_localised_time($booking['modif_date']);
        } elseif (preg_match('/#_BOOKINGID/', $result)) {
            $replacement = $booking['booking_id'];
        } elseif (preg_match('/#_TRANSFER_NBR_BE97/', $result)) {
            $replacement = $booking['transfer_nbr_be97'];
        } elseif (preg_match('/#_PAYMENT_URL/', $result)) {
            if ($payment_id && eme_event_can_pay_online($event)) {
                $replacement = eme_payment_url($payment_id);
            }
        } elseif (preg_match('/#_CANCEL_LINK$/', $result)) {
            $url = eme_cancel_url($payment['random_id']);
            $replacement = "<a href='{$url}'>" . __('Cancel booking', 'eme') . "</a>";
        } elseif (preg_match('/#_CANCEL_URL$/', $result)) {
            $replacement = eme_cancel_url($payment['random_id']);
        } elseif (preg_match('/#_CANCEL_CODE$/', $result)) {
            $replacement = $payment['random_id'];
        } elseif (preg_match('/#_FIELDS/', $result)) {
            $field_replace = "";
            foreach ($answers as $answer) {
                $tmp_answer = eme_convert_answer2tag($answer);
                $field_replace .= $answer['field_name'] . ": {$tmp_answer}\n";
            }
            $replacement = eme_trans_sanitize_html($field_replace, $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_PAYED/', $result)) {
            $replacement = $booking['booking_payed'] ? __('Yes') : __('No');
        } elseif ($deprecated && preg_match('/#_FIELDNAME(\\d+)/', $result, $matches) || preg_match('/#_FIELDNAME\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]);
            $formfield = eme_get_formfield_byid($field_id);
            $replacement = eme_trans_sanitize_html($formfield['field_name'], $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif ($deprecated && preg_match('/#_FIELD(\\d+)/', $result, $matches) || preg_match('/#_FIELD\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]);
            $formfield = eme_get_formfield_byid($field_id);
            $field_replace = "";
            foreach ($answers as $answer) {
                if ($answer['field_name'] == $formfield['field_name']) {
                    $tmp_answer = eme_convert_answer2tag($answer);
                    $field_replace = $tmp_answer;
                }
            }
            $replacement = eme_trans_sanitize_html($field_replace, $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_FIELDVALUE\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]);
            $formfield = eme_get_formfield_byid($field_id);
            foreach ($answers as $answer) {
                if ($answer['field_name'] == $formfield['field_name']) {
                    if (is_array($answer['answer'])) {
                        $tmp_answer = eme_convert_array2multi($answer['answer']);
                    } else {
                        $tmp_answer = $answer['answer'];
                    }
                    $field_replace = $tmp_answer;
                }
            }
            $replacement = eme_trans_sanitize_html($field_replace, $lang);
            if ($target == "html") {
                $replacement = apply_filters('eme_general', $replacement);
            } else {
                $replacement = apply_filters('eme_general_rss', $replacement);
            }
        } elseif (preg_match('/#_MULTIBOOKING_SEATS$/', $result)) {
            if ($is_multibooking) {
                // returns the total of all seats for all bookings in the payment id related to this booking
                $replacement = eme_bookings_total_booking_seats($bookings);
            }
        } elseif (preg_match('/#_MULTIBOOKING_TOTALPRICE$/', $result)) {
            if ($is_multibooking) {
                // returns the price for all bookings in the payment id related to this booking
                $price = eme_bookings_total_booking_price($bookings);
                $replacement = sprintf("%01.2f", $price);
            }
        } elseif (preg_match('/#_MULTIBOOKING_DETAILS_TEMPLATE\\{(\\d+)\\}$/', $result, $matches)) {
            $template_id = intval($matches[1]);
            $template = eme_get_template_format($template_id);
            $res = "";
            if ($template && $is_multibooking) {
                // don't let eme_replace_placeholders replace other shortcodes yet, let eme_replace_booking_placeholders finish and that will do it
                foreach ($bookings as $tmp_booking) {
                    $tmp_event = eme_get_event_by_booking_id($tmp_booking['booking_id']);
                    $tmp_res = eme_replace_placeholders($template, $tmp_event, "text", 0);
                    $res .= eme_replace_booking_placeholders($tmp_res, $tmp_event, $tmp_booking, $is_multibooking, "text") . "\n";
                }
            }
            $replacement = $res;
        } elseif (preg_match('/#_IS_MULTIBOOKING/', $result)) {
            $replacement = $is_multibooking;
        } else {
            $found = 0;
        }
        if ($found) {
            if ($need_escape) {
                $replacement = eme_sanitize_request(eme_sanitize_html(preg_replace('/\\n|\\r/', '', $replacement)));
            }
            $format = str_replace($orig_result, $replacement, $format);
        }
    }
    // now, replace any language tags found in the format itself
    $format = eme_translate($format, $lang);
    return do_shortcode($format);
}