function epl_waitlist_approved_until()
{
    global $regis_details;
    if (!epl_is_waitlist_approved()) {
        return '';
    }
    $time_limit = epl_waitlist_approved_regis_time_limit();
    global $event_details;
    if (!$time_limit) {
        return epl__("No Expiration");
    }
    $email_time = get_post_meta($regis_details['ID'], '_epl_waitlist_email_time', true);
    $expiration_time = date_i18n('l, M d Y H:i', strtotime("+ {$time_limit} hour", $email_time));
    return $expiration_time;
}
 function send_waitlist_approval_email()
 {
     global $event_details;
     $this->get_values();
     //get the email_field
     //get the notification id
     if (!epl_is_waitlist_approved()) {
         return epl_create_message(epl__('This waitlist needs to be approved before the email can be sent.'), 'warning');
     }
     $_notif = epl_get_element('_epl_waitlist_approved_notification', $event_details);
     $id = is_array($_notif) ? current($_notif) : $_notif;
     $notif_data = get_post($id, ARRAY_A) + (array) $this->ecm->get_post_meta_all($id);
     $this->erm->regis_id = $this->post_ID;
     $this->epl->epl_util->regis_id = $this->post_ID;
     update_post_meta($this->post_ID, '_epl_waitlist_email_time', EPL_TIME);
     $data['email_template'] = epl_get_element('_epl_email_template', $notif_data, 'default');
     $data['notif_data'] = $notif_data;
     $data['email_body'] = nl2br($this->epl->epl_util->notif_tags(stripslashes_deep(html_entity_decode($notif_data['post_content'], ENT_QUOTES)), $data));
     $data['customer_email'] = $this->get_primary_email_address();
     $r = $this->epl->epl_util->send_email($data);
     return $r ? epl__('Email Sent') : epl__('An error has occured');
 }
 /**
  * This function will create a global variable called $event_snapshot, which holds all the following information about the event
  * -Availability for each date, each time inside each date, each price inside each date and time.
  * -Availability errors
  *
  * Uses global vars $event_details, $current_att_count
  *
  * @since 1.0.0
  * @param event_id
  * @param refresh
  * @return  Sets the global $event_snapshot variable
  */
 function event_snapshot($event_id = null, $refresh = false)
 {
     global $event_details, $capacity, $current_att_count, $event_snapshot, $epl_error, $event_totals;
     $event_id = is_null($event_id) ? $this->get_current_event_id() : $event_id;
     setup_event_details($event_id);
     $meta = $this->current_data[$this->regis_id];
     $cart_selected_dates = epl_get_element($event_id, epl_get_element('_epl_start_date', $this->get_cart_values('_dates')));
     $cart_selected_times = (array) epl_get_element($event_id, epl_get_element('_epl_start_time', $this->get_cart_values('_dates')));
     $cart_selected_quantities = (array) epl_get_element($event_id, epl_get_element('_att_quantity', $this->get_cart_values('_dates')));
     static $_cache = array();
     $_is_cached = epl_get_element($event_id, $_cache);
     if ($_is_cached) {
         return $_cache[$event_id];
     }
     if (empty($cart_selected_dates) && epl_get_element('cart_action', $_REQUEST) != 'add') {
         $epl_error[] = array('', epl__('Please select at least one date.'));
     }
     $current_att_count = EPL_report_model::get_instance()->get_attendee_counts($event_id, true);
     $sold_out_text = apply_filters('merm__event_snapshot__sold_out_text', epl__('Sold Out.'));
     //get the attendee and money totals
     //$_totals = $this->calculate_cart_totals();
     setup_event_details($event_id);
     $grand_total = epl_get_element_m('grand_total', 'money_totals', $event_totals);
     $grand_total_key = "_grand_total";
     //this will hold the snapshot
     $event_snapshot = array();
     $qty_meta_key = "_total_att_" . $event_id;
     //$total_att = array_sum( ( array ) $meta[$this->regis_id]['_dates']['_att_quantity'][$event_details['ID']] );
     $total_att = epl_get_element_m($event_id, 'total', epl_get_element('_att_quantity', $event_totals));
     //event dates, times and prices
     $dates = epl_get_element('_epl_start_date', $event_details);
     $times = epl_get_element('_epl_start_time', $event_details);
     $prices = epl_get_element('_epl_price_name', $event_details);
     $rolling_regis = epl_get_element('_epl_rolling_regis', $event_details) == 10;
     if (epl_is_empty_array($dates)) {
         return;
     }
     //foreach event date
     foreach ($dates as $_date_key => $date_timestamp) {
         $date_timestamp = epl_get_date_timestamp($date_timestamp);
         //number registered for the date
         $date_total_att = 0;
         $_date = epl_formatted_date($event_details['_epl_start_date'][$_date_key], 'Y-m-d', 'date');
         //the date to display
         $_displ_date = epl_formatted_date($_date);
         $qty_meta_key = "_total_att_" . $event_details['ID'] . '_date_' . $_date_key;
         //find the capacity for this date.
         $cap = $event_details['_epl_date_capacity'][$_date_key];
         //find the number of people regitered for this date
         $num_att = epl_get_element($qty_meta_key, $current_att_count, 0);
         //find the available spcaes.  If there is no capacity, always available
         $date_avail = $this->avail_spaces($cap, $num_att);
         $_past = epl_compare_dates(EPL_TIME, $_date . ' 23:59:59', ">");
         $_date_avail_display = epl_is_ok_to_register($event_details, $_date_key);
         $_date_avail_display = $_date_avail_display === true ? epl__('Available') : $_date_avail_display;
         //snapshot template
         $_t = array('timestamp' => $date_timestamp, 'disp' => $_displ_date, 'avail' => $date_avail, 'avail_display' => $_date_avail_display, 'regis' => $num_att, 'db_key' => $qty_meta_key, 'cart' => 0, 'past' => $_past, 'hide' => $date_avail != '' && $date_avail <= 0);
         //Set the snapshot for this date
         $event_snapshot[$event_id][$_date_key]['date'] = $_t;
         $rolling_regis_time_avail = 0;
         //foreach time available for the event
         foreach ($times as $_time_key => $_time_id) {
             $time_total_att = 0;
             $_time = $event_details['_epl_start_time'][$_time_key];
             $qty_meta_key = "_total_att_" . $event_details['ID'] . '_time_' . $_date_key . '_' . $_time_key;
             //$cap = $capacity['time'][$_time_key];
             $cap = epl_get_element($_time_key, epl_get_element('_epl_time_capacity', $event_details), '');
             if ($rolling_regis && $cap == '') {
                 $cap = epl_get_element_m($_date_key, '_epl_date_per_time_capacity', $event_details);
             }
             $num_att = epl_nz(epl_get_element($qty_meta_key, $current_att_count), 0);
             $time_avail = $this->avail_spaces($cap, $num_att);
             $rolling_regis_time_avail += $cap == '' ? 999 : epl_nz($time_avail, 0);
             $_comp_time = epl_get_element($_time_key, $event_details['_epl_regis_endtime']);
             $_comp_time = !$_comp_time ? $_time : $_comp_time;
             //Is this time for this date in the past and not available any more?
             $_past = epl_compare_dates(EPL_TIME, $_date . ' ' . $_comp_time, ">");
             if ($rolling_regis && $_past) {
                 $event_snapshot[$event_id][$_date_key]['date']['hide'] = true;
             }
             $_t = array('timestamp' => strtotime($times[$_time_key], $date_timestamp), 'disp' => $times[$_time_key], 'avail' => $time_avail, 'avail_display' => $_date_avail_display, 'regis' => $num_att, 'db_key' => $qty_meta_key, 'past' => $_past);
             //Set the snapsot for this time for this date
             $event_snapshot[$event_id][$_date_key]['time'][$_time_key] = $_t;
             foreach ($prices as $_price_key => $_price_id) {
                 $_price = $event_details['_epl_price_name'][$_price_key];
                 $price_avail = 0;
                 $do_count = true;
                 $price_att = 0;
                 $price_type = epl_get_element($_price_key, epl_get_element('_epl_price_type', $event_details), 'att');
                 if (isset($meta['_dates']['_att_quantity'][$event_details['ID']])) {
                     if (is_array(epl_get_element($_price_key, $meta['_dates']['_att_quantity'][$event_details['ID']]))) {
                         $price_att = array_sum((array) epl_get_element($_price_key, $meta['_dates']['_att_quantity'][$event_details['ID']]));
                     } else {
                         $price_att = epl_get_element($_price_key, $meta['_dates']['_att_quantity'][$event_details['ID']]);
                     }
                 }
                 $qty_meta_key = "_total_att_" . $event_details['ID'] . '_price_' . $_date_key . '_' . $_time_key . '_' . $_price_key;
                 if (epl_is_date_level_price()) {
                     $price_att = epl_get_element_m($_date_key, $_price_key, $cart_selected_quantities);
                 }
                 $cap = epl_get_element($_price_key, epl_get_element('_epl_price_capacity', $event_details), '');
                 $num_att = epl_nz(epl_get_element($qty_meta_key, $current_att_count), 0);
                 $price_avail = $this->avail_spaces($cap, $num_att);
                 if (!epl_is_empty_array($offset = $this->is_offsetter_price($_price_key)) && $cap !== '' && $price_avail > 0) {
                     //check to make sure users are not using the price as offset against itself
                     if ($offset['offset_key'] != $_price_key) {
                         // see if available count of the offseter is > capacity for this price
                         $offset_avail = $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['price'][$offset['offset_key']]['avail'];
                         $offset_count = $offset['offset_count'];
                         if ((int) $offset_count > (int) $offset_avail) {
                             $price_avail = 0;
                         } elseif ($offset_avail >= $offset_count) {
                             $price_avail = intval($offset_avail / $offset_count);
                         }
                     }
                 }
                 //echo "<pre class='prettyprint'>" . __LINE__ . "> $event_id >>>> " . print_r($price_avail, true). "</pre>";
                 $time_total_att += $price_att;
                 $_t = array('disp' => $prices[$_price_key], 'avail' => $price_avail, 'avail_display' => $_date_avail_display, 'regis' => $num_att, 'db_key' => $qty_meta_key, 'cart' => $price_att, 'past' => $_past);
                 $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['price'][$_price_key] = $_t;
                 if (epl_is_date_level_time() && epl_get_element($_date_key, $cart_selected_times) != $_time_key) {
                     $do_count = false;
                 }
                 if (epl_is_date_level_price() && !in_array($_date_key, (array) $cart_selected_dates)) {
                     //if ( $_date_key != $_price_key ) {
                     $do_count = false;
                     //}
                 }
                 if (epl_is_time_specific_price($_price_key)) {
                     if ($event_details['_epl_price_parent_time_id'][$_price_key] != $_time_key) {
                         unset($event_snapshot[$event_id][$_date_key]['time'][$_time_key]['price'][$_price_key]);
                         $do_count = false;
                     }
                 }
                 if (!epl_is_time_optonal() && !in_array($_time_key, $cart_selected_times) || !in_array($_date_key, (array) $cart_selected_dates)) {
                     $do_count = false;
                 }
                 if (!$do_count || $price_type != 'att') {
                     $time_total_att -= $price_att;
                     if (isset($event_snapshot[$event_id][$_date_key]['time'][$_time_key]['price'][$_price_key]['cart'])) {
                         $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['price'][$_price_key]['cart'] = 0;
                     }
                 } else {
                     //check for a price availability for each date/time
                     if ($price_att > 0 && $price_avail !== '') {
                         $_error = array();
                         if ($price_avail === 0 || $price_avail < 0) {
                             $_error = array($_displ_date . '<br />' . $_time . '<br />' . $_price, $sold_out_text);
                         } elseif ($price_att > epl_nz($price_avail, 1000)) {
                             $_error = array($_displ_date . '<br />' . $_time . '<br />' . $_price, sprintf(epl__(' Only %d spaces left.'), $price_avail));
                         }
                         if (!empty($_error)) {
                             $epl_error[] = $_error;
                             $event_snapshot[$event_id]['error'][] = $_error;
                         }
                         $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['price'][$_price_key]['avail_display'] = epl_get_element(1, $_error);
                     }
                 }
                 /* if( $price_type != 'att' )
                    $time_total_att -= $price_att; */
             }
             $date_total_att += $time_total_att;
             $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['cart'] = $time_total_att;
             //echo "<pre class='prettyprint'>" . __LINE__ . "> $_date "  . print_r($time_total_att, true). "</pre>";
             //check for time availablility for each date
             if ($this->flow_mode == 'n' && !epl_is_time_optonal() && $time_total_att > 0 && ($time_avail !== '' || $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['past'] === true)) {
                 $_error = array();
                 if (!epl_is_ongoing_event() && $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['past'] == 1) {
                     $_error = array($_displ_date . '<br />' . $_time, epl__('This time has passed.'));
                 }
                 if ($time_avail === 0 || $time_avail < 0) {
                     $_error = array($_displ_date . '<br />' . $_time, $sold_out_text);
                 } elseif ($time_total_att > epl_nz($time_avail, 1000)) {
                     $_error = array($_displ_date . '<br />' . $_time, sprintf(epl__('Only %d spaces left.'), $time_avail));
                 }
                 if (!empty($_error)) {
                     $epl_error[] = $_error;
                     $event_snapshot[$event_id]['error'][] = $_error;
                 }
                 $event_snapshot[$event_id][$_date_key]['time'][$_time_key]['avail_display'] = epl_get_element(1, $_error);
             }
         }
         if ($rolling_regis && $rolling_regis_time_avail == 0 && $event_snapshot[$event_id][$_date_key]['date'] == '') {
             $event_snapshot[$event_id][$_date_key]['date']['hide'] = true;
         }
         //check for the date availability
         $event_snapshot[$event_id][$_date_key]['date']['cart'] = $date_total_att;
         if ($date_total_att > 0 && ($date_avail !== '' || $event_snapshot[$event_id][$_date_key]['date']['past'] === true) && (!epl_is_waitlist_approved() && !epl_is_waitlist_session_approved())) {
             $_error = array();
             if ($this->flow_mode == 'n' && ($date_avail === 0 || $date_avail < 0)) {
                 $_error = array($_displ_date, $sold_out_text);
                 if (epl_is_ok_for_waitlist() && ($wl_spaces_left = epl_waitlist_spaces_open()) !== false) {
                     $_error[1] .= '<br />' . epl__('If you would like to be added to the waiting list, please click on the button below.  You will not be charged at this time.');
                     if ($wl_spaces_left !== true) {
                         $_error[1] .= '<br />' . sprintf('Spaces available on the waiting list: %d', $wl_spaces_left);
                     }
                     if (epl_waitlist_enough_spaces($event_id) == false) {
                         $_error[1] .= '<br />' . sprintf('To continue, please select only %d.', $wl_spaces_left);
                     } else {
                         $_error[1] .= '<br />' . epl_anchor('#', epl__('Click here to add your name to the waitlist'), null, " class='open_add_to_waitlist_form epl_button' data-event_id='{$event_id}'");
                     }
                     $this->epl->epl_util->set_response_param('waitlist_form', '');
                 }
             } elseif ($this->flow_mode == 'n' && !epl_is_ongoing_event() && $event_snapshot[$event_id][$_date_key]['date']['past'] == 1) {
                 $_error = array($_displ_date, epl__('This date has passed.'));
             } elseif ($this->flow_mode == 'n' && $date_total_att > epl_nz($date_avail, 1000)) {
                 $_error = array($_displ_date, sprintf(epl__('Only %d spaces left.'), $date_avail));
             }
             $event_snapshot[$event_id][$_date_key]['date']['avail_display'] = epl_get_element(1, $_error);
             if (!empty($_error)) {
                 $event_snapshot[$event_id]['error'][] = $_error;
                 $epl_error[] = $_error;
             }
         }
         //$this->epl_table->add_row( '', $event_details['_epl_start_date'][$_date_key], $avail );
     }
     $_cache[$event_id] = $event_snapshot;
     return $event_snapshot;
 }
 function set_next_step_vars($current_step = null)
 {
     //$bt = debug_backtrace();
     //echo "<pre class='prettyprint'>" . __LINE__ . "> " . print_r($bt[0]['line'], true). "</pre>";
     //echo "<pre class='prettyprint'>" . __LINE__ . "> " . print_r($bt[0]['function'], true). "</pre>";
     /*
      * - if on regis form and offline or free, thank you
      * - if regis form and cc or pp, overview
      * - if overview and cc, show card form, complete
      * - if overview and pp, continue
      * - if overview and offline, complete
      *
      * - if epl_regis_flow() and regis form -> payment -> complete
      * - if epl_regis_flow() and regis form and free of offline -> complete
      */
     global $epl_current_step;
     $regis_flow_steps = array(1 => 'show_cart', 5 => 'regis_form', 10 => 'show_cart_overview', 30 => 'redirect', 100 => 'thank_you_page');
     $this->steps = array('show_cart' => array(1 => array('next' => 'regis_form', 'next_label' => epl__('Attendee Information')), 2 => array('next' => 'regis_form', 'next_label' => epl__('Attendee Information'))), 'regis_form' => array(1 => array('prev' => 'show_cart', 'next' => 'show_cart_overview', 'next_label' => epl__('Overview')), 2 => array('prev' => 'show_cart', 'next' => 'thank_you_page', 'next_label' => epl__('Confirm and Complete')), 10 => array('next' => 'thank_you_page', 'next_label' => epl__('Confirm and Complete'))), 'show_cart_overview' => array(1 => array('prev' => 'regis_form', 'next' => 'thank_you_page', 'next_label' => epl__('Confirm and Complete')), 2 => array('prev' => 'regis_form', 'next' => 'show_cart_overview', 'next_label' => epl__('Confirm and Complete')), 10 => array('prev' => 'show_cart', 'next' => 'thank_you_page')), 'payment_page' => array(1 => array('prev' => 'regis_form', 'next' => 'payment_page', 'next_label' => epl__('Overview')), 2 => array('prev' => 'regis_form', 'next' => 'payment_page', 'next_label' => epl__('Confirm and Complete')), 10 => array('next' => 'thank_you_page', 'next_label' => epl__('Confirm and Complete'))));
     $flow = epl_regis_flow();
     $this->step_data = array();
     $gateway_info = $this->erm->get_gateway_info();
     $url_vars_next = $url_vars_prev = array('epl_action' => $this->steps[$current_step][$flow]['next'], 'cart_action' => false, '_date_id' => false);
     $url_vars_prev['epl_action'] = epl_get_element('prev', $this->steps[$current_step][$flow]);
     $this->step_data['form_action'] = add_query_arg($url_vars_next, $this->url);
     $gw_check = false;
     if ($flow == 1 && $epl_current_step == 'show_cart_overview') {
         $gw_check = true;
     } elseif (($flow == 2 || $flow == 10) && $epl_current_step == 'regis_form') {
         $gw_check = true;
     }
     if ($epl_current_step != 'process_cart_action' && $epl_current_step != 'show_cart') {
         $this->step_data['prev_step_url'] = add_query_arg($url_vars_prev, $this->url);
     }
     $this->step_data['next_step'] = $this->steps[$current_step][$flow]['next'];
     $this->step_data['next_step_label'] = $this->steps[$current_step][$flow]['next_label'];
     if (epl_is_free_event() || epl_regis_flow() < 10 && epl_is_zero_total() || $this->erm->has_selected_offline_payment() || epl_is_waitlist_flow() && !epl_is_waitlist_approved()) {
         $this->step_data['next_step_label'] = apply_filters('epl_show_cart_overview_free_next_step_label', $this->steps[$current_step][$flow]['next_label']);
     } elseif (epl_get_element('_epl_pay_type', $gateway_info) == '_pp_exp' && $gw_check) {
         $url_vars_next = array('epl_action' => 'payment_page', 'cart_action' => false, '_date_id' => false);
         $url_vars_prev['epl_action'] = $this->steps[$current_step][$flow]['prev'];
         $this->step_data['form_action'] = add_query_arg($url_vars_next, $this->url);
         $this->step_data['next_step_label'] = apply_filters('epl_show_cart_overview_pp_exp_next_step_label', epl__('Confirm and Continue to PayPal'));
     } elseif (epl_get_element('_epl_pay_type', $gateway_info) == '_payson' && $gw_check) {
         $url_vars_next = array('epl_action' => 'payment_page', 'cart_action' => false, '_date_id' => false);
         $url_vars_prev['epl_action'] = $this->steps[$current_step][$flow]['prev'];
         $this->step_data['form_action'] = add_query_arg($url_vars_next, $this->url);
         $this->step_data['next_step_label'] = apply_filters('epl_show_cart_overview_pp_exp_next_step_label', epl__('Continue to Pay'));
     } elseif (epl_get_element('_epl_pay_type', $gateway_info) == '_moneris' && $gw_check) {
         $this->step_data['next_step_label'] = apply_filters('epl_show_cart_overview_pp_exp_next_step_label', epl__('Continue to Pay'));
         $us_version = epl_get_element('_epl_moneris_country', $gateway_info, 'ca') == 'usa';
         $this->step_data['form_action'] = 'https://www3.moneris.com/HPPDP/index.php';
         if ($gateway_info['_epl_sandbox'] == 10) {
             $this->step_data['form_action'] = 'https://esqa.moneris.com/HPPDP/index.php';
         }
         if ($us_version) {
             $this->step_data['form_action'] = 'https://esplus.moneris.com/DPHPP/index.php';
             if ($gateway_info['_epl_sandbox'] == 10) {
                 $this->step_data['form_action'] = 'https://esplusqa.moneris.com/DPHPP/index.php';
             }
             $this->egm->setup_moneris_form_USA();
         } else {
             $this->egm->setup_moneris_form();
         }
     } elseif (epl_get_element('_epl_pay_type', $gateway_info) == '_auth_net_sim' && $gw_check) {
         $this->step_data['next_step_label'] = apply_filters('epl_show_cart_overview_pp_exp_next_step_label', epl__('Continue to Pay'));
         $this->step_data['form_action'] = 'https://secure.authorize.net/gateway/transact.dll';
         if ($gateway_info['_epl_sandbox'] == 10) {
             $this->step_data['form_action'] = 'https://test.authorize.net/gateway/transact.dll';
         }
         $this->egm->setup_authnet_sim_form();
     } elseif ($this->erm->has_selected_cc_payment() && ($gw_check || $this->error)) {
         $url_vars_next = array('epl_action' => 'payment_page', 'cart_action' => false, '_date_id' => false);
         $this->step_data['form_action'] = add_query_arg($url_vars_next, $this->url);
         $this->step_data['next_step_label'] = apply_filters('epl_show_cart_overview_cc_next_step_label', $this->steps[$current_step][$flow]['next_label']);
     }
     $this->step_data = apply_filters('epl_front__set_next_step_vars__final', $this->step_data, $flow);
     return $this->step_data;
 }