function eme_replace_formfields_placeholders($event, $booking = "", $format = "", $eme_multibooking = 0)
{
    global $current_user;
    $event_id = $event['event_id'];
    $registration_wp_users_only = $event['registration_wp_users_only'];
    $is_admin = is_admin();
    if ($is_admin && $booking) {
        $editing_booking_from_backend = 1;
    } else {
        $editing_booking_from_backend = 0;
    }
    // if not in the backend and wp membership is required
    // or when editing an existing booking via backend (not a new)
    if ($registration_wp_users_only && !$is_admin || $editing_booking_from_backend) {
        $readonly = "disabled='disabled'";
    } else {
        $readonly = "";
    }
    if (empty($format)) {
        if (!empty($event['event_registration_form_format'])) {
            $format = $event['event_registration_form_format'];
        } elseif ($event['event_properties']['event_registration_form_format_tpl'] > 0) {
            $format = eme_get_template_format($event['event_properties']['event_registration_form_format_tpl']);
        } else {
            $format = get_option('eme_registration_form_format');
        }
    }
    $min_allowed = $event['event_properties']['min_allowed'];
    $max_allowed = $event['event_properties']['max_allowed'];
    if ($event['event_properties']['take_attendance']) {
        $min_allowed = 0;
        $max_allowed = 1;
    }
    if ($editing_booking_from_backend) {
        // in the admin itf, and editing a booking
        // then the avail seats are the total seats
        if (eme_is_multi($event['event_seats'])) {
            $avail_seats = eme_get_multitotal($event['event_seats']);
        } else {
            $avail_seats = $event['event_seats'];
        }
    } else {
        // the next gives the number of available seats, even for multiprice
        $avail_seats = eme_get_available_seats($event_id);
    }
    $booked_places_options = array();
    if (eme_is_multi($max_allowed)) {
        $multi_max_allowed = eme_convert_multi2array($max_allowed);
        $max_allowed_is_multi = 1;
    } else {
        $max_allowed_is_multi = 0;
    }
    if (eme_is_multi($min_allowed)) {
        $multi_min_allowed = eme_convert_multi2array($min_allowed);
        $min_allowed_is_multi = 1;
    } else {
        $min_allowed_is_multi = 0;
    }
    if (eme_is_multi($event['event_seats'])) {
        // in the admin itf, and editing a booking
        // then the avail seats are the total seats
        if ($editing_booking_from_backend) {
            $multi_avail = eme_convert_multi2array($event['event_seats']);
        } else {
            $multi_avail = eme_get_available_multiseats($event_id);
        }
        foreach ($multi_avail as $key => $avail_seats) {
            $booked_places_options[$key] = array();
            if ($max_allowed_is_multi) {
                $real_max_allowed = $multi_max_allowed[$key];
            } else {
                $real_max_allowed = $max_allowed;
            }
            // don't let people choose more seats than available
            if ($real_max_allowed > $avail_seats || $real_max_allowed == 0) {
                $real_max_allowed = $avail_seats;
            }
            if ($min_allowed_is_multi) {
                $real_min_allowed = $multi_min_allowed[$key];
            } else {
                // it's no use to have a non-multi minimum for multiseats
                $real_min_allowed = 0;
            }
            for ($i = $real_min_allowed; $i <= $real_max_allowed; $i++) {
                $booked_places_options[$key][$i] = $i;
            }
        }
    } elseif (eme_is_multi($event['price'])) {
        // we just need to loop through the same amount of seats as there are prices
        foreach (eme_convert_multi2array($event['price']) as $key => $value) {
            $booked_places_options[$key] = array();
            if ($max_allowed_is_multi) {
                $real_max_allowed = $multi_max_allowed[$key];
            } else {
                $real_max_allowed = $max_allowed;
            }
            // don't let people choose more seats than available
            if ($real_max_allowed > $avail_seats || $real_max_allowed == 0) {
                $real_max_allowed = $avail_seats;
            }
            if ($min_allowed_is_multi) {
                $real_min_allowed = $multi_min_allowed[$key];
            } else {
                // it's no use to have a non-multi minimum for multiseats/multiprice
                $real_min_allowed = 0;
            }
            for ($i = $real_min_allowed; $i <= $real_max_allowed; $i++) {
                $booked_places_options[$key][$i] = $i;
            }
        }
    } else {
        if ($max_allowed_is_multi) {
            $real_max_allowed = $multi_max_allowed[0];
        } else {
            $real_max_allowed = $max_allowed;
        }
        // don't let people choose more seats than available
        if ($real_max_allowed > $avail_seats || $real_max_allowed == 0) {
            $real_max_allowed = $avail_seats;
        }
        if ($min_allowed_is_multi) {
            $real_min_allowed = $multi_min_allowed[0];
        } else {
            $real_min_allowed = $min_allowed;
        }
        for ($i = $real_min_allowed; $i <= $real_max_allowed; $i++) {
            $booked_places_options[$i] = $i;
        }
    }
    $required_fields_count = 0;
    $eme_captcha_for_booking = get_option('eme_captcha_for_booking');
    # we need 4 required fields: #_NAME, #_EMAIL, #_SEATS and #_SUBMIT
    # for multiprice: 3 + number of possible prices (we add those later on)
    if (eme_is_multi($event['price'])) {
        $required_fields_min = 3;
    } else {
        $required_fields_min = 4;
    }
    // if we require the captcha: add 1
    if (!$is_admin && $eme_captcha_for_booking) {
        $required_fields_min++;
    }
    // for multi booking forms, the required field count per booking form is 1 (SEATS)
    if (!$is_admin && $eme_multibooking) {
        $required_fields_min = 1;
    }
    $bookerLastName = "";
    $bookerFirstName = "";
    $bookerAddress1 = "";
    $bookerAddress2 = "";
    $bookerCity = "";
    $bookerState = "";
    $bookerZip = "";
    $bookerCountry = "";
    $bookerEmail = "";
    $bookerComment = "";
    $bookerPhone = "";
    $bookedSeats = 0;
    if (is_user_logged_in()) {
        get_currentuserinfo();
        $bookerLastName = $current_user->user_lastname;
        if (empty($bookerLastName)) {
            $bookerLastName = $current_user->display_name;
        }
        $bookerFirstName = $current_user->user_firstname;
        $bookerEmail = $current_user->user_email;
    }
    if ($editing_booking_from_backend) {
        $person = eme_get_person($booking['person_id']);
        // when editing a booking
        $bookerLastName = eme_sanitize_html($person['lastname']);
        $bookerFirstName = eme_sanitize_html($person['firstname']);
        $bookerAddress1 = eme_sanitize_html($person['address1']);
        $bookerAddress2 = eme_sanitize_html($person['address2']);
        $bookerCity = eme_sanitize_html($person['city']);
        $bookerState = eme_sanitize_html($person['state']);
        $bookerZip = eme_sanitize_html($person['zip']);
        $bookerCountry = eme_sanitize_html($person['country']);
        $bookerEmail = eme_sanitize_html($person['email']);
        $bookerPhone = eme_sanitize_html($person['phone']);
        $bookerComment = eme_sanitize_html($booking['booking_comment']);
        $bookedSeats = eme_sanitize_html($booking['booking_seats']);
        if ($booking['booking_seats_mp']) {
            $booking_seats_mp = eme_convert_multi2array($booking['booking_seats_mp']);
            foreach ($booking_seats_mp as $key => $val) {
                $field_index = $key + 1;
                ${"bookedSeats" . $field_index} = eme_sanitize_html($val);
            }
        }
    } else {
        // check for previously filled in data
        // this in case people entered a wrong captcha
        if (isset($_POST['lastname'])) {
            $bookerLastName = eme_sanitize_html(stripslashes_deep($_POST['lastname']));
        }
        if (isset($_POST['firstname'])) {
            $bookerFirstName = eme_sanitize_html(stripslashes_deep($_POST['firstname']));
        }
        if (isset($_POST['address1'])) {
            $bookerAddress1 = eme_sanitize_html(stripslashes_deep($_POST['address1']));
        }
        if (isset($_POST['address2'])) {
            $bookerAddress2 = eme_sanitize_html(stripslashes_deep($_POST['address2']));
        }
        if (isset($_POST['city'])) {
            $bookerCity = eme_sanitize_html(stripslashes_deep($_POST['city']));
        }
        if (isset($_POST['state'])) {
            $bookerState = eme_sanitize_html(stripslashes_deep($_POST['state']));
        }
        if (isset($_POST['zip'])) {
            $bookerZip = eme_sanitize_html(stripslashes_deep($_POST['zip']));
        }
        if (isset($_POST['country'])) {
            $bookerCountry = eme_sanitize_html(stripslashes_deep($_POST['country']));
        }
        if (isset($_POST['email'])) {
            $bookerEmail = eme_sanitize_html(stripslashes_deep($_POST['email']));
        }
        if (isset($_POST['phone'])) {
            $bookerPhone = eme_sanitize_html(stripslashes_deep($_POST['phone']));
        }
        if (isset($_POST['comment'])) {
            $bookerComment = eme_sanitize_html(stripslashes_deep($_POST['comment']));
        }
    }
    // first we do the custom attributes, since these can contain other placeholders
    preg_match_all("/#(ESC|URL)?_ATT\\{.+?\\}(\\{.+?\\})?/", $format, $results);
    foreach ($results[0] as $resultKey => $result) {
        $need_escape = 0;
        $need_urlencode = 0;
        $orig_result = $result;
        if (strstr($result, '#ESC')) {
            $result = str_replace("#ESC", "#", $result);
            $need_escape = 1;
        } elseif (strstr($result, '#URL')) {
            $result = str_replace("#URL", "#", $result);
            $need_urlencode = 1;
        }
        $replacement = "";
        //Strip string of placeholder and just leave the reference
        $attRef = substr(substr($result, 0, strpos($result, '}')), 6);
        if (isset($event['event_attributes'][$attRef])) {
            $replacement = $event['event_attributes'][$attRef];
        }
        if (trim($replacement) == '' && isset($results[2][$resultKey]) && $results[2][$resultKey] != '') {
            //Check to see if we have a second set of braces;
            $replacement = substr($results[2][$resultKey], 1, strlen(trim($results[2][$resultKey])) - 2);
        }
        if ($need_escape) {
            $replacement = eme_sanitize_request(eme_sanitize_html(preg_replace('/\\n|\\r/', '', $replacement)));
        }
        if ($need_urlencode) {
            $replacement = rawurlencode($replacement);
        }
        $format = str_replace($orig_result, $replacement, $format);
    }
    // the 2 placeholders that can contain extra text are treated seperately first
    // the question mark is used for non greedy (minimal) matching
    if (preg_match('/#_CAPTCHAHTML\\{.+\\}/', $format)) {
        // only show the captcha when booking via the frontend, not the admin backend
        if (!$is_admin && $eme_captcha_for_booking) {
            $format = preg_replace('/#_CAPTCHAHTML\\{(.+?)\\}/', '$1', $format);
        } else {
            $format = preg_replace('/#_CAPTCHAHTML\\{(.+?)\\}/', '', $format);
        }
    }
    if (preg_match('/#_SUBMIT\\{.+\\}/', $format)) {
        if ($editing_booking_from_backend) {
            $format = preg_replace('/#_SUBMIT\\{(.+?)\\}/', "<input name='eme_submit_button' class='eme_submit_button' type='submit' value='" . __('Update booking', 'eme') . "' />", $format);
        } else {
            $format = preg_replace('/#_SUBMIT\\{(.+?)\\}/', "<input name='eme_submit_button' class='eme_submit_button' type='submit' value='" . eme_trans_sanitize_html('$1') . "' />", $format);
        }
        if (!$eme_multibooking) {
            $required_fields_count++;
        }
    }
    $deprecated = get_option('eme_deprecated');
    if ($deprecated && preg_match('/#_CAPTCHAHTML\\[.+\\]/', $format)) {
        // only show the captcha when booking via the frontend, not the admin backend
        if (!$is_admin && $eme_captcha_for_booking) {
            $format = preg_replace('/#_CAPTCHAHTML\\[(.+?)\\]/', '$1', $format);
        } else {
            $format = preg_replace('/#_CAPTCHAHTML\\[(.+?)\\]/', '', $format);
        }
    }
    if ($deprecated && preg_match('/#_SUBMIT\\[.+\\]/', $format)) {
        if ($editing_booking_from_backend) {
            $format = preg_replace('/#_SUBMIT\\[(.+?)\\]/', "<input name='eme_submit_button' class='eme_submit_button' type='submit' value='" . __('Update booking', 'eme') . "' />", $format);
        } else {
            $format = preg_replace('/#_SUBMIT\\[(.+?)\\]/', "<input name='eme_submit_button' class='eme_submit_button' type='submit' value='" . eme_trans_sanitize_html('$1') . "' />", $format);
        }
        if (!$eme_multibooking) {
            $required_fields_count++;
        }
    }
    // now the normal placeholders
    preg_match_all("/#(REQ)?_?[A-Z0-9_]+(\\{[A-Z0-9_]+\\})?/", $format, $placeholders);
    // make sure we set the largest matched placeholders first, otherwise if you found e.g.
    // #_LOCATION, part of #_LOCATIONPAGEURL would get replaced as well ...
    usort($placeholders[0], 'sort_stringlenth');
    # we need 3 required fields: #_NAME, #_EMAIL and #_SEATS
    # if these are not present: we don't replace anything and the form is worthless
    foreach ($placeholders[0] as $result) {
        $orig_result = $result;
        $found = 1;
        $required = 0;
        $required_att = "";
        $html5_wanted = 0;
        $replacement = "";
        if (strstr($result, '#REQ')) {
            $result = str_replace("#REQ", "#", $result);
            $required = 1;
            $required_att = "required='required'";
        }
        // also support RESPNAME, RESPEMAIL, ...
        if (strstr($result, '#_RESP')) {
            $result = str_replace("#_RESP", "#_", $result);
        }
        if ($eme_multibooking) {
            $var_prefix = "bookings[{$event_id}][";
            $var_postfix = "]";
        } else {
            $var_prefix = '';
            $var_postfix = '';
        }
        if (preg_match('/#_NAME|#_LASTNAME/', $result)) {
            if (!$eme_multibooking) {
                $replacement = "<input required='required' type='text' name='{$var_prefix}lastname{$var_postfix}' value='{$bookerLastName}' {$readonly} />";
                $required_fields_count++;
                // #_NAME is always required
                $required = 1;
            }
        } elseif (preg_match('/#_FIRSTNAME/', $result)) {
            if (!empty($bookerFirstName)) {
                $replacement = "<input {$required_att} type='text' name='{$var_prefix}firstname{$var_postfix}' value='{$bookerFirstName}' {$readonly} />";
            } else {
                $replacement = "<input {$required_att} type='text' name='{$var_prefix}firstname{$var_postfix}' value='{$bookerFirstName}' />";
            }
        } elseif (preg_match('/#_ADDRESS1/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}address1{$var_postfix}' value='{$bookerAddress1}' />";
        } elseif (preg_match('/#_ADDRESS2/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}address2{$var_postfix}' value='{$bookerAddress2}' />";
        } elseif (preg_match('/#_CITY/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}city{$var_postfix}' value='{$bookerCity}' />";
        } elseif (preg_match('/#_STATE/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}state{$var_postfix}' value='{$bookerState}' />";
        } elseif (preg_match('/#_ZIP/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}zip{$var_postfix}' value='{$bookerZip}' />";
        } elseif (preg_match('/#_COUNTRY/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}country{$var_postfix}' value='{$bookerCountry}' />";
        } elseif (preg_match('/#_HTML5_EMAIL/', $result)) {
            if (!$eme_multibooking) {
                $replacement = "<input required='required' type='email' name='{$var_prefix}email{$var_postfix}' value='{$bookerEmail}' {$readonly} />";
                $required_fields_count++;
                // #_EMAIL is always required
                $required = 1;
            }
        } elseif (preg_match('/#_EMAIL/', $result)) {
            if (!$eme_multibooking) {
                $replacement = "<input required='required' type='text' name='{$var_prefix}email{$var_postfix}' value='{$bookerEmail}' {$readonly} />";
                $required_fields_count++;
                // #_EMAIL is always required
                $required = 1;
            }
        } elseif (preg_match('/#_HTML5_PHONE/', $result)) {
            $replacement = "<input {$required_att} type='tel' name='{$var_prefix}phone{$var_postfix}' value='{$bookerPhone}' />";
        } elseif (preg_match('/#_PHONE/', $result)) {
            $replacement = "<input {$required_att} type='text' name='{$var_prefix}phone{$var_postfix}' value='{$bookerPhone}' />";
        } elseif (preg_match('/#_SEATS$|#_SPACES$/', $result)) {
            $postfield_name = "{$var_prefix}bookedSeats{$var_postfix}";
            if ($editing_booking_from_backend && isset($bookedSeats)) {
                $entered_val = $bookedSeats;
            } elseif ($eme_multibooking && isset($_POST['bookings'][$event_id]) && isset($_POST['bookings'][$event_id]['bookedSeats'])) {
                $entered_val = intval($_POST['bookings'][$event_id]['bookedSeats']);
            } elseif (isset($_POST['bookedSeats'])) {
                $entered_val = intval($_POST['bookedSeats']);
            } else {
                $entered_val = 0;
            }
            if ($event['event_properties']['take_attendance']) {
                $replacement = eme_ui_select_binary($entered_val, $postfield_name);
            } else {
                $replacement = eme_ui_select($entered_val, $postfield_name, $booked_places_options);
            }
            $required_fields_count++;
        } elseif ($deprecated && preg_match('/#_(SEATS|SPACES)(\\d+)/', $result, $matches) || preg_match('/#_(SEATS|SPACES)\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[2]);
            $postfield_name = "{$var_prefix}bookedSeats" . $field_id . $var_postfix;
            if ($editing_booking_from_backend && isset(${"bookedSeats" . $field_id})) {
                $entered_val = ${"bookedSeats" . $field_id};
            } elseif ($eme_multibooking && isset($_POST['bookings'][$event_id]) && isset($_POST['bookings'][$event_id]['bookedSeats' . $field_id])) {
                $entered_val = intval($_POST['bookings'][$event_id]['bookedSeats' . $field_id]);
            } elseif (isset($_POST['bookedSeats' . $field_id])) {
                $entered_val = intval($_POST['bookedSeats' . $field_id]);
            } else {
                $entered_val = 0;
            }
            if (eme_is_multi($event['event_seats']) || eme_is_multi($event['price'])) {
                if ($event['event_properties']['take_attendance']) {
                    $replacement = eme_ui_select_binary($entered_val, $postfield_name);
                } else {
                    $replacement = eme_ui_select($entered_val, $postfield_name, $booked_places_options[$field_id - 1]);
                }
            } else {
                if ($event['event_properties']['take_attendance']) {
                    $replacement = eme_ui_select_binary($entered_val, $postfield_name);
                } else {
                    $replacement = eme_ui_select($entered_val, $postfield_name, $booked_places_options);
                }
            }
            $required_fields_count++;
        } elseif (preg_match('/#_COMMENT/', $result)) {
            if (!$eme_multibooking) {
                $replacement = "<textarea {$required_att} name='{$var_prefix}comment{$var_postfix}'>{$bookerComment}</textarea>";
            }
        } elseif (preg_match('/#_CAPTCHA/', $result) && $eme_captcha_for_booking) {
            if (!$eme_multibooking) {
                $replacement = "<img src='" . EME_PLUGIN_URL . "captcha.php?sessionvar=eme_add_booking'><br /><input required='required' type='text' name='captcha_check' autocomplete='off' />";
                $required_fields_count++;
            }
        } 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']);
        } elseif ($deprecated && preg_match('/#_FIELD(\\d+)/', $result, $matches) || preg_match('/#_FIELD\\{(\\d+)\\}/', $result, $matches)) {
            $field_id = intval($matches[1]);
            $postfield_name = "{$var_prefix}FIELD" . $field_id . $var_postfix;
            $entered_val = "";
            if ($booking) {
                $answers = eme_get_answers($booking['booking_id']);
                $formfield = eme_get_formfield_byid($field_id);
                foreach ($answers as $answer) {
                    if ($answer['field_name'] == $formfield['field_name']) {
                        // the entered value for the function eme_get_formfield_html needs to be an array for multiple values
                        // since we store them with "||", we can use the good old eme_is_multi function and split in an array then
                        $entered_val = $answer['answer'];
                        if (eme_is_multi($entered_val)) {
                            $entered_val = eme_convert_multi2array($entered_val);
                        }
                    }
                }
            } elseif (isset($_POST[$postfield_name])) {
                $entered_val = stripslashes_deep($_POST[$postfield_name]);
            }
            $replacement = eme_get_formfield_html($field_id, $entered_val, $required);
        } elseif (preg_match('/#_SUBMIT/', $result, $matches)) {
            if (!$eme_multibooking) {
                if ($editing_booking_from_backend) {
                    $replacement = "<input name='eme_submit_button' type='submit' value='" . __('Update booking', 'eme') . "' />";
                } else {
                    $replacement = "<input name='eme_submit_button' type='submit' value='" . eme_trans_sanitize_html(get_option('eme_rsvp_addbooking_submit_string')) . "' />";
                }
                $required_fields_count++;
            }
        } else {
            $found = 0;
        }
        if ($required) {
            $replacement .= "<div class='eme-required-field'>&nbsp;" . __('(Required field)', 'eme') . "</div>";
        }
        if ($found) {
            $format = str_replace($orig_result, $replacement, $format);
        }
    }
    // now any leftover event placeholders
    $format = eme_replace_placeholders($format, $event);
    // now, replace any language tags found in the format itself
    $format = eme_translate($format);
    # we need 4 required fields: #_NAME, #_EMAIL, #_SEATS and #_SUBMIT
    # for multiprice: 3 + number of possible prices
    # if these are not present: we don't replace anything and the form is worthless
    if (eme_is_multi($event['price'])) {
        $matches = preg_split('/\\|\\|/', $event['price']);
        $count = count($matches);
        // the count can be >3+$count if conditional tags are used to combine a form for single and multiple prices
        if ($required_fields_count >= $required_fields_min + $count) {
            return $format;
        } else {
            $res = __('Not all required fields are present in the booking form.', 'eme');
            $res .= '<br />' . __("Since this is a multiprice event, make sure you changed the setting 'Registration Form Format' for the event to include #_SEATxx placeholders for each price.", 'eme');
            $res .= '<br />' . __("See the documentation about multiprice events.", 'eme');
            return "<div id='message' class='eme-rsvp-message'>{$res}</div>";
        }
    } elseif ($required_fields_count >= $required_fields_min) {
        // the count can be > 4 if conditional tags are used to combine a form for single and multiple prices
        return $format;
    } else {
        return __('Not all required fields are present in the booking form.', 'eme');
    }
}
Example #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);
}
Example #3
0
function eme_events_table($message = "", $scope = "future")
{
    global $eme_timezone;
    if (!empty($message)) {
        echo "<div id='message' class='updated fade'><p>" . eme_trans_sanitize_html($message) . "</p></div>";
    }
    //$list_limit = get_option('eme_events_admin_limit');
    //if ($list_limit<5 || $list_limit>200) {
    //   $list_limit=20;
    //   update_option('eme_events_admin_limit',$list_limit);
    //}
    //$offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
    //$events = eme_get_events ( $limit+1, "future", "ASC", $offset );
    $o_category = isset($_GET['category']) ? intval($_GET['category']) : 0;
    $status = isset($_GET['event_status']) ? intval($_GET['event_status']) : '';
    if (!empty($status)) {
        $extra_conditions = 'event_status = ' . $status;
    } else {
        $extra_conditions = '';
    }
    //$events = eme_get_events ( 0, $scope, "ASC", $offset, "", $o_category, '', '', 1, '', 0, $extra_conditions);
    $events = eme_get_events(0, $scope, "ASC", 0, "", $o_category, '', '', 1, '', 0, $extra_conditions);
    $events_count = count($events);
    $scope_names = array();
    $scope_names['past'] = __('Past events', 'eme');
    $scope_names['all'] = __('All events', 'eme');
    $scope_names['future'] = __('Future events', 'eme');
    ?>

<div class="wrap">
<div id="icon-events" class="icon32"><br />
</div>
<h1><?php 
    echo $scope_names[$scope];
    ?>
</h1>
   <?php 
    admin_show_warnings();
    ?>
   <!--<div id='new-event' class='switch-tab'><a href="<?php 
    echo admin_url("admin.php?page=events-manager&amp;eme_admin_action=edit_event");
    ?>
><?php 
    _e('New Event ...', 'eme');
    ?>
</a></div>-->
   <?php 
    $event_status_array = eme_status_array();
    ?>
 
      
   <div class="tablenav">
   <form id="posts-filter" action="" method="get">
   <input type='hidden' name='page' value='events-manager' />
   <select name="scope">
   <?php 
    foreach ($scope_names as $key => $value) {
        $selected = "";
        if ($key == $scope) {
            $selected = "selected='selected'";
        }
        echo "<option value='{$key}' {$selected}>{$value}</option>  ";
    }
    ?>
   </select>
   <select id="event_status" name="event_status">
      <option value="0"><?php 
    _e('Event Status', 'eme');
    ?>
</option>
      <?php 
    foreach ($event_status_array as $event_status_key => $event_status_value) {
        ?>
         <option value="<?php 
        echo $event_status_key;
        ?>
" <?php 
        if (isset($_GET['event_status']) && $_GET['event_status'] == $event_status_key) {
            echo 'selected="selected"';
        }
        ?>
><?php 
        echo $event_status_value;
        ?>
</option>
      <?php 
    }
    ?>
   </select>
   <select name="category">
   <option value='0'><?php 
    _e('All categories', 'eme');
    ?>
</option>
   <?php 
    $categories = eme_get_categories();
    foreach ($categories as $category) {
        $selected = "";
        if ($o_category == $category['category_id']) {
            $selected = "selected='selected'";
        }
        echo "<option value='" . $category['category_id'] . "' {$selected}>" . $category['category_name'] . "</option>";
    }
    ?>
   </select>
   <input id="post-query-submit" class="button-secondary" type="submit" value="<?php 
    _e('Filter');
    ?>
" />
   </form>

   <?php 
    if ($events_count > 0) {
        ?>
   <form id="eme_events_listform" action="" method="get">
   <input type='hidden' name='page' value='events-manager' />
   <select name="eme_admin_action">
   <option value="-1" selected="selected"><?php 
        _e('Bulk Actions');
        ?>
</option>
   <option value="deleteEvents"><?php 
        _e('Delete selected events', 'eme');
        ?>
</option>
   <option value="deleteRecurrence"><?php 
        _e('Delete selected recurrent events', 'eme');
        ?>
</option>
   <option value="publicEvents"><?php 
        _e('Publish selected events', 'eme');
        ?>
</option>
   <option value="privateEvents"><?php 
        _e('Make selected events private', 'eme');
        ?>
</option>
   <option value="draftEvents"><?php 
        _e('Make selected events draft', 'eme');
        ?>
</option>
   </select>
   <input type="submit" value="<?php 
        _e('Apply');
        ?>
" name="doaction2" id="doaction2" class="button-secondary action" />
   <div class="clear"></div>
   <br />

   <table class="widefat hover stripe" id="eme_admin_events">
   <thead>
      <tr>
         <th class='manage-column column-cb check-column' scope='col'><input
            class='select-all' type="checkbox" value='1' /></th>
         <th><?php 
        _e('ID', 'eme');
        ?>
</th>
         <th><?php 
        _e('Name', 'eme');
        ?>
</th>
         <th><?php 
        _e('Status', 'eme');
        ?>
</th>
         <th><?php 
        _e('Copy', 'eme');
        ?>
</th>
         <th><?php 
        _e('Location', 'eme');
        ?>
</th>
         <th><?php 
        _e('Date and time', 'eme');
        ?>
</th>
         <th><?php 
        _e('Recurrence info', 'eme');
        ?>
</th>
      </tr>
   </thead>
   <tbody>
   <?php 
        $eme_date_obj = new ExpressiveDate(null, $eme_timezone);
        $today = $eme_date_obj->getDate();
        foreach ($events as $event) {
            $localised_start_date = eme_localised_date($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone);
            $localised_start_time = eme_localised_time($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone);
            $localised_end_date = eme_localised_date($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone);
            $localised_end_time = eme_localised_time($event['event_end_date'] . " " . $event['event_end_time'] . " " . $eme_timezone);
            $datasort_startstring = strtotime($event['event_start_date'] . " " . $event['event_start_time'] . " " . $eme_timezone);
            $location_summary = "";
            if (isset($event['location_id']) && $event['location_id']) {
                $location = eme_get_location($event['location_id']);
                $location_summary = "<b>" . eme_trans_sanitize_html($location['location_name']) . "</b><br />" . eme_trans_sanitize_html($location['location_address']) . " - " . eme_trans_sanitize_html($location['location_town']);
            }
            $style = "";
            if ($event['event_start_date'] < $today) {
                $style = "style ='background-color: #FADDB7;'";
            }
            ?>
     <tr <?php 
            echo "{$style}";
            ?>
>
         <td><input type='checkbox' class='row-selector' value='<?php 
            echo $event['event_id'];
            ?>
' name='events[]' /></td>
         <td><?php 
            echo $event['event_id'];
            ?>
</td>
         <td><strong>
         <a class="row-title" href="<?php 
            echo admin_url("admin.php?page=events-manager&amp;eme_admin_action=edit_event&amp;event_id=" . $event['event_id']);
            ?>
" title="<?php 
            _e('Edit event', 'eme');
            ?>
"><?php 
            echo eme_trans_sanitize_html($event['event_name']);
            ?>
</a>
         </strong>
         <?php 
            $categories = explode(',', $event['event_category_ids']);
            foreach ($categories as $cat) {
                $category = eme_get_category($cat);
                if ($category) {
                    echo "<br /><span title='" . __('Category', 'eme') . ": " . eme_trans_sanitize_html($category['category_name']) . "'>" . eme_trans_sanitize_html($category['category_name']) . "</span>";
                }
            }
            if ($event['event_rsvp']) {
                $booked_seats = eme_get_booked_seats($event['event_id']);
                $available_seats = eme_get_available_seats($event['event_id']);
                $pending_seats = eme_get_pending_seats($event['event_id']);
                $total_seats = $event['event_seats'];
                if (eme_is_multi($event['event_seats'])) {
                    $available_seats_string = $available_seats . ' (' . eme_convert_array2multi(eme_get_available_multiseats($event['event_id'])) . ')';
                    $pending_seats_string = $pending_seats . ' (' . eme_convert_array2multi(eme_get_pending_multiseats($event['event_id'])) . ')';
                    $total_seats_string = eme_get_multitotal($total_seats) . ' (' . $event['event_seats'] . ')';
                } else {
                    $available_seats_string = $available_seats;
                    $pending_seats_string = $pending_seats;
                    $total_seats_string = $total_seats;
                }
                if ($pending_seats > 0) {
                    echo "<br />" . __('RSVP Info: ', 'eme') . __('Free: ', 'eme') . $available_seats_string . ", " . __('Pending: ', 'eme') . $pending_seats_string . ", " . __('Max: ', 'eme') . $total_seats_string;
                } else {
                    echo "<br />" . __('RSVP Info: ', 'eme') . __('Free: ', 'eme') . $available_seats_string . ", " . __('Max: ', 'eme') . $total_seats_string;
                }
                if ($booked_seats > 0 || $pending_seats > 0) {
                    $printable_address = admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_printable&amp;event_id=" . $event['event_id']);
                    $csv_address = admin_url("admin.php?page=eme-people&amp;eme_admin_action=booking_csv&amp;event_id=" . $event['event_id']);
                    echo " (<a id='booking_printable_" . $event['event_id'] . "' href='{$printable_address}'>" . __('Printable view', 'eme') . "</a>)";
                    echo " (<a id='booking_csv_" . $event['event_id'] . "' href='{$csv_address}'>" . __('CSV export', 'eme') . "</a>)";
                }
            }
            ?>
 
         </td>
         <td>
         <?php 
            if (isset($event_status_array[$event['event_status']])) {
                echo $event_status_array[$event['event_status']];
                $event_url = eme_event_url($event);
                if ($event['event_status'] == STATUS_DRAFT) {
                    echo "<br /> <a href='{$event_url}'>" . __('Preview event', 'eme') . "</a>";
                } else {
                    echo "<br /> <a href='{$event_url}'>" . __('View event', 'eme') . "</a>";
                }
            }
            ?>
 
         </td>
         <td>
         <a href="<?php 
            echo admin_url("admin.php?page=events-manager&amp;eme_admin_action=duplicate_event&amp;event_id=" . $event['event_id']);
            ?>
" title="<?php 
            _e('Duplicate this event', 'eme');
            ?>
"><img src='<?php 
            echo EME_PLUGIN_URL . "images/copy_24.png";
            ?>
'/></a>
         </td>
         <td>
             <?php 
            echo $location_summary;
            ?>
         </td>
         <td data-sort="<?php 
            echo $datasort_startstring;
            ?>
">
            <?php 
            echo $localised_start_date;
            if ($localised_end_date != '' && $localised_end_date != $localised_start_date) {
                echo " - " . $localised_end_date;
            }
            ?>
<br />
            <?php 
            if ($event['event_properties']['all_day'] == 1) {
                _e('All day', 'eme');
            } else {
                echo "{$localised_start_time} - {$localised_end_time}";
            }
            ?>
         </td>
         <td>
             <?php 
            if ($event['recurrence_id']) {
                $recurrence_desc = eme_get_recurrence_desc($event['recurrence_id']);
                ?>
               <b><?php 
                echo $recurrence_desc;
                ?>
            <br />
            <a href="<?php 
                echo admin_url("admin.php?page=events-manager&amp;eme_admin_action=edit_recurrence&amp;recurrence_id=" . $event['recurrence_id']);
                ?>
"><?php 
                print sprintf(__('Edit Recurrence ID %d', 'eme'), $event['recurrence_id']);
                ?>
</a></b>
            <?php 
            }
            ?>
         </td>
   </tr>
   <?php 
        }
        ?>
   
   </tbody>
   </table>

   </form>

<?php 
    } else {
        echo "<div id='events-admin-no-events'>" . get_option('eme_no_events_message') . "</div></div>";
    }
    ?>

   <script type="text/javascript">
   jQuery(document).ready( function() {
         jQuery('#eme_admin_events').dataTable( {
            "dom": 'Blfrtip',
	    "colReorder": true,
<?php 
    $locale_code = get_locale();
    $locale_file = EME_PLUGIN_DIR . "js/jquery-datatables/i18n/{$locale_code}.json";
    $locale_file_url = EME_PLUGIN_URL . "js/jquery-datatables/i18n/{$locale_code}.json";
    if ($locale_code != "en_US" && file_exists($locale_file)) {
        ?>
            "language": {
                            "url": "<?php 
        echo $locale_file_url;
        ?>
"
                        },
<?php 
    }
    ?>
            "stateSave": true,
            "pagingType": "full",
            "columnDefs": [
               { "sortable": false, "targets": [0,4,7] }
            ],
            "buttons": [
               'csv',
               'print',
               {
                  extend: 'colvis',
                  columns: ':not(:first-child)'
               }
            ]
         } );
   } );
   </script>

   </div>
</div>
<?php 
}