function espresso_seating_price_select_action($event_id, $atts = '')
 {
     global $org_options;
     $price_range = seating_chart::get_price_range($event_id);
     $price = "";
     if ($price_range['min'] != $price_range['max']) {
         $price = '<span class="section-title">' . __('Price Range', 'event_espresso') . '</span>: ' . $org_options['currency_symbol'] . number_format($price_range['min'], 2) . ' - ' . $org_options['currency_symbol'] . number_format($price_range['max'], 2);
     } else {
         $price = '<span class="section-title">' . __('Price', 'event_espresso') . '</span>: ' . $org_options['currency_symbol'] . number_format($price_range['min'], 2);
     }
     echo $price;
 }
function espresso_seating_chart_seat_info_filter($attendee_id, $event_id)
{
    global $wpdb;
    $booking_info = "";
    $seating_chart_id = seating_chart::check_event_has_seating_chart($event_id);
    if ($seating_chart_id !== false) {
        $seat = $wpdb->get_row("select scs.* , sces.id as booking_id from " . EVENTS_SEATING_CHART_SEAT_TABLE . " scs inner join " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " sces on scs.id = sces.seat_id where sces.attendee_id = '" . $attendee_id . "' ");
        if ($seat !== NULL) {
            $booking_info = "[" . __('Seat', 'event_espresso') . ": " . $seat->custom_tag . " | " . __('Booking ID', 'event_espresso') . ":" . $seat->booking_id . " ]";
        }
    }
    return $booking_info;
}
function add_new_attendee($event_id)
{
    if (isset($_REQUEST['regevent_action_admin']) && $_REQUEST['regevent_action_admin'] == 'post_attendee') {
        $attendee_id = event_espresso_add_attendees_to_db();
        // SEND CONFIRMATION EMAIL MESSAGES
        event_espresso_email_confirmations(array('attendee_id' => $attendee_id, 'send_admin_email' => 'true', 'send_attendee_email' => 'true'));
        //echo $attendee_id;
        ?>
<div id="message" class="updated fade">
  <p><strong>
    <?php 
        _e('Added Attendee to Database', 'event_espresso');
        ?>
    </strong></p>
</div>
<?php 
    }
    wp_register_script('reCopy', EVENT_ESPRESSO_PLUGINFULLURL . "scripts/reCopy.js", false, '1.1.0');
    wp_print_scripts('reCopy');
    global $wpdb;
    $sql = "SELECT * FROM " . EVENTS_DETAIL_TABLE . " WHERE is_active='Y' AND event_status != 'D' AND id = '" . $event_id . "' LIMIT 0,1";
    //Build the registration page
    if ($wpdb->get_results($sql)) {
        $events = $wpdb->get_results($sql);
        //These are the variables that can be used throughout the regsitration page
        foreach ($events as $event) {
            $event_id = $event->id;
            $event_name = stripslashes($event->event_name);
            $event_desc = stripslashes($event->event_desc);
            $display_desc = $event->display_desc;
            $event_address = $event->address;
            $event_city = $event->city;
            $event_state = $event->state;
            $event_zip = $event->zip;
            $event_description = stripslashes($event->event_desc);
            $event_identifier = $event->event_identifier;
            $event_cost = isset($event->event_cost) ? $event->event_cost : '';
            $member_only = isset($event->member_only) ? $event->member_only : '';
            $reg_limit = isset($event->reg_limit) ? $event->reg_limit : '';
            $allow_multiple = $event->allow_multiple;
            $start_date = $event->start_date;
            $end_date = $event->end_date;
            $reg_limit = $event->reg_limit;
            $additional_limit = $event->additional_limit;
            $is_active = array();
            $question_groups = unserialize($event->question_groups);
            //This function gets the status of the event.
            $is_active = event_espresso_get_is_active($event_id);
            //If the coupon code system is intalled then use it
            if (function_exists('event_espresso_coupon_registration_page')) {
                $use_coupon_code = $event->use_coupon_code;
            }
            //If the groupon code addon is installed, then use it
            if (function_exists('event_espresso_groupon_payment_page')) {
                $use_groupon_code = $event->use_groupon_code;
            }
            //Set a default value for additional limit
            if ($additional_limit == '') {
                $additional_limit = '5';
            }
        }
        //End foreach ($events as $event)
        //This is the start of the registration form. This is where you can start editing your display.
        $num_attendees = get_number_of_attendees_reg_limit($event_id, 'num_attendees');
        //Get the number of attendees
        $available_spaces = get_number_of_attendees_reg_limit($event_id, 'available_spaces');
        //Gets a count of the available spaces
        $number_available_spaces = get_number_of_attendees_reg_limit($event_id, 'number_available_spaces');
        //Gets the number of available spaces
        ?>
<script>$jaer = jQuery.noConflict();
	jQuery(document).ready(function($jaer) {
	jQuery(function(){
		//Registration form validation
		jQuery('#registration_form').validate();
	});
});

	</script>
<div class="metabox-holder">
  <div class="postbox">
    <div id="event_espressotration_form">
     
        <form method="post" action="<?php 
        echo $_SERVER['REQUEST_URI'];
        ?>
" onsubmit="return validateForm(this)"  id="registration_form">
          <h3 class="h3_event_title" id="h3_event_title-<?php 
        echo $event_id;
        ?>
"><?php 
        echo $event_name;
        ?>
</h3>
           <div  class="padding">
          <p class="start_date">
            <?php 
        _e('Start Date:', 'event_espresso');
        ?>
            <?php 
        echo event_date_display($start_date);
        ?>
</p>
          <p class="event_time">
            <?php 
        $time_selected = '';
        //This block of code is used to display the times of an event in either a dropdown or text format.
        if (!empty($time_selected) && $time_selected == true) {
            //If the customer is coming from a page where the time was preselected.
            echo event_espresso_display_selected_time($time_id);
            //Optional parameters start, end, default
        } else {
            if ($time_selected == false) {
                echo event_espresso_time_dropdown($event_id);
            }
        }
        //End time selected
        ?>
          </p>
          <?php 
        /*
         * Added for seating chart addon
         */
        if (defined('ESPRESSO_SEATING_CHART')) {
            $seating_chart_id = seating_chart::check_event_has_seating_chart($event_id);
            if ($seating_chart_id !== false) {
                ?>
								<p class="event_form_field">
									<label>Select a Seat:</label>
                                    <input type="text" name="seat_id" value="" class="ee_s_select_seat required" title="Please select a seat." event_id="<?php 
                echo $event_id;
                ?>
" readonly="readonly"  />
                           <?php 
                $seating_chart = $wpdb->get_row("select * from " . EVENTS_SEATING_CHART_TABLE . " where id = {$seating_chart_id}");
                if (trim($seating_chart->image_name) != "" && file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'seatingchart/images/' . $seating_chart->image_name)) {
                    ?>
                                    <br/>
                                    <a href="<?php 
                    echo EVENT_ESPRESSO_UPLOAD_URL . 'seatingchart/images/' . $seating_chart->image_name;
                    ?>
" target="_blank">Seating chart image</a>		
                            <?php 
                }
                ?>
                                </p>
          			<?php 
            }
        }
        /*
         * End
         */
        ?>
		  <?php 
        echo event_espresso_add_question_groups($question_groups);
        //Coupons
        if (function_exists('event_espresso_coupon_registration_page')) {
            echo event_espresso_coupon_registration_page($use_coupon_code, $event_id);
        }
        //End coupons display
        //Groupons
        if (function_exists('event_espresso_groupon_registration_page')) {
            echo event_espresso_groupon_registration_page($use_groupon_code, $event_id);
        }
        //End groupons display
        ?>
          <p class="event_form_field">
            <label for="event_cost">
              <?php 
        _e('Amount Paid:', 'event_espresso');
        ?>
            </label>
            <input tabindex="9" type="text" maxlength="10" size="15" name="event_cost" id="event_cost-<?php 
        echo $event_id;
        ?>
" <?php 
        echo $event_cost ? 'value="' . $event_cost . '"' : "";
        ?>
 />
            <input type="hidden" name="regevent_action_admin" id="regevent_action-<?php 
        echo $event_id;
        ?>
" value="post_attendee" />
            <input type="hidden" name="event_id" id="event_id-<?php 
        echo $event_id;
        ?>
" value="<?php 
        echo $event_id;
        ?>
" />
            <input type="hidden" name="admin" value="true" />
          </p>
          <p class="event_form_submit" id="event_form_submit-<?php 
        echo $event_id;
        ?>
">
            <input class="btn_event_form_submit" id="event_form_field-<?php 
        echo $event_id;
        ?>
" type="submit" name="Submit" value="<?php 
        _e('Submit', 'event_espresso');
        ?>
" />
          </p>
          <?php 
        echo event_espresso_additional_attendees($event_id, $additional_limit, $number_available_spaces, __('Number of Tickets', 'event_espresso'), true, $event_meta);
        ?>
        </form>
      </div>
    </div>
  </div>
<?php 
        event_list_attendees();
    }
    //End Build the registration page
}
             $msg = "Updated successfully";
         } else {
             $msg = "Update process failed!";
             foreach ($failed_to_update as $failed) {
                 $msg .= "<br/>{$failed}";
             }
         }
     }
     break;
 case 'bulk_delete':
     $msg = "";
     $deleted = 0;
     $ids = array();
     if (isset($_POST['seat_ids']) && count($_POST['seat_ids']) > 0) {
         $ids = $_POST['seat_ids'];
         $cls_seating_chart = new seating_chart();
         foreach ($ids as $id) {
             if ($cls_seating_chart->delete_seat($id)) {
                 $deleted++;
             } else {
                 $row = $wpdb->get_row("select * from " . EVENTS_SEATING_CHART_SEAT_TABLE . " where id = {$id}");
                 if ($row !== NULL) {
                     array_push($not_deleted, "Section: " . $row->section . "; Level: " . $row->level . "; Row: " . $row->row . "; Seat: " . $row->seat);
                 }
             }
         }
         if ($deleted > 0) {
             $msg .= "Total number of seats deleted: {$deleted}<br/>";
         }
         if (count($not_deleted) > 0) {
             $msg .= __('Following seats were not deleted because they have already been used in events:', 'event_espresso') . "<br/>";
 function espresso_export_stuff()
 {
     $today = date("Y-m-d-Hi", time());
     $export_all_events = isset($_REQUEST['all_events']) && $_REQUEST['all_events'] == "true" ? TRUE : FALSE;
     //Export data to Excel file
     if (isset($_REQUEST['export'])) {
         switch ($_REQUEST['export']) {
             case "report":
                 global $wpdb;
                 $event_id = isset($_REQUEST['event_id']) ? $_REQUEST['event_id'] : FALSE;
                 // export for one event only ?
                 if ($event_id) {
                     $SQL = "SELECT event_name, event_desc, event_identifier, question_groups, event_meta FROM " . EVENTS_DETAIL_TABLE;
                     $SQL .= " WHERE id = %d";
                     if ($results = $wpdb->get_row($wpdb->prepare($SQL, $event_id), ARRAY_N)) {
                         list($event_name, $event_description, $event_identifier, $question_groups, $event_meta) = $results;
                         $question_groups = maybe_unserialize($question_groups);
                         $event_meta = maybe_unserialize($event_meta);
                         if (!empty($event_meta['add_attendee_question_groups'])) {
                             $question_groups = array_unique(array_merge((array) $question_groups, (array) $event_meta['add_attendee_question_groups']));
                         }
                     }
                 } else {
                     // export for ALL EVENTS
                     $question_groups = array();
                     $event_meta = array();
                     $SQL = "SELECT event_name, event_desc, event_identifier, question_groups, event_meta FROM " . EVENTS_DETAIL_TABLE;
                     if ($results = $wpdb->get_results($SQL, ARRAY_N)) {
                         foreach ($results as $result) {
                             list($event_name, $event_description, $event_identifier, $q_groups, $e_meta) = $result;
                             $question_groups = array_unique(array_merge($question_groups, (array) maybe_unserialize($q_groups)));
                             $e_meta = (array) maybe_unserialize($e_meta);
                             $event_meta = array_unique(array_merge($event_meta, (array) $e_meta['add_attendee_question_groups']));
                         }
                     }
                 }
                 $basic_header = array(__('Group', 'event_espresso'), __('ID', 'event_espresso'), __('Reg ID', 'event_espresso'), __('Payment Method', 'event_espresso'), __('Reg Date', 'event_espresso'), __('Pay Status', 'event_espresso'), __('Type of Payment', 'event_espresso'), __('Transaction ID', 'event_espresso'), __('Price', 'event_espresso'), __('Coupon Code', 'event_espresso'), __('# Attendees', 'event_espresso'), __('Amount Paid', 'event_espresso'), __('Date Paid', 'event_espresso'), __('Event Name', 'event_espresso'), __('Price Option', 'event_espresso'), __('Event Date', 'event_espresso'), __('Event Time', 'event_espresso'), __('Website Check-in', 'event_espresso'), __('Tickets Scanned', 'event_espresso'), __('Seat Tag', 'event_espresso'), __('First Name', 'event_espresso'), __('Last Name', 'event_espresso'), __('Email', 'event_espresso'));
                 $question_groups = maybe_unserialize($question_groups);
                 $event_meta = maybe_unserialize($event_meta);
                 if (isset($event_meta['add_attendee_question_groups'])) {
                     //					if ( is_serialized(  $event_meta['add_attendee_question_groups'] ) ){
                     //						$add_attendee_question_groups = unserialize($event_meta['add_attendee_question_groups']);
                     //					} else {
                     //						$add_attendee_question_groups = $event_meta['add_attendee_question_groups'];
                     //					}
                     if (!empty($add_attendee_question_groups)) {
                         $question_groups = array_unique(array_merge((array) $question_groups, (array) $event_meta['add_attendee_question_groups']));
                     }
                 }
                 switch ($_REQUEST['action']) {
                     case "event":
                         espresso_event_export($event_name);
                         break;
                     case "payment":
                         $question_list = array();
                         //will be used to associate questions with correct answers
                         $question_filter = array();
                         //will be used to keep track of newly added and deleted questions
                         if (count($question_groups) > 0) {
                             $question_sequence = array();
                             $questions_in = '';
                             foreach ($question_groups as $g_id) {
                                 $questions_in .= $g_id . ',';
                             }
                             $questions_in = substr($questions_in, 0, -1);
                             $group_name = '';
                             $counter = 0;
                             $quest_sql = "SELECT q.id, q.question FROM " . EVENTS_QUESTION_TABLE . " q ";
                             $quest_sql .= " JOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id ";
                             $quest_sql .= " JOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id ";
                             $quest_sql .= " WHERE qgr.group_id in ( {$questions_in} ) ";
                             if (function_exists('espresso_member_data') && espresso_member_data('role') == 'espresso_event_manager') {
                                 $quest_sql .= " AND qg.wp_user = '******'id') . "' ";
                             }
                             //Fix from Jesse in the forums (http://eventespresso.com/forums/2010/10/form-questions-appearing-in-wrong-columns-in-excel-export/)
                             //$quest_sql .= " AND q.system_name is null ORDER BY qg.id, q.id ASC ";
                             //$quest_sql .= " AND q.system_name is null ";
                             $quest_sql .= " ORDER BY q.sequence, q.id ASC ";
                             $questions = $wpdb->get_results($quest_sql);
                             $ignore = array(1, 2, 3);
                             $num_rows = $wpdb->num_rows;
                             if ($num_rows > 0) {
                                 foreach ($questions as $question) {
                                     if (!isset($ignore[$question->id])) {
                                         $question_list[$question->id] = $question->question;
                                         $question_filter[$question->id] = $question->id;
                                         array_push($basic_header, escape_csv_val(stripslashes($question->question)));
                                         //array_push($question_sequence, $question->sequence);
                                     }
                                 }
                             }
                         }
                         if (count($question_filter) > 0) {
                             $question_filter = implode(",", $question_filter);
                         }
                         //$question_filter = str_replace( array( '1,','2,','3,' ), '', $question_filter );
                         $sql = '';
                         $espresso_member = function_exists('espresso_member_data') && espresso_member_data('role') == 'espresso_group_admin' ? TRUE : FALSE;
                         if ($espresso_member) {
                             $group = get_user_meta(espresso_member_data('id'), "espresso_group", true);
                             $group = maybe_unserialize($group);
                             $group = implode(",", $group);
                             $sql .= "(SELECT ed.event_name, ed.start_date, a.id AS att_id, a.registration_id, a.payment, a.date, a.payment_status, a.txn_type, a.txn_id";
                             $sql .= ", a.amount_pd, a.quantity, a.coupon_code, a.checked_in, a.checked_in_quantity";
                             $sql .= ", a.payment_date, a.event_time, a.price_option, a.final_price a_final_price, a.quantity a_quantity, a.fname, a.lname, a.email";
                             $sql .= " FROM " . EVENTS_ATTENDEE_TABLE . " a ";
                             $sql .= " JOIN " . EVENTS_DETAIL_TABLE . " ed ON ed.id=a.event_id ";
                             if ($group != '') {
                                 $sql .= " JOIN " . EVENTS_VENUE_REL_TABLE . " r ON r.event_id = ed.id ";
                                 $sql .= " JOIN " . EVENTS_LOCALE_REL_TABLE . " l ON  l.venue_id = r.venue_id ";
                             }
                             $sql .= $event_id ? " WHERE ed.id = '" . $event_id . "' " : '';
                             $sql .= $group != '' ? " AND  l.locale_id IN (" . $group . ") " : '';
                             $sql .= ") UNION (";
                         }
                         $sql .= "SELECT ed.event_name, ed.start_date, a.id AS att_id, a.registration_id, a.payment, a.date, a.payment_status, a.txn_type, a.txn_id";
                         $sql .= ", a.quantity, a.coupon_code, a.checked_in, a.checked_in_quantity, a.final_price a_final_price, a.amount_pd, a.quantity a_quantity";
                         $sql .= ", a.payment_date, a.event_time, a.price_option, a.fname, a.lname, a.email";
                         $sql .= " FROM " . EVENTS_ATTENDEE_TABLE . " a ";
                         $sql .= " JOIN " . EVENTS_DETAIL_TABLE . " ed ON ed.id=a.event_id ";
                         //$sql .= " JOIN " . EVENTS_ATTENDEE_COST_TABLE . " ac ON a.id=ac.attendee_id ";
                         $sql .= $event_id ? " WHERE ed.id = '" . $event_id . "' " : '';
                         if (function_exists('espresso_member_data') && (espresso_member_data('role') == 'espresso_event_manager' || espresso_member_data('role') == 'espresso_group_admin')) {
                             $sql .= " AND ed.wp_user = '******'id') . "' ";
                         }
                         $sql .= $espresso_member ? ") ORDER BY att_id " : " ORDER BY a.id ";
                         $participants = $wpdb->get_results($sql);
                         $filename = isset($_REQUEST['all_events']) && $_REQUEST['all_events'] == "true" ? __('all-events', 'event_espresso') : sanitize_title_with_dashes($event_name);
                         $filename = $filename . "-" . $today;
                         switch ($_REQUEST['type']) {
                             case "csv":
                                 $st = "";
                                 $et = ",";
                                 $s = $et . $st;
                                 header("Content-type: application/x-msdownload");
                                 header("Content-Disposition: attachment; filename=" . $filename . ".csv");
                                 //header("Content-Disposition: attachment; filename='" .$filename .".csv'");
                                 header("Pragma: no-cache");
                                 header("Expires: 0");
                                 //echo header
                                 echo implode($s, $basic_header) . "\r\n";
                                 break;
                             default:
                                 $st = "";
                                 $et = "\t";
                                 $s = $et . $st;
                                 header("Content-Disposition: attachment; filename=" . $filename . ".xls");
                                 //header("Content-Disposition: attachment; filename='" .$filename .".xls'");
                                 header("Content-Type: application/vnd.ms-excel");
                                 header("Pragma: no-cache");
                                 header("Expires: 0");
                                 //echo header
                                 echo implode($s, $basic_header) . $et . "\r\n";
                                 break;
                         }
                         if ($participants) {
                             $temp_reg_id = '';
                             //will temporarily hold the registration id for checking with the next row
                             $attendees_group = '';
                             //will hold the names of the group members
                             $group_counter = 1;
                             $amount_pd = 0;
                             foreach ($participants as $participant) {
                                 if ($temp_reg_id == '') {
                                     $temp_reg_id = $participant->registration_id;
                                     $amount_pd = $participant->amount_pd;
                                 }
                                 if ($temp_reg_id == $participant->registration_id) {
                                     //Do nothing
                                 } else {
                                     $group_counter++;
                                     $temp_reg_id = $participant->registration_id;
                                 }
                                 $attendees_group = "Group {$group_counter}";
                                 //Build the seating assignment
                                 $seatingchart_tag = '';
                                 if (defined("ESPRESSO_SEATING_CHART")) {
                                     if (class_exists("seating_chart")) {
                                         if (seating_chart::check_event_has_seating_chart($event_id)) {
                                             $rs = $wpdb->get_row("select scs.* from " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " sces inner join " . EVENTS_SEATING_CHART_SEAT_TABLE . " scs on sces.seat_id = scs.id where sces.attendee_id = " . $participant->att_id);
                                             if ($rs !== NULL) {
                                                 $participant->seatingchart_tag = $rs->custom_tag . " " . $rs->seat . " " . $rs->row;
                                             }
                                         }
                                     }
                                 } else {
                                     $participant->seatingchart_tag = '';
                                 }
                                 echo $attendees_group . $s . escape_csv_val($participant->att_id) . $s . escape_csv_val($participant->registration_id) . $s . escape_csv_val(stripslashes($participant->payment)) . $s . escape_csv_val(stripslashes(event_date_display($participant->date, get_option('date_format')))) . $s . escape_csv_val(stripslashes($participant->payment_status)) . $s . escape_csv_val(stripslashes($participant->txn_type)) . $s . escape_csv_val(stripslashes($participant->txn_id)) . $s . escape_csv_val($participant->a_final_price * $participant->a_quantity) . $s . escape_csv_val($participant->coupon_code) . $s . escape_csv_val($participant->quantity) . $s . escape_csv_val($participant->amount_pd) . $s . escape_csv_val(event_date_display($participant->payment_date, get_option('date_format'))) . $s . escape_csv_val($participant->event_name) . $s . escape_csv_val($participant->price_option) . $s . escape_csv_val(event_date_display($participant->start_date, get_option('date_format'))) . $s . escape_csv_val(event_date_display($participant->event_time, get_option('time_format'))) . $s . escape_csv_val($participant->checked_in) . $s . escape_csv_val($participant->checked_in_quantity) . $s . escape_csv_val($participant->seatingchart_tag) . $s . escape_csv_val($participant->fname) . $s . escape_csv_val($participant->lname) . $s . escape_csv_val($participant->email);
                                 $SQL = "SELECT question_id, answer FROM " . EVENTS_ANSWER_TABLE . " ";
                                 $SQL .= "WHERE question_id IN ({$question_filter}) AND attendee_id = %d";
                                 $answers = $wpdb->get_results($wpdb->prepare($SQL, $participant->att_id), OBJECT_K);
                                 foreach ($question_list as $k => $v) {
                                     // in case the event organizer removes a question from a question group,
                                     //  the orphaned answers will remian in the answers table.  This check will make sure they don't get exported.
                                     $search = array("\r", "\n", "\t");
                                     if (isset($answers[$k])) {
                                         $clean_answer = str_replace($search, " ", $answers[$k]->answer);
                                         $clean_answer = stripslashes(str_replace("&#039;", "'", trim($clean_answer)));
                                         $clean_answer = escape_csv_val($clean_answer);
                                         echo $s . $clean_answer;
                                     } else {
                                         echo $s;
                                     }
                                 }
                                 switch ($_REQUEST['type']) {
                                     case "csv":
                                         echo "\r\n";
                                         break;
                                     default:
                                         echo $et . "\r\n";
                                         break;
                                 }
                             }
                         } else {
                             echo __('No participant data has been collected.', 'event_espresso');
                         }
                         exit;
                         break;
                     default:
                         echo '<p>' . __('This Is Not A Valid Selection!', 'event_espresso') . '</p>';
                         break;
                 }
             default:
                 break;
         }
     }
 }
function events_payment_page($attendee_id, $price_id = 0, $coupon_code = '', $groupon_code = '')
{
    global $wpdb, $org_options, $simpleMath;
    $today = date("m-d-Y");
    $num_people = 0;
    $Organization = $org_options['organization'];
    $Organization_street1 = $org_options['organization_street1'];
    $Organization_street2 = $org_options['organization_street2'];
    $Organization_city = $org_options['organization_city'];
    $Organization_state = $org_options['organization_state'];
    $Organization_zip = $org_options['organization_zip'];
    $contact = $org_options['contact_email'];
    $registrar = $org_options['contact_email'];
    $currency_format = getCountryFullData($org_options['organization_country']);
    $message = $org_options['message'];
    $return_url = $org_options['return_url'];
    $cancel_return = $org_options['cancel_return'];
    $notify_url = $org_options['notify_url'];
    $event_page_id = $org_options['event_page_id'];
    $attendees = $wpdb->get_results("SELECT * FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id ='" . $attendee_id . "'");
    foreach ($attendees as $attendee) {
        //$attendee_id = $attendee->id;
        $attendee_last = $attendee->lname;
        $attendee_first = $attendee->fname;
        $attendee_address = $attendee->address;
        $attendee_address2 = $attendee->address2;
        $attendee_city = $attendee->city;
        $attendee_state = $attendee->state;
        $attendee_zip = $attendee->zip;
        $attendee_email = $attendee->email;
        //$attendee_organization_name = $attendee->organization_name;
        //$attendee_country = $attendee->country_id;
        $phone = $attendee->phone;
        $attendee_phone = $attendee->phone;
        $date = $attendee->date;
        $quantity = $attendee->quantity;
        $payment_status = $attendee->payment_status;
        $txn_type = $attendee->txn_type;
        //$event_cost = $attendee->amount_pd;
        $payment_date = $attendee->payment_date;
        $event_id = $attendee->event_id;
        $registration_id = $attendee->registration_id;
    }
    //$event_meta = event_espresso_get_event_meta($event_id);
    //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.attendee_id = '" . $attendee_id . "' and eq.admin_only = 'N' ORDER BY eq.sequence asc ");
    //echo $wpdb->last_query;
    $display_questions = '';
    foreach ($questions as $question) {
        $display_questions .= '<p>' . $question->question . ':<br /> ' . str_replace(',', '<br />', $question->answer) . '</p>';
    }
    $num_peoplea = $wpdb->get_results("SELECT COUNT(registration_id) FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id ='" . $registration_id . "'", ARRAY_N);
    $num_people = $num_peoplea[0][0];
    //If we are using the number of attendees dropdown, and
    if ($quantity > 1) {
        $num_people = $quantity;
    }
    $events = $wpdb->get_results("SELECT * FROM " . EVENTS_DETAIL_TABLE . " WHERE id ='" . $event_id . "'");
    foreach ($events as $event) {
        //$event_id = $event->id;
        $event_name = stripslashes_deep($event->event_name);
        $event_desc = stripslashes_deep($event->event_desc);
        $event_description = stripslashes_deep($event->event_desc);
        $event_identifier = $event->event_identifier;
        $send_mail = $event->send_mail;
        $active = $event->is_active;
        $conf_mail = $event->conf_mail;
        //$alt_email = $event->alt_email; //This is used to get the alternate email address that a payment can be made to using PayPal
        if (function_exists('event_espresso_coupon_payment_page')) {
            $use_coupon_code = $event->use_coupon_code;
        }
        if (function_exists('event_espresso_groupon_payment_page')) {
            $use_groupon_code = $event->use_groupon_code;
        }
    }
    $attendee_name = stripslashes_deep($attendee_first . ' ' . $attendee_last);
    //Figure out if the person has registered using a price selection
    if (!empty($_REQUEST['price_select']) && $_REQUEST['price_select'] == true) {
        $price_options = explode('|', $_REQUEST['price_option'], 2);
        $price_id = $price_options[0];
        $price_type = $price_options[1];
        $p_id = $price_id;
        $event_cost = event_espresso_get_final_price($price_id, $event_id);
    } elseif ($price_id > 0) {
        $event_cost = event_espresso_get_final_price($price_id, $event_id);
        $p_id = $price_id;
    } else {
        //$event_cost = $_POST['event_cost'];
        $event_cost = event_espresso_get_final_price($_POST['price_id'], $event_id);
        $p_id = $_POST['price_id'];
    }
    //Test the early discount amount to make sure we are getting the right amount
    //print_r(early_discount_amount($event_id, $event_cost));
    $event_price = number_format($event_cost, 2, '.', '');
    $event_price_x_attendees = number_format($event_cost * $num_people, 2, '.', '');
    $event_original_cost = number_format($simpleMath->multiply($event_cost, $num_people), 2, '.', '');
    /*
     * Added for seating chart addon
     */
    /*
     * This code block overrides the cost using seating chart add-on price
     */
    if (defined('ESPRESSO_SEATING_CHART')) {
        if (seating_chart::check_event_has_seating_chart($event_id) !== false) {
            $sc_cost_row = $wpdb->get_row("select sum(sces.purchase_price) as purchase_price from " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " sces inner join " . EVENTS_ATTENDEE_TABLE . " ea on sces.attendee_id = ea.id where ea.registration_id = '{$registration_id}'");
            if ($sc_cost_row !== NULL) {
                $event_cost = number_format($sc_cost_row->purchase_price, 2, '.', '');
                $event_original_cost = $event_cost;
                $event_price_x_attendees = $event_cost;
            }
        }
    }
    /*
     * End seating chart addon
     */
    if (function_exists('event_espresso_coupon_payment_page') && (!empty($_REQUEST['coupon_code']) || !empty($coupon_code))) {
        $event_cost = event_espresso_coupon_payment_page($use_coupon_code, $event_id, $event_original_cost, $attendee_id, $num_people);
        /*
         * at this point , the $event_cost is correct
         * The next line divided by the number of people and reassigned it to the same $even_cost var, making the event cost less
         * I renamed it to another variable
         */
        $event_price_x_attendees = number_format($event_cost, 2, '.', '');
        $coupon_code = $_REQUEST['coupon_code'];
    } else {
        if (function_exists('event_espresso_groupon_payment_page') && ($_REQUEST['groupon_code'] != '' || $coupon_code != '')) {
            $event_cost = event_espresso_groupon_payment_page($use_groupon_code, $event_id, $event_original_cost, $attendee_id);
            $groupon_code = $_REQUEST['groupon_code'];
        } else {
            $event_cost = $event_original_cost;
        }
    }
    if ($num_people != 0) {
        $event_individual_cost = number_format($event_cost / $num_people, 2, '.', '');
    }
    $event_discount_label = $event_original_cost > $event_cost ? ' (' . __('Discount of ', 'event_espresso') . $org_options['currency_symbol'] . number_format($event_original_cost - $event_cost, 2, ".", ",") . __(' applied', 'event_espresso') . ')' : '';
    if ($event_cost == '0.00') {
        $event_cost = '0.00';
        $payment_status = 'Completed';
        $sql = array('amount_pd' => $event_cost, 'payment_status' => $payment_status, 'payment_date' => $today);
        $sql_data = array('%s', '%s', '%s');
    } else {
        $sql = array('amount_pd' => $event_cost, 'payment_status' => $payment_status);
        $sql_data = array('%s', '%s');
    }
    //Add the cost and payment status to the attendee
    $update_id = array('id' => $attendee_id);
    $wpdb->update(EVENTS_ATTENDEE_TABLE, $sql, $update_id, $sql_data, array('%d'));
    //If this is a group registration, we need to make sure all attendees have the same payment status
    if (espresso_count_attendees_for_registration($attendee_id) > 1) {
        $wpdb->query("UPDATE " . EVENTS_ATTENDEE_TABLE . " SET payment_status = '{$payment_status}' WHERE registration_id ='" . $registration_id . "'");
    }
    $display_cost = $event_cost != "0.00" ? $org_options['currency_symbol'] . $event_individual_cost : __('Free', 'event_espresso');
    //Pull in the template
    if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "confirmation_display.php")) {
        require_once EVENT_ESPRESSO_TEMPLATE_DIR . "confirmation_display.php";
        //This is the path to the template file if available
    } else {
        require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/confirmation_display.php";
    }
}
                            <th style="text-align:center;width:50px;">Row</th>
                            <th style="text-align:center;width:50px;">Seat</th>
                            <th style="text-align:center;width:100px;">Price</th>
                            <th style="text-align:center;width:120px;">Member price</th>
                            <th style="text-align:center;width:110px;">Custom tag</th>
                            <th style="text-align:center;">Seat status</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php 
        foreach ($seats as $seat) {
            ?>
                        <tr>
                            <td>
                            <?php 
            $check = seating_chart::check_seat_available($event_id, $seat->id);
            if ($check == 0 || $check == -1) {
                ?>
                            <input type="checkbox" name="seat_ids[]" value="<?php 
                echo $seat->id;
                ?>
" />
                            <?php 
            }
            ?>
                            </td>
                            <td><?php 
            echo $seat->level;
            ?>
</td>
                            <td style="text-align:center;"><?php 
function add_event_to_db($recurrence_arr = array())
{
    // echo "<pre>";
    //print_r($_POST);
    //echo "</pre>";
    global $wpdb, $org_options, $current_user, $espresso_premium;
    $wpdb->show_errors();
    static $recurrence_id;
    if (get_option('event_espresso_re_active') == 1) {
        require_once EVENT_ESPRESSO_RECURRENCE_FULL_PATH . "functions/re_functions.php";
        $recurrence_id = array_key_exists('recurrence_id', $recurrence_arr) ? $recurrence_arr['recurrence_id'] : Null;
        if ($_POST['recurrence'] == 'Y' && count($recurrence_arr) < 2) {
            if (is_null($recurrence_id)) {
                $recurrence_id = add_recurrence_master_record();
            }
            $re_params = array('start_date' => $_POST['recurrence_type'] == 'a' ? $_POST['recurrence_start_date'] : $_POST['recurrence_manual_dates'], 'event_end_date' => $_POST['recurrence_type'] == 'a' ? $_POST['recurrence_event_end_date'] : $_POST['recurrence_manual_end_dates'], 'end_date' => $_POST['recurrence_type'] == 'a' ? $_POST['recurrence_end_date'] : $_POST['end_date'], 'registration_start' => $_POST['recurrence_regis_start_date'], 'registration_end' => $_POST['recurrence_regis_end_date'], 'frequency' => $_POST['recurrence_frequency'], 'interval' => $_POST['recurrence_interval'], 'type' => $_POST['recurrence_type'], 'weekdays' => $_POST['recurrence_weekday'], 'repeat_by' => $_POST['recurrence_repeat_by'], 'recurrence_regis_date_increment' => $_POST['recurrence_regis_date_increment'], 'recurrence_manual_dates' => $_POST['recurrence_manual_dates'], 'recurrence_manual_end_dates' => $_POST['recurrence_manual_end_dates'], 'recurrence_visibility' => $_POST['recurrence_visibility'], 'recurrence_id' => $recurrence_id, 'adding_to_db' => 'Y');
            $recurrence_dates = $_POST['recurrence_type'] == 'm' ? find_recurrence_manual_dates($re_params) : find_recurrence_dates($re_params);
        }
    }
    //echo_f('re array', $recurrence_dates);
    if (defined('EVENT_ESPRESSO_RECURRENCE_MODULE_ACTIVE') && $_POST['recurrence'] == 'Y' && count($recurrence_arr) == 0) {
        //skip the first insert because we do not have the start dates
    } else {
        $event_mata = array();
        //will be used to hold event meta data
        //If the Espresso Facebook Events is installed, add the event to Facebook
        //$fb = new FacebookEvents();
        //echo $fb->espresso_createevent();
        //echo $_POST['event'];
        $event_name = $_REQUEST['event'];
        $event_code = uniqid($current_user->ID . '-');
        $event_identifier = $_REQUEST['event_identifier'] == '' ? $event_identifier = sanitize_title_with_dashes($event_name . '-' . $event_code) : ($event_identifier = sanitize_title_with_dashes($_REQUEST['event_identifier']) . $event_code);
        $event_desc = $_REQUEST['event_desc'];
        $display_desc = $_REQUEST['display_desc'];
        $display_reg_form = $_REQUEST['display_reg_form'];
        $address = esc_html($_REQUEST['address']);
        $address2 = esc_html($_REQUEST['address2']);
        $city = esc_html($_REQUEST['city']);
        $state = esc_html($_REQUEST['state']);
        $zip = esc_html($_REQUEST['zip']);
        $country = esc_html($_REQUEST['country']);
        $phone = esc_html($_REQUEST['phone']);
        $externalURL = esc_html($_REQUEST['externalURL']);
        $post_type = $_REQUEST['espresso_post_type'];
        //$event_location = $address . ' ' . $city . ', ' . $state . ' ' . $zip;
        $event_location = ($address != '' ? $address . ' ' : '') . ($address2 != '' ? '<br />' . $address2 : '') . ($city != '' ? '<br />' . $city : '') . ($state != '' ? ', ' . $state : '') . ($zip != '' ? '<br />' . $zip : '') . ($country != '' ? '<br />' . $country : '');
        $reg_limit = $_REQUEST['reg_limit'];
        $allow_multiple = $_REQUEST['allow_multiple'];
        $additional_limit = $_REQUEST['additional_limit'];
        $member_only = isset($_REQUEST['member_only']) ? $_REQUEST['member_only'] : '';
        $is_active = $_REQUEST['is_active'];
        $event_status = $_REQUEST['event_status'];
        //Get the first instance of the start and end times
        $start_time = $_REQUEST['start_time'][0];
        $end_time = $_REQUEST['end_time'][0];
        // Add registration times
        $registration_startT = event_date_display($_REQUEST['registration_startT'], 'H:i');
        $registration_endT = event_date_display($_REQUEST['registration_endT'], 'H:i');
        // Add Timezone
        $timezone_string = isset($_REQUEST['timezone_string']) ? $_REQUEST['timezone_string'] : '';
        //Early discounts
        $early_disc = $_REQUEST['early_disc'];
        $early_disc_date = $_REQUEST['early_disc_date'];
        $early_disc_percentage = $_REQUEST['early_disc_percentage'];
        $conf_mail = $_REQUEST['conf_mail'];
        $use_coupon_code = $_REQUEST['use_coupon_code'];
        $alt_email = $_REQUEST['alt_email'];
        $send_mail = $_REQUEST['send_mail'];
        $email_id = isset($_REQUEST['email_name']) ? $_REQUEST['email_name'] : '';
        //Venue Information
        $venue_title = $_REQUEST['venue_title'];
        $venue_url = $_REQUEST['venue_url'];
        $venue_phone = $_REQUEST['venue_phone'];
        $venue_image = $_REQUEST['venue_image'];
        //Virtual location
        $virtual_url = $_REQUEST['virtual_url'];
        $virtual_phone = $_REQUEST['virtual_phone'];
        $registration_start = array_key_exists('registration_start', $recurrence_arr) ? $recurrence_arr['registration_start'] : $_REQUEST['registration_start'];
        $registration_end = array_key_exists('registration_end', $recurrence_arr) ? $recurrence_arr['registration_end'] : $_REQUEST['registration_end'];
        //Check which start/end date to use.  Will be determined by recurrenig events addon, if installed.
        if (array_key_exists('recurrence_start_date', $recurrence_arr)) {
            //Recurring event
            $start_date = $recurrence_arr['recurrence_start_date'];
        } elseif ($_REQUEST['start_date'] == '' && $_REQUEST['recurrence_start_date'] != '') {
            //If they leave the Event Start Date empty, the First Event Date in the recurrence module is selected
            $start_date = $_REQUEST['recurrence_start_date'];
        } elseif (isset($_POST['recurrence']) && $_POST['recurrence'] == 'Y' && $_REQUEST['start_date'] == '') {
            $start_date = $_REQUEST['recurrence_manual_dates'][0];
        } else {
            $start_date = $_REQUEST['start_date'];
        }
        if (array_key_exists('recurrence_event_end_date', $recurrence_arr)) {
            //Recurring event
            $end_date = $recurrence_arr['recurrence_event_end_date'];
        } elseif ($_REQUEST['end_date'] == '' && $_REQUEST['recurrence_event_end_date'] != '') {
            //If they leave the Event Start Date empty, the First Event Date in the recurrence module is selected
            $end_date = $_REQUEST['recurrence_event_end_date'];
        } elseif (isset($_POST['recurrence']) && $_POST['recurrence'] == 'Y' && $_REQUEST['end_date'] == '') {
            $end_date = $_REQUEST['recurrence_manual_end_dates'][count($_REQUEST['recurrence_manual_end_dates']) - 1];
        } else {
            $end_date = $_REQUEST['end_date'];
        }
        //$start_date = array_key_exists('recurrence_start_date', $recurrence_arr)?$recurrence_arr['recurrence_start_date']:($_REQUEST['start_date']==''?$_REQUEST['recurrence_start_date']:$_REQUEST['start_date']);
        //$end_date = array_key_exists('recurrence_start_date', $recurrence_arr)?$recurrence_arr['recurrence_start_date']:($_REQUEST['end_date']==''?$_REQUEST['recurrence_start_date']:$_REQUEST['end_date']);
        if (array_key_exists('visible_on', $recurrence_arr)) {
            //Recurring event
            $visible_on = $recurrence_arr['visible_on'];
        } elseif (isset($_REQUEST['visible_on']) && $_REQUEST['visible_on'] != '') {
            $visible_on = $_REQUEST['visible_on'];
        } elseif (isset($_REQUEST['visible_on']) && $_REQUEST['visible_on'] == '' && count($recurrence_dates) > 0) {
            $visible_on = $recurrence_dates[$start_date]['visible_on'];
        } else {
            $visible_on = date("Y-m-d");
        }
        if ($reg_limit == '') {
            $reg_limit = 999;
        }
        $question_groups = empty($_REQUEST['question_groups']) ? '' : serialize($_REQUEST['question_groups']);
        $add_attendee_question_groups = empty($_REQUEST['add_attendee_question_groups']) ? '' : serialize($_REQUEST['add_attendee_question_groups']);
        $event_mata['venue_id'] = isset($_REQUEST['venue_id']) ? $_REQUEST['venue_id'][0] : '';
        $event_mata['additional_attendee_reg_info'] = $_REQUEST['additional_attendee_reg_info'];
        $event_mata['add_attendee_question_groups'] = $add_attendee_question_groups;
        $event_mata['date_submitted'] = date("Y-m-d H:i:s");
        $event_mata['default_payment_status'] = $_REQUEST['default_payment_status'];
        if ($_REQUEST['emeta'] != '') {
            foreach ($_REQUEST['emeta'] as $k => $v) {
                $event_mata[$v] = strlen(trim($_REQUEST['emetad'][$k])) > 0 ? $_REQUEST['emetad'][$k] : '';
            }
        }
        //echo strlen(trim($_REQUEST['emetad'][$k]));
        //print_r($_REQUEST['emeta'] );
        $event_mata = serialize($event_mata);
        ############ Added by wp-developers ######################
        $require_pre_approval = 0;
        if (isset($_REQUEST['require_pre_approval'])) {
            $require_pre_approval = $_REQUEST['require_pre_approval'];
        }
        ################# END #################
        //When adding colums to the following arrays, be sure both arrays have equal values.
        $sql = array('event_code' => $event_code, 'event_name' => $event_name, 'event_desc' => $event_desc, 'display_desc' => $display_desc, 'display_reg_form' => $display_reg_form, 'event_identifier' => $event_identifier, 'address' => $address, 'address2' => $address2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country, 'phone' => $phone, 'virtual_url' => $virtual_url, 'virtual_phone' => $virtual_phone, 'venue_title' => $venue_title, 'venue_url' => $venue_url, 'venue_phone' => $venue_phone, 'venue_image' => $venue_image, 'registration_start' => $registration_start, 'registration_end' => $registration_end, 'start_date' => $start_date, 'end_date' => $end_date, 'allow_multiple' => $allow_multiple, 'send_mail' => $send_mail, 'is_active' => $is_active, 'event_status' => $event_status, 'conf_mail' => $conf_mail, 'use_coupon_code' => $use_coupon_code, 'member_only' => $member_only, 'externalURL' => $externalURL, 'early_disc' => $early_disc, 'early_disc_date' => $early_disc_date, 'early_disc_percentage' => $early_disc_percentage, 'alt_email' => $alt_email, 'question_groups' => $question_groups, 'registration_startT' => $registration_startT, 'registration_endT' => $registration_endT, 'reg_limit' => $reg_limit, 'additional_limit' => $additional_limit, 'recurrence_id' => $recurrence_id, 'email_id' => $email_id, 'wp_user' => $current_user->ID, 'event_meta' => $event_mata, 'require_pre_approval' => $require_pre_approval, 'timezone_string' => $timezone_string, 'submitted' => date('Y-m-d H:i:s', time()));
        $sql_data = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%s', '%s', '%s', '%s');
        /* echo 'Debug: <br />';
           print_r($sql);
           echo '<br />';
           print 'Number of vars: ' . count ($sql);
           echo '<br />';
           print 'Number of cols: ' . count($sql_data); */
        //Add groupon reference if installed
        if (function_exists('event_espresso_add_event_to_db_groupon')) {
            $sql = event_espresso_add_event_to_db_groupon($sql, $_REQUEST['use_groupon_code']);
            //print count ($sql);
            $sql_data = array_merge((array) $sql_data, (array) '%s');
            //print count($sql_data);
            if (!$wpdb->insert(EVENTS_DETAIL_TABLE, $sql, $sql_data)) {
                $error = true;
            }
        } else {
            if (!$wpdb->insert(EVENTS_DETAIL_TABLE, $sql, $sql_data)) {
                $error = true;
            }
        }
        $last_event_id = $wpdb->insert_id;
        ############# MailChimp Integration ##############
        if (get_option('event_mailchimp_active') == 'true' && $espresso_premium == true) {
            MailChimpController::add_event_list_rel($last_event_id);
        }
        if (function_exists('espresso_fb_createevent') == 'true' && $espresso_premium == true) {
            espresso_fb_createevent($last_event_id);
        }
        /*
         * Added for seating chart addon
         */
        if (isset($_REQUEST['seating_chart_id'])) {
            $cls_seating_chart = new seating_chart();
            $cls_seating_chart->associate_event_seating_chart($_REQUEST['seating_chart_id'], $last_event_id);
        }
        /*
         * End
         */
        //Add event to a category
        if (isset($_REQUEST['event_category']) && $_REQUEST['event_category'] != '') {
            foreach ($_REQUEST['event_category'] as $k => $v) {
                if ($v != '') {
                    $sql_cat = "INSERT INTO " . EVENTS_CATEGORY_REL_TABLE . " (event_id, cat_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    //echo "$sql3 <br>";
                    if (!$wpdb->query($sql_cat)) {
                        $error = true;
                    }
                }
            }
        }
        if (!empty($_REQUEST['event_person'])) {
            foreach ($_REQUEST['event_person'] as $k => $v) {
                if ($v != '') {
                    $sql_ppl = "INSERT INTO " . EVENTS_PERSONNEL_REL_TABLE . " (event_id, person_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    //echo "$sql_ppl <br>";
                    $wpdb->query($sql_ppl);
                }
            }
        }
        if (!empty($_REQUEST['venue_id'])) {
            foreach ($_REQUEST['venue_id'] as $k => $v) {
                if ($v != '' && $v != 0) {
                    $sql_venues = "INSERT INTO " . EVENTS_VENUE_REL_TABLE . " (event_id, venue_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    //echo "$sql_venues <br>";
                    $wpdb->query($sql_venues);
                }
            }
        }
        if (!empty($_REQUEST['event_discount'])) {
            foreach ($_REQUEST['event_discount'] as $k => $v) {
                if ($v != '') {
                    $sql_cat = "INSERT INTO " . EVENTS_DISCOUNT_REL_TABLE . " (event_id, discount_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    //echo "$sql3 <br>";
                    if (!$wpdb->query($sql_cat)) {
                        $error = true;
                    }
                }
            }
        }
        if (!empty($_REQUEST['start_time'])) {
            foreach ($_REQUEST['start_time'] as $k => $v) {
                if ($v != '') {
                    $time_qty = $_REQUEST['time_qty'][$k] == '' ? '0' : "'" . $_REQUEST['time_qty'][$k] . "'";
                    $sql3 = "INSERT INTO " . EVENTS_START_END_TABLE . " (event_id, start_time, end_time, reg_limit) VALUES ('" . $last_event_id . "', '" . event_date_display($v, 'H:i') . "', '" . event_date_display($_REQUEST['end_time'][$k], 'H:i') . "', " . $time_qty . ")";
                    //echo "$sql3 <br>";
                    if (!$wpdb->query($sql3)) {
                        $error = true;
                    }
                }
            }
        }
        if (!empty($_REQUEST['event_cost'])) {
            foreach ($_REQUEST['event_cost'] as $k => $v) {
                if ($v != '') {
                    $price_type = $_REQUEST['price_type'][$k] != '' ? $_REQUEST['price_type'][$k] : __('General Admission', 'event_espresso');
                    $member_price_type = !empty($_REQUEST['member_price_type'][$k]) ? $_REQUEST['member_price_type'][$k] : __('Members Admission', 'event_espresso');
                    $member_price = !empty($_REQUEST['member_price'][$k]) ? $_REQUEST['member_price'][$k] : $v;
                    $sql_price = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, surcharge_type, price_type, member_price, member_price_type) VALUES ('" . $last_event_id . "', '" . $v . "', '" . $_REQUEST['surcharge'][$k] . "', '" . $_REQUEST['surcharge_type'][$k] . "', '" . $price_type . "', '" . $member_price . "', '" . $member_price_type . "')";
                    //echo "$sql3 <br>";
                    if (!$wpdb->query($sql_price)) {
                        $error = true;
                    }
                }
            }
        } elseif ($_REQUEST['event_cost'][0] == 0) {
            $sql_price = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, price_type, member_price, member_price_type) VALUES ('" . $last_event_id . "', '0.00', '0.00', '" . __('Free', 'event_espresso') . "', '0.00', '" . __('Free', 'event_espresso') . "')";
            if (!$wpdb->query($sql_price)) {
                $error = true;
            }
        }
        // Create Event Post Code Here
        if ($_REQUEST['create_post'] == 'Y') {
            $post_type = $_REQUEST['espresso_post_type'];
            if ($post_type == 'post') {
                if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php") || file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php")) {
                    // Load message from template into message post variable
                    ob_start();
                    if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php")) {
                        require_once EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php";
                    } else {
                        require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php";
                    }
                    $post_content = ob_get_contents();
                    ob_end_clean();
                } else {
                    _e('There was error finding a post template. Please verify your post templates are available.', 'event_espresso');
                }
            } elseif ($post_type == 'espresso_event') {
                ob_start();
                echo $event_desc;
                $post_content = ob_get_contents();
                ob_end_clean();
            }
            $my_post = array();
            $my_post['post_title'] = esc_html($_REQUEST['event']);
            $my_post['post_content'] = $post_content;
            $my_post['post_status'] = 'publish';
            $my_post['post_author'] = $_REQUEST['user'];
            $my_post['post_category'] = $_REQUEST['post_category'];
            $my_post['tags_input'] = $_REQUEST['post_tags'];
            $my_post['post_type'] = $post_type;
            //print_r($my_post);
            // Insert the post into the database
            $post_id = wp_insert_post($my_post);
            // Store the POST ID so it can be displayed on the edit page
            $sql = array('post_id' => $post_id, 'post_type' => $post_type);
            add_post_meta($post_id, 'event_id', $last_event_id);
            add_post_meta($post_id, 'event_identifier', $event_identifier);
            add_post_meta($post_id, 'event_start_date', $_REQUEST['start_date']);
            add_post_meta($post_id, 'event_end_date', $_REQUEST['end_date']);
            add_post_meta($post_id, 'event_location', $event_location);
            add_post_meta($post_id, 'virtual_url', $virtual_url);
            add_post_meta($post_id, 'virtual_phone', $virtual_phone);
            add_post_meta($post_id, 'event_address', $address);
            add_post_meta($post_id, 'event_address2', $address2);
            add_post_meta($post_id, 'event_city', $city);
            add_post_meta($post_id, 'event_state', $state);
            add_post_meta($post_id, 'event_country', $country);
            add_post_meta($post_id, 'event_phone', $phone);
            add_post_meta($post_id, 'venue_title', $venue_title);
            add_post_meta($post_id, 'venue_url', $venue_url);
            add_post_meta($post_id, 'venue_phone', $venue_phone);
            add_post_meta($post_id, 'venue_image', $venue_image);
            add_post_meta($post_id, 'event_externalURL', $externalURL);
            add_post_meta($post_id, 'event_reg_limit', $reg_limit);
            add_post_meta($post_id, 'event_start_time', time_to_24hr($start_time));
            add_post_meta($post_id, 'event_end_time', time_to_24hr($end_time));
            add_post_meta($post_id, 'event_registration_start', $registration_start);
            add_post_meta($post_id, 'event_registration_end', $registration_end);
            add_post_meta($post_id, 'event_registration_startT', $registration_startT);
            add_post_meta($post_id, 'event_registration_endT', $registration_endT);
            //add_post_meta( $post_id, 'timezone_string', $_REQUEST['timezone_string'] );
            $sql_data = array('%d', '%s');
            $update_id = array('id' => $last_event_id);
            $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
        }
        if (empty($error)) {
            ?>
            <div id="message" class="updated fade"><p><strong><?php 
            _e('The event', 'event_espresso');
            ?>
                        <a href="<?php 
            echo espresso_reg_url($last_event_id);
            ?>
" target="_blank"><?php 
            echo stripslashes_deep($_REQUEST['event']);
            ?>
</a>

            <?php 
            _e('has been added for ', 'event_espresso');
            echo date("m/d/Y", strtotime($start_date));
            ?>
 <a href="admin.php?page=events&action=edit&event_id=<?php 
            echo $last_event_id;
            ?>
"><?php 
            _e('Edit this event?', 'event_espresso');
            ?>
</a></strong></p></div>
        <?php 
        } else {
            ?>
            <div id="message" class="error"><p><strong><?php 
            _e('There was an error in your submission, please try again. The event was not saved!', 'event_espresso');
            print $wpdb->print_error();
            ?>
.</strong></p></div>
            <?php 
        }
    }
    /*
     * With the recursion of this function, additional recurring events will be added
     */
    if (isset($recurrence_dates) && count($recurrence_dates) > 0) {
        foreach ($recurrence_dates as $k => $v) {
            add_event_to_db(array('recurrence_id' => $recurrence_id, 'recurrence_start_date' => $v['start_date'], 'recurrence_event_end_date' => $v['event_end_date'], 'registration_start' => $v['registration_start'], 'registration_end' => $v['registration_end'], 'visible_on' => $v['visible_on']));
        }
    }
    /*
     * End recursion, as part of recurring events.
     */
    return $last_event_id;
}
function add_event_to_db($recurrence_arr = array())
{
    global $wpdb, $org_options, $current_user, $espresso_premium;
    //Security check using nonce
    if (empty($_POST['nonce_verify_insert_event']) || !wp_verify_nonce($_POST['nonce_verify_insert_event'], 'espresso_verify_insert_event_nonce')) {
        if (!isset($recurrence_arr['bypass_nonce'])) {
            print '<h3 class="error">' . __('Sorry, there was a security error and your event was not saved.', 'event_espresso') . '</h3>';
            return;
        }
    }
    //Set FEM to false
    $use_fem = FALSE;
    $is_espresso_event_manager = false;
    //If using FEM
    if (isset($_REQUEST['ee_fem_action']) && $_REQUEST['ee_fem_action'] == 'ee_fem_add') {
        $use_fem = TRUE;
        if (function_exists('espresso_member_data') && espresso_member_data('role') == 'espresso_event_manager') {
            global $espresso_manager;
            $event_manager_approval = isset($espresso_manager['event_manager_approval']) && $espresso_manager['event_manager_approval'] == 'Y' ? true : false;
            $is_espresso_event_manager = TRUE;
        }
    }
    //Don't show sql errors if using the FEM
    if ($use_fem === FALSE) {
        $wpdb->show_errors();
    }
    static $recurrence_id = null;
    if (defined('EVENT_ESPRESSO_RECURRENCE_TABLE')) {
        require_once EVENT_ESPRESSO_RECURRENCE_FULL_PATH . "functions/re_functions.php";
        $recurrence_id = array_key_exists('recurrence_id', $recurrence_arr) ? $recurrence_arr['recurrence_id'] : Null;
        if ($_POST['recurrence'] == 'Y' && count($recurrence_arr) < 2) {
            if (is_null($recurrence_id)) {
                $recurrence_id = add_recurrence_master_record();
            }
            $re_params = array('start_date' => $_POST['recurrence_type'] == 'a' ? sanitize_text_field($_POST['recurrence_start_date']) : sanitize_text_field($_POST['recurrence_manual_dates']), 'event_end_date' => $_POST['recurrence_type'] == 'a' ? sanitize_text_field($_POST['recurrence_event_end_date']) : sanitize_text_field($_POST['recurrence_manual_end_dates']), 'end_date' => $_POST['recurrence_type'] == 'a' ? sanitize_text_field($_POST['recurrence_end_date']) : sanitize_text_field($_POST['end_date']), 'registration_start' => sanitize_text_field($_POST['recurrence_regis_start_date']), 'registration_end' => sanitize_text_field($_POST['recurrence_regis_end_date']), 'frequency' => sanitize_text_field($_POST['recurrence_frequency']), 'interval' => sanitize_text_field($_POST['recurrence_interval']), 'type' => sanitize_text_field($_POST['recurrence_type']), 'weekdays' => isset($_POST['recurrence_weekday']) ? $_POST['recurrence_weekday'] : '', 'repeat_by' => $_POST['recurrence_repeat_by'], 'recurrence_regis_date_increment' => $_POST['recurrence_regis_date_increment'], 'recurrence_manual_dates' => $_POST['recurrence_manual_dates'], 'recurrence_manual_end_dates' => $_POST['recurrence_manual_end_dates'], 'recurrence_id' => $recurrence_id, 'adding_to_db' => 'Y');
            $recurrence_dates = $_POST['recurrence_type'] == 'm' ? find_recurrence_manual_dates($re_params) : find_recurrence_dates($re_params);
        }
    }
    //echo_f('re array', $recurrence_dates);
    if (defined('EVENT_ESPRESSO_RECURRENCE_MODULE_ACTIVE') && $_POST['recurrence'] == 'Y' && count($recurrence_arr) == 0) {
        //skip the first insert because we do not have the start dates
    } else {
        $event_meta = array();
        //will be used to hold event meta data
        //Filters the event description based on user level
        $user_access = apply_filters('filter_hook_espresso_event_unfiltered_description', current_user_can('administrator'));
        $_REQUEST['event_desc'] = is_admin() || $user_access ? $_REQUEST['event_desc'] : apply_filters('filter_hook_espresso_event_wp_kses_post_description', wp_kses_post($_REQUEST['event_desc']));
        $event_code = uniqid($current_user->ID . '-');
        $event_name = !empty($_REQUEST['event']) ? sanitize_text_field($_REQUEST['event']) : $event_code;
        if (!isset($_REQUEST['event_identifier']) || $_REQUEST['event_identifier'] == '') {
            $event_identifier = sanitize_title_with_dashes($event_name . '-' . $event_code);
        } else {
            $event_identifier = sanitize_title_with_dashes($_REQUEST['event_identifier']) . $event_code;
        }
        $event_desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : '';
        $display_desc = !empty($_REQUEST['display_desc']) ? sanitize_text_field($_REQUEST['display_desc']) : 'Y';
        $display_reg_form = !empty($_REQUEST['display_reg_form']) ? sanitize_text_field($_REQUEST['display_reg_form']) : 'Y';
        $externalURL = isset($_REQUEST['externalURL']) ? sanitize_text_field($_REQUEST['externalURL']) : '';
        $post_type = !empty($_REQUEST['espresso_post_type']) ? sanitize_text_field($_REQUEST['espresso_post_type']) : '';
        $reg_limit = !empty($_REQUEST['reg_limit']) ? sanitize_text_field($_REQUEST['reg_limit']) : '999999';
        $_REQUEST['reg_limit'] = $reg_limit;
        $allow_multiple = !empty($_REQUEST['allow_multiple']) ? sanitize_text_field($_REQUEST['allow_multiple']) : 'N';
        $additional_limit = !empty($_REQUEST['additional_limit']) && $_REQUEST['additional_limit'] > 0 ? sanitize_text_field($_REQUEST['additional_limit']) : '5';
        $_REQUEST['additional_limit'] = $additional_limit;
        $member_only = !empty($_REQUEST['member_only']) ? sanitize_text_field($_REQUEST['member_only']) : 'N';
        $is_active = !empty($_REQUEST['is_active']) ? sanitize_text_field($_REQUEST['is_active']) : 'Y';
        $event_status = !empty($_REQUEST['event_status']) ? sanitize_text_field($_REQUEST['event_status']) : 'A';
        $use_coupon_code = !empty($_REQUEST['use_coupon_code']) ? sanitize_text_field($_REQUEST['use_coupon_code']) : 'N';
        $ticket_id = empty($_REQUEST['ticket_id']) ? 0 : sanitize_text_field($_REQUEST['ticket_id']);
        //Get the first instance of the start and end times
        $start_time = !empty($_REQUEST['start_time'][0]) ? sanitize_text_field($_REQUEST['start_time'][0]) : '8:00 AM';
        $_REQUEST['event_start_time'] = $start_time;
        $end_time = !empty($_REQUEST['end_time'][0]) ? sanitize_text_field($_REQUEST['end_time'][0]) : '5:00 PM';
        $_REQUEST['event_end_time'] = $end_time;
        // Add Timezone
        $timezone_string = isset($_REQUEST['timezone_string']) ? sanitize_text_field($_REQUEST['timezone_string']) : '';
        //Early discounts
        $early_disc = !empty($_REQUEST['early_disc']) ? sanitize_text_field($_REQUEST['early_disc']) : '';
        $early_disc_date = !empty($_REQUEST['early_disc_date']) ? sanitize_text_field($_REQUEST['early_disc_date']) : '';
        $early_disc_percentage = !empty($_REQUEST['early_disc_percentage']) ? sanitize_text_field($_REQUEST['early_disc_percentage']) : '';
        //Alternate email address field
        $alt_email = !empty($_REQUEST['alt_email']) ? sanitize_text_field($_REQUEST['alt_email']) : '';
        //Send a custom emal
        $send_mail = !empty($_REQUEST['send_mail']) ? sanitize_text_field($_REQUEST['send_mail']) : 'N';
        //Custom email content
        $conf_mail = !empty($_REQUEST['conf_mail']) ? esc_html($_REQUEST['conf_mail']) : '';
        //Use a premade custom email
        $email_id = isset($_REQUEST['email_name']) ? (int) $_REQUEST['email_name'] : '0';
        //Venue Information
        $venue_title = isset($_REQUEST['venue_title']) ? sanitize_text_field($_REQUEST['venue_title']) : '';
        $venue_url = isset($_REQUEST['venue_url']) ? sanitize_text_field($_REQUEST['venue_url']) : '';
        $venue_phone = isset($_REQUEST['venue_phone']) ? sanitize_text_field($_REQUEST['venue_phone']) : '';
        $venue_image = isset($_REQUEST['venue_image']) ? sanitize_text_field($_REQUEST['venue_image']) : '';
        //Virtual location
        $virtual_url = !empty($_REQUEST['virtual_url']) ? sanitize_text_field($_REQUEST['virtual_url']) : '';
        $virtual_phone = !empty($_REQUEST['virtual_phone']) ? sanitize_text_field($_REQUEST['virtual_phone']) : '';
        //Address/venue information
        $address = isset($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '';
        $address2 = isset($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '';
        $city = isset($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '';
        $state = isset($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : '';
        $zip = isset($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '';
        $country = isset($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : '';
        $phone = isset($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '';
        $event_location = '';
        if (!empty($address)) {
            $event_location .= $address . ' ';
        }
        if (!empty($address2)) {
            $event_location .= '<br />' . $address2;
        }
        if (!empty($city)) {
            $event_location .= '<br />' . $city;
        }
        if (!empty($state)) {
            $event_location .= ', ' . $state;
        }
        if (!empty($zip)) {
            $event_location .= ', ' . $state;
        }
        if (!empty($country)) {
            $event_location .= '<br />' . $country;
        }
        if ($is_espresso_event_manager == true && $use_fem == true && $event_manager_approval == true) {
            $event_status = 'P';
        }
        //Get the registration start and end times
        $_REQUEST['registration_startT'] = !empty($_REQUEST['registration_startT']) ? sanitize_text_field($_REQUEST['registration_startT']) : '12:01 AM';
        $_REQUEST['registration_endT'] = !empty($_REQUEST['registration_endT']) ? sanitize_text_field($_REQUEST['registration_endT']) : '11:59 PM';
        // Add registration times
        $registration_startT = event_date_display($_REQUEST['registration_startT'], 'H:i');
        $registration_endT = event_date_display($_REQUEST['registration_endT'], 'H:i');
        $_REQUEST['registration_start'] = !empty($_REQUEST['registration_start']) ? sanitize_text_field($_REQUEST['registration_start']) : date('Y-m-d');
        $_REQUEST['registration_end'] = !empty($_REQUEST['registration_end']) ? sanitize_text_field($_REQUEST['registration_end']) : date('Y-m-d', time() + 60 * 60 * 24 * 29);
        $registration_start = array_key_exists('registration_start', $recurrence_arr) ? $recurrence_arr['registration_start'] : $_REQUEST['registration_start'];
        $registration_end = array_key_exists('registration_end', $recurrence_arr) ? $recurrence_arr['registration_end'] : $_REQUEST['registration_end'];
        //Check which start/end date to use.  Will be determined by recurring events addon, if installed.
        if (array_key_exists('recurrence_start_date', $recurrence_arr)) {
            //Recurring event
            $start_date = $recurrence_arr['recurrence_start_date'];
        } elseif (!empty($_REQUEST['start_date']) && !empty($_REQUEST['recurrence_start_date'])) {
            //If they leave the Event Start Date empty, the First Event Date in the recurrence module is selected
            $start_date = sanitize_text_field($_REQUEST['recurrence_start_date']);
        } elseif (isset($_POST['recurrence']) && $_POST['recurrence'] == 'Y' && !empty($_REQUEST['start_date'])) {
            $start_date = sanitize_text_field($_REQUEST['recurrence_manual_dates'][0]);
        } else {
            $start_date = !empty($_REQUEST['start_date']) ? sanitize_text_field($_REQUEST['start_date']) : date('Y-m-d', time() + 60 * 60 * 24 * 30);
        }
        $_REQUEST['start_date'] = $start_date;
        if (array_key_exists('recurrence_event_end_date', $recurrence_arr)) {
            //If this is a Recurring event
            $end_date = $recurrence_arr['recurrence_event_end_date'];
        } elseif (!empty($_REQUEST['end_date']) && !empty($_REQUEST['recurrence_event_end_date'])) {
            //If they leave the Event Start Date empty, the First Event Date in the recurrence module is selected
            $end_date = $_REQUEST['recurrence_event_end_date'];
        } elseif (isset($_POST['recurrence']) && $_POST['recurrence'] == 'Y' && !empty($_REQUEST['end_date'])) {
            $end_date = $_REQUEST['recurrence_manual_end_dates'][count($_REQUEST['recurrence_manual_end_dates']) - 1];
        } else {
            $end_date = !empty($_REQUEST['end_date']) ? $_REQUEST['end_date'] : date('Y-m-d', time() + 60 * 60 * 24 * 30);
        }
        $_REQUEST['end_date'] = $end_date;
        if (array_key_exists('visible_on', $recurrence_arr)) {
            //If this is a Recurring event
            $visible_on = $recurrence_arr['visible_on'];
        } elseif (isset($_REQUEST['visible_on']) && $_REQUEST['visible_on'] != '') {
            $visible_on = $_REQUEST['visible_on'];
        } elseif (isset($_REQUEST['visible_on']) && $_REQUEST['visible_on'] == '' && count($recurrence_dates) > 0) {
            $visible_on = $recurrence_dates[$start_date]['visible_on'];
        } else {
            $visible_on = date("Y-m-d");
        }
        //Questions/question groups
        $question_groups = empty($_REQUEST['question_groups']) ? serialize(array(1)) : serialize($_REQUEST['question_groups']);
        $add_attendee_question_groups = empty($_REQUEST['add_attendee_question_groups']) ? '' : $_REQUEST['add_attendee_question_groups'];
        //Process event meta data
        $event_meta['venue_id'] = isset($_REQUEST['venue_id']) ? $_REQUEST['venue_id'][0] : 0;
        $event_meta['additional_attendee_reg_info'] = !empty($_REQUEST['additional_attendee_reg_info']) ? sanitize_text_field($_REQUEST['additional_attendee_reg_info']) : '2';
        $event_meta['add_attendee_question_groups'] = $add_attendee_question_groups;
        $event_meta['date_submitted'] = date("Y-m-d H:i:s");
        $event_meta['default_payment_status'] = !empty($_REQUEST['default_payment_status']) ? sanitize_text_field($_REQUEST['default_payment_status']) : '';
        //Process thumbnail uploads
        $event_thumbnail_url = '';
        if (isset($_REQUEST['upload_image']) && !empty($_REQUEST['upload_image'])) {
            $event_meta['event_thumbnail_url'] = sanitize_text_field($_REQUEST['upload_image']);
            $event_thumbnail_url = sanitize_text_field($event_meta['event_thumbnail_url']);
        }
        if (isset($_REQUEST['emeta']) && !empty($_REQUEST['emeta'])) {
            foreach ($_REQUEST['emeta'] as $k => $v) {
                $event_meta[$v] = strlen(trim($_REQUEST['emetad'][$k])) > 0 ? sanitize_text_field($_REQUEST['emetad'][$k]) : '';
            }
        }
        $event_meta = serialize($event_meta);
        //echo strlen(trim($_REQUEST['emetad'][$k]));
        //print_r($_REQUEST['emeta'] );
        ############ Added by wp-developers ######################
        $require_pre_approval = 0;
        if (isset($_REQUEST['require_pre_approval'])) {
            $require_pre_approval = sanitize_text_field($_REQUEST['require_pre_approval']);
        }
        ################# END #################
        //When adding colums to the following arrays, be sure both arrays have equal values.
        $sql = array('event_code' => $event_code, 'event_name' => $event_name, 'event_desc' => $event_desc, 'display_desc' => $display_desc, 'display_reg_form' => $display_reg_form, 'event_identifier' => $event_identifier, 'address' => $address, 'address2' => $address2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country, 'phone' => $phone, 'virtual_url' => $virtual_url, 'virtual_phone' => $virtual_phone, 'venue_title' => $venue_title, 'venue_url' => $venue_url, 'venue_phone' => $venue_phone, 'venue_image' => $venue_image, 'registration_start' => $registration_start, 'registration_end' => $registration_end, 'start_date' => $start_date, 'end_date' => $end_date, 'allow_multiple' => $allow_multiple, 'send_mail' => $send_mail, 'is_active' => $is_active, 'event_status' => $event_status, 'conf_mail' => $conf_mail, 'use_coupon_code' => $use_coupon_code, 'member_only' => $member_only, 'externalURL' => $externalURL, 'early_disc' => $early_disc, 'early_disc_date' => $early_disc_date, 'early_disc_percentage' => $early_disc_percentage, 'alt_email' => $alt_email, 'question_groups' => $question_groups, 'registration_startT' => $registration_startT, 'registration_endT' => $registration_endT, 'reg_limit' => (int) $reg_limit, 'additional_limit' => (int) $additional_limit, 'recurrence_id' => $recurrence_id, 'email_id' => (int) $email_id, 'wp_user' => (int) $current_user->ID, 'event_meta' => $event_meta, 'require_pre_approval' => $require_pre_approval, 'timezone_string' => $timezone_string, 'submitted' => date('Y-m-d H:i:s', time()), 'ticket_id' => (int) $ticket_id);
        $sql_data = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '%d');
        /* echo 'Debug: <br />';
        	  print_r($sql);
        	  echo '<br />';
        	  print 'Number of vars: ' . count ($sql);
        	  echo '<br />';
        	  print 'Number of cols: ' . count($sql_data); */
        //Add groupon reference if installed
        if (function_exists('event_espresso_add_event_to_db_groupon')) {
            $sql = event_espresso_add_event_to_db_groupon($sql, sanitize_text_field($_REQUEST['use_groupon_code']));
            //print count ($sql);
            $sql_data = array_merge((array) $sql_data, (array) '%s');
            //print count($sql_data);
            if (!$wpdb->insert(EVENTS_DETAIL_TABLE, $sql, $sql_data)) {
                $error = true;
            }
        } else {
            if (!$wpdb->insert(EVENTS_DETAIL_TABLE, $sql, $sql_data)) {
                $error = true;
            }
        }
        $last_event_id = $wpdb->insert_id;
        ############# MailChimp Integration ##############
        if (defined('EVENTS_MAILCHIMP_ATTENDEE_REL_TABLE') && $espresso_premium == true) {
            MailChimpController::add_event_list_rel($last_event_id);
        }
        if (function_exists('espresso_fb_createevent') == 'true' && $espresso_premium == true) {
            espresso_fb_createevent($last_event_id);
        }
        //Added for seating chart addon
        if (isset($_REQUEST['seating_chart_id'])) {
            $cls_seating_chart = new seating_chart();
            $cls_seating_chart->associate_event_seating_chart($_REQUEST['seating_chart_id'], $last_event_id);
        }
        //Add event to a category
        $string_cat = '';
        if (isset($_REQUEST['event_category']) && $_REQUEST['event_category'] != '') {
            foreach ($_REQUEST['event_category'] as $k => $v) {
                if ($v != '') {
                    $sql_cat = "INSERT INTO " . EVENTS_CATEGORY_REL_TABLE . " (event_id, cat_id) VALUES ('" . $last_event_id . "', '" . (int) $v . "')";
                    if (!$wpdb->query($wpdb->prepare($sql_cat, NULL))) {
                        $error = true;
                    }
                    //We get the category id's of the event and put them in events_detail_table.category_id as a well-formatted string (id,n id)
                    $string_cat .= $v . ",";
                }
            }
            if ($string_cat != "" && $string_cat != ",") {
                $cleaned_string_cat = substr($string_cat, 0, -1);
                $tmp = explode(",", $cleaned_string_cat);
                sort($tmp);
                $cleaned_string_cat = implode(",", $tmp);
                trim($cleaned_string_cat);
                $sql_insert_event_detail_category_id = "UPDATE " . EVENTS_DETAIL_TABLE . " SET category_id = '" . $cleaned_string_cat . "' WHERE id='" . $last_event_id . "'";
                $wpdb->query($wpdb->prepare($sql_insert_event_detail_category_id, NULL));
            }
        }
        //Process staff assignments
        if (isset($_REQUEST['event_person']) && !empty($_REQUEST['event_person'])) {
            foreach ($_REQUEST['event_person'] as $k => $v) {
                if ($v != '') {
                    $sql_ppl = "INSERT INTO " . EVENTS_PERSONNEL_REL_TABLE . " (event_id, person_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    //echo "$sql_ppl <br>";
                    $wpdb->query($wpdb->prepare($sql_ppl, NULL));
                }
            }
        }
        //Process dynamic adding of venues
        //If we are adding an venue from within the event editor.
        //Then we need to add it to the venue database and add the id to the event.
        if (isset($_REQUEST['add_new_venue_dynamic']) && $_REQUEST['add_new_venue_dynamic'] == 'true' && $_REQUEST['venue_id'][0] == '0') {
            require_once EVENT_ESPRESSO_INCLUDES_DIR . 'admin-files/venue-management/add_venue_to_db.php';
            $_REQUEST['venue_id'][0] = add_venue_to_db();
        }
        //Process venues
        if (isset($_REQUEST['venue_id']) && !empty($_REQUEST['venue_id'])) {
            foreach ($_REQUEST['venue_id'] as $k => $v) {
                if ($v != '' && $v != 0) {
                    $sql_venues = "INSERT INTO " . EVENTS_VENUE_REL_TABLE . " (event_id, venue_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    $wpdb->query($wpdb->prepare($sql_venues, NULL));
                }
            }
        }
        //Process the discounts
        if (isset($_REQUEST['event_discount']) && !empty($_REQUEST['event_discount']) && $_REQUEST['use_coupon_code'] == 'Y') {
            //if they have specified to use specific coupon codes, THEN we add entries ot teh discount rel table
            //otherwise we shouldn't
            foreach ($_REQUEST['event_discount'] as $k => $v) {
                if ($v != '') {
                    $sql_cat = "INSERT INTO " . EVENTS_DISCOUNT_REL_TABLE . " (event_id, discount_id) VALUES ('" . $last_event_id . "', '" . $v . "')";
                    if (!$wpdb->query($wpdb->prepare($sql_cat, NULL))) {
                        $error = true;
                    }
                }
            }
        }
        //Process event times
        if (isset($_REQUEST['start_time']) && !empty($_REQUEST['start_time'])) {
            foreach ($_REQUEST['start_time'] as $k => $v) {
                $time_qty = isset($_REQUEST['time_qty']) && strlen(trim($_REQUEST['time_qty'][$k])) > 0 ? "'" . $_REQUEST['time_qty'][$k] . "'" : '0';
                $v = !empty($v) ? $v : $start_time;
                $_REQUEST['end_time'][$k] = !empty($_REQUEST['end_time'][$k]) ? $_REQUEST['end_time'][$k] : $end_time;
                $sql3 = "INSERT INTO " . EVENTS_START_END_TABLE . " (event_id, start_time, end_time, reg_limit) VALUES ('" . $last_event_id . "', '" . event_date_display($v, 'H:i') . "', '" . event_date_display($_REQUEST['end_time'][$k], 'H:i') . "', " . $time_qty . ")";
                if (!$wpdb->query($wpdb->prepare($sql3, NULL))) {
                    $error = true;
                }
            }
        }
        //Process event costs
        if (isset($_REQUEST['event_cost']) && !empty($_REQUEST['event_cost'])) {
            foreach ($_REQUEST['event_cost'] as $k => $v) {
                if ($v != '') {
                    $v = (double) preg_replace('/[^0-9\\.]/ui', '', $v);
                    //Removes non-integer characters
                    $price_type = !empty($_REQUEST['price_type'][$k]) ? sanitize_text_field(stripslashes_deep($_REQUEST['price_type'][$k])) : __('General Admission', 'event_espresso');
                    $member_price_type = !empty($_REQUEST['member_price_type'][$k]) ? sanitize_text_field(stripslashes_deep($_REQUEST['member_price_type'][$k])) : __('Members Admission', 'event_espresso');
                    $member_price = !empty($_REQUEST['member_price'][$k]) ? $_REQUEST['member_price'][$k] : $v;
                    //$sql_price = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, surcharge_type, price_type, member_price, member_price_type) VALUES ('" . $last_event_id . "', '" . $v . "', '" . $_REQUEST['surcharge'][$k] . "', '" . $_REQUEST['surcharge_type'][$k] . "', '" . $price_type . "', '" . $member_price . "', '" . $member_price_type . "')";
                    //echo "$sql3 <br>";
                    $sql_price = array('event_id' => $last_event_id, 'event_cost' => $v, 'surcharge' => $_REQUEST['surcharge'][$k], 'surcharge_type' => $_REQUEST['surcharge_type'][$k], 'price_type' => $price_type, 'member_price' => $member_price, 'member_price_type' => $member_price_type);
                    $sql_price_data = array('%d', '%s', '%s', '%s', '%s', '%s', '%s');
                    if (!$wpdb->insert(EVENTS_PRICES_TABLE, $sql_price, $sql_price_data)) {
                        $error = true;
                    }
                }
            }
        } elseif (isset($_REQUEST['event_cost']) && $_REQUEST['event_cost'][0] == 0) {
            $sql_price = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, price_type, member_price, member_price_type) VALUES ('" . $last_event_id . "', '0.00', '0.00', '" . __('Free', 'event_espresso') . "', '0.00', '" . __('Free', 'event_espresso') . "')";
            if (!$wpdb->query($wpdb->prepare($sql_price, NULL))) {
                $error = true;
            }
        }
        //Process blog or custom post
        if (isset($_REQUEST['create_post']) && $_REQUEST['create_post'] == 'Y') {
            $post_type = !empty($_REQUEST['espresso_post_type']) ? $_REQUEST['espresso_post_type'] : 'post';
            if ($post_type == 'post') {
                if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php") || file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php")) {
                    // Load message from template into message post variable
                    ob_start();
                    if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php")) {
                        require_once EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php";
                    } else {
                        require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php";
                    }
                    $post_content = ob_get_contents();
                    ob_end_clean();
                } else {
                    _e('There was error finding a post template. Please verify your post templates are available.', 'event_espresso');
                }
            } elseif ($post_type == 'espresso_event') {
                ob_start();
                echo $event_desc;
                $post_content = ob_get_contents();
                ob_end_clean();
                // if there's a cart link shortcode in the post, replace the shortcode with one that includes the event_id
                if (preg_match("/ESPRESSO_CART_LINK/", $post_content)) {
                    $post_content = preg_replace('/ESPRESSO_CART_LINK/', 'ESPRESSO_CART_LINK event_id=' . $event_id, $post_content);
                }
            }
            $my_post = array();
            $my_post['post_title'] = sanitize_text_field($_REQUEST['event']);
            $my_post['post_content'] = $post_content;
            $my_post['post_status'] = 'publish';
            $my_post['post_author'] = !empty($_REQUEST['user']) ? $_REQUEST['user'] : '';
            $my_post['post_category'] = !empty($_REQUEST['post_category']) ? $_REQUEST['post_category'] : '';
            $my_post['tags_input'] = !empty($_REQUEST['post_tags']) ? $_REQUEST['post_tags'] : '';
            $my_post['post_type'] = !empty($post_type) ? $post_type : 'post';
            //print_r($my_post);
            // Insert the post into the database
            $post_id = wp_insert_post($my_post);
            // Store the POST ID so it can be displayed on the edit page
            $sql = array('post_id' => $post_id, 'post_type' => $post_type);
            add_post_meta($post_id, 'event_id', $last_event_id);
            add_post_meta($post_id, 'event_meta', $event_meta);
            add_post_meta($post_id, 'event_identifier', $event_identifier);
            add_post_meta($post_id, 'event_start_date', $start_date);
            add_post_meta($post_id, 'event_end_date', $end_date);
            add_post_meta($post_id, 'event_location', $event_location);
            add_post_meta($post_id, 'event_thumbnail_url', $event_thumbnail_url);
            add_post_meta($post_id, 'virtual_url', $virtual_url);
            add_post_meta($post_id, 'virtual_phone', $virtual_phone);
            add_post_meta($post_id, 'event_address', $address);
            add_post_meta($post_id, 'event_address2', $address2);
            add_post_meta($post_id, 'event_city', $city);
            add_post_meta($post_id, 'event_state', $state);
            add_post_meta($post_id, 'event_country', $country);
            add_post_meta($post_id, 'event_phone', $phone);
            add_post_meta($post_id, 'venue_title', $venue_title);
            add_post_meta($post_id, 'venue_url', $venue_url);
            add_post_meta($post_id, 'venue_phone', $venue_phone);
            add_post_meta($post_id, 'venue_image', $venue_image);
            add_post_meta($post_id, 'event_externalURL', $externalURL);
            add_post_meta($post_id, 'event_reg_limit', $reg_limit);
            add_post_meta($post_id, 'event_start_time', time_to_24hr($start_time));
            add_post_meta($post_id, 'event_end_time', time_to_24hr($end_time));
            add_post_meta($post_id, 'event_registration_start', $registration_start);
            add_post_meta($post_id, 'event_registration_end', $registration_end);
            add_post_meta($post_id, 'event_registration_startT', $registration_startT);
            add_post_meta($post_id, 'event_registration_endT', $registration_endT);
            //add_post_meta( $post_id, 'timezone_string', $_REQUEST['timezone_string'] );
            $sql_data = array('%d', '%s');
            $update_id = array('id' => $last_event_id);
            $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
        }
        if (empty($error)) {
            ?>
			<div id="message" class="updated fade"><p><strong><?php 
            _e('The event', 'event_espresso');
            ?>
			<a href="<?php 
            echo espresso_reg_url($last_event_id);
            ?>
" target="_blank">
				<?php 
            echo htmlentities(stripslashes(sanitize_text_field($_REQUEST['event'])), ENT_QUOTES, 'UTF-8');
            ?>
				
			</a>

			<?php 
            _e('has been added for ', 'event_espresso');
            echo date("m/d/Y", strtotime($start_date));
            ?>
 <a href="<?php 
            echo admin_url();
            ?>
admin.php?page=events&action=edit&event_id=<?php 
            echo $last_event_id;
            ?>
"><?php 
            _e('Edit this event?', 'event_espresso');
            ?>
</a></strong></p></div>
		<?php 
        } else {
            ?>
			<div id="message" class="error"><p><strong><?php 
            _e('There was an error in your submission. The event was not saved! Please try again.', 'event_espresso');
            ?>
 <?php 
            print $wpdb->print_error();
            ?>
</strong></p></div>
			<?php 
        }
    }
    //With the recursion of this function, additional recurring events will be added
    if (isset($recurrence_dates) && count($recurrence_dates) > 0) {
        foreach ($recurrence_dates as $k => $v) {
            add_event_to_db(array('recurrence_id' => $recurrence_id, 'recurrence_start_date' => $v['start_date'], 'recurrence_event_end_date' => $v['event_end_date'], 'registration_start' => $v['registration_start'], 'registration_end' => $v['registration_end']));
        }
    }
    $_REQUEST['event_id'] = !empty($last_event_id) ? $last_event_id : '';
    do_action('action_hook_espresso_insert_event_success', $_REQUEST);
    //If not using the FEM addon, then we return the event id
    if (!$use_fem === TRUE) {
        return @$last_event_id;
    }
}
Beispiel #10
0
function edit_attendee_record()
{
    do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
    global $wpdb, $org_options;
    $notifications['success'] = array();
    $notifications['error'] = array();
    $failed_nonce_msg = '
<div id="message" class="error">
	<p>
		<strong>' . __('An Error Occurred. The request failed to pass a security check.', 'event_espresso') . '</strong><br/>
		<span style="font-size:.9em;">' . __('Please press the back button on your browser to return to the previous page.', 'event_espresso') . '</span>
	</p>
</div>';
    $attendee_num = 1;
    $is_additional_attendee = FALSE;
    // **************************************************************************
    // **************************** EDIT ATTENDEE  ****************************
    // **************************************************************************
    if ($_REQUEST['form_action'] == 'edit_attendee') {
        $id = isset($_REQUEST['id']) ? absint($_REQUEST['id']) : '';
        $registration_id = isset($_REQUEST['registration_id']) ? sanitize_text_field($_REQUEST['registration_id']) : '';
        $multi_reg = FALSE;
        // check for multi reg, additional attendees, and verify reg id for primary attendee
        $SQL = "SELECT * FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " WHERE registration_id = %s";
        $check = $wpdb->get_row($wpdb->prepare($SQL, $registration_id));
        if ($check) {
            $registration_id = $check->primary_registration_id;
            $SQL = "SELECT distinct primary_registration_id, registration_id ";
            $SQL .= "FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " ";
            $SQL .= "WHERE primary_registration_id = %s";
            $registration_ids = $wpdb->get_results($wpdb->prepare($SQL, $registration_id), ARRAY_A);
            $multi_reg = TRUE;
        }
        // find the primary attendee id so we know which form to present since the additional attendees will have a different form
        $SQL = "SELECT id FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id =%s AND is_primary = 1 ";
        if ($r = $wpdb->get_row($wpdb->prepare($SQL, $registration_id))) {
            $primary_attendee = !empty($r->id) ? $r->id : $id;
            $is_additional_attendee = $primary_attendee != $id ? TRUE : FALSE;
        } else {
            $primary_attendee = FALSE;
        }
        // **************************************************************************
        // **************************  UPDATE PAYMENT  **************************
        // **************************************************************************
        if (!empty($_REQUEST['attendee_payment']) && $_REQUEST['attendee_payment'] == 'update_price') {
            if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'edit_attendee_' . $registration_id . '_update_price_nonce')) {
                wp_die($failed_nonce_msg);
            }
            $upd_price = (double) number_format(abs(sanitize_text_field($_REQUEST['final_price'])), 2, '.', '');
            $upd_qty = absint($_REQUEST['quantity']);
            $set_cols_and_values = array('final_price' => $upd_price, 'quantity' => $upd_qty);
            $set_format = array('%f', '%d');
            $where_cols_and_values = array('id' => $id);
            $where_format = array('%d');
            // run the update
            $upd_success = $wpdb->update(EVENTS_ATTENDEE_TABLE, $set_cols_and_values, $where_cols_and_values, $set_format, $where_format);
            // if there was an actual error
            if ($upd_success === FALSE) {
                $notifications['error'][] = __('An error occured. Attendee ticket price details could not be updated.', 'event_espresso');
            } else {
                // now we need to gather all the ticket prices for all attendees for the entire registraion and calculate a new total cost
                $upd_total = 0;
                $SQL = "SELECT payment_status, amount_pd, final_price, quantity, is_primary FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id = %s";
                if ($attendee_tickets = $wpdb->get_results($wpdb->prepare($SQL, $registration_id))) {
                    // loop thru tickets
                    foreach ($attendee_tickets as $attendee_ticket) {
                        // calculate total for each attendee and add to total cost
                        $upd_total += $attendee_ticket->final_price * $attendee_ticket->quantity;
                        // grab amount paid by primary attendee
                        if ($attendee_ticket->is_primary) {
                            $amount_pd = (double) $attendee_ticket->amount_pd;
                            $payment_status = $attendee_ticket->payment_status;
                        }
                    }
                }
                // format new total_cost
                $upd_total = (double) number_format($upd_total, 2, '.', '');
                // compare new total_cost with amount_pd
                if ($upd_total == $amount_pd) {
                    $upd_payment_status = __('Completed', 'event_espresso');
                } elseif ($upd_total > $amount_pd) {
                    $upd_payment_status = __('Pending', 'event_espresso');
                } elseif ($upd_total < $amount_pd) {
                    $upd_payment_status = __('Refund', 'event_espresso');
                }
                //				echo '<h4>$amount_pd : ' . $amount_pd . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                //				echo '<h4>$payment_status : ' . $payment_status . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                //				echo '<h4>$upd_total : ' . $upd_total . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                //				echo '<h4>$upd_payment_status : ' . $upd_payment_status . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                // compare old payment status with new payment status and update if things have changed
                if ($upd_payment_status != $payment_status) {
                    // update payment status for ALL attendees for the entire registration
                    $set_cols_and_values = array('payment_status' => $upd_payment_status);
                    $set_format = array('%s');
                    $where_cols_and_values = array('registration_id' => $registration_id);
                    $where_format = array('%s');
                    // run the update
                    $upd_success = $wpdb->update(EVENTS_ATTENDEE_TABLE, $set_cols_and_values, $where_cols_and_values, $set_format, $where_format);
                    // if there was an actual error
                    if ($upd_success === FALSE) {
                        $notifications['error'][] = __('An error occured while attempting to update the payment status for attendeefrom this registration.', 'event_espresso');
                    }
                }
                // now update the primary registrant's total cost field'
                $set_cols_and_values = array('total_cost' => $upd_total);
                $set_format = array('%f');
                $where_cols_and_values = array('id' => $id, 'is_primary' => TRUE);
                $where_format = array('%d', '%d');
                // run the update
                $upd_success = $wpdb->update(EVENTS_ATTENDEE_TABLE, $set_cols_and_values, $where_cols_and_values, $set_format, $where_format);
                // if there was an actual error
                if ($upd_success === FALSE) {
                    $notifications['error'][] = __('An error occured. The primary attendee ticket total could not be updated.', 'event_espresso');
                }
                // let's base our success on the lack of errors
                $notifications['success'][] = empty($notifications['error']) ? __('All attendee ticket price details have been successfully updated.', 'event_espresso') : __('Some attendee ticket price details were successfully updated, but the following error(s) may have prevented others from being updated:', 'event_espresso');
            }
        }
        // **************************************************************************
        // **************************  DELETE ATTENDEE  **************************
        // **************************************************************************
        if (!empty($_REQUEST['attendee_action']) && $_REQUEST['attendee_action'] == 'delete_attendee') {
            if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'edit_attendee_' . $registration_id . '_delete_attendee_nonce')) {
                wp_die($failed_nonce_msg);
            }
            $SQL = "DELETE FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id =%d";
            $del_results = $wpdb->query($wpdb->prepare($SQL, $id));
            if ($del_results === FALSE) {
                $notifications['error'][] = __('An error occured. The attendee could not be deleted.', 'event_espresso');
            } elseif ($del_results === 0) {
                $notifications['error'][] = __('The attendee record in the database could not be found and was therefore not deleted.', 'event_espresso');
            } else {
                if (defined('ESPRESSO_SEATING_CHART')) {
                    $SQL = "DELETE FROM " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " where attendee_id = %d";
                    if ($wpdb->query($wpdb->prepare($SQL, $id)) === FALSE) {
                        $notifications['error'][] = __('An error occured. The attendee seating chart data could not be deleted.', 'event_espresso');
                    }
                }
                // get id's for all attendees from this registration
                $SQL = "SELECT id from " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id = %s";
                $attendees = $wpdb->query($wpdb->prepare($SQL, $registration_id));
                if ($attendees === FALSE) {
                    $notifications['error'][] = __('An error occured while attempting to retrieve additional attendee data from the database.', 'event_espresso');
                } else {
                    // update quantities for attendees
                    $SQL = " UPDATE " . EVENTS_ATTENDEE_TABLE . " SET quantity = IF(quantity IS NULL ,NULL,IF(quantity > 0,IF(quantity-1>0,quantity-1,1),0)) ";
                    $SQL .= "WHERE registration_id =%s";
                    if ($wpdb->update($SQL, $registration_id) === FALSE) {
                        $notifications['error'][] = __('An error occured while attempting to update additional attendee ticket quantities.', 'event_espresso');
                    }
                    event_espresso_cleanup_multi_event_registration_id_group_data();
                }
                // let's base our success on the lack of errors
                $notifications['success'][] = empty($notifications['error']) ? __('All attendee details have been successfully deleted.', 'event_espresso') : __('One or more errors may have prevented some attendee details from being successfully deleted.', 'event_espresso');
            }
            // **************************************************************************
            // **************************  UPDATE ATTENDEE  **************************
            // **************************************************************************
        } else {
            if (!empty($_REQUEST['attendee_action']) && $_REQUEST['attendee_action'] == 'update_attendee') {
                if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'edit_attendee_' . $registration_id . '_update_attendee_nonce')) {
                    wp_die($failed_nonce_msg);
                }
                $event_id = isset($_POST['event_id']) ? $_POST['event_id'] : '';
                $txn_type = isset($_POST['txn_type']) ? $_POST['txn_type'] : '';
                $set_cols_and_values = array('fname' => isset($_POST['fname']) ? $_POST['fname'] : '', 'lname' => isset($_POST['lname']) ? $_POST['lname'] : '', 'address' => isset($_POST['address']) ? $_POST['address'] : '', 'address2' => isset($_POST['address2']) ? $_POST['address2'] : '', 'city' => isset($_POST['city']) ? $_POST['city'] : '', 'state' => isset($_POST['state']) ? $_POST['state'] : '', 'zip' => isset($_POST['zip']) ? $_POST['zip'] : '', 'phone' => isset($_POST['phone']) ? $_POST['phone'] : '', 'email' => isset($_POST['email']) ? $_POST['email'] : '');
                $set_format = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');
                // Update the time ?
                if (isset($_POST['start_time_id'])) {
                    $SQL = "SELECT ese.start_time, ese.end_time FROM " . EVENTS_START_END_TABLE . " ese WHERE ese.id=%d";
                    if ($times = $wpdb->get_results($wpdb->prepare($SQL, absint($_POST['start_time_id'])))) {
                        foreach ($times as $time) {
                            $start_time = $time->start_time;
                            $end_time = $time->end_time;
                        }
                        $set_cols_and_values['event_time'] = $start_time;
                        $set_cols_and_values['end_time'] = $end_time;
                        array_push($set_format, '%s', '%s');
                    }
                }
                //printr( $_POST, '$_POST  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
                $where_cols_and_values = array('id' => $id);
                $where_format = array('%d');
                // run the update
                $upd_success = $wpdb->update(EVENTS_ATTENDEE_TABLE, $set_cols_and_values, $where_cols_and_values, $set_format, $where_format);
                // if there was an actual error
                if ($upd_success === FALSE) {
                    $notifications['error'][] = __('An error occured. Attendee details could not be updated.', 'event_espresso');
                }
                // Added for seating chart addon
                $booking_id = 0;
                if (defined('ESPRESSO_SEATING_CHART')) {
                    if (seating_chart::check_event_has_seating_chart($event_id) !== false) {
                        if (isset($_POST['seat_id'])) {
                            $booking_id = seating_chart::parse_booking_info($_POST['seat_id']);
                            if ($booking_id > 0) {
                                seating_chart::confirm_a_seat($booking_id, $id);
                            }
                        }
                    }
                }
                // Insert Additional Questions From Post Here
                $reg_id = $id;
                $SQL = "SELECT question_groups, event_meta FROM " . EVENTS_DETAIL_TABLE . " WHERE id = %d";
                $questions = $wpdb->get_row($wpdb->prepare($SQL, $event_id));
                $question_groups = unserialize($questions->question_groups);
                $event_meta = unserialize($questions->event_meta);
                if ($is_additional_attendee && isset($event_meta['add_attendee_question_groups']) && $event_meta['add_attendee_question_groups'] != NULL) {
                    $question_groups = $event_meta['add_attendee_question_groups'];
                }
                $questions_in = '';
                foreach ($question_groups as $g_id) {
                    $questions_in .= $g_id . ',';
                }
                $questions_in = substr($questions_in, 0, -1);
                $group_name = '';
                $counter = 0;
                //pull the list of questions that are relevant to this event
                $SQL = "SELECT q.*, q.id AS q_id, at.id AS a_id, at.*, qg.group_name, qg.show_group_description, qg.show_group_name ";
                $SQL .= "FROM " . EVENTS_QUESTION_TABLE . " q ";
                $SQL .= "LEFT JOIN " . EVENTS_ANSWER_TABLE . " at on q.id = at.question_id ";
                $SQL .= "JOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id ";
                $SQL .= "JOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id ";
                $SQL .= "WHERE qgr.group_id in ( {$questions_in} ) ";
                $SQL .= "AND (at.attendee_id IS NULL OR at.attendee_id = '%d') ";
                $SQL .= "ORDER BY qg.id, q.id ASC";
                $questions = $wpdb->get_results($wpdb->prepare($SQL, $id));
                //			printr( $questions, '$questions  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
                $SQL = "SELECT id, question_id, answer FROM " . EVENTS_ANSWER_TABLE . " at WHERE at.attendee_id = %d";
                $answers = $wpdb->get_results($wpdb->prepare($SQL, $id), OBJECT_K);
                foreach ($answers as $answer) {
                    $answer_a[$answer->id] = $answer->question_id;
                }
                if ($questions) {
                    foreach ($questions as $question) {
                        //printr( $question, '$question  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
                        switch ($question->question_type) {
                            case "TEXT":
                            case "TEXTAREA":
                            case "SINGLE":
                            case "DROPDOWN":
                                if ($question->system_name != '') {
                                    $post_val = isset($_POST[$question->system_name]) ? $_POST[$question->system_name] : '';
                                } else {
                                    $post_val = isset($_POST[$question->question_type . '_' . $question->a_id]) ? $_POST[$question->question_type . '_' . $question->a_id] : '';
                                }
                                $post_val = sanitize_text_field(stripslashes($post_val));
                                break;
                            case "MULTIPLE":
                                $post_val = '';
                                for ($i = 0; $i < count($_POST[$question->question_type . '_' . $question->a_id]); $i++) {
                                    $post_val .= trim($_POST[$question->question_type . '_' . $question->a_id][$i]) . ",";
                                }
                                $post_val = sanitize_text_field(substr(stripslashes($post_val), 0, -1));
                                break;
                        }
                        //					echo '<h4>$post_val : ' . $post_val . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                        //					echo '<h4>$question->id : ' . $question->q_id . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                        //					printr( $answer_a, '$answer_a  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
                        if (in_array($question->q_id, $answer_a)) {
                            // existing answer
                            $set_cols_and_values = array('answer' => html_entity_decode(trim($post_val), ENT_QUOTES, 'UTF-8'));
                            //echo "<pre>".print_r($set_cols_and_values,true)."</pre>";
                            $set_format = array('%s');
                            $where_cols_and_values = array('attendee_id' => $id, 'question_id' => $question->q_id);
                            $where_format = array('%d', '%d');
                            // run the update
                            $upd_success = $wpdb->update(EVENTS_ANSWER_TABLE, $set_cols_and_values, $where_cols_and_values, $set_format, $where_format);
                            //echo '<h4>last_query : ' . $wpdb->last_query . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                        } else {
                            // new answer
                            $set_cols_and_values = array('registration_id' => $registration_id, 'attendee_id' => $id, 'question_id' => $question->q_id, 'answer' => html_entity_decode(trim($post_val), ENT_QUOTES, 'UTF-8'));
                            $set_format = array('%s', '%d', '%d', '%s');
                            // run the insert
                            $upd_success = $wpdb->insert(EVENTS_ANSWER_TABLE, $set_cols_and_values, $set_format);
                            //echo '<h4>last_query : ' . $wpdb->last_query . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                        }
                    }
                }
                // let's base our success on the lack of errors
                $notifications['success'][] = empty($notifications['error']) ? __('All attendee details have been successfully updated.', 'event_espresso') : __('One or more errors may have prevented some attendee details from being successfully updated.', 'event_espresso');
            }
        }
        // **************************************************************************
        // *************************  RETRIEVE ATTENDEE  *************************
        // **************************************************************************
        $counter = 0;
        $additional_attendees = NULL;
        $SQL = "SELECT att.*, evt.event_name, evt.question_groups, evt.event_meta, evt.additional_limit FROM " . EVENTS_ATTENDEE_TABLE . " att ";
        $SQL .= "JOIN " . EVENTS_DETAIL_TABLE . " evt ON att.event_id = evt.id ";
        // are we looking for an additional attendee ?
        if (isset($_REQUEST['attendee_num']) && $_REQUEST['attendee_num'] > 1 && isset($_REQUEST['id'])) {
            $SQL .= "WHERE  att.id = " . sanitize_text_field($_REQUEST['id']);
        } else {
            // check for multi reg & additional attendees by first finding primary attendee
            $SQL2 = "SELECT primary_registration_id FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " WHERE registration_id = %s";
            if ($primary_registration_id = $wpdb->get_var($wpdb->prepare($SQL2, sanitize_text_field($_REQUEST['registration_id'])))) {
                // now find all registrations
                $SQL3 = "SELECT registration_id FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " WHERE primary_registration_id = %s";
                $reg_ids = $wpdb->get_col($wpdb->prepare($SQL3, $primary_registration_id));
                $reg_ids = "'" . implode("','", $reg_ids) . "'";
            } else {
                $reg_ids = "'" . sanitize_text_field($_REQUEST['registration_id']) . "'";
            }
            $SQL .= " WHERE registration_id IN ( {$reg_ids} ) ORDER BY att.id";
        }
        $attendees = $wpdb->get_results($wpdb->prepare($SQL, NULL));
        foreach ($attendees as $attendee) {
            if ($counter == 0) {
                $id = $attendee->id;
                $registration_id = $attendee->registration_id;
                $lname = $attendee->lname;
                $fname = $attendee->fname;
                $address = $attendee->address;
                $address2 = $attendee->address2;
                $city = $attendee->city;
                $state = $attendee->state;
                $zip = $attendee->zip;
                $email = $attendee->email;
                $payment = $attendee->payment;
                $phone = $attendee->phone;
                $date = $attendee->date;
                $payment_status = $attendee->payment_status;
                $txn_type = $attendee->txn_type;
                $txn_id = $attendee->txn_id;
                $quantity = $attendee->quantity;
                $payment_date = $attendee->payment_date;
                $event_id = $attendee->event_id;
                $event_name = $attendee->event_name;
                $question_groups = unserialize($attendee->question_groups);
                $event_meta = unserialize($attendee->event_meta);
                $coupon_code = $attendee->coupon_code;
                $is_additional_attendee = $primary_attendee != $id ? true : false;
                $attendee_limit = $attendee->additional_limit;
                $amount_pd = $attendee->amount_pd;
                $total_cost = $attendee->total_cost;
                $orig_price = $attendee->orig_price;
                $final_price = $attendee->final_price;
                $start_date = $attendee->start_date;
                $event_time = $attendee->event_time;
                // Added for seating chart addon
                $booking_info = "";
                if (defined('ESPRESSO_SEATING_CHART')) {
                    $seating_chart_id = seating_chart::check_event_has_seating_chart($event_id);
                    if ($seating_chart_id !== false) {
                        $seat = $wpdb->get_row("select scs.* , sces.id as booking_id from " . EVENTS_SEATING_CHART_SEAT_TABLE . " scs inner join " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " sces on scs.id = sces.seat_id where sces.attendee_id = '" . $id . "' ");
                        if ($seat !== NULL) {
                            $booking_info = $seat->custom_tag . " #booking id: " . $seat->booking_id;
                        }
                    }
                }
                $event_date = event_date_display($start_date . ' ' . $event_time, get_option('date_format') . ' g:i a');
                if ($is_additional_attendee && isset($event_meta['add_attendee_question_groups']) && $event_meta['add_attendee_question_groups'] != NULL) {
                    $question_groups = $event_meta['add_attendee_question_groups'];
                }
                $counter++;
            } else {
                $additional_attendees[$attendee->id] = array('full_name' => $attendee->fname . ' ' . $attendee->lname, 'email' => $attendee->email, 'phone' => $attendee->phone);
            }
        }
        // display success messages
        if (!empty($notifications['success'])) {
            $success_msg = implode($notifications['success'], '<br />');
            ?>
				
<div id="message" class="updated fade">
	<p>
		<strong><?php 
            echo $success_msg;
            ?>
</strong>
	</p>
</div>

		<?php 
        }
        // display error messages
        if (!empty($notifications['error'])) {
            $error_msg = implode($notifications['error'], '<br />');
            ?>
				
<div id="message" class="error">
	<p>
		<strong><?php 
            echo $error_msg;
            ?>
</strong>
	</p>
</div>

		<?php 
        }
        ?>
		
<div>		
	<p>
		<a href="admin.php?page=events&event_id=<?php 
        echo $event_id;
        ?>
&event_admin_reports=list_attendee_payments">
			<strong>&laquo;&nbsp;<?php 
        _e('Back to Attendees List', 'event_espresso');
        ?>
</strong>
		</a>
	</p>
</div>

<div class="metabox-holder">
	<div class="postbox">
		<h3>
			<?php 
        _e('Registration Id <a href="admin.php?page=events&event_admin_reports=edit_attendee_record&event_id=' . $event_id . '&registration_id=' . $registration_id . '&form_action=edit_attendee">#' . $registration_id . '</a> | ID #' . $id . ' | Name: ' . $fname . ' ' . $lname . ' | Registered For:', 'event_espresso');
        ?>
			<a href="admin.php?page=events&event_admin_reports=list_attendee_payments&event_id=<?php 
        echo $event_id;
        ?>
"><?php 
        echo stripslashes_deep($event_name);
        ?>
</a> - <?php 
        echo $event_date;
        ?>
		</h3>
		<div class="inside">
			<table width="100%">
				<tr>
					<td width="50%" valign="top">
						<form method="post" action="<?php 
        echo $_SERVER['REQUEST_URI'];
        ?>
" class="espresso_form">
							<h4 class="qrtr-margin">
								<?php 
        _e('Registration Information', 'event_espresso');
        ?>
								<?php 
        echo $is_additional_attendee == false ? '[ <span class="green_text">' . __('Primary Attendee Record', 'event_espresso') . '</span> ]' : '[ <a href="admin.php?page=events&event_admin_reports=edit_attendee_record&event_id=' . $event_id . '&registration_id=' . $registration_id . '&form_action=edit_attendee">View/Edit Primary Attendee</a> ]';
        ?>
							</h4>
							<fieldset>
								<ul>
									<li>
										<?php 
        $time_id = 0;
        $SQL = "SELECT id FROM " . EVENTS_START_END_TABLE . " WHERE event_id=%d AND start_time =%s";
        if ($event_time = $wpdb->get_row($wpdb->prepare($SQL, $event_id, $event_time))) {
            $time_id = $event_time->id;
        }
        echo event_espresso_time_dropdown($event_id, $label = 1, $multi_reg = 0, $time_id);
        ?>
									</li>
									<li>
										<?php 
        //Added for seating chart addon.  Creates a field to select a seat from a popup.
        do_action('ee_seating_chart_css');
        do_action('ee_seating_chart_js');
        do_action('ee_seating_chart_flush_expired_seats');
        do_action('espresso_seating_chart_select', $event_id, $booking_info);
        ?>
									</li>
									<li>
										<?php 
        if (count($question_groups) > 0) {
            $questions_in = '';
            foreach ($question_groups as $g_id) {
                $questions_in .= $g_id . ',';
            }
            $questions_in = substr($questions_in, 0, -1);
            $group_name = '';
            $counter = 0;
            $FILTER = '';
            if (isset($event_meta['additional_attendee_reg_info']) && $event_meta['additional_attendee_reg_info'] == '2' && isset($_REQUEST['attendee_num']) && $_REQUEST['attendee_num'] > 1) {
                $FILTER .= " AND qg.system_group = 1 ";
            }
            //pull the list of questions that are relevant to this event
            $SQL = "SELECT q.*, at.*, qg.group_name, qg.show_group_description, qg.show_group_name ";
            $SQL .= "FROM " . EVENTS_QUESTION_TABLE . " q ";
            $SQL .= "LEFT JOIN " . EVENTS_ANSWER_TABLE . " at on q.id = at.question_id ";
            $SQL .= "JOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id ";
            $SQL .= "JOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id ";
            $SQL .= "WHERE qgr.group_id in ( {$questions_in} ) ";
            $SQL .= "AND ( at.attendee_id IS NULL OR at.attendee_id = %d ) ";
            $SQL .= $FILTER . " ";
            $SQL .= "ORDER BY qg.id, q.id ASC";
            $questions = $wpdb->get_results($wpdb->prepare($SQL, $id));
            $num_rows = $wpdb->num_rows;
            if ($num_rows > 0) {
                //Output the questions
                $question_displayed = array();
                foreach ($questions as $question) {
                    $counter++;
                    if (!in_array($question->id, $question_displayed)) {
                        $question_displayed[] = $question->id;
                        //echo '<p>';
                        echo event_form_build_edit($question, $question->answer, $show_admin_only = true);
                        //echo "</p>";
                        #echo $counter == $num_rows ? '</fieldset>' : '';
                    }
                }
            }
            //end questions display
        }
        ?>
									</li>
									<input type="hidden" name="id" value="<?php 
        echo $id;
        ?>
" />
									<input type="hidden" name="registration_id" value="<?php 
        echo $registration_id;
        ?>
" />
									<input type="hidden" name="event_id" value="<?php 
        echo $event_id;
        ?>
" />
									<input type="hidden" name="display_action" value="view_list" />
									<input type="hidden" name="form_action" value="edit_attendee" />
									<input type="hidden" name="attendee_action" value="update_attendee" />
									<?php 
        wp_nonce_field('edit_attendee_' . $registration_id . '_update_attendee_nonce');
        ?>
									<li>
										<input type="submit" name="Submit" class="button-primary action"  value="<?php 
        _e('Update Record', 'event_espresso');
        ?>
" />
									</li>
								</ul>
							</fieldset>
						</form></td>
					<td  width="50%" valign="top">
						<?php 
        if (count($additional_attendees) > 0) {
            ?>
 
						<h4>
							<?php 
            _e('Additional Attendees', 'event_espresso');
            ?>
						</h4>
						<ol>
							<?php 
            foreach ($additional_attendees as $att => $row) {
                $attendee_num++;
                ?>
							<li>
								<?php 
                // create edit link
                $edit_att_url_params = array('event_admin_reports' => 'edit_attendee_record', 'form_action' => 'edit_attendee', 'registration_id' => $registration_id, 'id' => $att, 'attendee_num' => $attendee_num, 'event_id' => $event_id);
                // add url params
                $edit_attendee_link = add_query_arg($edit_att_url_params, 'admin.php?page=events');
                ?>
								
								<a href="<?php 
                echo $edit_attendee_link;
                ?>
" title="<?php 
                _e('Edit Attendee', 'event_espresso');
                ?>
">
									<strong><?php 
                echo $row['full_name'];
                ?>
</strong> (<?php 
                echo $row['email'];
                ?>
)
								</a>
								&nbsp;&nbsp;|&nbsp;&nbsp;
								<?php 
                // create delete link
                $delete_att_url_params = array('event_admin_reports' => 'edit_attendee_record', 'form_action' => 'edit_attendee', 'attendee_action' => 'delete_attendee', 'registration_id' => $registration_id, 'id' => $att, 'attendee_num' => $attendee_num, 'event_id' => $event_id);
                // add url params
                $delete_attendee_link = add_query_arg($delete_att_url_params, 'admin.php?page=events');
                // add nonce
                $edit_attendee_link = wp_nonce_url($delete_attendee_link, 'edit_attendee_' . $registration_id . '_delete_attendee_nonce');
                ?>
								
								<a href="<?php 
                echo $delete_attendee_link;
                ?>
" title="<?php 
                _e('Delete Attendee', 'event_espresso');
                ?>
" onclick="return confirmDelete();">
									<?php 
                _e('Delete', 'event_espresso');
                ?>
								</a>
							</li>
							<?php 
            }
            ?>
						</ol>
						<?php 
        }
        ?>
						
						
						<br/>
						<h4 class="qrtr-margin"><?php 
        _e('Ticket Prices', 'event_espresso');
        ?>
</h4>
						
						<form method="POST" action="<?php 
        echo $_SERVER['REQUEST_URI'];
        ?>
&status=saved" class="espresso_form">
							<fieldset>
								<ul>
									<li>
											<strong class="att-tckt-prc-lbl"><?php 
        _e('Payment Status:', 'event_espresso');
        ?>
</strong> 
											<?php 
        echo $payment_status;
        ?>
 <?php 
        echo event_espresso_paid_status_icon($payment_status);
        ?>
&nbsp;&nbsp;[&nbsp;<a href="admin.php?page=events&amp;attendee_pay=paynow&amp;form_action=payment&amp;registration_id=<?php 
        echo $registration_id;
        ?>
&amp;event_admin_reports=enter_attendee_payments&amp;event_id=<?php 
        echo $event_id;
        ?>
" title="<?php 
        _e('Edit Payment', 'event_espresso');
        ?>
">
											<?php 
        _e('View/Edit Payment', 'event_espresso');
        ?>
											</a>&nbsp;]
									</li>
									<li>
											<strong class="att-tckt-prc-lbl"><?php 
        _e('Transaction ID:', 'event_espresso');
        ?>
</strong> 
											<?php 
        echo !empty($txn_id) ? $txn_id : 'N/A';
        ?>
									</li>
									<li>
											<strong class="att-tckt-prc-lbl"><?php 
        _e('Date Paid:', 'event_espresso');
        ?>
</strong> 
											<?php 
        echo !empty($payment_date) ? event_date_display($payment_date) : 'N/A';
        ?>
									</li>
									<li>
											<strong class="att-tckt-prc-lbl">
											<?php 
        _e('Total Amount Owing:', 'event_espresso');
        ?>
											</strong>
											<?php 
        echo $org_options['currency_symbol'];
        echo $total_cost;
        ?>
									</li>
									<li>
											<strong class="att-tckt-prc-lbl"><?php 
        _e('Total Amount Paid to Date:', 'event_espresso');
        ?>
</strong> 
											<?php 
        echo $org_options['currency_symbol'] . $amount_pd;
        //echo espresso_attendee_price(array('attendee_id' => $id, 'reg_total' => true));
        ?>
									</li>
									<li>
										<h6 class="qrtr-margin"><strong><?php 
        _e('Attendee Ticket Fees:', 'event_espresso');
        ?>
</strong></h6>
										<div  <?php 
        if (isset($_REQUEST['show_payment']) && $_REQUEST['show_payment'] == 'true') {
            echo ' class="yellow_inform"';
        }
        ?>
>
											<table  border="0">
												<tr>
													<td  align="left" valign="top">
														<label><?php 
        _e('Amount:', 'event_espresso');
        ?>
 ( <?php 
        echo $org_options['currency_symbol'];
        ?>
 )</label>
													</td>
													<td  align="center" valign="top">
														<label><?php 
        _e('# Tickets:', 'event_espresso');
        ?>
</label>
													</td>
													<td  align="right" valign="top">
														<label class="algn-rght"><?php 
        _e('Total:', 'event_espresso');
        ?>
</label>
													</td>
												</tr>
												<tr>
													<td align="left" valign="top">
														<input name="final_price" class="small-text algn-rght" type="text" value ="<?php 
        echo $final_price;
        ?>
" />
													</td>
													<td align="center" valign="top">
														<?php 
        // number of tickets currently purchased
        $quantity = !empty($quantity) ? $quantity : 1;
        // availalbe spaces left for event
        $available_spaces = get_number_of_attendees_reg_limit($event_id, 'number_available_spaces');
        if ($available_spaces != 'Unlimited') {
            // first add our purchased tickets ($quantity) back into available spaces
            // ( becuase a sold out show incluldes these tickets here, so admin should be allowed to play with these numbers - think about it )
            $available_spaces += $quantity;
            $attendee_limit = $attendee_limit <= $available_spaces ? $attendee_limit : $available_spaces;
        }
        // final check to make sure that attendee limit has to at LEAST be the number of tickets this attendee has already purchased
        // otherwise the ticket quantity selector may display less than what this attendee has already purchased
        $attendee_limit = $attendee_limit < $quantity ? $quantity : $attendee_limit;
        ?>
														<select name="quantity" class="price_id">
														<?php 
        for ($i = 0; $i <= $attendee_limit; $i++) {
            $selected = $i == $quantity ? ' selected="selected" ' : '';
            ?>
															<option <?php 
            echo $selected;
            ?>
 value="<?php 
            echo $i;
            ?>
"><?php 
            echo $i;
            ?>
</option>
														<?php 
        }
        ?>
														</select>
														<!--<input name="quantity" type="text" value ="<?php 
        echo !empty($quantity) ? $quantity : 1;
        ?>
"  />-->
													</td>
													<td  align="right" valign="top">
														<?php 
        $ticket_total = (double) ($final_price * $quantity) > 0 ? number_format($final_price * $quantity, 2, '.', '') : 0.0;
        ?>
														<input class="small-text algn-rght" type="text" name="total_owing" disabled="true" value ="<?php 
        echo $ticket_total;
        ?>
" />
													</td>
												</tr>
											</table>
										</div>
									</li>
									<li>
											<strong class="att-tckt-prc-lbl"><?php 
        _e('Original Ticket Price:', 'event_espresso');
        ?>
</strong> 
											<?php 
        echo $org_options['currency_symbol'] . '&nbsp;' . $orig_price;
        ?>
&nbsp;&nbsp;/&nbsp;&nbsp;<?php 
        _e('ticket', 'event_espresso');
        ?>
								
									</li>
									<li>
										<br/>
										<input type="submit" name="submit_ticket_prices" class="button-primary action"  value="Update Price" />
									</li>
								</ul>
							</fieldset>
							<input type="hidden" name="id" value="<?php 
        echo $id;
        ?>
" />
							<input type="hidden" name="registration_id" value="<?php 
        echo $registration_id;
        ?>
" />
							<input type="hidden" name="form_action" value="edit_attendee" />
							<input type="hidden" name="event_id" value="<?php 
        echo $event_id;
        ?>
" />
							<input type="hidden" name="attendee_payment" value="update_price" />
							<?php 
        wp_nonce_field('edit_attendee_' . $registration_id . '_update_price_nonce');
        ?>
						</form>
					</td>
				</tr>
			</table>
		</div>
	</div>
</div>
<?php 
    }
}
function events_payment_page($attendee_id = FALSE, $notifications = array())
{
    do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
    if (!$attendee_id) {
        wp_die(__('An error occured. No Attendee was received.', 'event_espresso'));
    }
    global $wpdb, $org_options;
    $num_people = 0;
    //	$Organization = $org_options['organization'];
    //	$Organization_street1 = $org_options['organization_street1'];
    //	$Organization_street2 = $org_options['organization_street2'];
    //	$Organization_city = $org_options['organization_city'];
    //	$Organization_state = $org_options['organization_state'];
    //	$Organization_zip = $org_options['organization_zip'];
    //	$contact = $org_options['contact_email'];
    //	$registrar = $org_options['contact_email'];
    //	$currency_format = getCountryFullData($org_options['organization_country']);
    $message = $org_options['message'];
    $return_url = $org_options['return_url'];
    $cancel_return = $org_options['cancel_return'];
    $notify_url = $org_options['notify_url'];
    $event_page_id = $org_options['event_page_id'];
    // GET ATTENDEE
    $SQL = "SELECT * FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id =%d";
    $attendee = $wpdb->get_row($wpdb->prepare($SQL, $attendee_id));
    //printr( $attendee, '$attendee  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
    $attendee_last = $attendee->lname;
    $attendee_first = $attendee->fname;
    $attendee_name = stripslashes_deep($attendee_first . ' ' . $attendee_last);
    $attendee_address = $attendee->address;
    $attendee_address2 = $attendee->address2;
    $attendee_city = $attendee->city;
    $attendee_state = $attendee->state;
    $attendee_zip = $attendee->zip;
    $attendee_email = $attendee->email;
    $phone = $attendee->phone;
    $attendee_phone = $attendee->phone;
    $date = $attendee->date;
    $quantity = (int) $attendee->quantity;
    $payment_status = $attendee->payment_status;
    $txn_type = $attendee->txn_type;
    $payment_date = $attendee->payment_date;
    $event_id = $attendee->event_id;
    $registration_id = $attendee->registration_id;
    $orig_price = (double) $attendee->orig_price;
    $final_price = (double) $attendee->final_price;
    //Get the questions for the attendee
    $SQL = "SELECT ea.answer, eq.question ";
    $SQL .= "\tFROM " . EVENTS_ANSWER_TABLE . " ea ";
    $SQL .= "LEFT JOIN " . EVENTS_QUESTION_TABLE . " eq ON eq.id = ea.question_id ";
    $SQL .= "\tWHERE ea.attendee_id = %d and eq.admin_only != 'Y' ";
    $SQL .= "\tORDER BY eq.sequence asc ";
    $questions = $wpdb->get_results($wpdb->prepare($SQL, $attendee_id));
    //	echo '<h4>LQ : ' . $wpdb->last_query . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
    //	printr( $questions, '$questions  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
    $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>' . $question->question . ':<br /> ' . str_replace(',', '<br />', $question->answer) . '</p>';
    }
    // update total cost for primary attendee
    $total_cost = (double) $final_price * (int) $quantity - $attendee->amount_pd;
    $total_attendees = (int) $quantity;
    $attendee_prices[] = array('option' => $attendee->price_option, 'qty' => (int) $quantity, 'price' => (double) ($final_price - $attendee->amount_pd));
    // get # of attendees
    $SQL = "SELECT price_option, quantity, final_price, amount_pd  FROM " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id =%s";
    $prices = $wpdb->get_results($wpdb->prepare($SQL, $registration_id));
    //printr( $prices, '$prices  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
    if ($prices !== FALSE) {
        $total_cost = 0;
        $total_attendees = 0;
        $attendee_prices = array();
        // ensure prices is an array
        $prices = is_array($prices) ? $prices : array($prices);
        foreach ($prices as $price) {
            // update total cost for all attendees
            $total_cost += (double) ($price->final_price * (int) $price->quantity) - (double) $price->amount_pd;
            $total_attendees += $price->quantity;
            $attendee_prices[] = array('option' => $price->price_option, 'qty' => (int) $price->quantity, 'price' => (double) ($price->final_price - $price->amount_pd));
        }
    }
    $SQL = "SELECT * FROM " . EVENTS_DETAIL_TABLE . " WHERE id = %d";
    $event = $wpdb->get_row($wpdb->prepare($SQL, $event_id));
    $event_name = isset($event->event_name) ? stripslashes_deep($event->event_name) : '';
    $event_description = $event_desc = isset($event->event_desc) ? stripslashes_deep($event->event_desc) : '';
    $event_identifier = isset($event->event_identifier) ? $event->event_identifier : '';
    $send_mail = isset($event->send_mail) ? $event->send_mail : '';
    $active = isset($event->is_active) ? $event->is_active : TRUE;
    $conf_mail = isset($event->conf_mail) ? $event->conf_mail : '';
    //$event_price_x_attendees = number_format( $final_price * $num_people, 2, '.', '' );
    $event_original_cost = $orig_price;
    // Added for seating chart addon
    // This code block overrides the cost using seating chart add-on price
    if (defined('ESPRESSO_SEATING_CHART') && class_exists("seating_chart") && seating_chart::check_event_has_seating_chart($event_id) !== false) {
        $SQL = "SELECT sum(sces.purchase_price) as purchase_price ";
        $SQL .= "FROM " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " sces ";
        $SQL .= "INNER JOIN " . EVENTS_ATTENDEE_TABLE . " ea ON sces.attendee_id = ea.id ";
        $SQL .= "WHERE ea.registration_id = %s";
        if ($seat = $wpdb->get_row($wpdb->prepare($SQL, $registration_id))) {
            $total_cost = number_format($seat->purchase_price, 2, '.', '');
            //$event_price_x_attendees = (float)$final_price;
        }
    }
    if ($total_cost == 0) {
        $payment_status = 'Completed';
        //DO NOT TRANSLATE
        $today = date(get_option('date_format'));
        $data = array('amount_pd' => 0.0, 'payment_status' => $payment_status, 'payment_date' => $today);
        $format = array('%f', '%s', '%s');
        $update_id = array('id' => $attendee_id);
        $wpdb->update(EVENTS_ATTENDEE_TABLE, $data, $update_id, $format, array('%d'));
        //If this is a group registration, we need to make sure all attendees have the same payment status
        if (espresso_count_attendees_for_registration($attendee_id) > 1) {
            $wpdb->query("UPDATE " . EVENTS_ATTENDEE_TABLE . " SET payment_status = '{$payment_status}' WHERE registration_id ='" . $registration_id . "'");
        }
    }
    if (function_exists('espresso_update_attendee_coupon_info') && $attendee_id && !empty($attendee->coupon_code)) {
        espresso_update_attendee_coupon_info($attendee_id, $attendee->coupon_code);
    }
    if (function_exists('espresso_update_groupon') && $attendee_id && !empty($attendee->coupon_code)) {
        espresso_update_groupon($attendee_id, $attendee->coupon_code);
    }
    //	echo '<h4>$attendee_id : ' . $attendee_id . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
    //	echo '<h4>$total_cost : ' . $total_cost . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
    espresso_update_primary_attendee_total_cost($attendee_id, $total_cost, __FILE__);
    if (!empty($notifications['coupons']) || !empty($notifications['groupons'])) {
        echo '<div id="event_espresso_notifications" class="clearfix event-data-display no-hide">';
        echo $notifications['coupons'];
        // add space between $coupon_notifications and  $groupon_notifications ( if any $groupon_notifications exist )
        echo !empty($notifications['coupons']) && !empty($notifications['groupons']) ? '<br/>' : '';
        echo $notifications['groupons'];
        echo '</div>';
    }
    if (isset($org_options['skip_confirmation_page']) && $org_options['skip_confirmation_page'] == 'Y') {
        $redirect_url = home_url() . '/?page_id=' . $org_options['event_page_id'] . '&regevent_action=confirm_registration';
        $_POST['regevent_action'] = 'confirm_registration';
        $_POST['confirm'] = 'Confirm Registration';
        $_POST['confirm_registration'] = TRUE;
        $_POST['attendee_id'] = $attendee_id;
        $_POST['event_id'] = $event_id;
        $_POST['registration_id'] = $registration_id;
        espresso_confirm_registration();
    } else {
        $display_cost = $total_cost > 0 ? $org_options['currency_symbol'] . number_format($total_cost, 2, '.', '') : __('Free', 'event_espresso');
        // Pull in the template
        if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "confirmation_display.php")) {
            require_once EVENT_ESPRESSO_TEMPLATE_DIR . "confirmation_display.php";
            //This is the path to the template file if available
        } else {
            require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/confirmation_display.php";
        }
    }
}
 static function get_row_list($seating_chart_id, $level, $section)
 {
     $rows_ar = seating_chart::get_row_ar_list($seating_chart_id);
     $rows = isset($rows_ar[$level][$section]) ? $rows_ar[$level][$section] : array();
     return $rows;
 }
                            <input type="radio" name="section_alignment[<?php 
        echo $section->level;
        ?>
][<?php 
        echo $section->section;
        ?>
]" value="right" <?php 
        echo $right;
        ?>
 />&nbsp;<?php 
        _e('Right', 'event_espresso');
        ?>
                        </td>
                        <td >
                            <?php 
        $sort_order = seating_chart::get_section_sort_order($seating_chart_id, $section->level, $section->section);
        $asc = "";
        $desc = "";
        if ($sort_order == 'desc') {
            $desc = 'checked="checked"';
        } else {
            $asc = 'checked="checked"';
        }
        ?>
                            <input type="radio" name="section_sort_order[<?php 
        echo $section->level;
        ?>
][<?php 
        echo $section->section;
        ?>
]" value="asc" <?php 
Beispiel #14
0
						<th scope="row" class="header">
							<?php 
    echo empty($price_type) ? __('Price per attendee:', 'event_espresso') : __('Type/Price per attendee:', 'event_espresso');
    ?>
						</th>
						<td>
							<span class="event_espresso_value"><?php 
    echo empty($price_type) ? $org_options['currency_symbol'] . number_format($final_price, 2) : stripslashes_deep($price_type) . ' / ' . $org_options['currency_symbol'] . number_format($final_price, 2);
    ?>
</span>
						</td>
					</tr>
<?php 
} else {
    // Added for seating chart addon
    $price_range = seating_chart::get_price_range($event_id);
    $price = "";
    if ($price_range['min'] != $price_range['max']) {
        $price = $org_options['currency_symbol'] . number_format($price_range['min'], 2) . ' - ' . $org_options['currency_symbol'] . number_format($price_range['max'], 2);
    } else {
        $price = $org_options['currency_symbol'] . number_format($price_range['min'], 2);
    }
    ?>
					<tr>
						<th scope="row" class="header"><?php 
    _e('Price:', 'event_espresso');
    ?>
</th>
						<td><span class="event_espresso_value"><?php 
    echo $price;
    ?>
function espresso_prepare_email_data($attendee_id, $multi_reg, $custom_data = '')
{
    global $wpdb, $org_options;
    do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
    $data = new stdClass();
    $data->multi_reg = $multi_reg;
    $data->seatingchart_tag = '';
    //print_r($custom_data);
    //Create vars for the custom data
    if (!empty($custom_data)) {
        extract($custom_data, EXTR_PREFIX_ALL, 'custom_data');
    }
    //echo $custom_data_email_type;
    //Get the event record
    if (empty($custom_data_email_type)) {
        $custom_data_email_type = '';
    }
    $data->email_type = $custom_data_email_type;
    $sql = "SELECT ed.* ";
    isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ? $sql .= ", v.name venue_name, v.address venue_address, v.address2 venue_address2, v.city venue_city, v.state venue_state, v.zip venue_zip, v.country venue_country, v.meta venue_meta " : '';
    $sql .= " FROM " . EVENTS_DETAIL_TABLE . " ed ";
    isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ? $sql .= " LEFT JOIN " . EVENTS_VENUE_REL_TABLE . " r ON r.event_id = ed.id LEFT JOIN " . EVENTS_VENUE_TABLE . " v ON v.id = r.venue_id " : '';
    $sql .= " JOIN " . EVENTS_ATTENDEE_TABLE . " ea ON ea.event_id=ed.id ";
    $sql .= " WHERE ea.id = '" . $attendee_id . "' ";
    $data->event = $wpdb->get_row($sql, OBJECT);
    //Get the attendee record
    $sql = "SELECT ea.* FROM " . EVENTS_ATTENDEE_TABLE . " ea WHERE ea.id = '" . $attendee_id . "' ";
    $data->attendee = $wpdb->get_row($sql, OBJECT);
    //Get the primary/first attendee
    $data->primary_attendee = espresso_is_primary_attendee($data->attendee->id) == true ? true : false;
    $data->event->event_meta = unserialize($data->event->event_meta);
    //Venue variables
    if (isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y') {
        $data->event->venue_meta = unserialize($data->event->venue_meta);
        //Debug
        //echo "<pre>".print_r($data->event->venue_meta,true)."</pre>";
        $data->event->venue_url = $data->event->venue_meta['website'];
        $data->event->venue_phone = $data->event->venue_meta['phone'];
        $data->event->venue_image = '<img src="' . $data->event->venue_meta['image'] . '" />';
        $data->event->venue_name = $data->event->venue_name;
        $data->event->address = $data->event->venue_address;
        $data->event->address2 = $data->event->venue_address2;
        $data->event->city = $data->event->venue_city;
        $data->event->state = $data->event->venue_state;
        $data->event->zip = $data->event->venue_zip;
        $data->event->country = $data->event->venue_country;
    } else {
        $data->event->venue_name = $data->event->venue_title;
    }
    //Build the table to hold the event and attendee info
    $data->table_open = '<table width="100%" border="1" cellpadding = "5" cellspacing="5" style="border-collapse:collapse;">';
    $data->table_heading = "<tr><th>" . __('Event Name', 'event_espresso') . "</th><th>" . __('Date', 'event_espresso') . "</th><th>" . __('Time', 'event_espresso') . "</th><th>" . __('Location', 'event_espresso') . "</th></tr>";
    $data->table_close = "</table>";
    //Clear ticket data
    $data->qr_code = '';
    $data->ticket_link = '';
    $data->admin_ticket_link = '';
    if (defined("ESPRESSO_SEATING_CHART")) {
        if (class_exists("seating_chart")) {
            if (seating_chart::check_event_has_seating_chart($data->event->id)) {
                $rs = $wpdb->get_row("select scs.* from " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " sces inner join " . EVENTS_SEATING_CHART_SEAT_TABLE . " scs on sces.seat_id = scs.id where sces.attendee_id = " . $attendee_id);
                if ($rs !== NULL) {
                    $data->seatingchart_tag = $rs->custom_tag . " " . $rs->seat . " " . $rs->row;
                }
            }
        }
    }
    //Old ticketing system
    if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . "/ticketing/template.php")) {
        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . "/ticketing/functions.php")) {
            include_once EVENT_ESPRESSO_UPLOAD_DIR . "/ticketing/functions.php";
            $data->qr_code = espresso_qr_code(array('attendee_id' => $data->attendee->id, 'registration_id' => $data->attendee->registration_id, 'event_code' => $data->event->event_code));
        }
        $data->ticket_link = espresso_ticket_links($data->attendee->registration_id, $data->attendee->id);
        $data->admin_ticket_link = $data->ticket_link;
    }
    //New ticketing system version 2.0
    if (function_exists('espresso_ticket_launch')) {
        $data->qr_code = espresso_ticket_qr_code(array('attendee_id' => $data->attendee->id, 'registration_id' => $data->attendee->registration_id, 'event_code' => $data->event->event_code));
        $data->ticket_link = espresso_ticket_links($data->attendee->registration_id, $data->attendee->id, TRUE);
        $data->admin_ticket_link = $data->ticket_link;
    }
    //certificate system
    if (function_exists('espresso_certificate_launch')) {
        $data->certificate_link = espresso_certificate_links($data->attendee->registration_id, $data->attendee->id);
        $data->admin_certificate_link = $data->certificate_link;
    }
    //Build the address
    $data->location = ($data->event->address != '' ? $data->event->address : '') . ($data->event->address2 != '' ? '<br />' . $data->event->address2 : '') . ($data->event->city != '' ? '<br />' . $data->event->city : '') . ($data->event->state != '' ? ', ' . $data->event->state : '') . ($data->event->zip != '' ? '<br />' . $data->event->zip : '') . ($data->event->country != '' ? '<br />' . $data->event->country : '');
    //Build Google map link
    $data->google_map_link = espresso_google_map_link(array('address' => $data->event->address, 'city' => $data->event->city, 'state' => $data->event->state, 'zip' => $data->event->zip, 'country' => $data->event->country));
    //Registration URL
    $data->event_url = espresso_reg_url($data->event->id);
    $data->event_link = '<a href="' . $data->event_url . '">' . stripslashes_deep($data->event->event_name) . '</a>';
    //Venue name
    if (!isset($data->event->venue_name)) {
        $data->event->venue_name = '';
    }
    //Table of events registered for
    $data->event_table .= espresso_generate_attendee_event_list($data);
    //Output custom questions
    if (function_exists('event_espresso_custom_questions_output')) {
        //Create the question display
        $email_questions_r = event_espresso_custom_questions_output(array('attendee_id' => $data->attendee->id, 'all_questions' => TRUE));
        if ($email_questions_r != '') {
            $data->email_questions = '<tr><td colspan = "6">' . $email_questions_r . '</td></tr>';
        }
        $data->event_table .= $data->email_questions;
    }
    //Payment URL
    $payment_url = add_query_arg('r_id', $data->attendee->registration_id, get_permalink($org_options['return_url']));
    $data->payment_link = '<a href="' . $payment_url . '">' . __('View Your Payment Details', 'event_espresso') . '</a>';
    // download link
    $data->invoice_link = '<a href="' . home_url() . '/?download_invoice=true&amp;attendee_id=' . $data->attendee->id . '&amp;r_id=' . $data->attendee->registration_id . '" target="_blank">' . __('Download PDF Invoice', 'event_espresso') . '</a>';
    //Edit attendee link
    $data->edit_attendee = espresso_edit_attendee($data->attendee->registration_id, $data->attendee->id, $data->attendee->event_id, 'attendee', __('Edit Registration Details', 'event_espresso'));
    $data->email_subject = !$data->multi_reg ? $data->event->event_name : $org_options['organization'] . __(' registration confirmation', 'event_espresso');
    //Build invoice email
    if ($custom_data_email_type == 'invoice') {
        $data->email_subject = $custom_data_invoice_subject;
        $data->event->conf_mail = $custom_data_invoice_message;
        $data->event->send_mail = 'Y';
        $data->event->email_id = empty($_REQUEST['email_name']) ? '' : $_REQUEST['email_name'];
    }
    //Build payment email
    if ($custom_data_email_type == 'payment') {
        $data->email_subject = $custom_data_payment_subject;
        $data->event->conf_mail = $custom_data_payment_message;
        $data->event->send_mail = 'Y';
        $data->event->email_id = 0;
    }
    //Build reminder email
    if ($custom_data_email_type == 'reminder') {
        $data->email_subject = $custom_data_email_subject;
        $data->event->conf_mail = $custom_data_email_text;
        $data->event->send_mail = 'Y';
        $data->event->email_id = $custom_data_email_id > 0 ? $custom_data_email_id : '';
    }
    return $data;
}
<?php

global $wpdb;
$msg = "";
if (isset($_POST['insert_seating_chart'])) {
    if (isset($_POST['name']) && !empty($_POST['name']) && strlen(trim($_POST['name'])) > 0) {
        $cls_seating_chart = new seating_chart();
        $seating_chart_id = $cls_seating_chart->insert_seating_chart($_POST);
        if ($seating_chart_id > 0) {
            $msg = "Seating chart created";
        } else {
            $msg = "Error: [" . mysql_errno() . "] - " . mysql_error();
        }
    } else {
        $msg = "Failed to create seating chart. Seating chart name missing!";
    }
}
?>


<!-- Tabs: Default to Add Custom-->  


<!-- Add New Chart: Fluid Left --> 
<div class="wrap" style="margin-bottom:10px;">
    <div id="icon-options-event" class="icon32"></div>
    <h2>Manage Seating Charts</h2>
    <?php 
if ($msg != "") {
    ?>
    <div id="message" class="updated fade below-h2" style="margin-top:10px;margin-bottom:10px;">
Beispiel #17
0
function espresso_seating_chart_clear_booking()
{
    seating_chart::clear_booking();
}
function update_event($recurrence_arr = array())
{
    //print_r($_REQUEST);
    global $wpdb, $org_options, $current_user, $espresso_premium;
    $wpdb->show_errors();
    /*
     * Begin Recurrence handling
     *
     * Will clean up in V 1.2.0
     *
     */
    if (get_option('event_espresso_re_active') == 1) {
        require_once EVENT_ESPRESSO_RECURRENCE_FULL_PATH . "functions/re_functions.php";
        if ($_POST['recurrence_id'] > 0) {
            /*
             * If the array is empty, then find the recurring dates
             */
            if (count($recurrence_arr) == 0) {
                // Prepare the parameters array for use with various RE functions
                $re_params = array('start_date' => $_POST['recurrence_start_date'], 'event_end_date' => $_POST['recurrence_event_end_date'], 'end_date' => $_POST['recurrence_end_date'], 'registration_start' => $_POST['recurrence_regis_start_date'], 'registration_end' => $_POST['recurrence_regis_end_date'], 'frequency' => $_POST['recurrence_frequency'], 'interval' => $_POST['recurrence_interval'], 'recurrence_type' => $_POST['recurrence_type'], 'weekdays' => $_POST['recurrence_weekday'], 'repeat_by' => $_POST['recurrence_repeat_by'], 'recurrence_regis_date_increment' => $_POST['recurrence_regis_date_increment'], 'recurrence_manual_dates' => $_POST['recurrence_manual_dates'], 'recurrence_manual_end_dates' => $_POST['recurrence_manual_end_dates'], 'recurrence_visibility' => $_POST['recurrence_visibility'], 'recurrence_id' => $_POST['recurrence_id']);
                //$re_params['adding_to_db'] = 'Y';
                //Has the form been modified
                $recurrence_form_modified = recurrence_form_modified($re_params);
                //echo ($recurrence_form_modified) ? "Yes" : 'No';
                if ($_POST['recurrence_apply_changes_to'] == 2) {
                    //Update all events in the series based on recurrence id
                    $recurrence_dates = $_POST['recurrence_type'] == 'm' ? find_recurrence_manual_dates($re_params) : find_recurrence_dates($re_params);
                    //$DEL_SQL = 'UPDATE ' . EVENTS_DETAIL_TABLE . " SET event_status = 'D' WHERE start_date NOT IN (" . $delete_in . ") AND recurrence_id = " . $wpdb->escape($_POST['recurrence_id']);
                    $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE recurrence_id = %d AND NOT event_status = 'D'";
                } else {
                    //Update this and upcoming events based on recurrence id and start_date >=start_date
                    $re_params['start_date'] = $_POST['start_date'];
                    $recurrence_dates = find_recurrence_dates($re_params);
                    //$DEL_SQL = 'UPDATE ' . EVENTS_DETAIL_TABLE . " SET event_status = 'D' WHERE start_date >='" . $wpdb->escape($_POST['start_date']) . "' AND start_date NOT IN (" . $delete_in . ") AND recurrence_id = " . $_POST['recurrence_id'];
                    $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE start_date >='" . $wpdb->escape($_POST['start_date']) . "' AND recurrence_id = %d and NOT event_status = 'D' ";
                }
                //Recurrence Form modified and changes need to apply to all
                if ($recurrence_form_modified && $_POST['recurrence_apply_changes_to'] > 1) {
                    //Update the recurrence table record with the new RE selections
                    update_recurrence_master_record();
                    /*
                     * Delete the records that don't belong in the formula
                     */
                    if (count($recurrence_dates) > 0) {
                        $delete_in = '';
                        foreach ($recurrence_dates as $k => $v) {
                            $delete_in .= "'" . $k . "',";
                        }
                        $delete_in = substr($delete_in, 0, -1);
                    }
                    if ($_POST['recurrence_apply_changes_to'] == 2) {
                        //Update all events in the series based on recurrence id
                        //$DEL_SQL = 'UPDATE ' . EVENTS_DETAIL_TABLE . " SET event_status = 'D' WHERE start_date NOT IN (" . $delete_in . ") AND recurrence_id = " . $_POST['recurrence_id'];
                        $DEL_SQL = 'DELETE EDT, EAT FROM ' . EVENTS_DETAIL_TABLE . " EDT\n                            LEFT JOIN " . EVENTS_ATTENDEE_TABLE . " EAT\n                                ON EDT.id = EAT.event_id\n                            WHERE EAT.id IS NULL\n                            AND EDT.start_date NOT IN (" . $delete_in . ")\n                            AND recurrence_id = " . $_POST['recurrence_id'];
                        $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE recurrence_id = %d and NOT event_status = 'D' ORDER BY start_date";
                    } else {
                        //Update this and upcoming events based on recurrence id and start_date >=start_date
                        //$DEL_SQL = 'UPDATE ' . EVENTS_DETAIL_TABLE . " SET event_status = 'D' WHERE start_date >='" . $wpdb->escape($_POST['start_date']) . "' AND start_date NOT IN (" . $delete_in . ") AND recurrence_id = " . $_POST['recurrence_id'];
                        $DEL_SQL = 'DELETE EDT, EAT FROM ' . EVENTS_DETAIL_TABLE . " EDT\n                            LEFT JOIN " . EVENTS_ATTENDEE_TABLE . " EAT\n                                ON EDT.id = EAT.event_id\n                            WHERE EAT.id IS NULL\n                            AND EDT.start_date >='" . $wpdb->escape($_POST['start_date']) . "'\n                            AND start_date NOT IN (" . $delete_in . ")\n                            AND recurrence_id = " . $_POST['recurrence_id'];
                        $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE start_date >='" . $wpdb->escape($_POST['start_date']) . "' AND recurrence_id = %d AND NOT event_status = 'D'  ORDER BY start_date";
                    }
                    if ($delete_in != '') {
                        $wpdb->query($DEL_SQL);
                    }
                    /*
                     * Add the new records based on the new formula
                     * The $recurrence_dates array will contain the new dates
                     */
                    if (!function_exists('add_event_to_db')) {
                        require_once 'insert_event.php';
                    }
                    foreach ($recurrence_dates as $k => $v) {
                        $result = $wpdb->get_row($wpdb->prepare("SELECT ID FROM " . EVENTS_DETAIL_TABLE . " WHERE recurrence_id = %d and start_date = %s and NOT event_status = 'D'", array($_POST['recurrence_id'], $k)));
                        if ($wpdb->num_rows == 0) {
                            add_event_to_db(array('recurrence_id' => $_POST['recurrence_id'], 'recurrence_start_date' => $v['start_date'], 'recurrence_event_end_date' => $v['end_date'], 'recurrence_end_date' => $v['start_date'], 'registration_start' => $v['registration_start'], 'registration_end' => $v['registration_end']));
                        } else {
                        }
                    }
                    /*
                     * Find all the event ids in the series and feed into the $recurrence_dates array
                     * This array will be used at the end of this document to invoke the recursion of update_event function so all the events in the series
                     * can be updated with the information.
                     */
                }
                $result = $wpdb->get_results($wpdb->prepare($UPDATE_SQL, array($_POST['recurrence_id'])));
                foreach ($result as $row) {
                    if ($row->start_date != '') {
                        $recurrence_dates[$row->start_date]['event_id'] = $row->id;
                        $recurrence_dates[$row->start_date]['event_identifier'] = $row->event_identifier;
                    }
                }
            }
        }
    }
    //  echo_f('rd',$recurrence_dates);
    if (defined('EVENT_ESPRESSO_RECURRENCE_MODULE_ACTIVE') && !empty($_POST['recurrence']) && $_POST['recurrence'] == 'Y' && count($recurrence_arr) == 0 && $_POST['recurrence_apply_changes_to'] > 1) {
        //skip the first update
    } else {
        $event_mata = array();
        //will be used to hold event meta data
        $event_id = array_key_exists('event_id', $recurrence_arr) ? $recurrence_arr['event_id'] : $_REQUEST['event_id'];
        $event_name = $_REQUEST['event'];
        //$event_identifier=array_key_exists('event_identifier', $recurrence_arr)?$recurrence_arr['event_identifier']:($_REQUEST['event_identifier'] == '') ? $event_identifier = sanitize_title_with_dashes($event_name.'-'.rand()) : $event_identifier = sanitize_title_with_dashes($_REQUEST['event_identifier']);
        $event_desc = $_REQUEST['event_desc'];
        $display_desc = $_REQUEST['display_desc'];
        $display_reg_form = $_REQUEST['display_reg_form'];
        $reg_limit = $_REQUEST['reg_limit'];
        $allow_multiple = $_REQUEST['allow_multiple'];
        $overflow_event_id = empty($_REQUEST['overflow_event_id']) ? '0' : $_REQUEST['overflow_event_id'];
        $allow_overflow = empty($_REQUEST['allow_overflow']) ? 'N' : $_REQUEST['allow_overflow'];
        $additional_limit = $_REQUEST['additional_limit'];
        //$member_only=$_REQUEST['member_only'];
        $member_only = empty($_REQUEST['member_only']) ? 'N' : $_REQUEST['member_only'];
        $is_active = $_REQUEST['is_active'];
        $event_status = $_REQUEST['event_status'];
        $address = !empty($_REQUEST['address']) ? esc_html($_REQUEST['address']) : '';
        $address2 = !empty($_REQUEST['address2']) ? esc_html($_REQUEST['address2']) : '';
        $city = !empty($_REQUEST['city']) ? esc_html($_REQUEST['city']) : '';
        $state = !empty($_REQUEST['state']) ? esc_html($_REQUEST['state']) : '';
        $zip = !empty($_REQUEST['zip']) ? esc_html($_REQUEST['zip']) : '';
        $country = !empty($_REQUEST['country']) ? esc_html($_REQUEST['country']) : '';
        $phone = !empty($_REQUEST['phone']) ? esc_html($_REQUEST['phone']) : '';
        $externalURL = !empty($_REQUEST['externalURL']) ? esc_html($_REQUEST['externalURL']) : '';
        //$event_location = $address . ' ' . $city . ', ' . $state . ' ' . $zip;
        $event_location = ($address != '' ? $address . ' ' : '') . ($city != '' ? '<br />' . $city : '') . ($state != '' ? ', ' . $state : '') . ($zip != '' ? '<br />' . $zip : '') . ($country != '' ? '<br />' . $country : '');
        //Get the first instance of the start and end times
        $start_time = $_REQUEST['start_time'][0];
        $end_time = $_REQUEST['end_time'][0];
        // Add registration times
        $registration_startT = event_date_display($_REQUEST['registration_startT'], 'H:i');
        $registration_endT = event_date_display($_REQUEST['registration_endT'], 'H:i');
        //Add timezone
        $timezone_string = empty($_REQUEST['timezone_string']) ? '' : $_REQUEST['timezone_string'];
        //Early discounts
        $early_disc = $_REQUEST['early_disc'];
        $early_disc_date = $_REQUEST['early_disc_date'];
        $early_disc_percentage = $_REQUEST['early_disc_percentage'];
        $conf_mail = $_REQUEST['conf_mail'];
        $use_coupon_code = $_REQUEST['use_coupon_code'];
        $alt_email = $_REQUEST['alt_email'];
        $send_mail = $_REQUEST['send_mail'];
        $email_id = empty($_REQUEST['email_name']) ? '' : $_REQUEST['email_name'];
        $event_category = serialize(empty($_REQUEST['event_category']) ? '' : $_REQUEST['event_category']);
        $event_discount = serialize(empty($_REQUEST['event_discount']) ? '' : $_REQUEST['event_discount']);
        $registration_start = array_key_exists('registration_start', $recurrence_arr) ? $recurrence_arr['registration_start'] : $_REQUEST['registration_start'];
        $registration_end = array_key_exists('registration_end', $recurrence_arr) ? $recurrence_arr['registration_end'] : $_REQUEST['registration_end'];
        $start_date = array_key_exists('recurrence_start_date', $recurrence_arr) ? $recurrence_arr['recurrence_start_date'] : ($_REQUEST['start_date'] == '' ? $_REQUEST['recurrence_start_date'] : $_REQUEST['start_date']);
        $end_date = array_key_exists('recurrence_event_end_date', $recurrence_arr) ? $recurrence_arr['recurrence_event_end_date'] : ($_REQUEST['end_date'] == '' ? $_REQUEST['recurrence_start_date'] : $_REQUEST['end_date']);
        $visible_on = array_key_exists('visible_on', $recurrence_arr) ? $recurrence_arr['visible_on'] : empty($_REQUEST['visible_on']) ? '' : $_REQUEST['visible_on'];
        //Venue Information
        $venue_title = isset($_REQUEST['venue_title']) ? $_REQUEST['venue_title'] : '';
        $venue_url = isset($_REQUEST['venue_url']) ? $_REQUEST['venue_url'] : '';
        $venue_phone = isset($_REQUEST['venue_phone']) ? $_REQUEST['venue_phone'] : '';
        $venue_image = isset($_REQUEST['venue_image']) ? $_REQUEST['venue_image'] : '';
        //Virtual location
        $virtual_url = isset($_REQUEST['virtual_url']) ? $_REQUEST['virtual_url'] : '';
        $virtual_phone = isset($_REQUEST['virtual_phone']) ? $_REQUEST['virtual_phone'] : '';
        if (isset($reg_limit) && $reg_limit == '') {
            $reg_limit = 999999;
        }
        $question_groups = serialize($_REQUEST['question_groups']);
        $add_attendee_question_groups = serialize(empty($_REQUEST['add_attendee_question_groups']) ? '' : $_REQUEST['add_attendee_question_groups']);
        $event_mata['default_payment_status'] = $_REQUEST['default_payment_status'];
        $event_mata['venue_id'] = empty($_REQUEST['venue_id']) ? '' : $_REQUEST['venue_id'][0];
        $event_mata['additional_attendee_reg_info'] = $_REQUEST['additional_attendee_reg_info'];
        $event_mata['add_attendee_question_groups'] = empty($_REQUEST['add_attendee_question_groups']) ? '' : $_REQUEST['add_attendee_question_groups'];
        $event_mata['date_submitted'] = $_REQUEST['date_submitted'];
        /*
         * Added for seating chart addon
         */
        if (isset($_REQUEST['seating_chart_id'])) {
            $cls_seating_chart = new seating_chart();
            $seating_chart_result = $cls_seating_chart->associate_event_seating_chart($_REQUEST['seating_chart_id'], $event_id);
            $tmp_seating_chart_id = $_REQUEST['seating_chart_id'];
            if ($tmp_seating_chart_id > 0) {
                if ($seating_chart_result === false) {
                    $tmp_seating_chart_row = $wpdb->get_row("select seating_chart_id from " . EVENTS_SEATING_CHART_EVENT_TABLE . " where event_id = {$event_id}");
                    if ($tmp_seating_chart_row !== NULL) {
                        $tmp_seating_chart_id = $tmp_seating_chart_row->seating_chart_id;
                    } else {
                        $tmp_seating_chart_id = 0;
                    }
                }
                if ($_REQUEST['allow_multiple'] == 'Y' && isset($_REQUEST['seating_chart_id']) && $tmp_seating_chart_id > 0) {
                    $event_mata['additional_attendee_reg_info'] = 3;
                }
            }
        }
        /*
         * End
         */
        if ($_REQUEST['emeta'] != '') {
            foreach ($_REQUEST['emeta'] as $k => $v) {
                $event_mata[$v] = $_REQUEST['emetad'][$k];
            }
        }
        $event_mata = serialize($event_mata);
        ############ Added by wp-developers ######################
        $require_pre_approval = 0;
        if (isset($_REQUEST['require_pre_approval'])) {
            $require_pre_approval = $_REQUEST['require_pre_approval'];
        }
        ################# END #################
        //When adding colums to the following arrays, be sure both arrays have equal values.
        $sql = array('event_name' => $event_name, 'event_desc' => $event_desc, 'display_desc' => $display_desc, 'display_reg_form' => $display_reg_form, 'address' => $address, 'address2' => $address2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country, 'phone' => $phone, 'virtual_url' => $virtual_url, 'virtual_phone' => $virtual_phone, 'venue_title' => $venue_title, 'venue_url' => $venue_url, 'venue_phone' => $venue_phone, 'venue_image' => $venue_image, 'registration_start' => $registration_start, 'registration_end' => $registration_end, 'start_date' => $start_date, 'end_date' => $end_date, 'allow_multiple' => $allow_multiple, 'send_mail' => $send_mail, 'is_active' => $is_active, 'event_status' => $event_status, 'conf_mail' => $conf_mail, 'use_coupon_code' => $use_coupon_code, 'member_only' => $member_only, 'externalURL' => $externalURL, 'early_disc' => $early_disc, 'early_disc_date' => $early_disc_date, 'early_disc_percentage' => $early_disc_percentage, 'alt_email' => $alt_email, 'question_groups' => $question_groups, 'allow_overflow' => $allow_overflow, 'overflow_event_id' => $overflow_event_id, 'additional_limit' => $additional_limit, 'reg_limit' => $reg_limit, 'email_id' => $email_id, 'registration_startT' => $registration_startT, 'registration_endT' => $registration_endT, 'event_meta' => $event_mata, 'require_pre_approval' => $require_pre_approval, 'timezone_string' => $timezone_string);
        $sql_data = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s');
        $update_id = array('id' => $event_id);
        /* echo 'Debug: <br />';
           print_r($sql);
           echo '<br />';
           print 'Number of vars: ' . count ($sql);
           echo '<br />';
           print 'Number of cols: ' . count($sql_data); */
        if (function_exists('event_espresso_add_event_to_db_groupon')) {
            $sql = event_espresso_add_event_to_db_groupon($sql, $_REQUEST['use_groupon_code']);
            ///print count ($sql);
            $sql_data = array_merge((array) $sql_data, (array) '%s');
            //print count($sql_data);
            $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
            /* echo 'Debug: <br />';
               print 'Number of vars: ' . count ($sql);
               echo '<br />';
               print 'Number of cols: ' . count($sql_data); */
        } else {
            $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
            /* echo 'Debug: <br />';
               print 'Number of vars: ' . count ($sql);
               echo '<br />';
               print 'Number of cols: ' . count($sql_data); */
        }
        //print $wpdb->print_error();
        $del_cats = "DELETE FROM " . EVENTS_CATEGORY_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($del_cats);
        if (!empty($_REQUEST['event_category'])) {
            foreach ($_REQUEST['event_category'] as $k => $v) {
                if ($v != '') {
                    $sql_cat = "INSERT INTO " . EVENTS_CATEGORY_REL_TABLE . " (event_id, cat_id) VALUES ('" . $event_id . "', '" . $v . "')";
                    //echo "$sql_cat <br>";
                    $wpdb->query($sql_cat);
                }
            }
        }
        $del_ppl = "DELETE FROM " . EVENTS_PERSONNEL_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($del_ppl);
        if (!empty($_REQUEST['event_person'])) {
            foreach ($_REQUEST['event_person'] as $k => $v) {
                if ($v != '') {
                    $sql_ppl = "INSERT INTO " . EVENTS_PERSONNEL_REL_TABLE . " (event_id, person_id) VALUES ('" . $event_id . "', '" . $v . "')";
                    //echo "$sql_ppl <br>";
                    $wpdb->query($sql_ppl);
                }
            }
        }
        $del_venues = "DELETE FROM " . EVENTS_VENUE_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($del_venues);
        if (!empty($_REQUEST['venue_id'])) {
            foreach ($_REQUEST['venue_id'] as $k => $v) {
                if ($v != '' && $v != 0) {
                    $sql_venues = "INSERT INTO " . EVENTS_VENUE_REL_TABLE . " (event_id, venue_id) VALUES ('" . $event_id . "', '" . $v . "')";
                    //echo "$sql_venues <br>";
                    $wpdb->query($sql_venues);
                }
            }
        }
        $del_discounts = "DELETE FROM " . EVENTS_DISCOUNT_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($del_discounts);
        if (!empty($_REQUEST['event_discount'])) {
            foreach ($_REQUEST['event_discount'] as $k => $v) {
                if ($v != '') {
                    $sql_discount = "INSERT INTO " . EVENTS_DISCOUNT_REL_TABLE . " (event_id, discount_id) VALUES ('" . $event_id . "', '" . $v . "')";
                    //echo "$sql_discount <br>";
                    $wpdb->query($sql_discount);
                }
            }
        }
        $del_times = "DELETE FROM " . EVENTS_START_END_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($del_times);
        if ($_REQUEST['start_time'] != '') {
            foreach ($_REQUEST['start_time'] as $k => $v) {
                if ($v != '') {
                    $time_qty = empty($_REQUEST['time_qty'][$k]) ? '0' : "'" . $_REQUEST['time_qty'][$k] . "'";
                    $sql_times = "INSERT INTO " . EVENTS_START_END_TABLE . " (event_id, start_time, end_time, reg_limit) VALUES ('" . $event_id . "', '" . event_date_display($v, 'H:i') . "', '" . event_date_display($_REQUEST['end_time'][$k], 'H:i') . "', " . $time_qty . ")";
                    //echo "$sql_times <br>";
                    $wpdb->query($sql_times);
                }
            }
        }
        $del_prices = "DELETE FROM " . EVENTS_PRICES_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($del_prices);
        if (!empty($_REQUEST['event_cost'])) {
            foreach ($_REQUEST['event_cost'] as $k => $v) {
                if ($v != '') {
                    $price_type = $_REQUEST['price_type'][$k] != '' ? $_REQUEST['price_type'][$k] : __('General Admission', 'event_espresso');
                    $member_price_type = !empty($_REQUEST['member_price_type'][$k]) ? $_REQUEST['member_price_type'][$k] : __('Members Admission', 'event_espresso');
                    $member_price = !empty($_REQUEST['member_price'][$k]) ? $_REQUEST['member_price'][$k] : $v;
                    $sql_prices = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, surcharge_type, price_type, member_price, member_price_type) VALUES ('" . $event_id . "', '" . $v . "', '" . $_REQUEST['surcharge'][$k] . "', '" . $_REQUEST['surcharge_type'][$k] . "', '" . $price_type . "', '" . $member_price . "', '" . $member_price_type . "')";
                    //echo "$sql_prices <br>";
                    $wpdb->query($sql_prices);
                }
            }
        } else {
            $sql_price = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, price_type, member_price, member_price_type) VALUES ('" . $event_id . "', '0.00', '0.00', '" . __('Free', 'event_espresso') . "', '0.00', '" . __('Free', 'event_espresso') . "')";
            if (!$wpdb->query($sql_price)) {
                $error = true;
            }
        }
        ############# MailChimp Integration ###############
        if (get_option('event_mailchimp_active') == 'true' && $espresso_premium == true) {
            MailChimpController::update_event_list_rel($event_id);
        }
        if (function_exists('espresso_fb_createevent') == 'true' && $espresso_premium == true) {
            espresso_fb_updateevent($event_id);
        }
        /// Create Event Post Code Here
        switch ($_REQUEST['create_post']) {
            case $_REQUEST['create_post'] == 'N':
                $sql = " SELECT * FROM " . EVENTS_DETAIL_TABLE;
                $sql .= " WHERE id = '" . $event_id . "' ";
                $wpdb->get_results($sql);
                $post_id = $wpdb->last_result[0]->post_id;
                if ($wpdb->num_rows > 0 && !empty($_REQUEST['delete_post']) && $_REQUEST['delete_post'] == 'Y') {
                    $sql = array('post_id' => '', 'post_type' => '');
                    $sql_data = array('%d', '%s');
                    $update_id = array('id' => $event_id);
                    $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
                    wp_delete_post($post_id, 'true');
                }
                break;
            case $_REQUEST['create_post'] == 'Y':
                $post_type = $_REQUEST['espresso_post_type'];
                if ($post_type == 'post') {
                    if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php") || file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php")) {
                        // Load message from template into message post variable
                        ob_start();
                        if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php")) {
                            require_once EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php";
                        } else {
                            require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php";
                        }
                        $post_content = ob_get_contents();
                        ob_end_clean();
                    } else {
                        _e('There was error finding a post template. Please verify your post templates are available.', 'event_espresso');
                    }
                } elseif ($post_type == 'espresso_event') {
                    ob_start();
                    echo $event_desc;
                    $post_content = ob_get_contents();
                    ob_end_clean();
                }
                $my_post = array();
                $sql = " SELECT * FROM " . EVENTS_DETAIL_TABLE;
                $sql .= " WHERE id = '" . $event_id . "' ";
                $wpdb->get_results($sql);
                $post_id = $wpdb->last_result[0]->post_id;
                $post_type = $_REQUEST['espresso_post_type'];
                if ($post_id > 0) {
                    $my_post['ID'] = $post_id;
                }
                $my_post['post_title'] = esc_html($_REQUEST['event']);
                $my_post['post_content'] = $post_content;
                $my_post['post_status'] = 'publish';
                $my_post['post_author'] = $_REQUEST['user'];
                $my_post['post_category'] = $_REQUEST['post_category'];
                //print_r ($my_post['post_category']);
                $my_post['tags_input'] = $_REQUEST['post_tags'];
                $my_post['post_type'] = $post_type;
                //print_r($my_post);
                // Insert the post into the database
                if ($post_id > 0) {
                    $post_id = wp_update_post($my_post);
                    update_post_meta($post_id, 'event_id', $event_id);
                    update_post_meta($post_id, 'event_identifier', $event_identifier);
                    update_post_meta($post_id, 'event_start_date', $start_date);
                    update_post_meta($post_id, 'event_end_date', $end_date);
                    update_post_meta($post_id, 'event_location', $event_location);
                    update_post_meta($post_id, 'virtual_url', $virtual_url);
                    update_post_meta($post_id, 'virtual_phone', $virtual_phone);
                    //
                    update_post_meta($post_id, 'event_address', $address);
                    update_post_meta($post_id, 'event_address2', $address2);
                    update_post_meta($post_id, 'event_city', $city);
                    update_post_meta($post_id, 'event_state', $state);
                    update_post_meta($post_id, 'event_country', $country);
                    update_post_meta($post_id, 'event_phone', $phone);
                    update_post_meta($post_id, 'venue_title', $venue_title);
                    update_post_meta($post_id, 'venue_url', $venue_url);
                    update_post_meta($post_id, 'venue_phone', $venue_phone);
                    update_post_meta($post_id, 'venue_image', $venue_image);
                    update_post_meta($post_id, 'event_externalURL', $externalURL);
                    update_post_meta($post_id, 'event_reg_limit', $reg_limit);
                    update_post_meta($post_id, 'event_start_time', time_to_24hr($start_time));
                    update_post_meta($post_id, 'event_end_time', time_to_24hr($end_time));
                    update_post_meta($post_id, 'event_registration_start', $registration_start);
                    update_post_meta($post_id, 'event_registration_end', $registration_end);
                    update_post_meta($post_id, 'event_registration_startT', $registration_startT);
                    update_post_meta($post_id, 'event_registration_endT', $registration_endT);
                    //update_post_meta( $post_id, 'timezone_string', $timezone_string );
                } else {
                    $post_id = wp_insert_post($my_post);
                    add_post_meta($post_id, 'event_id', $event_id);
                    add_post_meta($post_id, 'event_identifier', $event_identifier);
                    add_post_meta($post_id, 'event_start_date', $start_date);
                    add_post_meta($post_id, 'event_end_date', $end_date);
                    add_post_meta($post_id, 'event_location', $event_location);
                    add_post_meta($post_id, 'virtual_url', $virtual_url);
                    add_post_meta($post_id, 'virtual_phone', $virtual_phone);
                    //
                    add_post_meta($post_id, 'event_address', $address);
                    add_post_meta($post_id, 'event_address2', $address2);
                    add_post_meta($post_id, 'event_city', $city);
                    add_post_meta($post_id, 'event_state', $state);
                    add_post_meta($post_id, 'event_country', $country);
                    add_post_meta($post_id, 'event_phone', $phone);
                    add_post_meta($post_id, 'venue_title', $venue_title);
                    add_post_meta($post_id, 'venue_url', $venue_url);
                    add_post_meta($post_id, 'venue_phone', $venue_phone);
                    add_post_meta($post_id, 'venue_image', $venue_image);
                    add_post_meta($post_id, 'event_externalURL', $externalURL);
                    add_post_meta($post_id, 'event_reg_limit', $reg_limit);
                    add_post_meta($post_id, 'event_start_time', time_to_24hr($start_time));
                    add_post_meta($post_id, 'event_end_time', time_to_24hr($end_time));
                    add_post_meta($post_id, 'event_registration_start', $registration_start);
                    add_post_meta($post_id, 'event_registration_end', $registration_end);
                    add_post_meta($post_id, 'event_registration_startT', $registration_startT);
                    add_post_meta($post_id, 'event_registration_endT', $registration_endT);
                    //add_post_meta( $post_id, 'timezone_string', $timezone_string );
                }
                // Store the POST ID so it can be displayed on the edit page
                $sql = array('post_id' => $post_id, 'post_type' => $post_type);
                $sql_data = array('%d', '%s');
                $update_id = array('id' => $event_id);
                $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
                break;
        }
        ?>
        <div id="message" class="updated fade"><p><strong><?php 
        _e('Event details updated for', 'event_espresso');
        ?>
 <a href="<?php 
        echo espresso_reg_url($event_id);
        ?>
" target="_blank"><?php 
        echo stripslashes_deep($_REQUEST['event']);
        ?>
 for <?php 
        echo date("m/d/Y", strtotime($start_date));
        ?>
</a>.</strong></p></div>
        
        <?php 
        /*
         * Added for seating chart addon
         */
        if (isset($seating_chart_result) && $seating_chart_result === false) {
            ?>
        <p>Failed to associate new seating chart with this event. (Seats from current seating chart might have been used by some attendees)</p>
        <?php 
        }
        /*
         * End
         */
        ?>
   
        
        <?php 
    }
    /*
     * With the recursion of this function, additional recurring events will be updated
     */
    if (isset($recurrence_dates) && count($recurrence_dates) > 0 && $_POST['recurrence_apply_changes_to'] > 1) {
        //$recurrence_dates = array_shift($recurrence_dates); //Remove the first item from the array since it will be added after this recursion
        foreach ($recurrence_dates as $r_d) {
            if ($r_d['event_id'] != '' && count($r_d) > 2) {
                update_event(array('event_id' => $r_d['event_id'], 'event_identifier' => $r_d['event_identifier'], 'recurrence_id' => $r_d['recurrence_id'], 'recurrence_start_date' => $r_d['start_date'], 'recurrence_event_end_date' => $r_d['event_end_date'], 'registration_start' => $r_d['registration_start'], 'registration_end' => $r_d['registration_end'], 'visible_on' => $r_d['visible_on']));
            }
        }
    }
    /*
     * End recursion, as part of recurring events.
     */
}
Beispiel #19
0
 function event_espresso_add_attendees_to_db($event_id = NULL, $session_vars = NULL, $skip_check = FALSE)
 {
     //echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
     do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
     global $wpdb, $org_options, $espresso_premium;
     // check if user has already hit this page before ( ie: going back n forth thru reg process )
     if (is_null($session_vars)) {
         $SQL = "SELECT id FROM " . EVENTS_ATTENDEE_TABLE . " WHERE attendee_session=%s";
         $prev_sessions = $wpdb->get_col($wpdb->prepare($SQL, $_SESSION['espresso_session']['id']));
         if (!empty($prev_sessions)) {
             $_SESSION['espresso_session']['id'] = array();
             ee_init_session();
         }
     }
     $data_source = $_POST;
     $att_data_source = $_POST;
     $multi_reg = FALSE;
     $notifications = array('coupons' => '', 'groupons' => '');
     if (!is_null($event_id) && !is_null($session_vars)) {
         //event details, ie qty, price, start..
         $data_source = $session_vars['data'];
         //event attendee info ie name, questions....
         $att_data_source = $session_vars['event_attendees'];
         $multi_reg = TRUE;
     } else {
         $event_id = absint($data_source['event_id']);
     }
     $data_source['reg_form_nonce'] = isset($_POST['reg_form_nonce']) && !empty($_POST['reg_form_nonce']) ? $_POST['reg_form_nonce'] : NULL;
     wp_verify_nonce($data_source['reg_form_nonce']);
     $skip_check = $skip_check || isset($data_source['admin']) ? TRUE : FALSE;
     if (espresso_verify_recaptcha($skip_check)) {
         array_walk_recursive($data_source, 'wp_strip_all_tags');
         array_walk_recursive($att_data_source, 'wp_strip_all_tags');
         array_walk_recursive($data_source, 'espresso_apply_htmlentities');
         array_walk_recursive($att_data_source, 'espresso_apply_htmlentities');
         // Will be used for multi events to keep track of evant id change in the loop, for recording event total cost for each group
         static $temp_event_id = '';
         //using this var to keep track of the first attendee
         static $attendee_number = 1;
         static $loop_number = 1;
         static $total_cost = 0;
         static $primary_att_id = NULL;
         //		echo '<h1>$attendee_number : ' . $attendee_number . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h1>';
         //		printr( $data_source, '$data_source  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
         //		printr( $att_data_source, '$att_data_source  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
         if ($temp_event_id == '' || $temp_event_id != $event_id) {
             $temp_event_id = $event_id;
             $event_change = 1;
         } else {
             $event_change = 0;
         }
         $event_cost = isset($data_source['cost']) && $data_source['cost'] != '' ? $data_source['cost'] : 0.0;
         $final_price = $event_cost;
         $fname = isset($att_data_source['fname']) ? html_entity_decode(trim($att_data_source['fname']), ENT_QUOTES, 'UTF-8') : '';
         $lname = isset($att_data_source['lname']) ? html_entity_decode(trim($att_data_source['lname']), ENT_QUOTES, 'UTF-8') : '';
         $address = isset($att_data_source['address']) ? html_entity_decode(trim($att_data_source['address']), ENT_QUOTES, 'UTF-8') : '';
         $address2 = isset($att_data_source['address2']) ? html_entity_decode(trim($att_data_source['address2']), ENT_QUOTES, 'UTF-8') : '';
         $city = isset($att_data_source['city']) ? html_entity_decode(trim($att_data_source['city']), ENT_QUOTES, 'UTF-8') : '';
         $state = isset($att_data_source['state']) ? html_entity_decode(trim($att_data_source['state']), ENT_QUOTES, 'UTF-8') : '';
         $zip = isset($att_data_source['zip']) ? html_entity_decode(trim($att_data_source['zip']), ENT_QUOTES, 'UTF-8') : '';
         $phone = isset($att_data_source['phone']) ? html_entity_decode(trim($att_data_source['phone']), ENT_QUOTES, 'UTF-8') : '';
         $email = isset($att_data_source['email']) ? html_entity_decode(trim($att_data_source['email']), ENT_QUOTES, 'UTF-8') : '';
         $SQL = "SELECT question_groups, event_meta FROM " . EVENTS_DETAIL_TABLE . " WHERE id = %d";
         $questions = $wpdb->get_row($wpdb->prepare($SQL, $event_id));
         $event_meta = maybe_unserialize($questions->event_meta);
         $questions = maybe_unserialize($questions->question_groups);
         // Adding attenddee specific cost to events_attendee table
         if (isset($data_source['admin'])) {
             $attendee_quantity = 1;
             $final_price = $data_source['event_cost'];
             $orig_price = $data_source['event_cost'];
             $price_type = __('Admin', 'event_espresso');
             //echo '<h4>$orig_price : ' . $orig_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
             //echo '<h4>$final_price : ' . $final_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
         } elseif (isset($data_source['seat_id'])) {
             // Added for seating chart add-on
             // If a seat was selected then price of that seating will be used instead of event price
             $final_price = seating_chart::get_purchase_price($data_source['seat_id']);
             $orig_price = $data_source['cost'];
             //echo '<h4>$orig_price : ' . $orig_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
             //echo '<h4>$final_price : ' . $final_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
         } elseif (isset($att_data_source['price_id']) && !empty($att_data_source['price_id'])) {
             if ($att_data_source['price_id'] == 'free') {
                 $orig_price = 0.0;
                 $final_price = 0.0;
                 $price_type = __('Free Event', 'event_espresso');
             } else {
                 $orig_price = event_espresso_get_orig_price_and_surcharge($att_data_source['price_id']);
                 $final_price = isset($att_data_source['price_id']) ? event_espresso_get_final_price($att_data_source['price_id'], $event_id, $orig_price) : 0.0;
                 $price_type = isset($att_data_source['price_id']) ? espresso_ticket_information(array('type' => 'ticket', 'price_option' => $att_data_source['price_id'])) : '';
                 $surcharge = event_espresso_calculate_surcharge($orig_price->event_cost, $orig_price->surcharge, $orig_price->surcharge_type);
                 $orig_price = (double) number_format($orig_price->event_cost + $surcharge, 2, '.', '');
                 //					echo '<h4>$orig_price : ' . $orig_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                 //					echo '<h4>$final_price : ' . $final_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
             }
         } elseif (isset($data_source['price_select']) && $data_source['price_select'] == TRUE) {
             //Figure out if the person has registered using a price selection
             $price_options = explode('|', $data_source['price_option'], 2);
             $price_id = $price_options[0];
             $price_type = $price_options[1];
             $orig_price = event_espresso_get_orig_price_and_surcharge($price_id);
             $final_price = event_espresso_get_final_price($price_id, $event_id, $orig_price);
             $surcharge = event_espresso_calculate_surcharge($orig_price->event_cost, $orig_price->surcharge, $orig_price->surcharge_type);
             $orig_price = (double) number_format($orig_price->event_cost + $surcharge, 2, '.', '');
             //echo '<h4>$orig_price : ' . $orig_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
             //echo '<h4>$final_price : ' . $final_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
         } else {
             if ($data_source['price_id'] == 'free') {
                 $orig_price = 0.0;
                 $final_price = 0.0;
                 $price_type = __('Free Event', 'event_espresso');
             } else {
                 $orig_price = event_espresso_get_orig_price_and_surcharge($data_source['price_id']);
                 $final_price = isset($data_source['price_id']) ? event_espresso_get_final_price($data_source['price_id'], $event_id, $orig_price) : 0.0;
                 $price_type = isset($data_source['price_id']) ? espresso_ticket_information(array('type' => 'ticket', 'price_option' => $data_source['price_id'])) : '';
                 $surcharge = event_espresso_calculate_surcharge($orig_price->event_cost, $orig_price->surcharge, $orig_price->surcharge_type);
                 $orig_price = (double) number_format($orig_price->event_cost + $surcharge, 2, '.', '');
                 //echo '<h4>$orig_price : ' . $orig_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                 //echo '<h4>$final_price : ' . $final_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
             }
         }
         $final_price = apply_filters('filter_hook_espresso_attendee_cost', $final_price);
         $attendee_quantity = isset($data_source['num_people']) ? $data_source['num_people'] : 1;
         $coupon_code = '';
         //echo '<h4>$orig_price : ' . $orig_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
         //echo '<h4>$final_price : ' . $final_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
         if ($multi_reg) {
             $event_cost = $_SESSION['espresso_session']['grand_total'];
             //$coupon_code = $attendee_number == 1 ? $_SESSION['espresso_session']['event_espresso_coupon_code'] : '';
         }
         do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, 'line ' . __LINE__ . ' : attendee_cost=' . $final_price);
         $event_cost = apply_filters('filter_hook_espresso_cart_grand_total', $event_cost);
         //			$amount_pd = $attendee_number == 1 ? $event_cost : 0.00;
         $amount_pd = 0.0;
         //Check to see if the registration id already exists
         $incomplete_filter = !$multi_reg ? " AND payment_status ='Incomplete'" : '';
         $SQL = "SELECT attendee_session, id, registration_id FROM " . EVENTS_ATTENDEE_TABLE . " WHERE attendee_session =%s AND event_id = %d";
         $SQL .= $incomplete_filter;
         $check_sql = $wpdb->get_results($wpdb->prepare($SQL, $_SESSION['espresso_session']['id'], $event_id));
         $nmbr_of_regs = $wpdb->num_rows;
         //Check if the registration id has been created previously.
         $registration_id = empty($wpdb->last_result[0]->registration_id) ? apply_filters('filter_hook_espresso_registration_id', $event_id) : $wpdb->last_result[0]->registration_id;
         $txn_type = "";
         if (isset($data_source['admin'])) {
             $payment_status = "Completed";
             $payment = "Admin";
             $txn_type = __('Added by Admin', 'event_espresso');
             //$payment_date = date("m-d-Y");
             $payment_date = date(get_option('date_format'));
             $amount_pd = $data_source['event_cost'] != '' ? $data_source['event_cost'] : 0.0;
             $registration_id = uniqid('', true);
             $_SESSION['espresso_session']['id'] = uniqid('', true);
         } else {
             //print_r( $event_meta);
             $default_payment_status = $event_meta['default_payment_status'] != '' ? $event_meta['default_payment_status'] : $org_options['default_payment_status'];
             $payment_status = $multi_reg && $data_source['cost'] == 0.0 ? "Completed" : $default_payment_status;
             $payment = '';
         }
         $times_sql = "SELECT ese.start_time, ese.end_time, e.start_date, e.end_date ";
         $times_sql .= "FROM " . EVENTS_START_END_TABLE . " ese ";
         $times_sql .= "LEFT JOIN " . EVENTS_DETAIL_TABLE . " e ON ese.event_id = e.id WHERE ";
         $times_sql .= "e.id=%d";
         if (!empty($data_source['start_time_id'])) {
             $times_sql .= " AND ese.id=" . $data_source['start_time_id'];
         }
         $times = $wpdb->get_results($wpdb->prepare($times_sql, $event_id));
         foreach ($times as $time) {
             $start_time = $time->start_time;
             $end_time = $time->end_time;
             $start_date = $time->start_date;
             $end_date = $time->end_date;
         }
         //If we are using the number of attendees dropdown, add that number to the DB
         //echo $data_source['espresso_addtl_limit_dd'];
         if (isset($data_source['espresso_addtl_limit_dd'])) {
             $num_people = $data_source['num_people'];
         } elseif (isset($event_meta['additional_attendee_reg_info']) && $event_meta['additional_attendee_reg_info'] == 1) {
             $num_people = $data_source['num_people'];
         } else {
             $num_people = 1;
         }
         // check for coupon
         if (function_exists('event_espresso_process_coupon')) {
             if ($coupon_results = event_espresso_process_coupon($event_id, $final_price, $multi_reg)) {
                 //printr( $coupon_results, '$coupon_results  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
                 if ($coupon_results['valid']) {
                     $final_price = number_format($coupon_results['event_cost'], 2, '.', '');
                     $coupon_code = $coupon_results['code'];
                 }
                 if (!$multi_reg && !empty($coupon_results['msg'])) {
                     $notifications['coupons'] = $coupon_results['msg'];
                 }
             }
         }
         // check for groupon
         if (function_exists('event_espresso_process_groupon')) {
             if ($groupon_results = event_espresso_process_groupon($event_id, $final_price, $multi_reg)) {
                 //printr( $groupon_results, '$groupon_results  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
                 if ($groupon_results['valid']) {
                     $final_price = number_format($groupon_results['event_cost'], 2, '.', '');
                     $coupon_code = $groupon_results['code'];
                 }
                 if (!$multi_reg && !empty($groupon_results['msg'])) {
                     $notifications['groupons'] = $groupon_results['msg'];
                 }
             }
         }
         // check for groupon
         //			$use_groupon =  isset( $data_source['use_groupon'][ $event_id ] ) && function_exists( 'espresso_apply_goupon_to_attendee' ) ? $data_source['use_groupon'][ $event_id ] == 'Y' : 'N';
         //			if ( $use_groupon && isset( $data_source['groupon'] )) {
         //				if ( $new_att_price_data = espresso_apply_goupon_to_attendee( $event_id, $final_price, $data_source['groupon'] )) {
         //					extract( $new_att_price_data );
         //					$data_source['groupon'] = $groupon;
         //				}
         //			}
         $start_time = empty($start_time) ? '' : $start_time;
         $end_time = empty($end_time) ? '' : $end_time;
         $start_date = empty($start_date) ? '' : $start_date;
         $end_date = empty($end_date) ? '' : $end_date;
         $organization_name = empty($organization_name) ? '' : $organization_name;
         $country_id = empty($country_id) ? '' : $country_id;
         $payment_date = empty($payment_date) ? '' : $payment_date;
         $coupon_code = empty($coupon_code) ? '' : $coupon_code;
         $amount_pd = number_format((double) $amount_pd, 2, '.', '');
         $orig_price = number_format((double) $orig_price, 2, '.', '');
         $final_price = number_format((double) $final_price, 2, '.', '');
         $total_cost = $total_cost + $final_price;
         //echo '<h4>$amount_pd : ' . $amount_pd . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
         //echo '<h4>$orig_price : ' . $orig_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
         //echo '<h4>$final_price : ' . $final_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
         //echo '<h4>$total_cost : ' . $total_cost . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4><br /><br /><br />';
         //echo '<h4>$payment_status : ' . $payment_status . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4><br /><br /><br />';
         $columns_and_values = array('registration_id' => $registration_id, 'is_primary' => $attendee_number == 1 ? TRUE : FALSE, 'attendee_session' => $_SESSION['espresso_session']['id'], 'lname' => $lname, 'fname' => $fname, 'address' => $address, 'address2' => $address2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'email' => $email, 'phone' => $phone, 'payment' => $payment, 'txn_type' => $txn_type, 'coupon_code' => $coupon_code, 'event_time' => $start_time, 'end_time' => $end_time, 'start_date' => $start_date, 'end_date' => $end_date, 'price_option' => $price_type, 'organization_name' => $organization_name, 'country_id' => $country_id, 'payment_status' => $payment_status, 'payment_date' => $payment_date, 'event_id' => $event_id, 'quantity' => (int) $num_people, 'amount_pd' => $amount_pd, 'orig_price' => $orig_price, 'final_price' => $final_price);
         //			printr( $columns_and_values, '$columns_and_values  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
         $data_formats = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%f', '%f', '%f');
         // delete previous entries from this session in case user is jumping back n forth between pages during the reg process
         if ($nmbr_of_regs > 0 && $loop_number == 1) {
             if (!isset($data_source['admin'])) {
                 //Added for seating chart addon
                 $tmp_session = wp_strip_all_tags($_SESSION['espresso_session']['id']);
                 $SQL = "SELECT id, registration_id FROM " . EVENTS_ATTENDEE_TABLE . ' ';
                 $SQL .= "WHERE attendee_session = %s ";
                 $SQL .= $incomplete_filter;
                 if ($rem_attendee_ids = $wpdb->get_results($wpdb->prepare($SQL, $tmp_session))) {
                     foreach ($rem_attendee_ids as $v) {
                         if (defined('ESPRESSO_SEATING_CHART')) {
                             $SQL = "DELETE FROM " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . ' ';
                             $SQL .= "WHERE attendee_id = %d";
                             $wpdb->query($wpdb->prepare($SQL, $v->id));
                         }
                     }
                 }
                 $SQL = "DELETE t1, t2 FROM " . EVENTS_ATTENDEE_TABLE . "  t1 ";
                 $SQL .= "JOIN  " . EVENTS_ANSWER_TABLE . " t2 on t1.id = t2.attendee_id ";
                 $SQL .= "WHERE t1.attendee_session = %s ";
                 $SQL .= $incomplete_filter;
                 $wpdb->query($wpdb->prepare($SQL, $tmp_session));
             }
             //Added by Imon
             // First delete attempt might fail if there is no data in answer table. So, second attempt without joining answer table is taken bellow -
             $SQL = " DELETE FROM " . EVENTS_ATTENDEE_TABLE . ' ';
             $SQL .= "WHERE attendee_session = %s ";
             $SQL .= $incomplete_filter;
             $wpdb->query($wpdb->prepare($SQL, $tmp_session));
             // Clean up any attendee information from attendee_cost table where attendee is not available in attendee table
             event_espresso_cleanup_multi_event_registration_id_group_data();
         }
         $loop_number++;
         // save the attendee details - FINALLY !!!
         if (!$wpdb->insert(EVENTS_ATTENDEE_TABLE, $columns_and_values, $data_formats)) {
             $error = true;
         }
         $attendee_id = $wpdb->insert_id;
         // save attendee id for the primary attendee
         $primary_att_id = $attendee_number == 1 ? $attendee_id : FALSE;
         // Added for seating chart addon
         $booking_id = 0;
         if (defined('ESPRESSO_SEATING_CHART')) {
             if (seating_chart::check_event_has_seating_chart($event_id) !== false) {
                 if (isset($_POST['seat_id'])) {
                     $booking_id = seating_chart::parse_booking_info($_POST['seat_id']);
                     if ($booking_id > 0) {
                         seating_chart::confirm_a_seat($booking_id, $attendee_id);
                     }
                 }
             }
         }
         //Add a record for the primary attendee
         if ($attendee_number == 1) {
             $columns_and_values = array('attendee_id' => $primary_att_id, 'meta_key' => 'primary_attendee', 'meta_value' => 1);
             $data_formats = array('%s', '%s', '%s');
             if (!$wpdb->insert(EVENTS_ATTENDEE_META_TABLE, $columns_and_values, $data_formats)) {
                 $error = true;
             }
         }
         if (defined('EVENTS_MAILCHIMP_ATTENDEE_REL_TABLE') && $espresso_premium == true) {
             MailChimpController::list_subscribe($event_id, $attendee_id, $fname, $lname, $email);
         }
         //Defining the $base_questions variable in case there are no additional attendee questions
         $base_questions = $questions;
         //Since main attendee and additional attendees may have different questions,
         //$attendee_number check for 2 because is it statically set at 1 first and is incremented for the primary attendee above, hence 2
         $questions = $attendee_number > 1 && isset($event_meta['add_attendee_question_groups']) ? $event_meta['add_attendee_question_groups'] : $questions;
         add_attendee_questions($questions, $registration_id, $attendee_id, array('session_vars' => $att_data_source));
         //Add additional attendees to the database
         if ($event_meta['additional_attendee_reg_info'] > 1) {
             $questions = $event_meta['add_attendee_question_groups'];
             if (empty($questions)) {
                 $questions = $base_questions;
             }
             if (isset($att_data_source['x_attendee_fname'])) {
                 foreach ($att_data_source['x_attendee_fname'] as $k => $v) {
                     if (trim($v) != '' && trim($att_data_source['x_attendee_lname'][$k]) != '') {
                         // Added for seating chart addon
                         $seat_check = true;
                         $x_booking_id = 0;
                         if (defined('ESPRESSO_SEATING_CHART')) {
                             if (seating_chart::check_event_has_seating_chart($event_id) !== false) {
                                 if (!isset($att_data_source['x_seat_id'][$k]) || trim($att_data_source['x_seat_id'][$k]) == '') {
                                     $seat_check = false;
                                 } else {
                                     $x_booking_id = seating_chart::parse_booking_info($att_data_source['x_seat_id'][$k]);
                                     if ($x_booking_id > 0) {
                                         $seat_check = true;
                                     } else {
                                         $seat_check = false;
                                         //Keeps the system from adding an additional attndee if no seat is selected
                                     }
                                 }
                             }
                         }
                         if ($seat_check) {
                             $data = array('registration_id' => $registration_id, 'attendee_session' => $_SESSION['espresso_session']['id'], 'lname' => $att_data_source['x_attendee_lname'][$k], 'fname' => $v, 'email' => $att_data_source['x_attendee_email'][$k], 'address' => empty($att_data_source['x_attendee_address'][$k]) ? '' : $att_data_source['x_attendee_address'][$k], 'address2' => empty($att_data_source['x_attendee_address2'][$k]) ? '' : $att_data_source['x_attendee_address2'][$k], 'city' => empty($att_data_source['x_attendee_city'][$k]) ? '' : $att_data_source['x_attendee_city'][$k], 'state' => empty($att_data_source['x_attendee_state'][$k]) ? '' : $att_data_source['x_attendee_state'][$k], 'zip' => empty($att_data_source['x_attendee_zip'][$k]) ? '' : $att_data_source['x_attendee_zip'][$k], 'phone' => empty($att_data_source['x_attendee_phone'][$k]) ? '' : $att_data_source['x_attendee_phone'][$k], 'payment' => $payment, 'event_time' => $start_time, 'end_time' => $end_time, 'start_date' => $start_date, 'end_date' => $end_date, 'price_option' => $price_type, 'organization_name' => $organization_name, 'country_id' => $country_id, 'payment_status' => $payment_status, 'payment_date' => $payment_date, 'event_id' => $event_id, 'quantity' => (int) $num_people, 'amount_pd' => (double) 0.0, 'orig_price' => $orig_price, 'final_price' => $final_price);
                             $format = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%f', '%f', '%f');
                             $wpdb->insert(EVENTS_ATTENDEE_TABLE, $data, $format);
                             //Added by Imon
                             $ext_attendee_id = $wpdb->insert_id;
                             $mailchimp_attendee_id = $ext_attendee_id;
                             if (defined('EVENTS_MAILCHIMP_ATTENDEE_REL_TABLE') && $espresso_premium == true) {
                                 MailChimpController::list_subscribe($event_id, $mailchimp_attendee_id, $v, $att_data_source['x_attendee_lname'][$k], $att_data_source['x_attendee_email'][$k]);
                             }
                             //Added by Imon
                             $ext_att_data_source = array('registration_id' => $registration_id, 'attendee_session' => $_SESSION['espresso_session']['id'], 'lname' => $att_data_source['x_attendee_lname'][$k], 'fname' => $v, 'email' => $att_data_source['x_attendee_email'][$k], 'address' => empty($att_data_source['x_attendee_address'][$k]) ? '' : $att_data_source['x_attendee_address'][$k], 'address2' => empty($att_data_source['x_attendee_address2'][$k]) ? '' : $att_data_source['x_attendee_address2'][$k], 'city' => empty($att_data_source['x_attendee_city'][$k]) ? '' : $att_data_source['x_attendee_city'][$k], 'state' => empty($att_data_source['x_attendee_state'][$k]) ? '' : $att_data_source['x_attendee_state'][$k], 'zip' => empty($att_data_source['x_attendee_zip'][$k]) ? '' : $att_data_source['x_attendee_zip'][$k], 'phone' => empty($att_data_source['x_attendee_phone'][$k]) ? '' : $att_data_source['x_attendee_phone'][$k], 'payment' => $payment, 'amount_pd' => (double) 0.0, 'event_time' => $start_time, 'end_time' => $end_time, 'start_date' => $start_date, 'end_date' => $end_date, 'price_option' => $price_type, 'organization_name' => $organization_name, 'country_id' => $country_id, 'payment_status' => $payment_status, 'payment_date' => $payment_date, 'event_id' => $event_id, 'quantity' => (int) $num_people);
                             if (!is_array($questions) && !empty($questions)) {
                                 $questions = unserialize($questions);
                             }
                             $questions_in = '';
                             foreach ($questions as $g_id) {
                                 $questions_in .= $g_id . ',';
                             }
                             $questions_in = substr($questions_in, 0, -1);
                             $SQL = "SELECT q.*, qg.group_name FROM " . EVENTS_QUESTION_TABLE . " q ";
                             $SQL .= "JOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id ";
                             $SQL .= "JOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id ";
                             $SQL .= "WHERE qgr.group_id in ( {$questions_in} ) ";
                             $SQL .= "ORDER BY q.id ASC";
                             $questions_list = $wpdb->get_results($wpdb->prepare($SQL, NULL));
                             foreach ($questions_list as $question_list) {
                                 if ($question_list->system_name != '') {
                                     $ext_att_data_source[$question_list->system_name] = $att_data_source['x_attendee_' . $question_list->system_name][$k];
                                 } else {
                                     $ext_att_data_source[$question_list->question_type . '_' . $question_list->id] = $att_data_source['x_attendee_' . $question_list->question_type . '_' . $question_list->id][$k];
                                 }
                             }
                             echo add_attendee_questions($questions, $registration_id, $ext_attendee_id, array('session_vars' => $ext_att_data_source));
                         }
                         // Added for seating chart addon
                         if (defined('ESPRESSO_SEATING_CHART')) {
                             if (seating_chart::check_event_has_seating_chart($event_id) !== false && $x_booking_id > 0) {
                                 seating_chart::confirm_a_seat($x_booking_id, $ext_attendee_id);
                             }
                         }
                     }
                 }
             }
         }
         //Add member data if needed
         if (defined('EVENTS_MEMBER_REL_TABLE')) {
             require_once EVENT_ESPRESSO_MEMBERS_DIR . "member_functions.php";
             //Load Members functions
             require EVENT_ESPRESSO_MEMBERS_DIR . "user_vars.php";
             //Load Members functions
             if ($userid != 0) {
                 event_espresso_add_user_to_event($event_id, $userid, $attendee_id);
             }
         }
         $attendee_number++;
         if (isset($data_source['admin'])) {
             return $attendee_id;
         }
         //This shows the payment page
         if (!$multi_reg) {
             return events_payment_page($attendee_id, $notifications);
         }
         return array('registration_id' => $registration_id, 'notifications' => $notifications);
     }
 }
<?php

global $wpdb;
$msg = "";
$msg = "Can not add a seat becamse seating chart doens't exists.";
$seating_chart_id = 0;
$seating_chart = null;
if (isset($_REQUEST['seating_chart_id'])) {
    $seating_chart_id = $_REQUEST['seating_chart_id'];
    $seating_chart = $wpdb->get_row("select * from " . EVENTS_SEATING_CHART_TABLE . " where id = {$seating_chart_id} ");
    if ($seating_chart != NULL) {
        $msg = "";
        if (isset($_POST['insert_seat'])) {
            $cls_seating_chart = new seating_chart();
            $result = $cls_seating_chart->insert_seat($seating_chart_id, $_POST);
            if ($result !== false) {
                $msg = "Seat created";
            } else {
                $msg = "Error: [" . mysql_errno() . "] - " . mysql_error();
            }
        }
    }
} else {
    echo "Sorry no seating chart was selected";
    exit;
}
?>

<!-- START: Step Two: Fluid Left  -->
<div class="wrap">
    <div id="icon-options-event" class="icon32"></div>
        do_action('action_hook_espresso_registration_page_top', $event_id, $event_meta, $all_meta);
        ?>
	<div class="event_espresso_form_wrapper">
		<form method="post" action="<?php 
        echo get_permalink($event_page_id);
        ?>
" id="registration_form">
	<?php 
        //This hides the date/times and location when usign custom post types or the ESPRESSO_REG_FORM shortcode
        if ($reg_form_only == false) {
            do_action('action_hook_espresso_social_display_buttons', $event_id);
            if ($display_reg_form == 'Y') {
                // Added for seating chart addon
                $display_price_dropdown = TRUE;
                if (defined('ESPRESSO_SEATING_CHART')) {
                    $seating_chart_id = seating_chart::check_event_has_seating_chart($event_id);
                    if ($seating_chart_id !== FALSE) {
                        $display_price_dropdown = FALSE;
                    }
                }
                if ($display_price_dropdown == TRUE) {
                    $price_label = '<span class="section-title">' . __('Choose an Option: ', 'event_espresso') . '</span>';
                    ?>
						<p class="event_prices">
							<?php 
                    do_action('espresso_price_select', $event_id, array('show_label' => TRUE, 'label' => $price_label));
                    ?>
						</p>
	<?php 
                } else {
                    ?>
function espresso_ticket_launch($attendee_id = 0, $registration_id = 0)
{
    global $wpdb, $org_options;
    $data = new stdClass();
    //Make sure we have attendee data
    if ($attendee_id == 0 || $registration_id == 0) {
        return;
    }
    //Get the event record
    $sql = "SELECT ed.*, et.css_file, et.template_file, et.ticket_content, et.ticket_logo_url ";
    isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ? $sql .= ", v.id venue_id, v.name venue_name, v.address venue_address, v.address2 venue_address2, v.city venue_city, v.state venue_state, v.zip venue_zip, v.country venue_country, v.meta venue_meta " : '';
    $sql .= " FROM " . EVENTS_DETAIL_TABLE . " ed ";
    isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ? $sql .= " LEFT JOIN " . EVENTS_VENUE_REL_TABLE . " r ON r.event_id = ed.id LEFT JOIN " . EVENTS_VENUE_TABLE . " v ON v.id = r.venue_id " : '';
    $sql .= " JOIN " . EVENTS_ATTENDEE_TABLE . " ea ON ea.event_id=ed.id ";
    $sql .= " LEFT JOIN " . EVENTS_TICKET_TEMPLATES . " et ON et.id=ed.ticket_id ";
    $sql .= " WHERE ea.id = '" . $attendee_id . "' AND ea.registration_id = '" . $registration_id . "' ";
    //echo $sql;
    $data->event = $wpdb->get_row($sql, OBJECT);
    //Get the attendee record
    $sql = "SELECT ea.* FROM " . EVENTS_ATTENDEE_TABLE . " ea WHERE ea.id = '" . $attendee_id . "' AND ea.registration_id = '" . $registration_id . "' ";
    $data->attendee = $wpdb->get_row($sql, OBJECT);
    if (empty($data->attendee)) {
        //echo 'Invalid data supplied.';
        return;
    }
    //Get the primary/first attendee
    $data->primary_attendee = espresso_is_primary_attendee($data->attendee->id) == true ? true : false;
    //unserialize the event meta
    $data->event->event_meta = unserialize($data->event->event_meta);
    //Get the registration date
    $data->attendee->registration_date = $data->attendee->date;
    //Get the CSS file
    $data->event->css_file = !empty($data->event->css_file) && $data->event->css_file > '0' ? $data->event->css_file : 'simple.css';
    //echo $data->event->css_file;
    //Get the HTML file
    $data->event->template_file = !empty($data->event->template_file) && $data->event->template_file > '0' ? $data->event->template_file : 'index.php';
    //Venue information
    if (isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y') {
        $data->event->venue_id = !empty($data->event->venue_id) ? $data->event->venue_id : '';
        $data->event->venue_name = !empty($data->event->venue_name) ? $data->event->venue_name : '';
        $data->event->address = !empty($data->event->venue_address) ? $data->event->venue_address : '';
        $data->event->address2 = !empty($data->event->venue_address2) ? $data->event->venue_address2 : '';
        $data->event->city = !empty($data->event->venue_city) ? $data->event->venue_city : '';
        $data->event->state = !empty($data->event->venue_state) ? $data->event->venue_state : '';
        $data->event->zip = !empty($data->event->venue_zip) ? $data->event->venue_zip : '';
        $data->event->country = !empty($data->event->venue_country) ? $data->event->venue_country : '';
        $data->event->venue_meta = !empty($data->event->venue_meta) ? unserialize($data->event->venue_meta) : '';
    } else {
        $data->event->venue_name = !empty($data->event->venue_title) ? $data->event->venue_title : '';
    }
    //Create the Gravatar image
    $data->gravatar = '<img src="' . espresso_get_gravatar($data->attendee->email, $size = '100', $default = 'http://www.gravatar.com/avatar/') . '" alt="Gravatar">';
    //Google map IMAGE creation
    $data->event->google_map_image = espresso_google_map_link(array('id' => $data->event->venue_id, 'address' => $data->event->address, 'city' => $data->event->city, 'state' => $data->event->state, 'zip' => $data->event->zip, 'country' => $data->event->country, 'type' => 'map'));
    //Google map LINK creation
    $data->event->google_map_link = espresso_google_map_link(array('address' => $data->event->address, 'city' => $data->event->city, 'state' => $data->event->state, 'zip' => $data->event->zip, 'country' => $data->event->country, 'type' => 'text'));
    //Create the logo
    $data->event->ticket_logo_image = '';
    $data->event->ticket_logo_url = empty($data->event->ticket_logo_url) ? $org_options['default_logo_url'] : $data->event->ticket_logo_url;
    if (!empty($data->event->ticket_logo_url)) {
        $image_size = getimagesize($data->event->ticket_logo_url);
        $data->event->ticket_logo_image = '<img src="' . $data->event->ticket_logo_url . '" ' . $image_size[3] . ' alt="logo" /> ';
    }
    //Create the QR Code image
    $data->qr_code = espresso_ticket_qr_code(array('attendee_id' => $data->attendee->id, 'event_name' => stripslashes_deep($data->event->event_name), 'attendee_first' => $data->attendee->fname, 'attendee_last' => $data->attendee->lname, 'registration_id' => $data->attendee->registration_id, 'event_code' => $data->event->event_code, 'ticket_type' => $data->attendee->price_option, 'event_time' => $data->attendee->event_time, 'final_price' => $data->attendee->final_price));
    //Build the seating assignment
    $seatingchart_tag = '';
    if (defined("ESPRESSO_SEATING_CHART")) {
        if (class_exists("seating_chart")) {
            if (seating_chart::check_event_has_seating_chart($data->attendee->event_id)) {
                $rs = $wpdb->get_row("select scs.* from " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " sces inner join " . EVENTS_SEATING_CHART_SEAT_TABLE . " scs on sces.seat_id = scs.id where sces.attendee_id = " . $attendee_id);
                if ($rs !== NULL) {
                    $data->attendee->seatingchart_tag = $rs->custom_tag . " " . $rs->seat . " " . $rs->row;
                }
            }
        }
    }
    //Build the ticket name
    $ticket_name = sanitize_title_with_dashes($data->attendee->id . ' ' . $data->attendee->fname . ' ' . $data->attendee->lname);
    //Get the HTML as an object
    ob_start();
    if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . "tickets/templates/index.php")) {
        require_once EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/templates/' . $data->event->template_file;
    } else {
        require_once 'templates/' . $data->event->template_file;
    }
    $content = ob_get_clean();
    $content = espresso_replace_ticket_shortcodes($content, $data);
    //Check if debugging or mobile is set
    if (isset($_REQUEST['pdf']) && $_REQUEST['pdf'] == true) {
        //Create the PDF
        define('DOMPDF_ENABLE_REMOTE', true);
        require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'tpc/dompdf/dompdf_config.inc.php';
        $dompdf = new DOMPDF();
        $dompdf->load_html($content);
        //$dompdf->set_paper('A4', 'landscape');
        $dompdf->render();
        $dompdf->stream($ticket_name . ".pdf", array("Attachment" => false));
        exit(0);
    }
    echo $content;
    exit(0);
}
function update_event($recurrence_arr = array())
{
    //print_r($_REQUEST);
    global $wpdb, $org_options, $current_user, $espresso_premium;
    //Security check using nonce
    if (empty($_POST['nonce_verify_update_event']) || !wp_verify_nonce($_POST['nonce_verify_update_event'], 'espresso_verify_update_event_nonce')) {
        if ($recurrence_arr['bypass_nonce'] == FALSE) {
            print '<h3 class="error">' . __('Sorry, there was a security error and your event was not updated.', 'event_espresso') . '</h3>';
            return;
        }
    }
    $wpdb->show_errors();
    /*
     * Begin Recurrence handling
     *
     * Will clean up in V 1.2.0
     *
     */
    if (defined('EVENT_ESPRESSO_RECURRENCE_TABLE')) {
        require_once EVENT_ESPRESSO_RECURRENCE_FULL_PATH . "functions/re_functions.php";
        if ($_POST['recurrence_id'] > 0) {
            /*
             * If the array is empty, then find the recurring dates
             */
            if (count($recurrence_arr) == 0) {
                // Prepare the parameters array for use with various RE functions
                $re_params = array('start_date' => !empty($_POST['recurrence_start_date']) ? sanitize_text_field($_POST['recurrence_start_date']) : '', 'event_end_date' => !empty($_POST['recurrence_event_end_date']) ? sanitize_text_field($_POST['recurrence_event_end_date']) : '', 'end_date' => !empty($_POST['recurrence_end_date']) ? sanitize_text_field($_POST['recurrence_end_date']) : '', 'registration_start' => !empty($_POST['recurrence_regis_start_date']) ? sanitize_text_field($_POST['recurrence_regis_start_date']) : '', 'registration_end' => !empty($_POST['recurrence_regis_end_date']) ? sanitize_text_field($_POST['recurrence_regis_end_date']) : '', 'frequency' => !empty($_POST['recurrence_frequency']) ? sanitize_text_field($_POST['recurrence_frequency']) : '', 'interval' => !empty($_POST['recurrence_interval']) ? sanitize_text_field($_POST['recurrence_interval']) : '', 'recurrence_type' => !empty($_POST['recurrence_type']) ? sanitize_text_field($_POST['recurrence_type']) : '', 'weekdays' => !empty($_POST['recurrence_weekday']) ? $_POST['recurrence_weekday'] : '', 'repeat_by' => !empty($_POST['recurrence_repeat_by']) ? $_POST['recurrence_repeat_by'] : '', 'recurrence_manual_dates' => !empty($_POST['recurrence_manual_dates']) ? $_POST['recurrence_manual_dates'] : '', 'recurrence_manual_end_dates' => !empty($_POST['recurrence_manual_end_dates']) ? $_POST['recurrence_manual_end_dates'] : '', 'recurrence_id' => !empty($_POST['recurrence_id']) ? $_POST['recurrence_id'] : '', 'recurrence_regis_date_increment' => !empty($_POST['recurrence_regis_date_increment']) ? $_POST['recurrence_regis_date_increment'] : '');
                //$re_params['adding_to_db'] = 'Y';
                //Has the form been modified
                $recurrence_form_modified = recurrence_form_modified($re_params);
                //echo ($recurrence_form_modified) ? "Yes" : 'No';
                if ($_POST['recurrence_apply_changes_to'] == 2) {
                    //Update all events in the series based on recurrence id
                    $recurrence_dates = $_POST['recurrence_type'] == 'm' ? find_recurrence_manual_dates($re_params) : find_recurrence_dates($re_params);
                    $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE recurrence_id = %d AND NOT event_status = 'D'";
                } else {
                    //Update this and upcoming events based on recurrence id and start_date >=start_date
                    $re_params['start_date'] = sanitize_text_field($_POST['start_date']);
                    $recurrence_dates = find_recurrence_dates($re_params);
                    $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE start_date >='" . sanitize_text_field($_POST['start_date']) . "' AND recurrence_id = %d and NOT event_status = 'D' ";
                }
                //Recurrence Form modified and changes need to apply to all
                if ($recurrence_form_modified && $_POST['recurrence_apply_changes_to'] > 1) {
                    //Update the recurrence table record with the new RE selections
                    update_recurrence_master_record();
                    /*
                     * Delete the records that don't belong in the formula
                     */
                    if (count($recurrence_dates) > 0) {
                        $delete_in = '';
                        foreach ($recurrence_dates as $k => $v) {
                            $delete_in .= "'" . $k . "',";
                        }
                        $delete_in = substr($delete_in, 0, -1);
                    }
                    if ($_POST['recurrence_apply_changes_to'] == 2) {
                        //Update all events in the series based on recurrence id
                        //$DEL_SQL = 'UPDATE ' . EVENTS_DETAIL_TABLE . " SET event_status = 'D' WHERE start_date NOT IN (" . $delete_in . ") AND recurrence_id = " . $_POST['recurrence_id'];
                        $DEL_SQL = 'DELETE EDT, EAT FROM ' . EVENTS_DETAIL_TABLE . " EDT\n                            LEFT JOIN " . EVENTS_ATTENDEE_TABLE . " EAT\n                                ON EDT.id = EAT.event_id\n                            WHERE EAT.id IS NULL\n                            AND EDT.start_date NOT IN (" . $delete_in . ")\n                            AND recurrence_id = " . sanitize_text_field($_POST['recurrence_id']);
                        $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE recurrence_id = %d and NOT event_status = 'D' ORDER BY start_date";
                    } else {
                        $DEL_SQL = 'DELETE EDT, EAT FROM ' . EVENTS_DETAIL_TABLE . " EDT\n                            LEFT JOIN " . EVENTS_ATTENDEE_TABLE . " EAT\n                                ON EDT.id = EAT.event_id\n                            WHERE EAT.id IS NULL\n                            AND EDT.start_date >='" . esc_sql(sanitize_text_field($_POST['start_date'])) . "'\n                            AND EDT.start_date NOT IN (" . $delete_in . ")\n                            AND recurrence_id = " . $_POST['recurrence_id'];
                        $UPDATE_SQL = "SELECT id,start_date,event_identifier FROM " . EVENTS_DETAIL_TABLE . " WHERE start_date >='" . sanitize_text_field($_POST['start_date']) . "' AND recurrence_id = %d AND NOT event_status = 'D'  ORDER BY start_date";
                    }
                    if ($delete_in != '') {
                        $wpdb->query($wpdb->prepare($DEL_SQL, NULL));
                    }
                    /*
                     * Add the new records based on the new formula
                     * The $recurrence_dates array will contain the new dates
                     */
                    if (!function_exists('add_event_to_db')) {
                        require_once 'insert_event.php';
                    }
                    foreach ($recurrence_dates as $k => $v) {
                        $result = $wpdb->get_row($wpdb->prepare("SELECT ID FROM " . EVENTS_DETAIL_TABLE . " WHERE recurrence_id = %d and start_date = %s and NOT event_status = 'D'", array($_POST['recurrence_id'], $k)));
                        if ($wpdb->num_rows == 0) {
                            add_event_to_db(array('recurrence_id' => sanitize_text_field($_POST['recurrence_id']), 'recurrence_start_date' => $v['start_date'], 'recurrence_event_end_date' => $v['event_end_date'], 'recurrence_end_date' => $v['start_date'], 'registration_start' => $v['registration_start'], 'registration_end' => $v['registration_end'], 'bypass_nonce' => TRUE));
                        } else {
                        }
                    }
                    /*
                     * Find all the event ids in the series and feed into the $recurrence_dates array
                     * This array will be used at the end of this document to invoke the recursion of update_event function so all the events in the series
                     * can be updated with the information.
                     */
                }
                $result = $wpdb->get_results($wpdb->prepare($UPDATE_SQL, array(sanitize_text_field($_POST['recurrence_id']))));
                foreach ($result as $row) {
                    if ($row->start_date != '') {
                        $recurrence_dates[$row->start_date]['event_id'] = $row->id;
                        $recurrence_dates[$row->start_date]['event_identifier'] = $row->event_identifier;
                    }
                }
            }
        }
    }
    //  echo_f('rd',$recurrence_dates);
    if (defined('EVENT_ESPRESSO_RECURRENCE_MODULE_ACTIVE') && !empty($_POST['recurrence']) && $_POST['recurrence'] == 'Y' && count($recurrence_arr) == 0 && $_POST['recurrence_apply_changes_to'] > 1) {
        //skip the first update
    } else {
        //Filters the event description based on user level
        $user_access = apply_filters('filter_hook_espresso_event_unfiltered_description', current_user_can('administrator'));
        $_REQUEST['event_desc'] = is_admin() || $user_access ? $_REQUEST['event_desc'] : apply_filters('filter_hook_espresso_event_wp_kses_post_description', wp_kses_post($_REQUEST['event_desc']));
        $event_meta = array();
        //will be used to hold event meta data
        $event_id = array_key_exists('event_id', $recurrence_arr) ? $recurrence_arr['event_id'] : (int) $_REQUEST['event_id'];
        $event_name = sanitize_text_field($_REQUEST['event']);
        $event_desc = !empty($_REQUEST['event_desc']) ? $_REQUEST['event_desc'] : '';
        $display_desc = sanitize_text_field($_REQUEST['display_desc']);
        $display_reg_form = sanitize_text_field($_REQUEST['display_reg_form']);
        $externalURL = !empty($_REQUEST['externalURL']) ? esc_html($_REQUEST['externalURL']) : '';
        $reg_limit = (int) $_REQUEST['reg_limit'];
        $allow_multiple = $_REQUEST['allow_multiple'];
        $overflow_event_id = empty($_REQUEST['overflow_event_id']) ? '0' : (int) $_REQUEST['overflow_event_id'];
        $allow_overflow = empty($_REQUEST['allow_overflow']) ? 'N' : sanitize_text_field($_REQUEST['allow_overflow']);
        $additional_limit = !empty($_REQUEST['additional_limit']) && $_REQUEST['additional_limit'] > 0 ? (int) $_REQUEST['additional_limit'] : '5';
        $member_only = empty($_REQUEST['member_only']) ? 'N' : sanitize_text_field($_REQUEST['member_only']);
        $is_active = !empty($_REQUEST['is_active']) ? sanitize_text_field($_REQUEST['is_active']) : 'Y';
        $event_status = !empty($_REQUEST['event_status']) ? sanitize_text_field($_REQUEST['event_status']) : 'A';
        //Get the first instance of the start and end times
        $start_time = sanitize_text_field($_REQUEST['start_time'][0]);
        $end_time = sanitize_text_field($_REQUEST['end_time'][0]);
        // Add registration times
        $registration_startT = event_date_display(sanitize_text_field($_REQUEST['registration_startT']), 'H:i');
        $registration_endT = event_date_display(sanitize_text_field($_REQUEST['registration_endT']), 'H:i');
        //Add timezone
        $timezone_string = empty($_REQUEST['timezone_string']) ? '' : sanitize_text_field($_REQUEST['timezone_string']);
        //Early discounts
        $early_disc = !empty($_REQUEST['early_disc']) ? sanitize_text_field($_REQUEST['early_disc']) : '';
        $early_disc_date = !empty($_REQUEST['early_disc_date']) ? sanitize_text_field($_REQUEST['early_disc_date']) : '';
        $early_disc_percentage = !empty($_REQUEST['early_disc_percentage']) ? sanitize_text_field($_REQUEST['early_disc_percentage']) : '';
        $conf_mail = esc_html($_REQUEST['conf_mail']);
        $use_coupon_code = !empty($_REQUEST['use_coupon_code']) ? sanitize_text_field($_REQUEST['use_coupon_code']) : '';
        $alt_email = isset($_REQUEST['alt_email']) && !empty($_REQUEST['alt_email']) ? sanitize_text_field($_REQUEST['alt_email']) : '';
        $send_mail = sanitize_text_field($_REQUEST['send_mail']);
        $email_id = isset($_REQUEST['email_name']) ? (int) $_REQUEST['email_name'] : '0';
        $ticket_id = isset($_REQUEST['ticket_id']) ? (int) $_REQUEST['ticket_id'] : '0';
        $event_category = empty($_REQUEST['event_category']) ? '' : serialize(sanitize_text_field($_REQUEST['event_category']));
        $event_discount = empty($_REQUEST['event_discount']) ? '' : serialize(sanitize_text_field($_REQUEST['event_discount']));
        $registration_start = array_key_exists('registration_start', $recurrence_arr) ? $recurrence_arr['registration_start'] : sanitize_text_field($_REQUEST['registration_start']);
        $registration_end = array_key_exists('registration_end', $recurrence_arr) ? $recurrence_arr['registration_end'] : sanitize_text_field($_REQUEST['registration_end']);
        $start_date = array_key_exists('recurrence_start_date', $recurrence_arr) ? $recurrence_arr['recurrence_start_date'] : (empty($_REQUEST['start_date']) ? $_REQUEST['recurrence_start_date'] : sanitize_text_field($_REQUEST['start_date']));
        $end_date = array_key_exists('recurrence_event_end_date', $recurrence_arr) ? $recurrence_arr['recurrence_event_end_date'] : (empty($_REQUEST['end_date']) ? sanitize_text_field($_REQUEST['recurrence_start_date']) : sanitize_text_field($_REQUEST['end_date']));
        $question_groups = serialize($_REQUEST['question_groups']);
        $add_attendee_question_groups = empty($_REQUEST['add_attendee_question_groups']) ? '' : $_REQUEST['add_attendee_question_groups'];
        //Venue Information
        $venue_title = isset($_REQUEST['venue_title']) ? sanitize_text_field($_REQUEST['venue_title']) : '';
        $venue_url = isset($_REQUEST['venue_url']) ? sanitize_text_field($_REQUEST['venue_url']) : '';
        $venue_phone = isset($_REQUEST['venue_phone']) ? sanitize_text_field($_REQUEST['venue_phone']) : '';
        $venue_image = isset($_REQUEST['venue_image']) ? sanitize_text_field($_REQUEST['venue_image']) : '';
        //Virtual location
        $virtual_url = isset($_REQUEST['virtual_url']) ? sanitize_text_field($_REQUEST['virtual_url']) : '';
        $virtual_phone = isset($_REQUEST['virtual_phone']) ? sanitize_text_field($_REQUEST['virtual_phone']) : '';
        //Address/venue information
        $address = !empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '';
        $address2 = !empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '';
        $city = !empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '';
        $state = !empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : '';
        $zip = !empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '';
        $country = !empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : '';
        $phone = !empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '';
        $event_location = '';
        if (!empty($address)) {
            $event_location .= $address . ' ';
        }
        if (!empty($address2)) {
            $event_location .= '<br />' . $address2;
        }
        if (!empty($city)) {
            $event_location .= '<br />' . $city;
        }
        if (!empty($state)) {
            $event_location .= ', ' . $state;
        }
        if (!empty($zip)) {
            $event_location .= ', ' . $state;
        }
        if (!empty($country)) {
            $event_location .= '<br />' . $country;
        }
        if (isset($reg_limit) && empty($reg_limit)) {
            $reg_limit = 999999;
        }
        $event_meta['default_payment_status'] = !empty($_REQUEST['default_payment_status']) ? sanitize_text_field($_REQUEST['default_payment_status']) : '';
        $event_meta['venue_id'] = empty($_REQUEST['venue_id']) ? '' : (int) $_REQUEST['venue_id'][0];
        $event_meta['additional_attendee_reg_info'] = !empty($_REQUEST['additional_attendee_reg_info']) ? sanitize_text_field($_REQUEST['additional_attendee_reg_info']) : '';
        $event_meta['add_attendee_question_groups'] = $add_attendee_question_groups;
        $event_meta['date_submitted'] = sanitize_text_field($_REQUEST['date_submitted']);
        //Added for seating chart addon
        if (isset($_REQUEST['seating_chart_id'])) {
            $cls_seating_chart = new seating_chart();
            $seating_chart_result = $cls_seating_chart->associate_event_seating_chart((int) $_REQUEST['seating_chart_id'], $event_id);
            $tmp_seating_chart_id = (int) $_REQUEST['seating_chart_id'];
            if ($tmp_seating_chart_id > 0) {
                if ($seating_chart_result === false) {
                    $tmp_seating_chart_row = $wpdb->get_row($wpdb->prepare("select seating_chart_id from " . EVENTS_SEATING_CHART_EVENT_TABLE . " where event_id = {$event_id}", NULL));
                    if ($tmp_seating_chart_row !== NULL) {
                        $tmp_seating_chart_id = $tmp_seating_chart_row->seating_chart_id;
                    } else {
                        $tmp_seating_chart_id = 0;
                    }
                }
                if ($_REQUEST['allow_multiple'] == 'Y' && isset($_REQUEST['seating_chart_id']) && $tmp_seating_chart_id > 0) {
                    $event_meta['additional_attendee_reg_info'] = 3;
                }
            }
        }
        //Process thumbnail image
        $event_thumbnail_url = '';
        if (isset($_REQUEST['upload_image']) && !empty($_REQUEST['upload_image'])) {
            $event_meta['event_thumbnail_url'] = sanitize_text_field($_REQUEST['upload_image']);
            $event_thumbnail_url = sanitize_text_field($event_meta['event_thumbnail_url']);
        }
        if (!empty($_REQUEST['emeta'])) {
            foreach ($_REQUEST['emeta'] as $k => $v) {
                $event_meta[$v] = sanitize_text_field($_REQUEST['emetad'][$k]);
            }
        }
        //Filter to update the event meta as needed
        $event_meta = apply_filters('filter_hook_espresso_update_event_update_meta', $event_meta, $event_id);
        //print_r($_REQUEST['emeta'] );
        $event_meta = serialize($event_meta);
        ############ Added by wp-developers ######################
        $require_pre_approval = 0;
        if (isset($_REQUEST['require_pre_approval'])) {
            $require_pre_approval = sanitize_text_field($_REQUEST['require_pre_approval']);
        }
        ################# END #################
        //When adding colums to the following arrays, be sure both arrays have equal values.
        $sql = array('event_name' => $event_name, 'event_desc' => $event_desc, 'display_desc' => $display_desc, 'display_reg_form' => $display_reg_form, 'address' => $address, 'address2' => $address2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country, 'phone' => $phone, 'virtual_url' => $virtual_url, 'virtual_phone' => $virtual_phone, 'venue_title' => $venue_title, 'venue_url' => $venue_url, 'venue_phone' => $venue_phone, 'venue_image' => $venue_image, 'registration_start' => $registration_start, 'registration_end' => $registration_end, 'start_date' => $start_date, 'end_date' => $end_date, 'allow_multiple' => $allow_multiple, 'send_mail' => $send_mail, 'is_active' => $is_active, 'event_status' => $event_status, 'conf_mail' => $conf_mail, 'use_coupon_code' => $use_coupon_code, 'member_only' => $member_only, 'externalURL' => $externalURL, 'early_disc' => $early_disc, 'early_disc_date' => $early_disc_date, 'early_disc_percentage' => $early_disc_percentage, 'alt_email' => $alt_email, 'question_groups' => $question_groups, 'allow_overflow' => $allow_overflow, 'overflow_event_id' => $overflow_event_id, 'additional_limit' => $additional_limit, 'reg_limit' => $reg_limit, 'email_id' => $email_id, 'registration_startT' => $registration_startT, 'registration_endT' => $registration_endT, 'event_meta' => $event_meta, 'require_pre_approval' => $require_pre_approval, 'timezone_string' => $timezone_string, 'ticket_id' => $ticket_id);
        $sql_data = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%s', '%s', '%s', '%s', '%s', '%d');
        $update_id = array('id' => $event_id);
        /* echo 'Debug: <br />';
           print_r($sql);
           echo '<br />';
           print 'Number of vars: ' . count ($sql);
           echo '<br />';
           print 'Number of cols: ' . count($sql_data); */
        if (function_exists('event_espresso_add_event_to_db_groupon')) {
            $sql = event_espresso_add_event_to_db_groupon($sql, $_REQUEST['use_groupon_code']);
            ///print count ($sql);
            $sql_data = array_merge((array) $sql_data, (array) '%s');
            //print count($sql_data);
            $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
            /* echo 'Debug: <br />';
               print 'Number of vars: ' . count ($sql);
               echo '<br />';
               print 'Number of cols: ' . count($sql_data); */
        } else {
            $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
            /* echo 'Debug: <br />';
               print 'Number of vars: ' . count ($sql);
               echo '<br />';
               print 'Number of cols: ' . count($sql_data); */
        }
        //print $wpdb->print_error();
        //BEGIN CATEGORY MODIFICATION
        //We first delete the previous entry then we get the category id's of the event and put them in events_detail_table.category_id as a well-formatted string (id,n id)
        $del_cats = "DELETE FROM " . EVENTS_CATEGORY_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($wpdb->prepare($del_cats, NULL));
        $update_event_detail_category_id = "UPDATE " . EVENTS_DETAIL_TABLE . " SET category_id = NULL WHERE id='" . $event_id . "'";
        $wpdb->query($wpdb->prepare($update_event_detail_category_id, NULL));
        $string_cat = '';
        if (!empty($_REQUEST['event_category'])) {
            foreach ($_REQUEST['event_category'] as $k => $v) {
                if (!empty($v)) {
                    $sql_cat = "INSERT INTO " . EVENTS_CATEGORY_REL_TABLE . " (event_id, cat_id) VALUES ('" . $event_id . "', '" . (int) $v . "')";
                    $wpdb->query($wpdb->prepare($sql_cat, array()));
                    $string_cat .= sanitize_text_field($v) . ",";
                }
            }
            if (!empty($string_cat) && $string_cat != ",") {
                $cleaned_string_cat = substr($string_cat, 0, -1);
                $tmp = explode(",", $cleaned_string_cat);
                sort($tmp);
                $cleaned_string_cat = implode(",", $tmp);
                trim($cleaned_string_cat);
                $sql_update_event_detail_category_id = "UPDATE " . EVENTS_DETAIL_TABLE . " SET category_id = '" . $cleaned_string_cat . "' WHERE id='" . $event_id . "'";
                $wpdb->query($wpdb->prepare($sql_update_event_detail_category_id, NULL));
            }
        }
        //END CATEGORY MODIFICATION
        //Staff
        $update_all_staff = FALSE;
        if (isset($_POST['rem_apply_to_all_staff']) && $_POST['recurrence_apply_changes_to'] == 2) {
            $update_all_staff = TRUE;
        }
        if ($_POST['event_id'] == $event_id || $update_all_staff == TRUE) {
            $del_ppl = "DELETE FROM " . EVENTS_PERSONNEL_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
            $wpdb->query($wpdb->prepare($del_ppl, NULL));
            if (!empty($_REQUEST['event_person'])) {
                foreach ($_REQUEST['event_person'] as $k => $v) {
                    if (!empty($v)) {
                        $sql_ppl = "INSERT INTO " . EVENTS_PERSONNEL_REL_TABLE . " (event_id, person_id) VALUES ('" . $event_id . "', '" . (int) $v . "')";
                        $wpdb->query($wpdb->prepare($sql_ppl, array()));
                    }
                }
            }
        }
        //Venues
        $del_venues = "DELETE FROM " . EVENTS_VENUE_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($wpdb->prepare($del_venues, NULL));
        if (!empty($_REQUEST['venue_id'])) {
            foreach ($_REQUEST['venue_id'] as $k => $v) {
                if (!empty($v) && $v != 0) {
                    $sql_venues = "INSERT INTO " . EVENTS_VENUE_REL_TABLE . " (event_id, venue_id) VALUES ('" . $event_id . "', '" . (int) $v . "')";
                    $wpdb->query($wpdb->prepare($sql_venues, array()));
                }
            }
        }
        //Discounts
        $del_discounts = "DELETE FROM " . EVENTS_DISCOUNT_REL_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($wpdb->prepare($del_discounts, NULL));
        if (!empty($_REQUEST['event_discount']) && $_REQUEST['use_coupon_code'] == 'Y') {
            //only re-add the coupon codes if they've specified to use all global coupon codes
            //and 'specific' coupon codes
            foreach ($_REQUEST['event_discount'] as $k => $v) {
                if (!empty($v)) {
                    $sql_discount = "INSERT INTO " . EVENTS_DISCOUNT_REL_TABLE . " (event_id, discount_id) VALUES ('" . $event_id . "', '" . (int) $v . "')";
                    $wpdb->query($wpdb->prepare($sql_discount, array()));
                }
            }
        }
        $del_times = "DELETE FROM " . EVENTS_START_END_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($wpdb->prepare($del_times, NULL));
        if (!empty($_REQUEST['start_time'])) {
            foreach ($_REQUEST['start_time'] as $k => $v) {
                if (!empty($v)) {
                    $time_qty = empty($_REQUEST['time_qty'][$k]) ? '0' : "'" . (int) $_REQUEST['time_qty'][$k] . "'";
                    $sql_times = "INSERT INTO " . EVENTS_START_END_TABLE . " (event_id, start_time, end_time, reg_limit) VALUES ('" . $event_id . "', '" . event_date_display(sanitize_text_field($v), 'H:i') . "', '" . event_date_display(sanitize_text_field($_REQUEST['end_time'][$k]), 'H:i') . "', " . $time_qty . ")";
                    $wpdb->query($wpdb->prepare($sql_times, array()));
                }
            }
        }
        $del_prices = "DELETE FROM " . EVENTS_PRICES_TABLE . " WHERE event_id = '" . $event_id . "'";
        $wpdb->query($wpdb->prepare($del_prices, NULL));
        if (!empty($_REQUEST['event_cost'])) {
            foreach ($_REQUEST['event_cost'] as $k => $v) {
                if (!empty($v)) {
                    $v = (double) preg_replace('/[^0-9\\.]/ui', '', $v);
                    //Removes non-integer characters
                    $price_type = $_REQUEST['price_type'][$k] != '' ? sanitize_text_field(stripslashes_deep($_REQUEST['price_type'][$k])) : __('General Admission', 'event_espresso');
                    $member_price_type = !empty($_REQUEST['member_price_type'][$k]) ? sanitize_text_field(stripslashes_deep($_REQUEST['member_price_type'][$k])) : __('Members Admission', 'event_espresso');
                    $member_price = !empty($_REQUEST['member_price'][$k]) ? (double) $_REQUEST['member_price'][$k] : $v;
                    $sql_price = array('event_id' => $event_id, 'event_cost' => $v, 'surcharge' => sanitize_text_field($_REQUEST['surcharge'][$k]), 'surcharge_type' => sanitize_text_field($_REQUEST['surcharge_type'][$k]), 'price_type' => $price_type, 'member_price' => $member_price, 'member_price_type' => $member_price_type);
                    $sql_price_data = array('%d', '%s', '%s', '%s', '%s', '%s', '%s');
                    if (!$wpdb->insert(EVENTS_PRICES_TABLE, $sql_price, $sql_price_data)) {
                        $error = true;
                    }
                }
            }
        } else {
            $sql_price = "INSERT INTO " . EVENTS_PRICES_TABLE . " (event_id, event_cost, surcharge, price_type, member_price, member_price_type) VALUES ('" . $event_id . "', '0.00', '0.00', '" . __('Free', 'event_espresso') . "', '0.00', '" . __('Free', 'event_espresso') . "')";
            if (!$wpdb->query($wpdb->prepare($sql_price, array()))) {
                $error = true;
            }
        }
        ############# MailChimp Integration ###############
        if (defined('EVENTS_MAILCHIMP_ATTENDEE_REL_TABLE') && $espresso_premium == true) {
            MailChimpController::update_event_list_rel($event_id);
        }
        // Create Event Post Code Here
        if (isset($_REQUEST['create_post'])) {
            switch ($_REQUEST['create_post']) {
                case 'N':
                    $sql = " SELECT * FROM " . EVENTS_DETAIL_TABLE;
                    $sql .= " WHERE id = '" . $event_id . "' ";
                    $wpdb->get_results($wpdb->prepare($sql, NULL));
                    $post_id = $wpdb->last_result[0]->post_id;
                    if ($wpdb->num_rows > 0 && !empty($_REQUEST['delete_post']) && $_REQUEST['delete_post'] == 'Y') {
                        $sql = array('post_id' => '', 'post_type' => '');
                        $sql_data = array('%d', '%s');
                        $update_id = array('id' => $event_id);
                        $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
                        wp_delete_post($post_id, 'true');
                    }
                    break;
                case 'Y':
                    $post_type = $_REQUEST['espresso_post_type'];
                    if ($post_type == 'post') {
                        if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php") || file_exists(EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php")) {
                            // Load message from template into message post variable
                            ob_start();
                            if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php")) {
                                require_once EVENT_ESPRESSO_TEMPLATE_DIR . "event_post.php";
                            } else {
                                require_once EVENT_ESPRESSO_PLUGINFULLPATH . "templates/event_post.php";
                            }
                            $post_content = ob_get_contents();
                            ob_end_clean();
                        } else {
                            _e('There was error finding a post template. Please verify your post templates are available.', 'event_espresso');
                        }
                    } elseif ($post_type == 'espresso_event') {
                        ob_start();
                        echo $event_desc;
                        $post_content = ob_get_contents();
                        ob_end_clean();
                        // if there's a cart link shortcode in the post, replace the shortcode with one that includes the event_id
                        if (preg_match("/ESPRESSO_CART_LINK/", $post_content)) {
                            $post_content = preg_replace('/ESPRESSO_CART_LINK/', 'ESPRESSO_CART_LINK event_id=' . $event_id, $post_content);
                        }
                    }
                    $my_post = array();
                    $sql = " SELECT * FROM " . EVENTS_DETAIL_TABLE;
                    $sql .= " WHERE id = '" . $event_id . "' ";
                    $wpdb->get_results($wpdb->prepare($sql, NULL));
                    $post_id = $wpdb->last_result[0]->post_id;
                    $post_type = $_REQUEST['espresso_post_type'];
                    if ($post_id > 0) {
                        $my_post['ID'] = $post_id;
                    }
                    $my_post['post_title'] = sanitize_text_field($_REQUEST['event']);
                    $my_post['post_content'] = $post_content;
                    $my_post['post_status'] = 'publish';
                    $my_post['post_author'] = !empty($_REQUEST['user']) ? (int) $_REQUEST['user'] : '';
                    $my_post['post_category'] = !empty($_REQUEST['post_category']) ? $_REQUEST['post_category'] : '';
                    $my_post['tags_input'] = !empty($_REQUEST['post_tags']) ? $_REQUEST['post_tags'] : '';
                    $my_post['post_type'] = !empty($post_type) ? $post_type : 'post';
                    //print_r($my_post);
                    // Insert the post into the database
                    if ($post_id > 0) {
                        $post_id = wp_update_post($my_post);
                        update_post_meta($post_id, 'event_id', $event_id);
                        update_post_meta($post_id, 'event_meta', $event_meta);
                        update_post_meta($post_id, 'event_identifier', $event_identifier);
                        update_post_meta($post_id, 'event_start_date', $start_date);
                        update_post_meta($post_id, 'event_end_date', $end_date);
                        update_post_meta($post_id, 'event_location', $event_location);
                        update_post_meta($post_id, 'event_thumbnail_url', $event_thumbnail_url);
                        update_post_meta($post_id, 'virtual_url', $virtual_url);
                        update_post_meta($post_id, 'virtual_phone', $virtual_phone);
                        //
                        update_post_meta($post_id, 'event_address', $address);
                        update_post_meta($post_id, 'event_address2', $address2);
                        update_post_meta($post_id, 'event_city', $city);
                        update_post_meta($post_id, 'event_state', $state);
                        update_post_meta($post_id, 'event_country', $country);
                        update_post_meta($post_id, 'event_phone', $phone);
                        update_post_meta($post_id, 'venue_title', $venue_title);
                        update_post_meta($post_id, 'venue_url', $venue_url);
                        update_post_meta($post_id, 'venue_phone', $venue_phone);
                        update_post_meta($post_id, 'venue_image', $venue_image);
                        update_post_meta($post_id, 'event_externalURL', $externalURL);
                        update_post_meta($post_id, 'event_reg_limit', $reg_limit);
                        update_post_meta($post_id, 'event_start_time', time_to_24hr($start_time));
                        update_post_meta($post_id, 'event_end_time', time_to_24hr($end_time));
                        update_post_meta($post_id, 'event_registration_start', $registration_start);
                        update_post_meta($post_id, 'event_registration_end', $registration_end);
                        update_post_meta($post_id, 'event_registration_startT', $registration_startT);
                        update_post_meta($post_id, 'event_registration_endT', $registration_endT);
                    } else {
                        $post_id = wp_insert_post($my_post);
                        add_post_meta($post_id, 'event_id', $event_id);
                        add_post_meta($post_id, 'event_meta', $event_meta);
                        add_post_meta($post_id, 'event_identifier', $event_identifier);
                        add_post_meta($post_id, 'event_start_date', $start_date);
                        add_post_meta($post_id, 'event_end_date', $end_date);
                        add_post_meta($post_id, 'event_location', $event_location);
                        add_post_meta($post_id, 'event_thumbnail_url', $event_thumbnail_url);
                        add_post_meta($post_id, 'virtual_url', $virtual_url);
                        add_post_meta($post_id, 'virtual_phone', $virtual_phone);
                        //
                        add_post_meta($post_id, 'event_address', $address);
                        add_post_meta($post_id, 'event_address2', $address2);
                        add_post_meta($post_id, 'event_city', $city);
                        add_post_meta($post_id, 'event_state', $state);
                        add_post_meta($post_id, 'event_country', $country);
                        add_post_meta($post_id, 'event_phone', $phone);
                        add_post_meta($post_id, 'venue_title', $venue_title);
                        add_post_meta($post_id, 'venue_url', $venue_url);
                        add_post_meta($post_id, 'venue_phone', $venue_phone);
                        add_post_meta($post_id, 'venue_image', $venue_image);
                        add_post_meta($post_id, 'event_externalURL', $externalURL);
                        add_post_meta($post_id, 'event_reg_limit', $reg_limit);
                        add_post_meta($post_id, 'event_start_time', time_to_24hr($start_time));
                        add_post_meta($post_id, 'event_end_time', time_to_24hr($end_time));
                        add_post_meta($post_id, 'event_registration_start', $registration_start);
                        add_post_meta($post_id, 'event_registration_end', $registration_end);
                        add_post_meta($post_id, 'event_registration_startT', $registration_startT);
                        add_post_meta($post_id, 'event_registration_endT', $registration_endT);
                    }
                    // Store the POST ID so it can be displayed on the edit page
                    $sql = array('post_id' => $post_id, 'post_type' => $post_type);
                    $sql_data = array('%d', '%s');
                    $update_id = array('id' => $event_id);
                    $wpdb->update(EVENTS_DETAIL_TABLE, $sql, $update_id, $sql_data, array('%d'));
                    break;
            }
        }
        ?>
        <div id="message" class="updated fade"><p><strong><?php 
        _e('Event details updated for', 'event_espresso');
        ?>
 <a href="<?php 
        echo espresso_reg_url($event_id);
        ?>
" target="_blank">
		<?php 
        echo htmlentities(stripslashes(sanitize_text_field($_REQUEST['event'])), ENT_QUOTES, 'UTF-8');
        ?>
 for <?php 
        echo date("m/d/Y", strtotime($start_date));
        ?>
</a>.</strong></p></div>
        
        <?php 
        /*
         * Added for seating chart addon
         */
        if (isset($seating_chart_result) && $seating_chart_result === false) {
            echo '<p>Failed to associate new seating chart with this event. (Seats from current seating chart might have been used by some attendees)</p>';
        }
    }
    /*
     * With the recursion of this function, additional recurring events will be updated
     */
    if (isset($recurrence_dates) && count($recurrence_dates) > 0 && $_POST['recurrence_apply_changes_to'] > 1) {
        //$recurrence_dates = array_shift($recurrence_dates); //Remove the first item from the array since it will be added after this recursion
        foreach ($recurrence_dates as $r_d) {
            if ($r_d['event_id'] != '' && count($r_d) > 2) {
                update_event(array('event_id' => $r_d['event_id'], 'event_identifier' => $r_d['event_identifier'], 'recurrence_id' => $r_d['recurrence_id'], 'recurrence_start_date' => $r_d['start_date'], 'recurrence_event_end_date' => $r_d['event_end_date'], 'registration_start' => $r_d['registration_start'], 'registration_end' => $r_d['registration_end'], 'visible_on' => $r_d['visible_on'], 'bypass_nonce' => TRUE));
            }
        }
    }
    /*
     * End recursion, as part of recurring events.
     */
    do_action('action_hook_espresso_update_event_success', $_REQUEST);
}
 function event_espresso_add_attendees_to_db($event_id = NULL, $session_vars = NULL)
 {
     global $wpdb, $org_options, $espresso_premium;
     //print_r($session_vars);
     $count = $wpdb->get_col($wpdb->prepare("SELECT id FROM " . EVENTS_ATTENDEE_TABLE . " WHERE attendee_session=%s", $_SESSION['espresso_session']['id']));
     if (!empty($count) && empty($_REQUEST['confirm_registration']) && is_null($session_vars)) {
         $_SESSION['espresso_session']['id'] = array();
         ee_init_session();
     }
     $data_source = $_POST;
     $att_data_source = $_POST;
     $multi_reg = false;
     static $attendee_number = 1;
     //using this var to keep track of the first attendee
     static $loop_number = 1;
     if (!is_null($event_id) && !is_null($session_vars)) {
         $data_source = $session_vars['data'];
         //event details, ie qty, price, start..
         $att_data_source = $session_vars['event_attendees'];
         //event attendee info ie name, questions....
         $multi_reg = true;
     } else {
         $event_id = $data_source['event_id'];
     }
     //echo '<p>$att_data_source = ';print_r( $att_data_source); echo '</p>';
     static $temp_event_id = '';
     // Will be used for multi events to
     // keep track of evant id change in the loop,
     // for recording event total cost for each group
     if ($temp_event_id == '' || $temp_event_id != $event_id) {
         $temp_event_id = $event_id;
         $event_change = 1;
         $total_cost = isset($data_source['cost']) ? $data_source['cost'] : 0;
     } else {
         $event_change = 0;
         $total_cost = 0;
     }
     // echo "<pre>", print_r($data_source), "</pre>";
     //echo "<pre>", print_r($att_data_source), "</pre>";
     // exit;
     $Organization = $org_options['organization'];
     $Organization_street1 = $org_options['organization_street1'];
     $Organization_street2 = $org_options['organization_street2'];
     $Organization_city = $org_options['organization_city'];
     $Organization_state = $org_options['organization_state'];
     $Organization_zip = $org_options['organization_zip'];
     $contact = $org_options['contact_email'];
     $contact_email = $org_options['contact_email'];
     $paypal_id = $org_options['paypal_id'];
     $paypal_cur = isset($org_options['currency_format']) ? $org_options['currency_format'] : '';
     $return_url = $org_options['return_url'];
     $cancel_return = $org_options['cancel_return'];
     $notify_url = $org_options['notify_url'];
     $default_mail = $org_options['default_mail'];
     $conf_message = $org_options['message'];
     $email_before_payment = $org_options['email_before_payment'];
     $fname = isset($att_data_source['fname']) ? $att_data_source['fname'] : '';
     $lname = isset($att_data_source['lname']) ? $att_data_source['lname'] : '';
     $address = isset($att_data_source['address']) ? $att_data_source['address'] : '';
     $address2 = isset($att_data_source['address2']) ? $att_data_source['address2'] : '';
     $city = isset($att_data_source['city']) ? $att_data_source['city'] : '';
     $state = isset($att_data_source['state']) ? $att_data_source['state'] : '';
     $zip = isset($att_data_source['zip']) ? $att_data_source['zip'] : '';
     $phone = isset($att_data_source['phone']) ? $att_data_source['phone'] : '';
     $email = isset($att_data_source['email']) ? $att_data_source['email'] : '';
     //$num_people = $data_source ['num_people'];
     $amount_pd = isset($data_source["event_cost"]) && $data_source["event_cost"] != '' ? $data_source["event_cost"] : 0.0;
     //echo $amount_pd;
     //return;
     //echo '<p>$amount_pd = '.$amount_pd.'</p>';
     $questions = $wpdb->get_row("SELECT question_groups, event_meta FROM " . EVENTS_DETAIL_TABLE . " WHERE id = '" . $event_id . "'");
     $event_meta = unserialize($questions->event_meta);
     $questions = unserialize($questions->question_groups);
     //echo '<p>$data_source[price_select] = '.$data_source['price_select'].'</p>';
     //$payment = $data_source['payment'];
     //Figure out if the person has registered using a price selection
     if ($multi_reg) {
         $event_cost = $_SESSION['espresso_session']['grand_total'];
         $amount_pd = $attendee_number == 1 ? $event_cost : 0.0;
         $coupon_code = $attendee_number == 1 ? $_SESSION['espresso_session']['coupon_code'] : '';
         $price_type = isset($data_source['price_type']) ? $data_source['price_type'] : espresso_ticket_information(array('type' => 'ticket', 'price_option' => $data_source['price_id']));
         $attendee_number++;
     } elseif (isset($data_source['price_select']) && $data_source['price_select'] == true) {
         $price_options = explode('|', $data_source['price_option'], 2);
         $price_id = $price_options[0];
         $price_type = $price_options[1];
         $event_cost = event_espresso_get_final_price($price_id, $event_id);
         /* echo '$event_id = '.$event_id.'<br />';
         	  echo '$price_id = '.$price_id.'<br />';
         	  echo '$event_cost = '.$event_cost;
         	  return; */
     } else {
         $event_cost = isset($data_source['price_id']) ? event_espresso_get_final_price($data_source['price_id'], $event_id) : 0.0;
         $coupon_code = '';
         $price_type = isset($data_source['price_id']) ? espresso_ticket_information(array('type' => 'ticket', 'price_option' => $data_source['price_id'])) : '';
     }
     //Display the confirmation page
     if (!empty($data_source['confirm_registration'])) {
         $registration_id = $data_source['registration_id'];
         echo espresso_confirm_registration($registration_id);
         return;
     }
     //Check to see if the registration id already exists
     $incomplete_filter = !$multi_reg ? " AND payment_status ='Incomplete'" : '';
     $check_sql = $wpdb->get_results("SELECT attendee_session, id, registration_id FROM " . EVENTS_ATTENDEE_TABLE . " WHERE attendee_session ='" . $_SESSION['espresso_session']['id'] . "' AND event_id ='" . $event_id . "' {$incomplete_filter}");
     $num_rows = $wpdb->num_rows;
     $registration_id = empty($wpdb->last_result[0]->registration_id) ? $registration_id = uniqid('', true) : $wpdb->last_result[0]->registration_id;
     $txn_type = "";
     if (isset($data_source['admin'])) {
         $payment_status = "Completed";
         $payment = "Admin";
         $txn_type = __('Added by Admin', 'event_espresso');
         $payment_date = date("m-d-Y");
         $amount_pd = $data_source["event_cost"] == '' ? 0.0 : $data_source["event_cost"];
         $registration_id = uniqid('', true);
         $_SESSION['espresso_session']['id'] = uniqid('', true);
     } else {
         if ($org_options['use_captcha'] == 'Y' && !$multi_reg && !is_user_logged_in()) {
             //Recaptcha portion
             //require_once('includes/recaptchalib.php');
             if (!function_exists('recaptcha_check_answer')) {
                 require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'includes/recaptchalib.php';
             }
             $resp = recaptcha_check_answer($org_options['recaptcha_privatekey'], $_SERVER["REMOTE_ADDR"], $data_source["recaptcha_challenge_field"], $data_source["recaptcha_response_field"]);
             if (!$resp->is_valid) {
                 echo '<div class="attention-icon"><p class="event_espresso_attention"><strong>' . __('Sorry, you did not enter the correct anti-spam phrase. Please click your browser\'s back button and try again.', 'event_espresso') . '</strong></p></div>';
                 return;
             }
         }
         //print_r( $event_meta);
         $default_payment_status = $event_meta['default_payment_status'] != '' && $org_options['default_payment_status'] != $event_meta['default_payment_status'] ? $event_meta['default_payment_status'] : $org_options['default_payment_status'];
         $payment_status = $multi_reg && $data_source['cost'] == 0 ? "Completed" : $default_payment_status;
         $payment = '';
     }
     $times_sql = "SELECT ese.start_time, ese.end_time, e.start_date, e.end_date ";
     $times_sql .= "FROM " . EVENTS_START_END_TABLE . " ese ";
     $times_sql .= "LEFT JOIN " . EVENTS_DETAIL_TABLE . " e ON ese.event_id = e.id WHERE ";
     if (!empty($data_source['start_time_id'])) {
         $times_sql .= "ese.id='" . $data_source['start_time_id'] . "' AND ";
     }
     $times_sql .= "e.id='" . $event_id . "' ";
     $times = $wpdb->get_results($times_sql);
     foreach ($times as $time) {
         $start_time = $time->start_time;
         $end_time = $time->end_time;
         $start_date = $time->start_date;
         $end_date = $time->end_date;
     }
     //If we are using the number of attendees dropdown, add that number to the DB
     //echo $data_source['espresso_addtl_limit_dd'];
     if (isset($data_source['espresso_addtl_limit_dd'])) {
         $num_people = $data_source['num_people'];
     }
     if (isset($event_meta['additional_attendee_reg_info']) && $event_meta['additional_attendee_reg_info'] == 1) {
         $num_people = $data_source['num_people'];
     } else {
         $num_people = 1;
     }
     $start_time = empty($start_time) ? '' : $start_time;
     $end_time = empty($end_time) ? '' : $end_time;
     $start_date = empty($start_date) ? '' : $start_date;
     $end_date = empty($end_date) ? '' : $end_date;
     $organization_name = empty($organization_name) ? '' : $organization_name;
     $country_id = empty($country_id) ? '' : $country_id;
     $payment_date = empty($payment_date) ? '' : $payment_date;
     $coupon_code = empty($coupon_code) ? '' : $coupon_code;
     $sql = array('registration_id' => $registration_id, 'attendee_session' => $_SESSION['espresso_session']['id'], 'lname' => $lname, 'fname' => $fname, 'address' => $address, 'address2' => $address2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'email' => $email, 'phone' => $phone, 'payment' => $payment, 'amount_pd' => $amount_pd, 'txn_type' => $txn_type, 'coupon_code' => $coupon_code, 'event_time' => $start_time, 'end_time' => $end_time, 'start_date' => $start_date, 'end_date' => $end_date, 'price_option' => $price_type, 'organization_name' => $organization_name, 'country_id' => $country_id, 'payment_status' => $payment_status, 'payment_date' => $payment_date, 'event_id' => $event_id, 'quantity' => $num_people);
     $sql_data = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d');
     //Debugging output
     /* echo 'Debug: <br />';
     	  print_r($sql);
     	  echo '<br />';
     	  print 'Number of vars: ' . count ($sql);
     	  echo '<br />';
     	  print 'Number of cols: ' . count($sql_data); */
     if ($num_rows > 0 && $loop_number == 1) {
         if (!isset($data_source['admin'])) {
             /*
              * Added for seating chart addon
              */
             $tmp_session = $_SESSION['espresso_session']['id'];
             $rem_attendee_ids = $wpdb->get_results(" select t1.id, t1.registration_id FROM " . EVENTS_ATTENDEE_TABLE . "  t1 WHERE t1.attendee_session ='" . $_SESSION['espresso_session']['id'] . "'  {$incomplete_filter} ");
             foreach ($rem_attendee_ids as $v) {
                 if (defined('ESPRESSO_SEATING_CHART')) {
                     $wpdb->query("delete from " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " where attendee_id = " . $v->id);
                 }
             }
             /*
              * End
              */
             $wpdb->query(" DELETE t1, t2 FROM " . EVENTS_ATTENDEE_TABLE . "  t1 JOIN  " . EVENTS_ANSWER_TABLE . " t2 on t1.id = t2.attendee_id WHERE t1.attendee_session ='" . $_SESSION['espresso_session']['id'] . "'  {$incomplete_filter} ");
         }
         //Added by Imon
         // First delete attempt might fail if there is no data in answer table. So, second attempt without joining answer table is taken bellow -
         $wpdb->query(" DELETE t1 FROM " . EVENTS_ATTENDEE_TABLE . "  t1 WHERE t1.attendee_session ='" . $_SESSION['espresso_session']['id'] . "'  {$incomplete_filter} ");
         // Clean up any attendee information from attendee_cost table where attendee is not available in attendee table
         event_espresso_cleanup_multi_event_registration_id_group_data();
         event_espresso_cleanup_attendee_cost_data();
     }
     $loop_number++;
     //Add new or updated data
     if (!$wpdb->insert(EVENTS_ATTENDEE_TABLE, $sql, $sql_data)) {
         $error = true;
     }
     $attendee_id = $wpdb->insert_id;
     /*
      * Added for seating chart addon
      */
     $booking_id = 0;
     if (defined('ESPRESSO_SEATING_CHART')) {
         if (seating_chart::check_event_has_seating_chart($event_id) !== false) {
             if (isset($_POST['seat_id'])) {
                 $booking_id = seating_chart::parse_booking_info($_POST['seat_id']);
                 if ($booking_id > 0) {
                     seating_chart::confirm_a_seat($booking_id, $attendee_id);
                 }
             }
         }
     }
     //Add a record for the primary attendee
     $sql = array('attendee_id' => $attendee_id, 'meta_key' => 'primary_attendee', 'meta_value' => 1);
     $sql_data = array('%s', '%s', '%s');
     //Debugging output
     /* echo 'Debug: <br />';
     	  print_r($sql);
     	  echo '<br />';
     	  print 'Number of vars: ' . count ($sql);
     	  echo '<br />';
     	  print 'Number of cols: ' . count($sql_data); */
     if (!$wpdb->insert(EVENTS_ATTENDEE_META_TABLE, $sql, $sql_data)) {
         $error = true;
     }
     /**
      * Adding attenddee specific cost to events_attendee_cost table
      */
     if (!isset($data_source['admin'])) {
         if (isset($att_data_source['price_id'])) {
             $attendee_price_id = $att_data_source['price_id'];
             $events_prices = $wpdb->get_row("select * from " . EVENTS_PRICES_TABLE . "  where id = {$attendee_price_id} ");
         } elseif (isset($data_source['price_select']) && $data_source['price_select'] == true) {
             $price_options = explode('|', $data_source['price_option'], 2);
             $attendee_price_id = $price_options[0];
             $events_prices = $wpdb->get_row("select * from " . EVENTS_PRICES_TABLE . "  where id = {$attendee_price_id} ");
         } else {
             $events_prices = $wpdb->get_row("select * from " . EVENTS_PRICES_TABLE . " where event_id = {$event_id}");
             $attendee_price_id = $events_prices->id;
         }
         /*
          * Added for seating chart add-on
          * If a seat was selected then price of that seating will be used instead of event price
          */
         $attendee_quantity = 1;
         if (isset($data_source['seat_id'])) {
             $attendee_cost = seating_chart::get_purchase_price($booking_id);
         } else {
             $attendee_cost = event_espresso_get_final_price($attendee_price_id, $event_id);
             if (isset($data_source['num_people'])) {
                 $attendee_quantity = $data_source['num_people'];
             }
         }
     } else {
         /* echo  '$data_source[\'event_cost\'] = '.$data_source['event_cost'];
         	  return; */
         $attendee_quantity = 1;
         $attendee_cost = $data_source['event_cost'];
     }
     $attendee_cost_data = array("attendee_id" => $attendee_id, "quantity" => $attendee_quantity, "cost" => $attendee_cost);
     /* echo '$attendee_cost_data = ';
     	  print_r($attendee_cost_data);
     	  return; */
     $wpdb->insert(EVENTS_ATTENDEE_COST_TABLE, $attendee_cost_data);
     /**
      * End
      */
     if (get_option('event_mailchimp_active') == 'true' && $espresso_premium == true) {
         MailChimpController::list_subscribe($event_id, $attendee_id, $fname, $lname, $email);
     }
     //Since main attendee and additional attendees may have different questions,
     //$attendee_number check for 2 because is it statically set at 1 first and is incremented for the primary attendee above, hence 2
     $questions = $attendee_number > 2 && isset($event_meta['add_attendee_question_groups']) ? $event_meta['add_attendee_question_groups'] : $questions;
     add_attendee_questions($questions, $registration_id, $attendee_id, array('session_vars' => $att_data_source));
     //Add additional attendees to the database
     if ($event_meta['additional_attendee_reg_info'] == 1) {
         if (!empty($_REQUEST['num_people']) && $_REQUEST['num_people'] > 1) {
         }
     } else {
         $questions = $event_meta['add_attendee_question_groups'];
         //Debug
         //echo "<pre>".print_r($questions,true)."</pre>";
         if (isset($att_data_source['x_attendee_fname'])) {
             $amount_pd = 0.0;
             //additional attendee can't hold this info
             foreach ($att_data_source['x_attendee_fname'] as $k => $v) {
                 if (trim($v) != '' && trim($att_data_source['x_attendee_lname'][$k]) != '') {
                     /*
                      * Added for seating chart addon
                      */
                     $seat_check = true;
                     $x_booking_id = 0;
                     if (defined('ESPRESSO_SEATING_CHART')) {
                         if (seating_chart::check_event_has_seating_chart($event_id) !== false) {
                             if (!isset($att_data_source['x_seat_id'][$k]) || trim($att_data_source['x_seat_id'][$k]) == '') {
                                 $seat_check = false;
                             } else {
                                 $x_booking_id = seating_chart::parse_booking_info($att_data_source['x_seat_id'][$k]);
                                 if ($x_booking_id > 0) {
                                     $seat_check = true;
                                 } else {
                                     $seat_check = false;
                                     //Keeps the system from adding an additional attndee if no seat is selected
                                 }
                             }
                         }
                     }
                     if ($seat_check) {
                         /*
                          * End
                          */
                         $sql_a = array('registration_id' => $registration_id, 'attendee_session' => $_SESSION['espresso_session']['id'], 'lname' => $att_data_source['x_attendee_lname'][$k], 'fname' => $v, 'email' => $att_data_source['x_attendee_email'][$k], 'address' => empty($att_data_source['x_attendee_address'][$k]) ? '' : $att_data_source['x_attendee_address'][$k], 'address2' => empty($att_data_source['x_attendee_address2'][$k]) ? '' : $att_data_source['x_attendee_address2'][$k], 'city' => empty($att_data_source['x_attendee_city'][$k]) ? '' : $att_data_source['x_attendee_city'][$k], 'state' => empty($att_data_source['x_attendee_state'][$k]) ? '' : $att_data_source['x_attendee_state'][$k], 'zip' => empty($att_data_source['x_attendee_zip'][$k]) ? '' : $att_data_source['x_attendee_zip'][$k], 'phone' => empty($att_data_source['x_attendee_phone'][$k]) ? '' : $att_data_source['x_attendee_phone'][$k], 'payment' => $payment, 'amount_pd' => $amount_pd, 'event_time' => $start_time, 'end_time' => $end_time, 'start_date' => $start_date, 'end_date' => $end_date, 'price_option' => $price_type, 'organization_name' => $organization_name, 'country_id' => $country_id, 'payment_status' => $payment_status, 'payment_date' => $payment_date, 'event_id' => $event_id, 'quantity' => $num_people);
                         $sql_data_a = array('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d');
                         $wpdb->insert(EVENTS_ATTENDEE_TABLE, $sql_a, $sql_data_a);
                         //Added by Imon
                         $ext_attendee_id = $wpdb->insert_id;
                         $mailchimp_attendee_id = $ext_attendee_id;
                         /**
                          * Adding attenddee specific cost to events_attendee cost table
                          */
                         $attendee_cost_data = array("attendee_id" => $ext_attendee_id, "quantity" => $attendee_quantity, "cost" => $attendee_cost);
                         $wpdb->insert(EVENTS_ATTENDEE_COST_TABLE, $attendee_cost_data);
                         /**
                          * End
                          */
                         if (get_option('event_mailchimp_active') == 'true' && $espresso_premium == true) {
                             MailChimpController::list_subscribe($event_id, $mailchimp_attendee_id, $v, $att_data_source['x_attendee_lname'][$k], $att_data_source['x_attendee_email'][$k]);
                         }
                         //Added by Imon
                         $ext_att_data_source = array('registration_id' => $registration_id, 'attendee_session' => $_SESSION['espresso_session']['id'], 'lname' => $att_data_source['x_attendee_lname'][$k], 'fname' => $v, 'email' => $att_data_source['x_attendee_email'][$k], 'address' => empty($att_data_source['x_attendee_address'][$k]) ? '' : $att_data_source['x_attendee_address'][$k], 'address2' => empty($att_data_source['x_attendee_address2'][$k]) ? '' : $att_data_source['x_attendee_address2'][$k], 'city' => empty($att_data_source['x_attendee_city'][$k]) ? '' : $att_data_source['x_attendee_city'][$k], 'state' => empty($att_data_source['x_attendee_state'][$k]) ? '' : $att_data_source['x_attendee_state'][$k], 'zip' => empty($att_data_source['x_attendee_zip'][$k]) ? '' : $att_data_source['x_attendee_zip'][$k], 'phone' => empty($att_data_source['x_attendee_phone'][$k]) ? '' : $att_data_source['x_attendee_phone'][$k], 'payment' => $payment, 'amount_pd' => $amount_pd, 'event_time' => $start_time, 'end_time' => $end_time, 'start_date' => $start_date, 'end_date' => $end_date, 'price_option' => $price_type, 'organization_name' => $organization_name, 'country_id' => $country_id, 'payment_status' => $payment_status, 'payment_date' => $payment_date, 'event_id' => $event_id, 'quantity' => $num_people);
                         $questions_in = '';
                         //Debug
                         //echo "<pre questions - >".print_r($questions,true)."</pre>";
                         if (!is_array($questions) && !empty($questions)) {
                             $questions = unserialize($questions);
                         }
                         foreach ($questions as $g_id) {
                             $questions_in .= $g_id . ',';
                         }
                         $questions_in = substr($questions_in, 0, -1);
                         $questions_list = $wpdb->get_results("SELECT q.*, qg.group_name\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . EVENTS_QUESTION_TABLE . " q\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tJOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ton q.id = qgr.question_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tJOIN " . EVENTS_QST_GROUP_TABLE . " qg\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ton qg.id = qgr.group_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE qgr.group_id in (" . $questions_in . ") ORDER BY q.id ASC");
                         foreach ($questions_list as $question_list) {
                             if ($question_list->system_name != '') {
                                 $ext_att_data_source[$question_list->system_name] = $att_data_source['x_attendee_' . $question_list->system_name][$k];
                             } else {
                                 $ext_att_data_source[$question_list->question_type . '_' . $question_list->id] = $att_data_source['x_attendee_' . $question_list->question_type . '_' . $question_list->id][$k];
                             }
                         }
                         echo add_attendee_questions($questions, $registration_id, $ext_attendee_id, array('session_vars' => $ext_att_data_source));
                         /*
                          * Added for seating chart addon
                          */
                     }
                     if (defined('ESPRESSO_SEATING_CHART')) {
                         if (seating_chart::check_event_has_seating_chart($event_id) !== false && $x_booking_id > 0) {
                             seating_chart::confirm_a_seat($x_booking_id, $ext_attendee_id);
                         }
                     }
                     /*
                      * End
                      */
                 }
             }
         }
     }
     //Add member data if needed
     if (get_option('events_members_active') == 'true') {
         require_once EVENT_ESPRESSO_MEMBERS_DIR . "member_functions.php";
         //Load Members functions
         require EVENT_ESPRESSO_MEMBERS_DIR . "user_vars.php";
         //Load Members functions
         if ($userid != 0) {
             event_espresso_add_user_to_event($event_id, $userid, $attendee_id);
         }
     }
     //This shows the payment page
     if (isset($data_source['admin'])) {
         return $attendee_id;
     }
     if (!$multi_reg) {
         return events_payment_page($attendee_id);
     }
     return $registration_id;
 }
<?php

global $wpdb;
$msg = "Seating chart not found";
$seating_chart_id = 0;
if (isset($_REQUEST['seating_chart_id'])) {
    $seating_chart_id = $_REQUEST['seating_chart_id'];
    $seating_chart = $wpdb->get_row("select * from " . EVENTS_SEATING_CHART_TABLE . " where id = {$seating_chart_id} ");
    if ($seating_chart != NULL) {
        $msg = "";
        if (isset($_POST['update_seating_chart']) && $_POST['update_seating_chart'] == 1) {
            $cls_seating_chart = new seating_chart();
            $result = $cls_seating_chart->save_seating_chart($seating_chart_id, $_POST);
            if ($result === true) {
                $seating_chart = $wpdb->get_row("select * from " . EVENTS_SEATING_CHART_TABLE . " where id = {$seating_chart_id} ");
                $msg = "Seating chart info updated successfully";
            } else {
                $msg = "Failed to update seating chart info";
            }
        }
    } else {
        $seating_chart_id = 0;
    }
}
?>

<div class="wrap" style="margin-bottom:10px;"> 
    <div id="icon-options-event" class="icon32"></div>
    <h2>Manage Seating Charts</h2>
    <?php 
if ($msg != "") {
Beispiel #26
0
    function event_espresso_additional_attendees($event_id = 0, $additional_limit = 2, $available_spaces = 999, $label = '', $show_label = true, $event_meta = '')
    {
        $event_id = $event_id == 0 ? $_REQUEST['event_id'] : $event_id;
        if ($event_meta == '' && ($event_id != '' || $event_id != 0)) {
            $event_meta = event_espresso_get_event_meta($event_id);
        }
        $i = 0;
        if ($event_meta['additional_attendee_reg_info'] == 1) {
            $label = $label == '' ? __('Number of Tickets', 'event_espresso') : $label;
            $html = '<span class="espresso_additional_limit">';
            $html .= $show_label == true ? '<label for="num_people">' . $label . '</label>' : '';
            $html .= '<select name="num_people" id="num_people-' . $event_id . '" style="width:70px;">';
            while ($i <= $additional_limit && $i < $available_spaces) {
                $i++;
                $html .= '<option value="' . $i . '">' . $i . '</option>';
            }
            $html .= '</select>';
            //$html .= '<br />';
            $html .= '<input type="hidden" name="espresso_addtl_limit_dd" value="true">';
            $html .= '</span>';
            $buffer = '';
        } else {
            while ($i <= $additional_limit && $i < $available_spaces) {
                $i++;
            }
            $i = $i - 1;
            $html = '<p class="event_form_field additional_header" id="additional_header">';
            // fixed for translation string, previous string untranslatable - http://events.codebasehq.com/projects/event-espresso/tickets/11
            //$html .= '<a onclick="return false;" href="#">' . __('Add More Attendees? (click to toggle, limit ' . $i . ')', 'event_espresso') . '</a>';
            $html .= '<a onclick="return false;" href="#">' . __('Add More Attendees? (click to toggle, limit ', 'event_espresso');
            $html .= $i . ')</a>';
            $html .= '</p>';
            $html .= '<div id="additional_attendees">';
            $html .= '<div class="clone espresso_add_attendee">';
            /*
             * Added for seating chart addon
             */
            if (defined('ESPRESSO_SEATING_CHART')) {
                if (seating_chart::check_event_has_seating_chart($_REQUEST['event_id']) !== false) {
                    $html .= '<p>';
                    $html .= '<label>' . __('Select a Seat:', 'event_espresso') . '</label>';
                    $html .= '<input type="text" name="x_seat_id[]" value="" class="ee_s_select_seat" event_id="' . $_REQUEST['event_id'] . '" readonly="readonly" />';
                    $html .= '<br/>[' . __('If you do not select a seat this attendee will not be added', 'event_espresso') . ']';
                    $html .= '</p>';
                }
            }
            if ($event_meta['additional_attendee_reg_info'] == 2) {
                $html .= '<p>';
                $html .= '<label for="x_attendee_fname">' . __('First Name:', 'event_espresso') . '</label>';
                $html .= '<input type="text" name="x_attendee_fname[]" class="input"/>';
                $html .= '</p>';
                $html .= '<p>';
                $html .= '<label for="x_attendee_lname">' . __('Last Name:', 'event_espresso') . '</label>';
                $html .= '<input type="text" name="x_attendee_lname[]" class="input"/>';
                $html .= '</p>';
                $html .= '<p>';
                $html .= '<label for="x_attendee_email">' . __('Email:', 'event_espresso') . '</label>';
                $html .= '<input type="text" name="x_attendee_email[]" class="input"/>';
                $html .= '</p>';
            } else {
                $html .= event_espresso_add_question_groups($event_meta['add_attendee_question_groups'], '', null, 0, array("x_attendee" => true));
            }
            $html .= '<a href="#" class="add" rel=".clone" title="' . __('Add an Additonal Attendee', 'event_espresso') . '"><img src="' . EVENT_ESPRESSO_PLUGINFULLURL . 'images/icons/add.png" alt="' . __('Add an Additonal Attendee', 'event_espresso') . '" /></a>';
            $html .= '</div>';
            $html .= '<hr />';
            $html .= '</div>';
            ob_start();
            ?>
			<script type="text/javascript">$jaer = jQuery.noConflict();jQuery(document).ready(function($jaer) { $jaer(function(){var removeLink = '<a style="" class="remove" href="#" onclick="$jaer(this).parent().slideUp(function(){ $jaer(this).remove() }); return false"><img src="<?php 
            echo EVENT_ESPRESSO_PLUGINFULLURL . "images/icons/remove.gif";
            ?>
" alt="<?php 
            _e('Remove Attendee', 'event_espresso');
            ?>
" /></a>';$jaer('a.add').relCopy({limit: <?php 
            echo $i;
            ?>
, append: removeLink});$jaer("#additional_attendees").hide();/*toggle the componenet with class msg_body*/$jaer("#additional_header").click(function(){$jaer(this).next("#additional_attendees").slideToggle(500);});});});</script>
			<?php 
            $buffer = ob_get_contents();
            ob_end_clean();
        }
        return $html . $buffer;
    }
    function event_espresso_additional_attendees($event_id = 0, $additional_limit = 2, $available_spaces = 999, $label = '', $show_label = true, $event_meta = '', $qstn_class = '')
    {
        global $espresso_premium;
        $event_id = $event_id == 0 ? $_REQUEST['event_id'] : $event_id;
        if ($event_meta == 'admin') {
            $admin = true;
            $event_meta = '';
        }
        if ($event_meta == '' && ($event_id != '' || $event_id != 0)) {
            $event_meta = event_espresso_get_event_meta($event_id);
        }
        //If the additional attednee questions are empty, then default to the first question group
        if (empty($event_meta['add_attendee_question_groups'])) {
            $event_meta['add_attendee_question_groups'] = array(1 => 1);
        }
        $i = 0;
        if (isset($event_meta['additional_attendee_reg_info']) && $event_meta['additional_attendee_reg_info'] == 1 || $espresso_premium == FALSE) {
            $label = $label == '' ? __('Number of Tickets', 'event_espresso') : $label;
            $html = '<p class="espresso_additional_limit highlight-bg">';
            $html .= $show_label == true ? '<label for="num_people">' . $label . '</label>' : '';
            $html .= '<select name="num_people" id="num_people-' . $event_id . '" style="width:70px;">';
            while ($i < $additional_limit && $i < $available_spaces) {
                $i++;
                $html .= '<option value="' . $i . '">' . $i . '</option>';
            }
            $html .= '</select>';
            //$html .= '<br />';
            $html .= '<input type="hidden" name="espresso_addtl_limit_dd" value="true">';
            $html .= '</p>';
            $buffer = '';
        } else {
            //			while (($i < $additional_limit) && ($i < $available_spaces)) {
            //				$i++;
            //			}
            $i = min($additional_limit, $available_spaces) - 1;
            $html = '<div id="additional_header" class="event_form_field additional_header espresso_add_subtract_attendees">';
            // fixed for translation string, previous string untranslatable - http://events.codebasehq.com/projects/event-espresso/tickets/11
            $html .= '<a id="add-additional-attendee-1" rel="1" class="add-additional-attendee-lnk additional-attendee-lnk ui-state-highlight">' . sprintf(__('Add More Attendees? (click to toggle, limit %s)', 'event_espresso'), $i) . '</a></div>';
            //ob_start();
            $attendee_form = '<div id="additional_attendee_XXXXXX" class="espresso_add_attendee">';
            $attendee_form .= '<h4 class="additional-attendee-nmbr-h4">' . __('Attendee #', 'event_espresso') . 'XXXXXX</h4>';
            /*
             * Added for seating chart addon
             */
            if (defined('ESPRESSO_SEATING_CHART')) {
                if (seating_chart::check_event_has_seating_chart($_REQUEST['event_id']) !== false) {
                    $attendee_form .= '<p>';
                    $attendee_form .= '<label>' . __('Select a Seat:', 'event_espresso') . '</label>';
                    $attendee_form .= '<input type="text" name="x_seat_id[XXXXXX]" value="" class="ee_s_select_seat" event_id="' . $_REQUEST['event_id'] . '" readonly="readonly" />';
                    $attendee_form .= '<br/>[' . __('If you do not select a seat this attendee will not be added', 'event_espresso') . ']';
                    $attendee_form .= '</p>';
                }
            }
            if ($event_meta['additional_attendee_reg_info'] == 2) {
                $attendee_form .= '<p>';
                $attendee_form .= '<label for="x_attendee_fname">' . __('First Name:', 'event_espresso') . '</label>';
                $attendee_form .= '<input type="text" name="x_attendee_fname[XXXXXX]" class="ee-reg-page-text-input fname"/>';
                $attendee_form .= '</p>';
                $attendee_form .= '<p>';
                $attendee_form .= '<label for="x_attendee_lname">' . __('Last Name:', 'event_espresso') . '</label>';
                $attendee_form .= '<input type="text" name="x_attendee_lname[XXXXXX]" class="ee-reg-page-text-input lname"/>';
                $attendee_form .= '</p>';
                $attendee_form .= '<p>';
                $attendee_form .= '<label for="x_attendee_email">' . __('Email:', 'event_espresso') . '</label>';
                $attendee_form .= '<input type="text" name="x_attendee_email[XXXXXX]" class="ee-reg-page-text-input email"/>';
                $attendee_form .= '</p>';
            } else {
                $attendee_form .= '<input type="hidden" name="x_attendee_nmbr[XXXXXX]" class="x_attendee_nmbr" value="XXXXXX"/>';
                $meta = array("x_attendee" => true);
                if (!empty($admin)) {
                    $meta['admin_only'] = true;
                }
                $attendee_form .= event_espresso_add_question_groups($event_meta['add_attendee_question_groups'], '', null, 0, $meta, $qstn_class);
            }
            $attendee_form .= '<div class="espresso_add_subtract_attendees">';
            $attendee_form .= '
			<div class="additional-attendee-div"><a id="remove-additional-attendee-XXXXXX" rel="XXXXXX" class="remove-additional-attendee-lnk additional-attendee-lnk ui-priority-primary " title="' . __('Remove Attendee Above', 'event_espresso') . '">
				<img src="' . EVENT_ESPRESSO_PLUGINFULLURL . 'images/icons/remove.gif" alt="' . __('Remove Attendee', 'event_espresso') . '" />
				' . __('Remove Attendee Above', 'event_espresso') . '
			</a></div>';
            $attendee_form .= '
			<div class="additional-attendee-div"><a id="add-additional-attendee-XXXXXX" rel="XXXXXX" class="add-additional-attendee-lnk additional-attendee-lnk ui-priority-primary " title="' . __('Add Additional Attendee', 'event_espresso') . '">
				<img src="' . EVENT_ESPRESSO_PLUGINFULLURL . 'images/icons/add.png" alt="' . __('Add Additional Attendee', 'event_espresso') . '" />
				' . __('Add Additional Attendee', 'event_espresso') . '
			</a></div>';
            $attendee_form .= '</div></div>';
            wp_register_script('espresso_add_reg_attendees', EVENT_ESPRESSO_PLUGINFULLURL . 'scripts/espresso_add_reg_attendees.js', array('jquery'), '0.1', TRUE);
            wp_enqueue_script('espresso_add_reg_attendees');
            $espresso_add_reg_attendees = array('additional_limit' => min($additional_limit, $available_spaces), 'attendee_form' => stripslashes($attendee_form));
            wp_localize_script('espresso_add_reg_attendees', 'espresso_add_reg_attendees', $espresso_add_reg_attendees);
        }
        return $html;
    }
function edit_attendee_record()
{
    global $wpdb, $org_options;
    $attendee_num = 1;
    if ($_REQUEST['form_action'] == 'edit_attendee') {
        $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
        $registration_id = isset($_REQUEST['registration_id']) ? $_REQUEST['registration_id'] : '';
        $multi_reg = false;
        $check = $wpdb->get_row("select * from " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " where registration_id = '{$registration_id}' ");
        if ($check !== NULL) {
            $registration_id = $check->primary_registration_id;
            $registration_ids = $wpdb->get_results("select distinct primary_registration_id, registration_id from " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " where primary_registration_id = '{$registration_id}' ", ARRAY_A);
            $multi_reg = true;
        }
        /*
         * find the primary attendee so we know which form to present
         * since the additional attendees will have a different form
         */
        //Update the payment amount for the attendee
        if (!empty($_REQUEST['attendee_payment']) && $_REQUEST['attendee_payment'] == 'update_payment') {
            $attendee_cost_data = array("attendee_id" => $ext_attendee_id, "quantity" => $attendee_quantity, "cost" => $attendee_cost);
            $wpdb->insert(EVENTS_ATTENDEE_COST_TABLE, $attendee_cost_data);
            $c_sql = "UPDATE " . EVENTS_ATTENDEE_COST_TABLE . " SET cost = '" . $_REQUEST['amount_pd'] . "', quantity = '" . $_REQUEST['quantity'] . "' WHERE attendee_id = '" . $_REQUEST['id'] . "' ";
            $wpdb->query($c_sql);
            /*
             * Calculate total cost from attendee cost table
             */
            $event_cost = 0;
            if ($multi_reg) {
                foreach ($registration_ids as $reg_ids) {
                    $event_cost += $wpdb->get_var($wpdb->prepare("select ea.registration_id, sum(eac.cost * eac.quantity) from " . EVENTS_ATTENDEE_COST_TABLE . " eac inner join " . EVENTS_ATTENDEE_TABLE . " ea on eac.attendee_id = ea.id where ea.registration_id = '%s' group by ea.registration_id ", $reg_ids['registration_id']), 1, 0);
                }
            } else {
                $event_cost = $wpdb->get_var($wpdb->prepare("select ea.registration_id, sum(eac.cost * eac.quantity) from " . EVENTS_ATTENDEE_COST_TABLE . " eac inner join " . EVENTS_ATTENDEE_TABLE . " ea on eac.attendee_id = ea.id where ea.registration_id = '%s' group by ea.registration_id ", $registration_id), 1, 0);
            }
            $a_sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET quantity = '%d' WHERE id = '%d' ";
            $wpdb->query($wpdb->prepare($a_sql, $_REQUEST['quantity'], $_REQUEST['id']));
            /*
             * Get primary attendee id to update the amount_pd
             */
            $primary_attendee_id = $wpdb->get_var($wpdb->prepare("select id from " . EVENTS_ATTENDEE_TABLE . " where registration_id = '%s' order by id limit 1 ", $registration_id));
            $a_sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET amount_pd = '%f' WHERE id = '%d' ";
            $wpdb->query($wpdb->prepare($a_sql, $event_cost, $primary_attendee_id));
        }
        $r = $wpdb->get_row("SELECT id from " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id ='{$registration_id}' ORDER BY id ");
        $primary_attendee = !empty($r->id) ? $r->id : $id;
        $is_additional_attendee = $primary_attendee != $id ? true : false;
        if (!empty($_REQUEST['attendee_action']) && $_REQUEST['attendee_action'] == 'delete_attendee') {
            $sql = " DELETE FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id ='{$id}'";
            $wpdb->query($sql);
            if (defined('ESPRESSO_SEATING_CHART')) {
                $wpdb->query("DELETE FROM " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " where attendee_id = {$id}");
            }
            $wpdb->query("SELECT id from " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id ='{$registration_id}' ");
            if ($wpdb->num_rows == 0) {
                $sql = " UPDATE " . EVENTS_ATTENDEE_TABLE . " SET quantity = IF(quantity IS NULL ,NULL,IF(quantity > 0,IF(quantity-1>0,quantity-1,1),0)) WHERE registration_id ='{$registration_id}'";
                $wpdb->query($sql);
                $sql = " UPDATE " . EVENTS_ATTENDEE_COST_TABLE . " SET quantity = IF(quantity IS NULL ,NULL,IF(quantity > 0,IF(quantity-1>0,quantity-1,1),0)) WHERE attendee_id ='{$id}'";
                $wpdb->query($sql);
                event_espresso_cleanup_multi_event_registration_id_group_data();
                event_espresso_cleanup_attendee_cost_data();
            }
        } else {
            if (!empty($_REQUEST['attendee_action']) && $_REQUEST['attendee_action'] == 'update_attendee') {
                /*
                 * Update the attendee information
                 */
                $update_time = false;
                if (isset($_POST['start_time_id'])) {
                    $times_sql = "SELECT ese.start_time, ese.end_time ";
                    $times_sql .= "FROM " . EVENTS_START_END_TABLE . " ese ";
                    $times_sql .= " WHERE ";
                    $times_sql .= "ese.id='" . $_POST['start_time_id'] . "' ";
                    $times = $wpdb->get_results($times_sql);
                    if ($wpdb->num_rows > 0) {
                        foreach ($times as $time) {
                            $start_time = $time->start_time;
                            $end_time = $time->end_time;
                        }
                        $update_time = true;
                    }
                }
                $fname = isset($_POST['fname']) ? $_POST['fname'] : '';
                $lname = isset($_POST['lname']) ? $_POST['lname'] : '';
                $address = isset($_POST['address']) ? $_POST['address'] : '';
                $address2 = isset($_POST['address2']) ? $_POST['address2'] : '';
                $city = isset($_POST['city']) ? $_POST['city'] : '';
                $state = isset($_POST['state']) ? $_POST['state'] : '';
                $zip = isset($_POST['zip']) ? $_POST['zip'] : '';
                $phone = isset($_POST['phone']) ? $_POST['phone'] : '';
                $email = isset($_POST['email']) ? $_POST['email'] : '';
                $event_id = isset($_POST['event_id']) ? $_POST['event_id'] : '';
                $txn_type = isset($_POST['txn_type']) ? $_POST['txn_type'] : '';
                $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET fname='{$fname}', lname='{$lname}', address='{$address}',address2='{$address2}', city='{$city}', state='{$state}', zip='{$zip}', phone='{$phone}', email='{$email}', txn_type='{$txn_type}' ";
                if ($update_time == true) {
                    $sql .= ", event_time='{$start_time}', end_time='{$end_time}' ";
                }
                $sql .= " WHERE id ='{$id}' ";
                $wpdb->query($sql);
                // Insert Additional Questions From Post Here
                $reg_id = $id;
                $response_source = $_POST;
                $questions = $wpdb->get_row("SELECT question_groups, event_meta FROM " . EVENTS_DETAIL_TABLE . " WHERE id = " . $event_id . " ");
                $question_groups = unserialize($questions->question_groups);
                $event_meta = unserialize($questions->event_meta);
                if ($is_additional_attendee && isset($event_meta['add_attendee_question_groups']) && $event_meta['add_attendee_question_groups'] != NULL) {
                    $question_groups = $event_meta['add_attendee_question_groups'];
                }
                $questions_in = '';
                foreach ($question_groups as $g_id) {
                    $questions_in .= $g_id . ',';
                }
                $questions_in = substr($questions_in, 0, -1);
                $group_name = '';
                $counter = 0;
                //pull the list of questions that are relevant to this event
                $q_sql_1 = "SELECT q.*, q.id q_id, qg.group_name FROM " . EVENTS_QUESTION_TABLE . " q\n\t\t\t\t\t\tJOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id\n\t\t\t\t\t\tJOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id\n\t\t\t\t\t\tWHERE qgr.group_id in (" . $questions_in . ")\n\t\t\t\t\t\tORDER BY qg.id, q.sequence ASC";
                $questions = $wpdb->get_results($q_sql_1);
                $a_sql = "SELECT id, question_id, answer FROM " . EVENTS_ANSWER_TABLE . " at WHERE at.attendee_id = '" . $id . "' ";
                $answers = $wpdb->get_results($a_sql, OBJECT_K);
                foreach ($answers as $answer) {
                    $answer_a[] = $answer->question_id;
                }
                if ($questions) {
                    foreach ($questions as $question) {
                        switch ($question->question_type) {
                            case "TEXT":
                            case "TEXTAREA":
                            case "DROPDOWN":
                                $post_val = $question->system_name != '' ? $response_source[$question->system_name] : $response_source[$question->question_type . '_' . $question->q_id];
                                if (in_array($question->q_id, $answer_a)) {
                                    $sql = "UPDATE " . EVENTS_ANSWER_TABLE . " SET answer='{$post_val}' WHERE attendee_id = '{$id}' AND question_id ='{$question->q_id}'";
                                } else {
                                    $sql = "INSERT INTO " . EVENTS_ANSWER_TABLE . " (registration_id, answer,attendee_id,question_id) VALUES ('{$registration_id}','{$post_val}', {$id},{$question->q_id})";
                                }
                                $wpdb->query($sql);
                                break;
                            case "SINGLE":
                                $post_val = $question->system_name != '' ? $response_source[$question->system_name] : $response_source[$question->question_type . '_' . $question->q_id];
                                if (in_array($question->q_id, $answer_a)) {
                                    $sql = "UPDATE " . EVENTS_ANSWER_TABLE . " SET answer='{$post_val}' WHERE attendee_id = '{$id}' AND question_id ='{$question->q_id}'";
                                } else {
                                    $sql = "INSERT INTO " . EVENTS_ANSWER_TABLE . " (registration_id, answer,attendee_id,question_id) VALUES ('{$registration_id}','{$post_val}', {$id},{$question->q_id})";
                                }
                                $wpdb->query($sql);
                                break;
                            case "MULTIPLE":
                                $value_string = '';
                                for ($i = 0; $i < count($response_source[$question->question_type . '_' . $question->id]); $i++) {
                                    $value_string .= trim($response_source[$question->question_type . '_' . $question->id][$i]) . ",";
                                }
                                if (in_array($question->q_id, $answer_a)) {
                                    $sql = "UPDATE " . EVENTS_ANSWER_TABLE . " SET answer='{$value_string}' WHERE attendee_id = '{$id}' AND question_id ='{$question->q_id}'";
                                } else {
                                    $sql = "INSERT INTO " . EVENTS_ANSWER_TABLE . " (registration_id, answer,attendee_id,question_id) VALUES ('{$registration_id}','{$value_string}', {$id}, {$question->q_id})";
                                }
                                $wpdb->query($sql);
                                break;
                        }
                    }
                }
            }
        }
        $counter = 0;
        $additional_attendees = NULL;
        $WHERE = isset($_REQUEST['registration_id']) ? "registration_id ='" . $_REQUEST['registration_id'] . "'" : "id = " . $_REQUEST['id'];
        if (isset($_REQUEST['attendee_num']) && $_REQUEST['attendee_num'] > 1 && isset($_REQUEST['registration_id']) && isset($_REQUEST['id'])) {
            $WHERE = " t1.registration_id ='" . $_REQUEST['registration_id'] . "' AND t1.id = " . $_REQUEST['id'];
        }
        $results = $wpdb->get_results("SELECT t1.*, t2.event_name, t2.question_groups, t2.event_meta FROM " . EVENTS_ATTENDEE_TABLE . " t1\n                 JOIN " . EVENTS_DETAIL_TABLE . " t2\n                 ON t1.event_id = t2.id\n                 WHERE {$WHERE}\n                 ORDER BY t1.id");
        foreach ($results as $result) {
            if ($counter == 0) {
                $id = $result->id;
                $registration_id = $result->registration_id;
                $lname = $result->lname;
                $fname = $result->fname;
                $address = $result->address;
                $address2 = $result->address2;
                $city = $result->city;
                $state = $result->state;
                $zip = $result->zip;
                $email = $result->email;
                $hear = isset($result->hear) ? $result->hear : '';
                $payment = $result->payment;
                $phone = $result->phone;
                $date = $result->date;
                $payment_status = $result->payment_status;
                $txn_type = $result->txn_type;
                $txn_id = $result->txn_id;
                $amount_pd = $result->amount_pd;
                $quantity = $result->quantity;
                $payment_date = $result->payment_date;
                $event_id = $result->event_id;
                $event_name = $result->event_name;
                $question_groups = unserialize($result->question_groups);
                $question_groups = unserialize($result->question_groups);
                $event_meta = unserialize($result->event_meta);
                $coupon_code = $result->coupon_code;
                $quantity = $result->quantity;
                $is_additional_attendee = $primary_attendee != $id ? true : false;
                $start_date = $result->start_date;
                $event_time = $result->event_time;
                $event_date = event_date_display($start_date . ' ' . $event_time, get_option('date_format') . ' g:i a');
                if ($is_additional_attendee && isset($event_meta['add_attendee_question_groups']) && $event_meta['add_attendee_question_groups'] != NULL) {
                    $question_groups = $event_meta['add_attendee_question_groups'];
                }
                $counter = 1;
            } else {
                $additional_attendees[$result->id] = array('full_name' => $result->fname . ' ' . $result->lname, 'email' => $result->email, 'phone' => $result->phone);
            }
        }
        if (!empty($_REQUEST['status']) && $_REQUEST['status'] == 'saved') {
            ?>

			<div id="message" class="updated fade">
			  <p><strong>
			<?php 
            _e('Attendee details saved for ' . $fname . ' ' . $lname . '.', 'event_espresso');
            ?>
			    </strong></p>
			</div>
			<?php 
        }
        ?>
		<div class="metabox-holder">
		  <div class="postbox">
		    <h3>
					<?php 
        _e('Registration Id <a href="admin.php?page=events&event_admin_reports=edit_attendee_record&event_id=' . $event_id . '&registration_id=' . $registration_id . '&form_action=edit_attendee">#' . $registration_id . '</a> | ID #' . $id . ' | Name: ' . $fname . ' ' . $lname . ' | Registered For:', 'event_espresso');
        ?>
		      <a href="admin.php?page=events&event_admin_reports=list_attendee_payments&event_id=<?php 
        echo $event_id;
        ?>
"><?php 
        echo stripslashes_deep($event_name);
        ?>
</a> - <?php 
        echo $event_date;
        ?>
</h3>
		    <div class="inside">
		      <table width="100%">
		        <tr>
		          <td width="50%"><form method="post" action="<?php 
        echo $_SERVER['REQUEST_URI'];
        ?>
" class="espresso_form">
		              <h4>
		<?php 
        _e('Registration Information', 'event_espresso');
        ?>
		<?php 
        echo $is_additional_attendee == false ? '[ <span class="green_text">' . __('Primary Attendee Record', 'event_espresso') . '</span> ]' : '[ <a href="admin.php?page=events&event_admin_reports=edit_attendee_record&event_id=' . $event_id . '&registration_id=' . $registration_id . '&form_action=edit_attendee">View/Edit Primary Attendee</a> ]';
        ?>
 </h4>
		              <fieldset>
		                <ul>
		                  <li>
		<?php 
        $time_id = 0;
        $sql = "SELECT id FROM " . EVENTS_START_END_TABLE . " WHERE event_id='" . $event_id . "' AND start_time = '" . $event_time . "' ";
        $event_times = $wpdb->get_results($sql);
        if ($wpdb->num_rows > 0) {
            $time_id = $wpdb->last_result[0]->id;
        }
        echo event_espresso_time_dropdown($event_id, $label = 1, $multi_reg = 0, $time_id);
        ?>
		                  </li>
		                  <li>
												<?php 
        if (count($question_groups) > 0) {
            $questions_in = '';
            foreach ($question_groups as $g_id) {
                $questions_in .= $g_id . ',';
            }
            $questions_in = substr($questions_in, 0, -1);
            $group_name = '';
            $counter = 0;
            $FILTER = '';
            if (isset($event_meta['additional_attendee_reg_info']) && $event_meta['additional_attendee_reg_info'] == '2' && isset($_REQUEST['attendee_num']) && $_REQUEST['attendee_num'] > 1) {
                $FILTER .= " AND qg.system_group = 1 ";
            }
            //pull the list of questions that are relevant to this event
            $q_sql_2 = "SELECT q.*, q.id q_id, at.*, qg.group_name, qg.show_group_description, qg.show_group_name FROM " . EVENTS_QUESTION_TABLE . " q\n\t\t\t\t\tLEFT JOIN " . EVENTS_ANSWER_TABLE . " at on q.id = at.question_id\n\t\t\t\t\tJOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id\n\t\t\t\t\tJOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id\n\t\t\t\t\tWHERE qgr.group_id in (" . $questions_in . ")\n\t\t\t\t\tAND (at.attendee_id IS NULL OR at.attendee_id = '" . $id . "')\n\t\t\t\t\t" . $FILTER . "\n\t\t\t\t\tORDER BY qg.id, q.id ASC";
            $questions = $wpdb->get_results($q_sql_2);
            $num_rows = $wpdb->num_rows;
            if ($num_rows > 0) {
                //Output the questions
                $question_displayed = array();
                foreach ($questions as $question) {
                    $counter++;
                    if (!in_array($question->id, $question_displayed)) {
                        $question_displayed[] = $question->id;
                        echo '<p>';
                        echo event_form_build_edit($question, empty($question->answer) ? '' : $question->answer, $show_admin_only = true);
                        echo "</p>";
                        echo $counter == $num_rows ? '</fieldset>' : '';
                    }
                }
            }
            //end questions display
        }
        ?>
		                  </li>
		                  <input type="hidden" name="id" value="<?php 
        echo $id;
        ?>
" />
		                  <input type="hidden" name="registration_id" value="<?php 
        echo $registration_id;
        ?>
" />
		                  <input type="hidden" name="event_id" value="<?php 
        echo $event_id;
        ?>
" />
		                  <input type="hidden" name="display_action" value="view_list" />
		                  <input type="hidden" name="form_action" value="edit_attendee" />
		                  <input type="hidden" name="attendee_action" value="update_attendee" />
		                  <li>
		                    <input type="submit" name="Submit" value="<?php 
        _e('Update Record', 'event_espresso');
        ?>
" />
		                  </li>
		                </ul>
		              </fieldset>
		            </form></td>
		          <td  width="50%" valign="top"><?php 
        if (count($additional_attendees) > 0) {
            ?>
			            <h4>
			<?php 
            _e('Additional Attendees', 'event_espresso');
            ?>
			            </h4>
			            <ol>
			<?php 
            foreach ($additional_attendees as $att => $row) {
                $attendee_num++;
                ?>
				              <li><a href="admin.php?page=events&amp;event_admin_reports=edit_attendee_record&amp;event_id=<?php 
                echo $event_id;
                ?>
&amp;id=<?php 
                echo $att;
                ?>
&amp;registration_id=<?php 
                echo $registration_id;
                ?>
&amp;form_action=edit_attendee&amp;attendee_num=<?php 
                echo $attendee_num;
                ?>
" title="<?php 
                _e('Edit Attendee', 'event_espresso');
                ?>
"><strong><?php 
                echo $row['full_name'];
                ?>
</strong> (<?php 
                echo $row['email'];
                ?>
)</a> | <a href="admin.php?page=events&amp;event_admin_reports=edit_attendee_record&amp;event_id=<?php 
                echo $event_id;
                ?>
&amp;registration_id=<?php 
                echo $registration_id;
                ?>
&amp;attendee_id=<?php 
                echo $att;
                ?>
&amp;form_action=edit_attendee&amp;attendee_action=delete_attendee&amp;id=<?php 
                echo $att;
                ?>
" title="<?php 
                _e('Delete Attendee', 'event_espresso');
                ?>
" onclick="return confirmDelete();">
				<?php 
                _e('Delete', 'event_espresso');
                ?>
				                </a></li>
				<?php 
            }
            ?>
			            </ol>
		<?php 
        }
        ?>
									<?php 
        /**
         * Begin Attendee Payment Information
         * */
        $has_seating_chart = false;
        if (defined('ESPRESSO_SEATING_CHART')) {
            $has_seating_chart = seating_chart::check_event_has_seating_chart($event_id);
        }
        /**
         * If attendee was added in old system i.e. before version 3.1.10 and attendee_cost table got introduced then this option can not be used
         * */
        $ice_age = true;
        $ice_row = $wpdb->get_row($wpdb->prepare("select * from " . EVENTS_ATTENDEE_COST_TABLE . " where attendee_id = '%d'", $id));
        if ($ice_row !== NULL) {
            $ice_age = false;
        }
        if (!$has_seating_chart && !$ice_age) {
            ?>
			            <h4>
									<?php 
            _e('Payment Information', 'event_espresso');
            ?>
			            </h4>
			            <form method="POST" action="<?php 
            echo $_SERVER['REQUEST_URI'];
            ?>
&status=saved" class="espresso_form">
			              <fieldset>
			                <ul>
			                  <li>
			                    <p><strong>
									<?php 
            _e('Payment Status:', 'event_espresso');
            ?>
			                      </strong> <?php 
            echo $payment_status;
            ?>
 <?php 
            echo event_espresso_paid_status_icon($payment_status);
            ?>
 [ <a href="admin.php?page=events&amp;attendee_pay=paynow&amp;form_action=payment&amp;registration_id=<?php 
            echo $registration_id;
            ?>
&amp;event_admin_reports=enter_attendee_payments&amp;event_id=<?php 
            echo $event_id;
            ?>
" title="<?php 
            _e('Edit Payment', 'event_espresso');
            ?>
">
									<?php 
            _e('View/Edit Payment', 'event_espresso');
            ?>
			                      </a> ]</p>
			                  </li>
			                  <li>
			                    <p><strong>
									<?php 
            _e('Transaction ID:', 'event_espresso');
            ?>
			                      </strong> <?php 
            echo !empty($txn_id) ? $txn_id : 'N/A';
            ?>
</p>
			                  </li>
			                  <li>
			                    <p><strong>
										<?php 
            _e('Date Paid:', 'event_espresso');
            ?>
			                      </strong> <?php 
            echo !empty($payment_date) ? event_date_display($payment_date) : 'N/A';
            ?>
</p>
			                  </li>
			<?php 
            if ($multi_reg == true) {
                ?>
				                  <li>
				                    <p><strong>
				<?php 
                _e('Multiple Event Total:', 'event_espresso');
                ?>
				                      </strong> <?php 
                echo $org_options['currency_symbol'];
                echo espresso_attendee_price(array('attendee_id' => $id, 'session_total' => true));
                ?>
</p>
				                  </li>
															<?php 
            }
            ?>
			                  <li>
			                    <p><strong>
			<?php 
            _e('This Registration Total:', 'event_espresso');
            ?>
			                      </strong> <?php 
            echo $org_options['currency_symbol'];
            echo espresso_attendee_price(array('attendee_id' => $id, 'reg_total' => true));
            ?>
</p>
			                  </li>
			                  <li> <div  <?php 
            if (isset($_REQUEST['show_payment']) && $_REQUEST['show_payment'] == 'true') {
                echo ' class="yellow_inform"';
            }
            ?>
><strong>
			<?php 
            _e('This Attendee:', 'event_espresso');
            ?>
														</strong>
														<table width="100%" border="0">
															<tr>
																<td width="25%" align="left" valign="top"><label>
			<?php 
            _e('Amount:', 'event_espresso');
            ?>
																	</label></td>
																<td width="25%" align="left" valign="top"><label>
			<?php 
            _e('# Tickets:', 'event_espresso');
            ?>
																	</label></td>
																<td width="50%" align="left" valign="top"><label>
			<?php 
            _e('Total:', 'event_espresso');
            ?>
																	</label></td>
															</tr>
															<tr>
																<td align="left" valign="top"><?php 
            echo $org_options['currency_symbol'];
            ?>
																	<input name="amount_pd" type="text" value ="<?php 
            echo espresso_attendee_price(array('attendee_id' => $id, 'single_price' => true));
            ?>
" /></td>
																<td align="left" valign="top"> X
																	<input name="quantity" type="text" value ="<?php 
            echo !empty($quantity) ? $quantity : 1;
            ?>
"  /></td>
																<td align="left" valign="top"><?php 
            echo $org_options['currency_symbol'];
            echo espresso_attendee_price(array('attendee_id' => $id));
            ?>
</td>
															</tr>
														</table></div>
			                  </li>
			                  <li>
			                    <input type="submit" name="Submit" value="Update Payment" />
			                  </li>
			                </ul>
			              </fieldset>
			              <input type="hidden" name="id" value="<?php 
            echo $id;
            ?>
" />
			              <input type="hidden" name="registration_id" value="<?php 
            echo $registration_id;
            ?>
" />
			              <input type="hidden" name="form_action" value="edit_attendee" />
			              <input type="hidden" name="event_id" value="<?php 
            echo $event_id;
            ?>
" />
			              <input type="hidden" name="attendee_payment" value="update_payment" />
			            </form>
			<?php 
        }
        // !$has_seating_chart
        ?>
</td>
		        </tr>
		      </table>
		      <p> <strong> <a href="admin.php?page=events&event_id=<?php 
        echo $event_id;
        ?>
&event_admin_reports=list_attendee_payments"> &lt;&lt;
		<?php 
        _e('Back to List', 'event_espresso');
        ?>
							</a> </strong> </p>
		    </div>
		  </div>
		</div>
		<?php 
    }
}
function output_event_seating_chart()
{
    global $wpdb;
    $seating_chart_event = NULL;
    seating_chart::clear_booking();
    if (isset($_REQUEST['event_id']) && is_numeric($_REQUEST['event_id']) || isset($_REQUEST['seating_chart_id']) && is_numeric($_REQUEST['seating_chart_id'])) {
        $event_id = isset($_REQUEST['event_id']) && is_numeric($_REQUEST['event_id']) ? $_REQUEST['event_id'] : 0;
        $seating_chart_id = isset($_REQUEST['seating_chart_id']) && is_numeric($_REQUEST['seating_chart_id']) ? $_REQUEST['seating_chart_id'] : 0;
        if ($event_id > 0) {
            $seating_chart_event = $wpdb->get_row("select * from " . EVENTS_SEATING_CHART_EVENT_TABLE . " where event_id = {$event_id} ");
            $seating_chart_id = $seating_chart_event->seating_chart_id;
        }
        if ($seating_chart_id > 0) {
            $venue = NULL;
            if ($event_id > 0) {
                $venue = $wpdb->get_results("select v.* from " . EVENTS_VENUE_TABLE . "  v inner join " . EVENTS_VENUE_REL_TABLE . " vr on v.id = vr.venue_id where vr.event_id = {$event_id} ");
            }
            echo "<h2>" . (is_array($venue) && count($venue) > 0 ? $venue[0]->name : __('Choose a Seat', 'event_espresso')) . "</h2>";
            echo "<div id='ee_s_layout'>";
            #$seating_chart_id = $seating_chart_event->seating_chart_id;
            $levels = seating_chart::get_level_list($seating_chart_id);
            $sections_ar = seating_chart::get_section_ar_list($seating_chart_id);
            $rows_ar = seating_chart::get_row_ar_list($seating_chart_id);
            $seats_ar = array();
            $seats_ar['asc'] = seating_chart::get_seat_ar_list($seating_chart_id, 'asc');
            $seats_ar['desc'] = seating_chart::get_seat_ar_list($seating_chart_id, 'desc');
            foreach ($levels as $level) {
                ?>

                <div id="ee_s_level_<?php 
                echo str_replace(" ", "_", $level->level);
                ?>
" class="ee_s_level">
                    <h4 class="level_head"><strong><?php 
                _e('Level:', 'event_espresso');
                ?>
</strong> <?php 
                echo $level->level;
                ?>
</h4>
                    <div class="ee_s_clear">&nbsp;</div>
                <?php 
                $sections = isset($sections_ar[$level->level]) ? $sections_ar[$level->level] : array();
                //echo "<pre>".print_r($sections,true)."</pre>";
                foreach ($sections as $section) {
                    $alignment = seating_chart::get_section_alignment($seating_chart_id, $level->level, $section->section);
                    $section->section_title = __('Section:', 'event_espresso');
                    $section->section_name = $section->section;
                    ?>
                        <div id="ee_s_section_<?php 
                    echo str_replace(" ", "_", $section->section);
                    ?>
" class="ee_s_section" style="float:<?php 
                    echo $alignment;
                    ?>
;">
                            <h5 class="section_head" style="min-width:<?php 
                    echo strlen($section->section) * 8;
                    ?>
px;"><strong><?php 
                    echo $section->section_title;
                    ?>
</strong> <?php 
                    echo $section->section_name;
                    ?>
</h5>
                    <?php 
                    $rows = isset($rows_ar[$level->level][$section->section]) ? $rows_ar[$level->level][$section->section] : array();
                    //$wpdb->get_results("select distinct row from " . EVENTS_SEATING_CHART_SEAT_TABLE . " where seating_chart_id = {$seating_chart_event->seating_chart_id} and level = '{$level->level}' and section = '{$section->section}' order by row ");
                    foreach ($rows as $row) {
                        $alignment = seating_chart::get_section_alignment($seating_chart_id, $level->level, $section->section);
                        $sort_order = seating_chart::get_section_sort_order($seating_chart_id, $level->level, $section->section);
                        ?>
                                <div id="ee_s_row_<?php 
                        echo str_replace(" ", "_", $row->row);
                        ?>
" class="ee_s_row" style="clear: both;">
                            <?php 
                        $seats = $seats_ar[$sort_order][$level->level][$section->section][$row->row];
                        foreach ($seats as $seat) {
                            $ee_seat_availability_class = "";
                            $ee_seat_placeholder = "";
                            $ee_seat_reserved = "";
                            $price = 0;
                            if (function_exists('espresso_members_version') && is_user_logged_in()) {
                                $price = $seat->member_price;
                            } else {
                                $price = $seat->price;
                            }
                            $check = seating_chart::check_seat_available($event_id, $seat->id);
                            if ($check == 0) {
                                $ee_seat_availability_class = 'ee_s_available';
                            } else {
                                $ee_seat_availability_class = 'ee_s_unavailable';
                            }
                            if (strtolower($seat->custom_tag) == "placeholder") {
                                $ee_seat_placeholder = "_placeholder";
                                $ee_seat_availability_class = "placeholder";
                            }
                            if (strtolower($seat->custom_tag) == "reserved") {
                                $ee_seat_reserved = "_reserved";
                                $ee_seat_availability_class = "ee_s_unavailable";
                            }
                            ?>
                                        <div id="ee_s_seat_<?php 
                            echo $seat->id;
                            ?>
" class="ee_s_seat<?php 
                            echo $ee_seat_placeholder . $ee_seat_reserved;
                            ?>
 <?php 
                            echo $ee_seat_availability_class;
                            ?>
"
                                             event_id="<?php 
                            echo $event_id;
                            ?>
"
                                             seat_id="<?php 
                            echo $seat->id;
                            ?>
"
                                             seat="<?php 
                            echo $seat->seat;
                            ?>
"
                                             price="<?php 
                            echo $price;
                            ?>
"
                                             row="<?php 
                            echo $row->row;
                            ?>
"
                                             section="<?php 
                            echo $section->section;
                            ?>
"
                                             level="<?php 
                            echo $level->level;
                            ?>
"  >
                                            <span style="display:none;" class="ee_s_custom_tag"><?php 
                            echo $seat->custom_tag;
                            ?>
</span>
                                            <span style="display:none;" class="ee_s_description"><?php 
                            echo $seat->description;
                            ?>
</span>
                                        </div>
                                        <?php 
                        }
                        ?>
                                </div>
                                    <?php 
                    }
                    ?>
                        </div>
                    <?php 
                }
                ?>
                    <div class="ee_s_clear">&nbsp;</div>
                </div>
                <?php 
            }
            echo "</div>";
        }
    }
}