function espresso_confirm_registration($registration_id)
{
    global $wpdb, $org_options;
    //Get the questions for the attendee
    $questions = $wpdb->get_results("SELECT ea.answer, eq.question\n\t\t\t\t\t\tFROM " . EVENTS_ANSWER_TABLE . " ea\n\t\t\t\t\t\tLEFT JOIN " . EVENTS_QUESTION_TABLE . " eq ON eq.id = ea.question_id\n\t\t\t\t\t\tWHERE ea.registration_id = '" . $registration_id . "' AND system_name IS NULL ORDER BY eq.sequence asc ");
    //echo $wpdb->last_query;
    $display_questions = '';
    foreach ($questions as $question) {
        $display_questions .= '<p class="espresso_questions"><strong>' . $question->question . '</strong>:<br /> ' . str_replace(',', '<br />', $question->answer) . '</p>';
    }
    //Get the event information
    $events = $wpdb->get_results("SELECT ed.* FROM " . EVENTS_DETAIL_TABLE . " ed\n\t\t\t\t\t\tJOIN " . EVENTS_ATTENDEE_TABLE . " ea\n\t\t\t\t\t\tON ed.id = ea.event_id\n\t\t\t\t\t\tWHERE ea.registration_id='" . $registration_id . "'");
    foreach ($events as $event) {
        $event_id = $event->id;
        $event_name = stripslashes_deep($event->event_name);
        $event_desc = stripslashes_deep($event->event_desc);
        $display_desc = $event->display_desc;
        $event_identifier = $event->event_identifier;
        $reg_limit = $event->reg_limit;
        $active = $event->is_active;
        $send_mail = $event->send_mail;
        $conf_mail = $event->conf_mail;
        $email_id = $event->email_id;
        $alt_email = $event->alt_email;
        $start_date = event_date_display($event->start_date);
        $end_date = $event->end_date;
        $virtual_url = $event->virtual_url;
        $virtual_phone = $event->virtual_phone;
        $event_address = $event->address;
        $event_address2 = $event->address2;
        $event_city = $event->city;
        $event_state = $event->state;
        $event_zip = $event->zip;
        $event_country = $event->country;
        $location = ($event_address != '' ? $event_address : '') . ($event_address2 != '' ? '<br />' . $event_address2 : '') . ($event_city != '' ? '<br />' . $event_city : '') . ($event_state != '' ? ', ' . $event_state : '') . ($event_zip != '' ? '<br />' . $event_zip : '') . ($event_country != '' ? '<br />' . $event_country : '');
        $location_phone = $event->phone;
        $require_pre_approval = $event->require_pre_approval;
        $google_map_link = espresso_google_map_link(array('address' => $event_address, 'city' => $event_city, 'state' => $event_state, 'zip' => $event_zip, 'country' => $event_country));
    }
    //Build links
    $event_url = espresso_reg_url($event_id);
    $event_link = '<a href="' . $event_url . '">' . $event_name . '</a>';
    $sql = "SELECT * FROM " . EVENTS_ATTENDEE_TABLE;
    if ($registration_id != '') {
        $sql .= " WHERE registration_id = '" . $registration_id . "' ";
    } elseif ($attendee_id != '') {
        $sql .= " WHERE id = '" . $attendee_id . "' ";
    } else {
        _e('No ID Supplied', 'event_espresso');
    }
    $sql .= " ORDER BY id ";
    $sql .= " LIMIT 0,1 ";
    //Get the first attendees details
    $attendees = $wpdb->get_results($sql);
    //global $attendee_id;
    foreach ($attendees as $attendee) {
        $attendee_id = $attendee->id;
        $attendee_email = $attendee->email;
        $lname = $attendee->lname;
        $fname = $attendee->fname;
        $address = $attendee->address;
        $address2 = $attendee->address2;
        $city = $attendee->city;
        $state = $attendee->state;
        $zip = $attendee->zip;
        $payment_status = $attendee->payment_status;
        $txn_type = $attendee->txn_type;
        $amount_pd = $attendee->amount_pd;
        $event_cost = $attendee->amount_pd;
        $payment_date = $attendee->payment_date;
        $phone = $attendee->phone;
        $event_time = $attendee->event_time;
        $end_time = $attendee->end_time;
        $date = $attendee->date;
        $pre_approve = $attendee->pre_approve;
    }
    ####### Added by wp-developers ##############
    $pre_approval_check = is_attendee_approved($event_id, $attendee_id);
    ###########################################
    ###### Modified by wp-developers ###############
    if ($pre_approval_check) {
        //Pull in the "Thank You" page template
        if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "payment_page.php")) {
            require_once EVENT_ESPRESSO_TEMPLATE_DIR . "payment_page.php";
            //This is the path to the template file if available
        } else {
            require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/payment_page.php";
        }
        if ($amount_pd != '0.00') {
            //Show payment options
            if (file_exists(EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php")) {
                require_once EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php";
            } else {
                require_once EVENT_ESPRESSO_PLUGINFULLPATH . "gateways/gateway_display.php";
            }
            //Check to see if the site owner wants to send an confirmation eamil before payment is recieved.
            if ($org_options['email_before_payment'] == 'Y') {
                event_espresso_email_confirmations(array('registration_id' => $registration_id, 'send_admin_email' => 'true', 'send_attendee_email' => 'true'));
            }
        } else {
            event_espresso_email_confirmations(array('registration_id' => $registration_id, 'send_admin_email' => 'true', 'send_attendee_email' => 'true'));
        }
    } else {
        if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/process-registration/pending_approval_page.php')) {
            require_once 'pending_approval_page.php';
            echo espresso_pending_registration_approval($registration_id);
            return;
        }
    }
    ################ End ##############################
    //return __('Your Registration Has Been Confirmed', 'event_espresso');
    //unset($_SESSION['espresso_session']['id']);
    //session_destroy();
}
function espresso_confirm_registration()
{
    do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
    global $wpdb, $org_options;
    if (!empty($_POST['confirm_registration'])) {
        $registration_id = sanitize_text_field($_POST['registration_id']);
    } else {
        wp_die(__('An error has occured. The registration ID could not be found.', 'event_espresso'));
    }
    echo '<div id="espresso-payment_page-dv" >';
    do_action('action_hook_espresso_confirmation_page_before', $registration_id);
    //Get the questions for the attendee
    $SQL = "SELECT ea.answer, eq.question FROM " . EVENTS_ANSWER_TABLE . " ea ";
    $SQL .= "LEFT JOIN " . EVENTS_QUESTION_TABLE . " eq ON eq.id = ea.question_id ";
    $SQL .= "WHERE ea.registration_id = %s ";
    $SQL .= "AND system_name IS NULL ORDER BY eq.sequence asc ";
    $questions = $wpdb->get_results($wpdb->prepare($SQL, $registration_id));
    //echo $wpdb->last_query;
    $display_questions = '';
    foreach ($questions as $question) {
        $question->question = trim(stripslashes(str_replace('&#039;', "'", $question->question)));
        $question->question = htmlspecialchars($question->question, ENT_QUOTES, 'UTF-8');
        $question->answer = trim(stripslashes(str_replace('&#039;', "'", $question->answer)));
        $question->answer = htmlspecialchars($question->answer, ENT_QUOTES, 'UTF-8');
        $display_questions .= '<p class="espresso_questions"><strong>' . $question->question . '</strong>:<br /> ' . str_replace(',', '<br />', $question->answer) . '</p>';
    }
    //Get the event information
    $SQL = "SELECT ed.*  FROM " . EVENTS_DETAIL_TABLE . " ed ";
    $SQL .= "JOIN " . EVENTS_ATTENDEE_TABLE . " ea ON ed.id = ea.event_id ";
    $SQL .= "WHERE ea.registration_id=%s";
    $events = $wpdb->get_results($wpdb->prepare($SQL, $registration_id));
    foreach ($events as $event) {
        $event_id = $event->id;
        $event_name = stripslashes_deep($event->event_name);
        $event_desc = stripslashes_deep($event->event_desc);
        $display_desc = $event->display_desc;
        $event_identifier = $event->event_identifier;
        $reg_limit = $event->reg_limit;
        $active = $event->is_active;
        $send_mail = $event->send_mail;
        $conf_mail = $event->conf_mail;
        $email_id = $event->email_id;
        $alt_email = $event->alt_email;
        $start_date = event_date_display($event->start_date);
        $end_date = $event->end_date;
        $virtual_url = $event->virtual_url;
        $virtual_phone = $event->virtual_phone;
        $event_address = $event->address;
        $event_address2 = $event->address2;
        $event_city = $event->city;
        $event_state = $event->state;
        $event_zip = $event->zip;
        $event_country = $event->country;
        $location = ($event_address != '' ? $event_address : '') . ($event_address2 != '' ? '<br />' . $event_address2 : '') . ($event_city != '' ? '<br />' . $event_city : '') . ($event_state != '' ? ', ' . $event_state : '') . ($event_zip != '' ? '<br />' . $event_zip : '') . ($event_country != '' ? '<br />' . $event_country : '');
        $location_phone = $event->phone;
        $require_pre_approval = $event->require_pre_approval;
        $google_map_link = espresso_google_map_link(array('address' => $event_address, 'city' => $event_city, 'state' => $event_state, 'zip' => $event_zip, 'country' => $event_country));
    }
    //Build links
    $event_url = espresso_reg_url($event_id);
    $event_link = '<a href="' . $event_url . '">' . $event_name . '</a>';
    $SQL = "SELECT * FROM " . EVENTS_ATTENDEE_TABLE;
    if ($registration_id != '') {
        $SQL .= " WHERE registration_id = '" . $registration_id . "' ";
    } elseif ($attendee_id != '') {
        $SQL .= " WHERE id = '" . $attendee_id . "' ";
    } else {
        _e('No ID Supplied', 'event_espresso');
    }
    $SQL .= " AND is_primary = 1 ";
    $SQL .= " ORDER BY id ";
    $SQL .= " LIMIT 0,1 ";
    //Get the first attendees details
    if (!($attendee = $wpdb->get_row($wpdb->prepare($SQL, NULL)))) {
        wp_die(__('An error occured. The primary attendee could not be found.', 'event_espresso'));
    }
    $attendee_id = $attendee->id;
    $attendee_email = isset($attendee->email) ? $attendee->email : '';
    $lname = isset($attendee->lname) ? htmlspecialchars(stripslashes($attendee->lname), ENT_QUOTES, 'UTF-8') : '';
    $fname = isset($attendee->fname) ? htmlspecialchars(stripslashes($attendee->fname), ENT_QUOTES, 'UTF-8') : '';
    $address = isset($attendee->address) ? htmlspecialchars(stripslashes($attendee->address), ENT_QUOTES, 'UTF-8') : '';
    $address2 = isset($attendee->address2) ? htmlspecialchars(stripslashes($attendee->address2), ENT_QUOTES, 'UTF-8') : '';
    $city = isset($attendee->city) ? htmlspecialchars(stripslashes($attendee->city), ENT_QUOTES, 'UTF-8') : '';
    $state = isset($attendee->state) ? htmlspecialchars(stripslashes($attendee->state), ENT_QUOTES, 'UTF-8') : '';
    $country = isset($attendee->country) ? htmlspecialchars(stripslashes($attendee->country), ENT_QUOTES, 'UTF-8') : '';
    $zip = isset($attendee->zip) ? $attendee->zip : '';
    $payment_status = $attendee->payment_status;
    $txn_type = $attendee->txn_type;
    $amount_pd = (double) $attendee->amount_pd;
    $total_cost = (double) $attendee->total_cost;
    $payment_date = $attendee->payment_date;
    $phone = $attendee->phone;
    $event_time = $attendee->event_time;
    $end_time = $attendee->end_time;
    $date = $attendee->date;
    $pre_approve = $attendee->pre_approve;
    $session_id = $attendee->attendee_session;
    if ($attendee->is_primary) {
        $event_cost = $total_cost;
    }
    $attendee_pre_approved = is_attendee_approved($event_id, $attendee_id);
    if ($attendee_pre_approved) {
        //Pull in the "Payment Overview" page template
        if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "payment_page.php")) {
            require_once EVENT_ESPRESSO_TEMPLATE_DIR . "payment_page.php";
            //This is the path to the template file if available
        } else {
            require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/payment_page.php";
        }
        //Show payment options
        if ($total_cost > 0) {
            if (file_exists(EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php")) {
                require_once EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php";
            } else {
                require_once EVENT_ESPRESSO_PLUGINFULLPATH . "gateways/gateway_display.php";
            }
            //Check to see if the site owner wants to send an confirmation eamil before payment is recieved.
            if ($org_options['email_before_payment'] == 'Y') {
                event_espresso_email_confirmations(array('session_id' => $session_id, 'send_admin_email' => 'true', 'send_attendee_email' => 'true'));
            }
        } else {
            event_espresso_email_confirmations(array('session_id' => $session_id, 'send_admin_email' => 'true', 'send_attendee_email' => 'true'));
        }
    } else {
        if (file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/process-registration/pending_approval_page.php')) {
            require_once 'pending_approval_page.php';
            echo espresso_pending_registration_approval($registration_id);
            return;
        }
    }
    echo '</div>';
}