';
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($wpdb->prepare($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:
';
print_r($sql);
echo '
';
print 'Number of vars: ' . count ($sql);
echo '
';
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($wpdb->prepare(" 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($wpdb->prepare("delete from " . EVENTS_SEATING_CHART_EVENT_SEAT_TABLE . " where attendee_id = " . $v->id));
}
}
/*
* End
*/
$wpdb->query($wpdb->prepare(" 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($wpdb->prepare(" 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->prepare($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:
';
print_r($sql);
echo '
';
print 'Number of vars: ' . count ($sql);
echo '
';
print 'Number of cols: ' . count($sql_data); */
if ( !$wpdb->prepare($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($wpdb->prepare("select * from " . EVENTS_PRICES_TABLE . " where id = $attendee_price_id "));
} else {
$events_prices = $wpdb->get_row($wpdb->prepare("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);
do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, 'line 355: attendee_cost='.$attendee_cost);
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->prepare($wpdb->insert(EVENTS_ATTENDEE_COST_TABLE, $attendee_cost_data));
/**
* End
*/
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 > 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'];
if ( empty($questions) ){
$questions = $base_questions;
}
//Debug
//echo "
".print_r($questions,true)."
";
if (isset($att_data_source['x_attendee_fname'])) {
$amount_pd = 0.00; //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->prepare($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->prepare($wpdb->insert(EVENTS_ATTENDEE_COST_TABLE, $attendee_cost_data));
/**
* End
*/
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' => $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 "
".print_r($questions,true)."
";
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($wpdb->prepare("SELECT q.*, qg.group_name
FROM " . EVENTS_QUESTION_TABLE . " q
JOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr
on q.id = qgr.question_id
JOIN " . EVENTS_QST_GROUP_TABLE . " qg
on qg.id = qgr.group_id
WHERE 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 (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);
}
}
//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;
}
}
if (!function_exists('event_espresso_add_attendees_to_db_multi')) {
//This function is called from the shopping cart
function event_espresso_add_attendees_to_db_multi() {
do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
global $wpdb, $org_options, $no_recaptcha;
//Added by Imon
$primary_registration_id = NULL;
$events_in_session = $_SESSION['espresso_session']['events_in_session'];
if (event_espresso_invoke_cart_error($events_in_session))
return false;
$count_of_events = count($events_in_session);
$current_session_id = $_SESSION['espresso_session']['id'];
//Debug
//echo "
", print_r($_SESSION), "
";
//echo '
'.print_r($_POST, true).'
';
//echo "
", print_r($events_in_session), "
";
//echo "
", print_r($org_options), "
";
$event_name = $count_of_events . ' ' . $org_options['organization'] . __(' events', 'event_espresso');
$event_cost = $_SESSION['espresso_session']['grand_total'];
$multi_reg = true;
// If there are events in the session, add them one by one to the attendee table
if ($count_of_events > 0) {
//first event key will be used to find the first attendee
$first_event_id = key($events_in_session);
//Debug
//echo '
$events_in_session - '.print_r($events_in_session, true).'
';
reset($events_in_session);
foreach ($events_in_session as $key => $_event_id) {
//Debug
//echo '
$_event_id - '. $_event_id.'
';
//echo '
'.print_r($_event_id, true).'
';
$event_meta = event_espresso_get_event_meta($key);
$event_attendees = $_event_id['event_attendees'];
$session_vars['data'] = $_event_id;
//Debug
//echo '
$_event_id - '. $_event_id.'
';
//echo '
'.print_r($session_vars['data'], true).'
';
if (is_array($event_attendees)) {
$counter = 1;
foreach ($event_attendees as $k_price_id => $v_attendees) { //foreach price type in event attendees
$session_vars['data'] = $_event_id;
//Debug
//echo '
$session_vars[\'data\' - ]'.print_r($session_vars['data'], true).'
';
foreach ($v_attendees as $vkey => $vval) {
//Added by Imon
$vval['price_id'] = $k_price_id;
$session_vars['event_attendees'] = $vval; //this has all the attendee information, name, questions....
$session_vars['data']['price_type'] = $_event_id['price_id'][$k_price_id]['price_type'];
if (isset($event_meta['additional_attendee_reg_info']) && $event_meta['additional_attendee_reg_info'] == 1) {
//Getting he wrong number of attendees at this point
//Debug
//echo '
$_REQUEST[\'num_people\'] - '.$_REQUEST['num_people'].'
';
//echo '
$_event_id[\'price_id\'][$k_price_id] - '.$_event_id['price_id'][$k_price_id].'
';
//echo '
$_event_id[\'price_id\'][$k_price_id] - '.print_r($_event_id['price_id'][$k_price_id]['attendee_quantity'], true).'
';
//echo '
'.print_r($_POST, true).'
';
$num_people = $_event_id['price_id'][$k_price_id]['attendee_quantity'];
$session_vars['data']['num_people'] = empty($num_people) || $num_people == 0 ? 1 : $num_people;
//Debug
//echo '
$session_vars[\'data\'][\'num_people\'] - '.$session_vars['data']['num_people'].'
';
}
//Debug
/* echo $key.'
';
echo '
$session_vars - '.print_r($session_vars, true).'
';
echo '
'; */
$tmp_registration_id = event_espresso_add_attendees_to_db($key, $session_vars);
//Debug
//echo 'tmp_registration_id =' . $tmp_registration_id.'
';
if ($primary_registration_id === NULL) {
$primary_registration_id = $tmp_registration_id;
}
$c2_sql = "select * from " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " where primary_registration_id = '$primary_registration_id' and registration_id = '$tmp_registration_id'";
//Debug
//echo $c2_sql.'
';
$check = $wpdb->get_row($c2_sql);
if ($check === NULL) {
$tmp_data = array("primary_registration_id" => $primary_registration_id, "registration_id" => $tmp_registration_id);
$wpdb->prepare($wpdb->insert(EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE, $tmp_data));
}
}
$counter++;
}
}
}
//Post the gateway page with the payment options
if ($event_cost != '0.00') {
//find first registrant's name, email, count of registrants
$sql = "SELECT id, fname, lname, email, address, city, state, zip, event_id, registration_id,
(SELECT count( id )
FROM " . EVENTS_ATTENDEE_TABLE .
" WHERE attendee_session = '" . $wpdb->escape($current_session_id) . "'
) AS quantity
FROM " . EVENTS_ATTENDEE_TABLE
. " WHERE event_id = " . $wpdb->escape($first_event_id)
. " AND attendee_session = '" . $wpdb->escape($current_session_id) . "' LIMIT 1";
//echo $sql;
$r = $wpdb->get_row($sql);
$event_id = $r->event_id;
$attendee_id = $r->id;
$fname = $r->fname;
$lname = $r->lname;
$address = $r->address;
$city = $r->city;
$state = $r->state;
$zip = $r->zip;
$attendee_email = $r->email;
$registration_id = $r->registration_id;
$quantity = espresso_count_attendees_for_registration($r->registration_id);
?>
®event_action=show_shopping_cart">
*/ ?>
$_SESSION['espresso_session']['id'], 'send_admin_email' => 'true', 'send_attendee_email' => 'true', 'multi_reg' => true));
}
} elseif ($event_cost == '0.00') { ?>
$_SESSION['espresso_session']['id'], 'send_admin_email' => 'true', 'send_attendee_email' => 'true', 'multi_reg' => true));
event_espresso_clear_session();
}
}
}
}