", print_r( $_POST ), "";
$events_in_session = $_SESSION['espresso_session']['events_in_session'];
/*
* added the cart_link_# to the page to prevent element id conflicts on the html page
*
*/
$id = $_POST['id'];
$direct_to_cart = isset($_POST['direct_to_cart']) ? $_POST['direct_to_cart'] : 0;
$moving_to_cart = isset($_POST['moving_to_cart']) ? urldecode($_POST['moving_to_cart']) : "Please wait redirecting to cart page";
//One link, multiple events
if (strpos($id, "-")) {
$event_group = str_replace('cart_link_', '', $id);
$event_group = explode("-", $event_group);
foreach ($event_group as $event) {
$event_title = get_event_field('event_name', EVENTS_DETAIL_TABLE, ' WHERE id = ' . $event);
event_espresso_add_event_process((int) $event, $event_title);
}
} else { //one event per click
$id = str_replace('cart_link_', '', $id);
event_espresso_add_event_process($id, $_POST['name']);
}
$r = event_espresso_cart_link(array('event_id' => $id, 'view_cart' => TRUE, 'event_page_id' => $_POST['event_page_id'], 'direct_to_cart' => $direct_to_cart, 'moving_to_cart' => $moving_to_cart));
echo event_espresso_json_response(array('html' => $r, 'code' => 1));
//echo '' . __( 'View Cart', 'event_espresso' ) . '';
die();
}
}
/**
* Processor function for adding items to the session
*
* @param event_id
* @param event_name
*
* @return true
*/
if (!function_exists('event_espresso_add_event_process')) {
function event_espresso_add_event_process($event_id, $event_name) {
do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
$events_in_session = $_SESSION['espresso_session']['events_in_session'];
$events_in_session[$event_id] = array(
'id' => $event_id,
'event_name' => stripslashes_deep($event_name),
'attendee_quantitiy' => 1,
'start_time_id' => '',
'price_id' => array(),
'cost' => 0,
'event_attendees' => array()
);
$_SESSION['espresso_session']['events_in_session'] = $events_in_session;
return true;
}
}
/**
* Convert passed array to json object
*
* @param array
*
* @return JSON object
*/
if (!function_exists('event_espresso_json_response')) {
function event_espresso_json_response($params = array()) {
do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
$params['code'] = 1;
return json_encode($params);
}
}
/**
* Return an individual Session variable
*
* @param key
*
* @return value of session key
*/
if (!function_exists('event_espresso_return_session_var')) {
function event_espresso_return_session_var($k = null) {
do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
if (is_null($k))
return;
return array_key_exists($k, $_SESSION) ? $_SESSION[$k] : null;
}
}
/**
* Updates item information in the session
*
* @param $_POST
*
* @return true
*/
if (!function_exists('event_espresso_update_item_in_session')) {
function event_espresso_update_item_in_session($update_section = null) {
global $wpdb;
do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
/*
* - grab the event sessions
* - loop through the events and for each one
* -- update the pricing, time options
* -- update the attendee information
*/
$events_in_session = $_SESSION['espresso_session']['events_in_session'];
if (!is_array($events_in_session))
return false;
//holds the updated infromation
$updated_events_in_session = $events_in_session;
//$updated_events_in_session = array( );
if ($update_section == 'details') {
foreach ($events_in_session as $k => $v) {
$event_cost = 0;
$event_id = $k;
$event_individual_cost[$event_id] = 0;
$updated_events_in_session[$event_id]['id'] = $event_id;
/*
* if the array key exists, update that array key with the value from post
*/
//Start time selection
$start_time_id = '';
if (array_key_exists('start_time_id', $_POST) && array_key_exists($event_id, $_POST['start_time_id'])) {
$updated_events_in_session[$event_id]['start_time_id'] = $wpdb->escape($_POST['start_time_id'][$event_id]);
//unset the post key so it doesn't get added below
unset($_POST['start_time_id'][$event_id]);
}
//Pricing selection
$price_id = null;
//resetting this session var for just in case the event organizer makes changes when someone is
//registering, the old price ids don't stay in the session
$updated_events_in_session[$event_id]['price_id'] = array();
/*
* the price id comes this way
* - from a dropdown >> price_id[event_id][price_id]
* - from a radio >> price_id[event_id] with a value of price_id
*/
$attendee_quantitiy = 1;
$price_id = $_POST['price_id'][$event_id];
if (is_array($price_id)) {
foreach ($price_id as $_price_id => $val) {
//assign the event type and the quantity
$updated_events_in_session[$event_id]['price_id'][$_price_id]['attendee_quantity'] = $wpdb->escape($val);
$updated_events_in_session[$event_id]['price_id'][$_price_id]['price_type'] = $events_in_session[$event_id]['price_id'][$_price_id]['price_type'];
$attendee_quantitiy++;
}
} else {
if (isset($price_id)) {
$updated_events_in_session[$event_id]['price_id'][$price_id]['attendee_quantity'] = 1;
$updated_events_in_session[$event_id]['price_id'][$price_id]['price_type'] = $events_in_session[$event_id]['price_id'][$price_id]['price_type'];
}
}
$updated_events_in_session[$event_id]['attendee_quantitiy'] = $attendee_quantitiy;
//Get Cost of each event
//$updated_events_in_session[$event_id]['cost'] = $event_individual_cost[$event_id];
//$updated_events_in_session[$event_id]['event_name'] = $wpdb->escape( $_POST['event_name'][$event_id] );
if (isset($_POST['event_espresso_coupon_code'])) {
$_SESSION['espresso_session']['coupon_code'] = $wpdb->escape($_POST['event_espresso_coupon_code']);
}
}
}
if ($update_section == 'attendees') {
//show the empty cart error
if (event_espresso_invoke_cart_error($events_in_session))
return false;
foreach ($events_in_session as $k_event_id => $v_event_id) {
//unset the event attendees array because they may have decreased the number of attendees
if (isset($updated_events_in_session[$k_event_id]['event_attendees']))
$updated_events_in_session[$k_event_id]['event_attendees'] = array();
$price_id = $v_event_id['price_id'];
if (is_array($price_id)) {
foreach ($price_id as $_price_id => $val) {
$index = 1;
//assign the event type and the quantity
foreach ($_POST as $post_name => $post_value) {
//$field_values come in as arrays since their names are designated as arrays,e.g. fname[eventid][price_id][index]
if (is_array($post_value) && array_key_exists($k_event_id, $post_value) && array_key_exists($_price_id, $post_value[$k_event_id])) {
foreach ($post_value[$k_event_id][$_price_id] as $mkey => $mval) {
if (is_array($mval)) {
array_walk_recursive($mval, 'sanitize_text_field');
} else {
$mval = sanitize_text_field($mval);
}
$updated_events_in_session[$k_event_id]['event_attendees'][$_price_id][$mkey][$post_name] = $mval;
//echo "multi $k > $field_name >" . $mkey . " > " . $mval . "
";
}
}
}
}
}
}
}
$_SESSION['espresso_session']['events_in_session'] = $updated_events_in_session;
//echo "
", print_r($updated_events_in_session), ""; return true; die(); } } /** * Calculates total of the items in the session * * @param $_POST * * @return JSON (grand total) */ if (!function_exists('event_espresso_calculate_total')) { function event_espresso_calculate_total($update_section = null) { //print_r($_POST); global $wpdb; $events_in_session = $_SESSION['espresso_session']['events_in_session']; do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, ''); if (is_array($events_in_session)) { $event_total_cost = 0; foreach ($events_in_session as $k => $v) { $event_cost = 0; $event_id = $k; $event_individual_cost[$event_id] = 0; $start_time_id = ''; if (array_key_exists('start_time_id', $_POST) && array_key_exists($event_id, $_POST['start_time_id'])) { $start_time_id = $_POST['start_time_id'][$event_id]; } /* * two ways the price id comes this way * - from a dropdown >> price_id[event_id][price_id] * - from a radio >> price_id[event_id] with a value of price_id */ $price_id = $_POST['price_id'][$event_id]; if (is_array($price_id)) { foreach ($price_id as $_price_id => $val) { $attendee_quantitiy = $wpdb->escape($val); if ($attendee_quantitiy > 0) { $event_cost = event_espresso_get_final_price($_price_id, $event_id); do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, 'line 324: event_cost='.$event_cost); $event_individual_cost[$event_id] += number_format($event_cost * $attendee_quantitiy, 2, '.', ''); } } } else { $attendee_quantitiy = 1; $event_cost = event_espresso_get_final_price($price_id, $event_id); do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, 'line 331: event_cost='.$event_cost); $event_individual_cost[$event_id] = number_format($event_cost * $attendee_quantitiy, 2, '.', ''); } $_SESSION['espresso_session']['events_in_session'][$event_id]['cost'] = $event_individual_cost[$event_id]; $event_total_cost += $event_individual_cost[$event_id]; } $_SESSION['espresso_session']['pre_discount_total'] = number_format($event_total_cost, 2, '.', ''); if (function_exists('event_espresso_coupon_payment_page') && isset($_POST['event_espresso_coupon_code'])) { if (isset($_POST['event_espresso_coupon_code'])) { $event_total_cost_array = event_espresso_coupon_payment_page('Y', NULL, $event_total_cost, NULL); //Returns an array //array('event_cost'=>$event_cost, 'valid'=>$valid, 'percentage'=>$percentage, 'discount'=>$discount_type_price); $event_total_cost = $event_total_cost_array['event_cost']; } } $grand_total = number_format($event_total_cost, 2, '.', ''); $_SESSION['espresso_session']['grand_total'] = $grand_total; event_espresso_update_item_in_session($update_section); } //} if ($update_section == null) { echo event_espresso_json_response(array('grand_total' => $grand_total)); die(); } } } /** * Delete and item from the session * * @param $_POST * * @return JSON 0 or 1 */ if (!function_exists('event_espresso_delete_item_from_session')) { function event_espresso_delete_item_from_session() { global $wpdb; do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, ''); $events_in_session = $_SESSION['espresso_session']['events_in_session']; /* * added the cart_link_# to the page to prevent element id conflicts on the html page * */ $id = $_POST['id']; $id = str_replace('cart_link_', '', $id); unset($events_in_session[$id]); if (count($events_in_session) == 0) { unset($_SESSION['espresso_session']['coupon_code']); unset($_SESSION['espresso_session']['events_in_session']); unset($_SESSION['espresso_session']['grand_total']); } else $_SESSION['espresso_session']['events_in_session'] = $events_in_session; echo event_espresso_json_response(); die(); } } /** * Loads the registration form based on information in the session * * @return HTML form */ if (!function_exists('event_espresso_load_checkout_page')) { function event_espresso_load_checkout_page() { global $wpdb, $org_options; do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, ''); $events_in_session = $_SESSION['espresso_session']['events_in_session']; if (event_espresso_invoke_cart_error($events_in_session)) return false; //echo "
", print_r( $_SESSION ), ""; if (file_exists(EVENT_ESPRESSO_TEMPLATE_DIR . "multi_registration_page.php")) { require_once(EVENT_ESPRESSO_TEMPLATE_DIR . "multi_registration_page.php"); //This is the path to the template file if available } else { require_once(EVENT_ESPRESSO_PLUGINFULLPATH . "templates/multi_registration_page.php"); } $response['html'] = ''; //if the counte of event in the session >0, ok to process if (count($events_in_session) > 0) { //for each one of the events in session, grab the event ids, drop into temp array, impode to construct SQL IN clasue (IN(1,5,7)) foreach ($events_in_session as $event) { // echo $event['id']; if (is_numeric($event['id'])) $events_IN[] = $event['id']; } $events_IN = implode(',', $events_IN); $sql = "SELECT e.* FROM " . EVENTS_DETAIL_TABLE . " e "; $sql .= " WHERE e.id in ($events_IN) "; $sql .= " ORDER BY e.start_date "; $result = $wpdb->get_results($sql); //will hold data to pass to the form builder function $meta = array(); //echo "
", print_r($_POST), ""; ?>
" , print_r($_POST) , ""; die(); } } /** * Creates the # of Attendees dropdown in the shopping cart page * * @param $event_id * @param $price_id * @param $qty - of attendees allowed in this registration * @param $value - previously selected value * * @return Dropdown */ if (!function_exists('event_espresso_multi_qty_dd')) { function event_espresso_multi_qty_dd($event_id, $price_id, $qty, $value = '') { $counter = 0; do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, ''); ?>
| price_type; ?> | event_cost, 2) . $message . ' ' . $surcharge; ?> | allow_multiple == 'Y') { $attendee_limit = $result->additional_limit + 1; if ($available_spaces != 'Unlimited') $attendee_limit = ($attendee_limit <= $available_spaces) ? $attendee_limit : $available_spaces; event_espresso_multi_qty_dd($event_id, $result->id, $attendee_limit, empty($_SESSION['espresso_session']['events_in_session'][$event_id]['price_id'][$result->id]['attendee_quantity']) ? '' : $_SESSION['espresso_session']['events_in_session'][$event_id]['price_id'][$result->id]['attendee_quantity']); } else { $checked = (($wpdb->num_rows == 1) || (array_key_exists($result->id, $_SESSION['espresso_session']['events_in_session'][$event_id]['price_id']) && isset($_SESSION['espresso_session']['events_in_session'][$event_id]['price_id'][$result->id]['attendee_quantity']))) ? ' checked="checked"' : ''; ?> value="id; ?>" /> |