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); /* * 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; $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 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 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 JOIN " . EVENTS_DETAIL_TABLE . " t2 ON t1.event_id = t2.id WHERE $WHERE 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; /* * 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; } } } /* *End */ $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') { ?>