Ejemplo n.º 1
0
    function event_espresso_add_attendees_to_db_multi()
    {
        //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;
        if (espresso_verify_recaptcha()) {
            $primary_registration_id = NULL;
            $multi_reg = true;
            $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'];
            $biz_name = $count_of_events . ' ' . $org_options['organization'] . __(' events', 'event_espresso');
            $event_cost = $_SESSION['espresso_session']['grand_total'];
            $event_cost = apply_filters('filter_hook_espresso_cart_grand_total', $event_cost);
            // 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);
                reset($events_in_session);
                foreach ($events_in_session as $event_id => $event) {
                    $event_meta = event_espresso_get_event_meta($event_id);
                    $session_vars['data'] = $event;
                    if (is_array($event['event_attendees'])) {
                        $counter = 1;
                        //foreach price type in event attendees
                        foreach ($event['event_attendees'] as $price_id => $event_attendees) {
                            $session_vars['data'] = $event;
                            foreach ($event_attendees as $attendee) {
                                $attendee['price_id'] = $price_id;
                                //this has all the attendee information, name, questions....
                                $session_vars['event_attendees'] = $attendee;
                                $session_vars['data']['price_type'] = $event['price_id'][$price_id]['price_type'];
                                if (isset($event_meta['additional_attendee_reg_info']) && $event_meta['additional_attendee_reg_info'] == 1) {
                                    $num_people = (int) $event['price_id'][$price_id]['attendee_quantity'];
                                    $session_vars['data']['num_people'] = empty($num_people) || $num_people == 0 ? 1 : $num_people;
                                }
                                // ADD ATTENDEE TO DB
                                $return_data = event_espresso_add_attendees_to_db($event_id, $session_vars, TRUE);
                                $tmp_registration_id = $return_data['registration_id'];
                                $notifications = $return_data['notifications'];
                                if ($primary_registration_id === NULL) {
                                    $primary_registration_id = $tmp_registration_id;
                                }
                                $SQL = "SELECT * FROM " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . "  ";
                                $SQL .= "WHERE primary_registration_id = %s AND registration_id = %s";
                                $check = $wpdb->get_row($wpdb->prepare($SQL, $primary_registration_id, $tmp_registration_id));
                                if ($check === NULL) {
                                    $tmp_data = array('primary_registration_id' => $primary_registration_id, 'registration_id' => $tmp_registration_id);
                                    $wpdb->insert(EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE, $tmp_data, array('%s', '%s'));
                                }
                                $counter++;
                            }
                        }
                    }
                }
                $SQL = "SELECT a.*, ed.id AS event_id, ed.event_name, dc.coupon_code_price, dc.use_percentage ";
                $SQL .= "FROM " . EVENTS_ATTENDEE_TABLE . " a JOIN " . EVENTS_DETAIL_TABLE . " ed ON a.event_id=ed.id ";
                $SQL .= "LEFT JOIN " . EVENTS_DISCOUNT_CODES_TABLE . " dc ON a.coupon_code=dc.coupon_code ";
                $SQL .= "WHERE attendee_session=%s ORDER BY a.id ASC";
                $attendees = $wpdb->get_results($wpdb->prepare($SQL, $current_session_id));
                //printr( $attendees, '$attendees  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
                $quantity = 0;
                $final_total = 0;
                $sub_total = 0;
                $discounted_total = 0;
                $discount_amount = 0;
                //$coupon_amount = ! empty($attendees[0]->coupon_code_price) ? $attendees[0]->coupon_code_price : 0;
                $is_coupon_pct = !empty($attendees[0]->use_percentage) && $attendees[0]->use_percentage == 'Y' ? TRUE : FALSE;
                //printr( $attendees, '$attendees  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
                foreach ($attendees as $attendee) {
                    if ($attendee->is_primary) {
                        $primary_attendee_id = $attendee_id = $attendee->id;
                        $coupon_code = $attendee->coupon_code;
                        $event_id = $attendee->event_id;
                        $fname = $attendee->fname;
                        $lname = $attendee->lname;
                        $address = $attendee->address;
                        $city = $attendee->city;
                        $state = $attendee->state;
                        $zip = $attendee->zip;
                        $attendee_email = $attendee->email;
                        $registration_id = $attendee->registration_id;
                    }
                    $final_total += $attendee->final_price;
                    $sub_total += (int) $attendee->quantity * $attendee->orig_price;
                    $discounted_total += (int) $attendee->quantity * $attendee->final_price;
                    $quantity += (int) $attendee->quantity;
                    //echo '<h2>$attendee->id : ' . $attendee->id . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h2>';
                    //echo '<h4>$attendee->orig_price : ' . $attendee->orig_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                    //echo '<h4>$attendee->final_price : ' . $attendee->final_price . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                    //echo '<h4>$attendee->quantity : ' . (int)$attendee->quantity . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                    //echo '<h4>$sub_total : ' . $sub_total . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                    //echo '<h4>$discounted_total : ' . $discounted_total . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                }
                $discount_amount = $sub_total - $discounted_total;
                $total_cost = $discounted_total;
                //echo '<h4>$discount_amount : ' . $discount_amount . '  <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>';
                //echo '<h4>$final_total : ' . $final_total . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4><br/>';
                $total_cost = $total_cost < 0 ? 0.0 : (double) $total_cost;
                if (function_exists('espresso_update_attendee_coupon_info') && $primary_attendee_id && !empty($attendee->coupon_code)) {
                    espresso_update_attendee_coupon_info($primary_attendee_id, $attendee->coupon_code);
                }
                if (function_exists('espresso_update_groupon') && $primary_attendee_id && !empty($coupon_code)) {
                    espresso_update_groupon($primary_attendee_id, $coupon_code);
                }
                espresso_update_primary_attendee_total_cost($primary_attendee_id, $total_cost, __FILE__);
                //echo '<h4>$total_cost : ' . $total_cost . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                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>';
                }
                //Post the gateway page with the payment options
                if ($total_cost > 0) {
                    ?>

<div class="espresso_payment_overview event-display-boxes ui-widget" >
  <h3 class="section-heading ui-widget-header ui-corner-top">
		<?php 
                    _e('Payment Overview', 'event_espresso');
                    ?>
  </h3>
	<div class="event-data-display ui-widget-content ui-corner-bottom" >

		<div class="event-messages ui-state-highlight"> <span class="ui-icon ui-icon-alert"></span>
			<p class="instruct">
				<?php 
                    _e('Your registration is not complete until payment is received.', 'event_espresso');
                    ?>
			</p>
		</div>
		<p><?php 
                    echo $org_options['email_before_payment'] == 'Y' ? __('A confirmation email has been sent with additional details of your registration.', 'event_espresso') : '';
                    ?>
</p>
		<table>
			<?php 
                    foreach ($attendees as $attendee) {
                        ?>
			<tr>
				<td width="70%">
					<?php 
                        echo '<strong>' . stripslashes_deep($attendee->event_name) . '</strong>';
                        ?>
&nbsp;-&nbsp;<?php 
                        echo stripslashes_deep($attendee->price_option);
                        ?>
 <?php 
                        echo $attendee->final_price < $attendee->orig_price ? '<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size:.8em;">' . $org_options['currency_symbol'] . number_format($attendee->orig_price - $attendee->final_price, 2) . __(' discount per registration', 'event_espresso') . '</span>' : '';
                        ?>
<br/>
					&nbsp;&nbsp;&nbsp;&nbsp;<?php 
                        echo __('Attendee:', 'event_espresso') . ' ' . stripslashes_deep($attendee->fname . ' ' . $attendee->lname);
                        ?>
				</td>
				<td width="10%"><?php 
                        echo $org_options['currency_symbol'] . number_format($attendee->final_price, 2);
                        ?>
</td>
				<td width="10%"><?php 
                        echo 'x ' . (int) $attendee->quantity;
                        ?>
</td>
				<td width="10%" style="text-align:right;"><?php 
                        echo $org_options['currency_symbol'] . number_format($attendee->final_price * (int) $attendee->quantity, 2);
                        ?>
</td>
			</tr>
			<?php 
                    }
                    ?>
			
			<tr>
				<td colspan="3"><?php 
                    _e('Sub-Total:', 'event_espresso');
                    ?>
</td>
				<td colspan="" style="text-align:right"><?php 
                    echo $org_options['currency_symbol'] . number_format($sub_total, 2);
                    ?>
</td>
			</tr>
			<?php 
                    if (!empty($discount_amount)) {
                        ?>
			<tr>
				<td colspan="3"><?php 
                        _e('Total Discounts:', 'event_espresso');
                        ?>
</td>
				<td colspan="" style="text-align:right"><?php 
                        echo '-' . $org_options['currency_symbol'] . number_format($discount_amount, 2);
                        ?>
</td>
			</tr>
			<?php 
                    }
                    ?>
			<tr>
				<td colspan="3"><strong class="event_espresso_name">
					<?php 
                    _e('Total Amount due: ', 'event_espresso');
                    ?>
					</strong></td>
				<td colspan="" style="text-align:right"><?php 
                    echo $org_options['currency_symbol'];
                    echo number_format($total_cost, 2);
                    ?>
</td>
			</tr>
		</table>
		<p class="event_espresso_refresh_total">
			<a href="?page_id=<?php 
                    echo $org_options['event_page_id'];
                    ?>
&regevent_action=show_shopping_cart">
			<?php 
                    _e('Edit Cart', 'event_espresso');
                    ?>
			</a>
			<?php 
                    _e(' or ', 'event_espresso');
                    ?>
			<a href="?page_id=<?php 
                    echo $org_options['event_page_id'];
                    ?>
&registration_id=<?php 
                    echo $registration_id;
                    ?>
&id=<?php 
                    echo $attendee_id;
                    ?>
&regevent_action=edit_attendee&primary=<?php 
                    echo $primary_attendee_id;
                    ?>
&event_id=<?php 
                    echo $event_id;
                    ?>
&attendee_num=1">
			<?php 
                    _e('Edit Registrant Information', 'event_espresso');
                    ?>
			</a> 
		</p>
	</div>
</div>
<br/><br/>
<?php 
                    //Show payment options
                    if (file_exists(EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php")) {
                        require_once EVENT_ESPRESSO_GATEWAY_DIR . "gateway_display.php";
                    } else {
                        require_once EVENT_ESPRESSO_PLUGINFULLPATH . "gateways/gateway_display.php";
                    }
                    //Check to see if the site owner wants to send an confirmation eamil before payment is recieved.
                    if ($org_options['email_before_payment'] == 'Y') {
                        event_espresso_email_confirmations(array('session_id' => $_SESSION['espresso_session']['id'], 'send_admin_email' => 'true', 'send_attendee_email' => 'true', 'multi_reg' => true));
                    }
                } elseif ($total_cost == 0.0) {
                    ?>
<p>
	<?php 
                    _e('Thank you! Your registration is confirmed for', 'event_espresso');
                    ?>
	<strong><?php 
                    echo stripslashes_deep($biz_name);
                    ?>
</strong></p>
<p>
	<?php 
                    _e('A confirmation email has been sent with additional details of your registration.', 'event_espresso');
                    ?>
</p>
<?php 
                    event_espresso_email_confirmations(array('session_id' => $_SESSION['espresso_session']['id'], 'send_admin_email' => 'true', 'send_attendee_email' => 'true', 'multi_reg' => true));
                    event_espresso_clear_session();
                }
            }
        }
    }
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";
        }
    }
}