function epl_is_waitlist_flow() { global $epl_is_waitlist_flow, $regis_details; if (epl_get_element('epl_wl_flow', $_POST, 0) == 1) { return true; } if (!epl_is_waitlist_record() && EPL_IS_ADMIN) { return false; } $regis_status = get_the_regis_status(null, true); if ($regis_status == 2 || $regis_status == 5) { return false; } if (!epl_is_waitlist_approved() && !epl_is_waitlist_session_approved() && ($epl_is_waitlist_flow == true || epl_get_element('epl_wl_flow', $_REQUEST, 0) == 1 || get_the_regis_status(null, true) == 20)) { return true; } }
function add_registration_to_db($meta = array()) { //get_the_event_prices(); $meta = $this->current_data; global $wpdb, $event_details, $multi_time, $multi_price, $epl_is_waitlist_flow, $epl_current_step, $event_totals, $cart_totals; if (epl_is_empty_array($event_details)) { $this->ecm->setup_event_details(intval(epl_get_element('event_id', $_REQUEST))); } $event_id = $this->get_current_event_id(); //have to create the dates manually as on some servers the //wp_insert_post would set the dates back to UTC $now = date_i18n("Y-m-d H:i:s"); $_post = array("post_date" => date_i18n("Y-m-d H:i:s"), "post_date_gmt" => get_gmt_from_date($now), 'post_type' => 'epl_registration', 'post_title' => $this->regis_id, 'post_content' => '', 'post_status' => 'publish'); if (is_user_logged_in()) { $current_user = wp_get_current_user(); $_post['post_author'] = $current_user->ID; } $_post = apply_filters('erm__add_registration_to_db__post_array', $_post); //$_db_insert_method = 'update_post_meta'; $_db_insert_method = 'add_post_meta'; //as of 1.3, faster to delete everything and add than update_post_meta $regis_post_ID = null; if (isset($this->current_data['post_ID'])) { //If this post is already in the db, the meta will be deleted before $_post['ID'] = intval($this->current_data['post_ID']); $regis_post_ID = $_post['ID']; //as of 1.3, much faster to delete and insert then to update_post_meta $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} \n WHERE post_id = %d \n AND (NOT meta_key = '_epl_payment_note' \n AND NOT meta_key = '_epl_regis_note' \n AND NOT meta_key = '_epl_regis_incr_id')", $_post['ID'])); } else { $regis_key = epl_get_element('_regis_id', $_SESSION['__epl'], null); if ($regis_key) { $regis_post_ID = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts}\n WHERE post_status ='publish' \n AND post_type='epl_registration' \n AND post_title=%s\n ORDER BY ID DESC\n LIMIT 1", $regis_key)); } if (is_null($regis_post_ID)) { //create new regis record. $regis_post_ID = wp_insert_post($_post); $this->current_data['post_ID'] = $regis_post_ID; } //$_db_insert_method = 'add_post_meta'; } $this->current_data['post_ID'] = $regis_post_ID; $db_data = array(); //get the attendee and money totals for the cart $_totals = $this->calculate_cart_totals(true); $start_week = epl_get_element_m('_epl_start_week', $this->regis_id, $meta, 0); $attendance_dates_total = array(); $_price_type = ''; //temp holder $events_in_cart = $this->get_events_in_cart(); $grand_total = $cart_totals['money_totals']['grand_total']; $original_total = $cart_totals['money_totals']['original_total']; $db_data[] = array($regis_post_ID, '_epl_original_total', $original_total); $db_data[] = array($regis_post_ID, '_epl_grand_total', $grand_total); $db_data[] = array($regis_post_ID, '_epl_pre_discount_total', epl_get_element('pre_discount_total', $cart_totals['money_totals'], $grand_total)); $db_data[] = array($regis_post_ID, '_epl_discount_amount', epl_get_element('discount_amount', $cart_totals['money_totals'], 0)); $db_data[] = array($regis_post_ID, '_epl_discount_code_id', epl_get_element('discount_code_id', $cart_totals['money_totals'], '')); $db_data[] = array($regis_post_ID, '_epl_discount_code_source', epl_get_element('discount_code_source', $cart_totals['money_totals'], '')); $db_data[] = array($regis_post_ID, '_epl_discount_code', epl_get_element('discount_code', $cart_totals['money_totals'], '')); $db_data[] = array($regis_post_ID, '_epl_surcharge', epl_get_element('surcharge', $cart_totals['money_totals'], 0)); $db_data[] = array($regis_post_ID, '_epl_subtotal', epl_get_element('subtotal', $cart_totals['money_totals'], 0)); foreach ($events_in_cart as $event_id => $totals) { setup_event_details($event_id); $event_dates = epl_get_element('_epl_start_date', $event_details); $event_dates_keys = array_keys($event_dates); $event_type = epl_get_element('_epl_event_type', $event_details); $db_data[] = array($regis_post_ID, '_epl_original_total_' . $event_id, $_totals[$event_id]['money_totals']['original_total']); $db_data[] = array($regis_post_ID, '_epl_grand_total_' . $event_id, $_totals[$event_id]['money_totals']['grand_total']); $db_data[] = array($regis_post_ID, '_epl_pre_discount_total_' . $event_id, epl_get_element('pre_discount_total', $_totals[$event_id]['money_totals'], 0)); $db_data[] = array($regis_post_ID, '_epl_discount_amount_' . $event_id, epl_get_element('discount_amount', $_totals[$event_id]['money_totals'], 0)); $db_data[] = array($regis_post_ID, '_epl_surcharge_' . $event_id, epl_get_element('surcharge', $_totals[$event_id]['money_totals'], 0)); $db_data[] = array($regis_post_ID, '_epl_subtotal_' . $event_id, epl_get_element('subtotal', $_totals[$event_id]['money_totals'], 0)); $db_data[] = array($regis_post_ID, '_epl_discount_code_' . $event_id, epl_get_element('discount_code', $_totals[$event_id], '')); //add the total number of attendees for the whole event //add the number of attendees for each date in the cart. $dates = (array) $meta[$this->regis_id]['_dates']['_epl_start_date'][$event_id]; $times = epl_get_element($event_id, epl_get_element('_epl_start_time', $meta[$this->regis_id]['_dates']), epl_get_element('_epl_start_time', $event_details)); $prices = $meta[$this->regis_id]['_dates']['_att_quantity'][$event_id]; //$total_att = array_sum( ( array ) $meta[$this->regis_id]['_dates']['_att_quantity'][$event_details['ID']] ); $start_week = epl_get_element_m('_epl_start_week', $this->regis_id, $meta, 0); $pack_regis = epl_get_element('_epl_pack_regis', $event_details) == 10; $pack_regis_consecutive = epl_get_element('_epl_pack_regis_consecutive', $event_details, 10) == 10; $rolling_regis = epl_get_element('_epl_rolling_regis', $event_details) == 10; $discount_code_id = epl_get_element('discount_code_id', $totals['money_totals'], null); if (!is_null($discount_code_id)) { $db_data[] = array($regis_post_ID, '_epl_discount_id_' . $discount_code_id, 1); } foreach ($dates as $_dkey => $_date_id) { //if multiple dates, find the qty for a specific date. $date_total_att = 0; $time_total_att = 0; $dg = epl_get_element_m($_dkey, '_epl_date_group_no', $event_details, false); if ($event_type == 20) { $_date_id = current($_date_id); } foreach ($times as $_tkey => $_time_id) { $time_total_att = 0; foreach ($prices as $_pkey => $_price_id) { $price_type = epl_get_element($_pkey, epl_get_element('_epl_price_type', $event_details), 'att'); if ($_price_type == '' || $_price_type != $price_type) { $_price_type = $price_type; //$time_total_att = 0; } $price_att_qty = $meta[$this->regis_id]['_dates']['_att_quantity'][$event_id][$_pkey]; /* * if date level price * - for each price key, * -- combine dates listed in the price key with the dates in teh cart */ if (epl_is_date_level_price() && !isset($price_att_qty[$_date_id])) { continue; } //$price_att_qty = array_sum( ( array ) $meta[$this->regis_id]['_dates']['_att_quantity'][$event_id][$_pkey] ); //will only insert attendee price type $price_qty_meta_key = "_total_{$price_type}_" . $event_id . '_price_' . $_date_id . '_' . $_time_id . '_' . $_pkey; $offset_another = false; $offset_another_key = epl_get_element_m($_pkey, '_epl_price_to_offset', $event_details); $offset_another_count = intval(epl_get_element_m($_pkey, '_epl_price_offset_count', $event_details, 0)); if ($offset_another_key && $offset_another_count > 0) { $offset_another = true; $price_qty_offset_meta_key = "_total_{$price_type}_" . $event_id . '_price_' . $_date_id . '_' . $_time_id . '_' . $offset_another_key; } if (epl_is_time_specific_price($_pkey)) { // $price_att_qty = $meta[$this->regis_id]['_dates']['_att_quantity'][$event_id][$_pkey]; if ($price_att_qty > 0 && $event_details['_epl_price_parent_time_id'][$_pkey] == $_time_id) { $time_total_att += $price_att_qty; $db_data[] = array($regis_post_ID, $price_qty_meta_key, $price_att_qty); if ($offset_another) { $db_data[] = array($regis_post_ID, $price_qty_offset_meta_key, $offset_another_count); if ($offset_another_key != $_pkey) { $time_total_att += $offset_another_count - $price_att_qty; } } } } else { if (epl_is_date_level_price()) { $price_att_qty = $price_att_qty[$_date_id]; } else { $price_att_qty = array_sum((array) $price_att_qty); } if (!epl_is_date_level_time()) { $time_total_att += $price_att_qty; $db_data[] = array($regis_post_ID, $price_qty_meta_key, $price_att_qty); if ($offset_another && $price_att_qty > 0) { $db_data[] = array($regis_post_ID, $price_qty_offset_meta_key, $offset_another_count); if ($offset_another_key != $_pkey) { $time_total_att += $offset_another_count - $price_att_qty; } } } else { if ($_date_id == $_tkey) { $time_total_att += $price_att_qty; $db_data[] = array($regis_post_ID, $price_qty_meta_key, $price_att_qty); if ($offset_another && $price_att_qty > 0) { $db_data[] = array($regis_post_ID, $price_qty_offset_meta_key, $offset_another_count); if ($offset_another_key != $_pkey) { $time_total_att += $offset_another_count - $price_att_qty; } } } } } if ($price_type != 'att') { $time_total_att -= $price_att_qty; } if ($_price_type != $price_type) { $_price_type = $price_type; //$time_total_att -= $price_att_qty; } $pack_size = epl_get_element_m($_pkey, '_epl_price_pack_size', $event_details, null); if ($price_att_qty > 0 && $pack_size && $pack_regis && $pack_regis_consecutive) { $attendance_start_date = $event_dates[$_date_id]; //find the position of the date in the cart $pos = array_search($_date_id, $event_dates_keys); if ($start_week == 1) { $_new_date_key = epl_get_element($pos++, $event_dates_keys); $att_start_date = epl_get_element($_new_date_key, $event_dates); } $attendance_dates = array_slice($event_dates, $pos, $pack_size, true); $attendance_dates_total[$_date_id][$_time_id][$_pkey]['count'] = $price_att_qty; $attendance_dates_total[$_date_id][$_time_id][$_pkey]['dates'] = $attendance_dates; $attendance_end_date = end($attendance_dates); for ($i = 1; $i <= $price_att_qty; $i++) { $price_pack_meta_key = "_pack_attendance_dates_" . $event_id . '_' . $_pkey . '_' . $i; $db_data[] = array($regis_post_ID, $price_pack_meta_key, $attendance_dates); } } } if ($time_total_att > 0) { $time_qty_meta_key = "_total_att_" . $event_id . '_time_' . $_date_id . '_' . $_time_id; if (!epl_is_date_level_time()) { $date_total_att += $time_total_att; if (!$pack_regis || !$pack_regis_consecutive) { $db_data[] = array($regis_post_ID, $time_qty_meta_key, $time_total_att); } } else { if ($_date_id == $_tkey) { $date_total_att += $time_total_att; $db_data[] = array($regis_post_ID, $time_qty_meta_key, $time_total_att); } } } } //date if ($date_total_att > 0) { $date_qty_meta_key = "_total_att_" . $event_id . '_date_' . $_date_id; if (epl_is_waitlist_flow() || epl_is_waitlist_record()) { if (!$pack_regis) { $date_waitlist_qty_meta_key = "_total_waitlist_att_" . $event_id . '_date_' . $_date_id; } $db_data[] = array($regis_post_ID, $date_waitlist_qty_meta_key, $date_total_att); } elseif (!$pack_regis || !$pack_regis_consecutive) { $db_data[] = array($regis_post_ID, $date_qty_meta_key, $date_total_att); } } } $qty_meta_key = "_total_att_" . $event_id; $total_att = $totals['_att_quantity']['total'][$event_id]; if (!epl_is_waitlist_flow()) { $db_data[] = array($regis_post_ID, $qty_meta_key, $total_att); } $db_data[] = array($regis_post_ID, '_epl_event_id', $event_id); do_action('epl_erm__add_registration_to_db', $regis_post_ID, $event_id); } //store the whole session, useful for admin side or future edit //also store individual ones for easier data access and queries. //update_post_meta( $regis_post_ID, '_grand_total', $meta[$this->regis_id]['grand_total'] ); //removing in 1.4 // $db_data[] = array( $regis_post_ID, '_epl_events', $this->epl_util->clean_input( $meta[$this->regis_id]['_events'] ) ); //$db_data[] = array( $regis_post_ID, '_epl_dates', $this->epl_util->clean_input( $meta[$this->regis_id]['_dates'] ) ); //$db_data[] = array( $regis_post_ID, '_epl_attendee_info', $this->epl_util->clean_input( $meta[$this->regis_id]['_attendee_info'] ) ); $db_data[] = array($regis_post_ID, '_epl_plugin_version', EPL_PLUGIN_VERSION); //TODO - move this to run just once $db_data[] = array($regis_post_ID, '_epl_payment_method', $this->get_payment_profile_id()); $db_data[] = array($regis_post_ID, '_epl_regis_user_id', get_current_user_id()); $gateway_info = $this->get_gateway_info(); if ($epl_current_step == 'show_cart_overview' || $epl_current_step == 'payment_page') { $this->update_payment_data(array('post_ID' => $regis_post_ID, '_epl_regis_status' => 1, '_epl_grand_total' => $grand_total, '_epl_payment_method' => $this->get_payment_profile_id())); } $total_counts = array(); if ($pack_regis && $pack_regis_consecutive) { $totals_data = array(); //get readdy to VOMIT :) foreach ($attendance_dates_total as $date_key => $date_data) { foreach ($date_data as $time_key => $time_data) { foreach ($time_data as $price_key => $price_dates) { foreach ($price_dates['dates'] as $_date_key => $timestamp) { if (isset($totals_data["_total_att_" . $event_id . '_date_' . $_date_key])) { $totals_data["_total_att_" . $event_id . '_date_' . $_date_key] += $price_dates['count']; $totals_data["_total_att_" . $event_id . '_time_' . $_date_key . '_' . $time_key] += $price_dates['count']; } else { $totals_data["_total_att_" . $event_id . '_date_' . $_date_key] = $price_dates['count']; $totals_data["_total_att_" . $event_id . '_time_' . $_date_key . '_' . $time_key] = $price_dates['count']; } } } } } foreach ($totals_data as $db_ky => $count) { $db_data[] = array($regis_post_ID, $db_ky, $count); } } $db_data[] = array($regis_post_ID, '__epl', $this->epl_util->clean_input($meta)); /* * as of 1.4, switching to one insert call with multiple values instead of add_post_meta which will run * an insert statement for each key. Much faster. Doing add_post_meta for array * as sanitized input (slashes) will mess up the serialize/unserialize. */ $i = ''; foreach ($db_data as $k => $values) { if (is_array($values[2])) { add_post_meta($regis_post_ID, $values[1], $values[2]); } else { $i .= "({$values['0']},'{$values['1']}', '{$values['2']}'),"; } } $i = substr($i, 0, -1); global $wpdb; $i = "INSERT INTO {$wpdb->postmeta} (post_id,meta_key,meta_value) VALUES {$i}"; $i = $wpdb->query($i); $this->current_data['post_ID'] = $regis_post_ID; $this->refresh_data(); }
<?php the_registration_details(); ?> <div class="epl_cart_wrapper epl_thank_you_page"> <?php do_action('epl_regis_complete_top_message'); ?> <?php if (epl_is_waitlist_record()) { ?> <div class="epl_info"><?php epl_e('Your name has been added to the waiting list. You will receive an email once a spot opens.'); ?> </div> <?php } ?> <div class="epl_section"> <div class="epl_fl_r"> <div><strong><?php epl_e('Registration ID'); ?>
function column_data($column_name, $post_ID) { global $epl_fields, $event_details, $regis_details; $this->regis_meta = $this->ecm->setup_regis_details($post_ID); $regis_id = $this->regis_meta['__epl']['_regis_id']; $event_id = ''; $event_name = ''; $num_attendees = ''; if (isset($this->regis_meta['_epl_events']) && !empty($this->regis_meta['_epl_events'])) { $event_id = key($this->regis_meta['_epl_events']); $this->ecm->setup_event_details($event_id); //$event_name = get_post( $event_id )->post_title; $event_name = $event_details['post_title']; $href = add_query_arg(array('epl_action' => 'epl_attendee_list', 'epl_download_trigger' => 1, 'event_id' => $event_id), epl_get_url()); $xl_href = add_query_arg(array('epl_action' => 'epl_excel_attendee_list', 'epl_download_trigger' => 1, 'post_ID' => $post_ID, 'event_id' => $event_id), epl_get_url()); //$event_name = '<a href="' . $href . '"><img src="' . EPL_FULL_URL . 'images/doc_excel_csv.png" /></a> <a data-post_id = "' . $post_ID . '" data-event_id="' . $event_id . '" class="epl_event_snapshot" href="#"><img id = "' . $event_id . '" src="' . EPL_FULL_URL . 'images/application_view_list.png" /> </a><span class="">' . $event_name . '</span>'; //$xevent_name = '<a href="' . $xl_href . '"><img src="' . EPL_FULL_URL . 'images/doc_excel_csv.png" /></a>'; //$event_name = $xevent_name . '<a href="' . $href . '"><img src="' . EPL_FULL_URL . 'images/doc_excel_csv.png" /></a><span class="event_name">' . $event_name . '</span>'; $xevent_name = '<span class="event_name1">' . $event_name . '</span><br />'; //<a href="' . $xl_href . '">Excel</a>, '; $event_name = $xevent_name . '<a href="' . $href . '">CSV</a>'; } switch ($column_name) { case 'attendees': if (is_array($this->regis_meta['__epl'][$regis_id]['_attendee_info']) && is_array($this->personal_field_ids)) { $d = array_intersect_key($this->regis_meta['__epl'][$regis_id]['_attendee_info'], $this->personal_field_ids); $r = array(); $fn = epl_array_flatten(current($d)); $ln = epl_array_flatten(next($d)); foreach ((array) $fn as $k => $v) { $r[] = $v . ' ' . stripslashes_deep(html_entity_decode(htmlspecialchars_decode(epl_get_element($k, $ln)), ENT_QUOTES, 'UTF-8')); } echo implode('<br>', array_unique($r)); } break; case 'id': echo $post_ID; break; case 'event': //TODO move to view $data = array(); echo '<table class="epl_regis_list_regis_details">'; foreach ((array) $this->regis_meta['__epl'][$regis_id]['_events'] as $event_id => $totals) { setup_event_details($event_id); $data['event_name'] = $event_details['post_title']; $data['quantity'] = epl_get_element($event_id, epl_get_element_m('total', '_att_quantity', $totals), 0); if ($data['quantity'] == 0) { //1.3 fix foreach ($this->regis_meta['__epl'][$regis_id]['_dates']['_att_quantity'][$event_id] as $pr => $q) { $data['quantity'] += array_sum($q); } } $link = epl_anchor(admin_url('post.php?post=' . $event_details['ID'] . '&action=edit'), $event_details['post_title']); echo "<tr><td>{$link}</td><td class='qty'>{$data['quantity']}</td></tr>"; } echo '</table>'; break; case 'num_attendees': /* $this->get_values( $post_ID ); $data['event_id'] = $event_id; //events, dates, times, prices, quantities $data['cart_data'] = $this->earm->__in( $this->event_meta + $this->regis_meta )->show_cart(); echo $this->epl->load_view( 'admin/registration/regis-list-cart-section', $data, true ); */ $num_attendees = $this->regis_meta['_total_att_' . $event_id]; if (epl_is_waitlist_record()) { foreach ($this->regis_meta as $key => $value) { if (strpos($key, "_total_waitlist_att_") !== false) { $num_attendees = $value . ' (' . epl__('waitlist') . ')'; break; } } } echo "<span class='num_attendees'>{$num_attendees}</span> "; if ($num_attendees > 0) { $href = add_query_arg(array('epl_action' => 'epl_regis_snapshot', 'post_ID' => $post_ID, 'event_id' => $event_id), epl_get_url()); echo ' <a data-post_id = "' . $post_ID . '" data-event_id="' . $event_id . '" class="epl_regis_snapshot" href="#"><img src="' . EPL_FULL_URL . 'images/application_view_list.png" /> </a>'; } echo epl_get_send_email_button($post_ID, $event_id, true); break; case 'payment_status': $payment_info = $this->payment_info_box($post_ID); echo $payment_info; $notes = epl_get_element('_epl_regis_note', $this->regis_meta, null); if ($notes) { $notes = get_post_meta($post_ID, '_epl_regis_note', false); foreach ($notes as $note) { $d = date_i18n('Y-m-d H:i', $note['timestamp']); echo "<p>{$note['action']}<span style='float:right'>{$d}</span></p>"; } } break; case 'payment': echo "Payment Info"; break; default: break; } // end switch }
function check_for_waitlist() { if (epl_is_waitlist_record() && !epl_is_waitlist_session_approved()) { if (!epl_is_valid_url_hash()) { return epl__('There seems to be something wrong with the url. Please contact the website administrator.'); } if (!epl_is_waitlist_approved()) { return epl__('This waitlist has not been approved.'); } if (epl_is_waitlist_link_expired()) { return epl__('This link has expired.'); } $_SESSION['__epl']['waitlist_approved'] = intval($_GET['event_id']); $this->erm->setup_current_data(); wp_redirect(add_query_arg(array('epl_rid' => false, 'epl_wlh' => false), epl_get_url())); die; } return true; }