function form_data($regis_id, $_regis_key, $event_id, $tickets_to_show = null)
 {
     global $event_details, $regis_details, $wpdb;
     $attendee_info = $regis_details['__epl'][$_regis_key]['_attendee_info'];
     if ($this->debug) {
         echo "<pre class='prettyprint'>" . __LINE__ . "> " . basename(__FILE__) . " > " . print_r($attendee_info, true) . "</pre>";
     }
     $event_ticket_buyer_forms = array_flip(epl_get_element('_epl_primary_regis_forms', $event_details, array()));
     $event_addit_forms = epl_get_element('_epl_addit_regis_forms', $event_details) ? array_flip($event_details['_epl_addit_regis_forms']) : array();
     if (version_compare(epl_regis_plugin_version(), '1.4', '>=') && epl_sc_is_enabled() && epl_get_setting('epl_sc_options', 'epl_sc_forms_to_use') == 1) {
         $sc_event_ticket_buyer_forms = array_flip(epl_get_setting('epl_sc_options', 'epl_sc_primary_regis_forms', array()));
         $event_ticket_buyer_forms = $sc_event_ticket_buyer_forms;
         // + $event_ticket_buyer_forms;
         $event_addit_forms = array_flip(epl_get_setting('epl_sc_options', 'epl_sc_addit_regis_forms', array()));
     }
     if (empty($event_ticket_buyer_forms)) {
         $event_ticket_buyer_forms = array('4e8b3920c839b' => 1);
     }
     /*
      * find price forms if any.
      */
     $price_forms = epl_get_element('_epl_price_forms', $event_details, array());
     $_price_forms = array();
     foreach ($price_forms as $k => $v) {
         $_price_forms += $v;
     }
     //find the list of all forms
     $available_forms = $this->ecm->get_list_of_available_forms();
     $available_fields = $this->ecm->get_list_of_available_fields();
     //isolate the ticket buyer forms that are selected inside the event
     $ticket_buyer_forms = array_intersect_key($available_forms, $event_ticket_buyer_forms);
     //isolate the additional forms for attendees.
     $addit_forms = array_intersect_key($available_forms, array_merge($event_addit_forms, $_price_forms));
     //This will combine all the fields in all the forms so that we can construct a header row.
     $tickey_buyer_fields = array();
     foreach ($ticket_buyer_forms as $_form_id => $_form_info) {
         $tickey_buyer_fields = array_merge($tickey_buyer_fields, $_form_info['epl_form_fields']);
     }
     //combine all the fields from the attendee forms
     $event_addit_fields = array();
     foreach ($addit_forms as $_form_id => $_form_info) {
         //$event_addit_fields += $_form_info['epl_form_fields'];
         $event_addit_fields = array_merge($event_addit_fields, $_form_info['epl_form_fields']);
     }
     $epl_fields_inside_form = array_flip($tickey_buyer_fields);
     //get the field ids inside the form
     $epl_addit_fields_inside_form = array_flip($event_addit_fields);
     //get the field ids inside the form
     //when creating a form in form manager, the user may rearrange fields.  Find their desired order
     $epl_fields_to_display = $this->epl_util->sort_array_by_array($available_fields, $epl_fields_inside_form);
     $epl_addit_fields_to_display = $this->epl_util->sort_array_by_array($available_fields, $epl_addit_fields_inside_form);
     //final list of all the fields to display
     //$epl_fields_to_display = $epl_fields_to_display + $epl_addit_fields_to_display;
     $ins = array();
     $ins['regis_id'] = $regis_id;
     $ins['event_id'] = $event_id;
     $ins['field_id'] = array();
     $ins['input_slug'] = array();
     $ins['value'] = array();
     if (!$this->primary_pulled) {
         //################################### Ticket buyer form data ############################################
         if ($this->debug) {
             echo "<pre class='prettyprint'>" . __LINE__ . "> " . basename(__FILE__) . " > " . print_r($epl_fields_to_display, true) . "</pre>";
         }
         $form_data_array_tmp = array();
         foreach ($epl_fields_to_display as $field_id => $field_atts) {
             //1.3 stores in [field id][event id][0]
             //2.0 stores in [field id][0]
             //if ( epl_sc_is_enabled() && isset( $attendee_info[$field_id][0] ) ) {
             if (isset($attendee_info[$field_id][0])) {
                 $value = epl_get_element(0, $attendee_info[$field_id]);
             } else {
                 $value = isset($attendee_info[$field_id]) ? epl_get_element(0, $attendee_info[$field_id][$event_id]) : '';
             }
             $raw_value = $value;
             if ($field_atts['input_slug'] == 'email') {
                 $email_list[$regis_post_id] = $value;
                 if ($regis_post_id && $regis_post_id != $this_regis_post_id) {
                     unset($email_list[$regis_post_id]);
                 }
             }
             if ($field_atts['input_type'] == 'select' || $field_atts['input_type'] == 'radio') {
                 $value = $raw_value;
                 //(isset( $field_atts['epl_field_choice_text'][$value] ) && $field_atts['epl_field_choice_text'][$value] !== '') ? $field_atts['epl_field_choice_text'][$value] : $value;
             } elseif ($field_atts['input_type'] == 'checkbox') {
                 if (!epl_is_empty_array($field_atts['epl_field_choice_value'])) {
                     $value = implode(',', (array) $raw_value);
                 } elseif (is_array($value)) {
                     $value = implode(',', $raw_value);
                 }
             }
             //if ( $value != '' ) {
             $ins['field_id'][] = $field_id;
             $ins['input_slug'][] = $field_atts['input_slug'];
             $ins['form_no'] = $this->form_no;
             $ins['value'][] = str_replace($this->delim, " ", $value);
             //$wpdb->insert( $wpdb->epl_regis_form_data, $ins );
             //}
         }
         $ins['field_id'] = implode($this->delim, $ins['field_id']);
         $ins['input_slug'] = implode($this->delim, $ins['input_slug']);
         $ins['form_no'] = $this->form_no;
         $ins['value'] = implode($this->delim, $ins['value']);
         if ($this->debug) {
             echo "<pre class='prettyprint'>" . __LINE__ . "> " . basename(__FILE__) . " > " . print_r($ins, true) . "</pre>";
         }
         $wpdb->insert($wpdb->epl_regis_form_data, $ins);
         //###################  End Ticket Buyer Data #########################################
     }
     //$this->primary_pulled = true;
     $ins['event_id'] = $event_id;
     $ins['field_id'] = array();
     $ins['input_slug'] = array();
     $ins['value'] = array();
     $counter = 0;
     $att_counter = 1;
     foreach ($tickets_to_show as $ticket_id => $ticket_quantities) {
         if (is_array($ticket_quantities)) {
             $tmp_price_inner_keys = array_keys($ticket_quantities);
             $ticket_qty = array_sum($ticket_quantities);
         }
         if ($ticket_qty == 0) {
             continue;
         }
         if (epl_is_empty_array($price_forms)) {
         }
         if ($this->debug) {
             echo "<pre class='prettyprint'>" . __LINE__ . "> " . basename(__FILE__) . " > " . print_r($epl_addit_fields_to_display, true) . "</pre>";
         }
         foreach ($ticket_quantities as $ticket_qty_id => $quantities) {
             if (version_compare($version, '1.2.9', '<')) {
                 $counter = 1;
             }
             for ($i = 0; $i < $quantities; $i++) {
                 $this->form_no++;
                 //not good, runs every time in the loop
                 /* if ( $pack_regis && $attendance_dates = epl_get_element( "_pack_attendance_dates_{$event_id}_{$ticket_id}_" . ($i + 1), $regis_data, null ) ) {
                 
                                       $pack_count = count( $attendance_dates );
                                       $attendance_date_number = array_search( $date_id, array_keys( $attendance_dates ) ) + 1;
                                       }
                 
                                       if ( $pack_regis && $date_id && !isset( $attendance_dates[$date_id] ) ) {
                                       break;
                                       continue;
                                       } */
                 $ticket_label = epl_escape_csv_val(epl_get_element($ticket_id, $event_details['_epl_price_name']));
                 if (epl_is_date_level_price()) {
                     $reserved_date_key = $ticket_qty_id;
                     $reserved_dates = epl_get_element_m($ticket_qty_id, '_epl_start_date', $event_details);
                 }
                 if (epl_is_date_level_time()) {
                     $reserved_time_key = $reserved_times[$ticket_qty_id];
                     $reserved_times_display = epl_get_element_m($reserved_time_key, '_epl_start_time', $event_details);
                 }
                 $ins['field_id'] = array();
                 $ins['input_slug'] = array();
                 $ins['value'] = array();
                 foreach ($epl_addit_fields_to_display as $field_id => $field_atts) {
                     $value = '';
                     //if ( $this->debug )
                     //  echo "<pre class='prettyprint'>" . __LINE__ . "> " . basename( __FILE__ ) . " > " . print_r( epl_get_num_events_in_cart(), true ) . "</pre>";
                     //new v1.2.b9+
                     //if ( epl_sc_is_enabled() || isset( $attendee_info[$field_id][0] ) ) { //if this, price specific forms will get the primary form vals also
                     if (epl_sc_is_enabled()) {
                         $value = epl_get_element(0, $attendee_info[$field_id]);
                     } else {
                         $value = isset($attendee_info[$field_id]) ? epl_get_element(0, $attendee_info[$field_id][$event_id]) : '';
                     }
                     if (isset($attendee_info[$field_id][$event_id][$ticket_id])) {
                         $value = epl_get_element($counter, $attendee_info[$field_id][$event_id][$ticket_id]);
                     } elseif (isset($attendee_info[$field_id][$event_id][$counter])) {
                         $value = $attendee_info[$field_id][$event_id][$counter];
                     }
                     $raw_value = $value;
                     if ($field_atts['input_type'] == 'select' || $field_atts['input_type'] == 'radio') {
                         $value = $raw_value;
                         //(isset( $field_atts['epl_field_choice_text'][$value] ) && $field_atts['epl_field_choice_text'][$value] !== '') ? $field_atts['epl_field_choice_text'][$value] : $value;
                     } elseif ($field_atts['input_type'] == 'checkbox') {
                         if (!epl_is_empty_array($field_atts['epl_field_choice_value'])) {
                             $value = implode(',', (array) $raw_value);
                         } elseif (!epl_is_empty_array($value)) {
                             $value = implode(',', $raw_value);
                         } else {
                             $value = html_entity_decode(htmlspecialchars_decode($value));
                         }
                     }
                     /* else {
                     
                                               $value = html_entity_decode( htmlspecialchars_decode( $value ) );
                                               } */
                     // if ( $value != '' ) { //FOR NOW, WILL ENTER EMPTY ROW IN THE TABLE, WILL HELP TRACK COUNTS
                     $ins['field_id'][] = $field_id;
                     $ins['input_slug'][] = $field_atts['input_slug'];
                     $ins['form_no'] = $this->form_no;
                     $ins['value'][] = str_replace($this->delim, " ", $value);
                     //$wpdb->insert( $wpdb->epl_regis_form_data, $ins );
                     //}
                 }
                 //if ( !epl_is_empty_array( $ins['field_id'] ) ) {
                 // echo "<pre class='prettyprint'>" . __LINE__ . "> " . print_r($ins, true). "</pre>";
                 $ins['field_id'] = implode($this->delim, $ins['field_id']);
                 $ins['input_slug'] = implode($this->delim, $ins['input_slug']);
                 $ins['form_no'] = $this->form_no;
                 $ins['value'] = implode($this->delim, $ins['value']);
                 if ($this->debug) {
                     echo "<pre class='prettyprint'>" . __LINE__ . "> " . basename(__FILE__) . " >counter:{$counter} , ticket_id: {$ticket_id} " . print_r($ins, true) . "</pre>";
                 }
                 $wpdb->insert($wpdb->epl_regis_form_data, $ins);
                 //}
                 $counter++;
                 $att_counter++;
             }
         }
     }
 }
 function _exp_checkout_do_payment()
 {
     global $event_details, $cart_totals;
     $event_id = $event_details['ID'];
     if (is_null($event_id)) {
         //return false;
     }
     $regis_id = $this->erm->get_regis_id();
     $post_ID = $this->erm->get_regis_post_id();
     $this->ecm->setup_event_details($event_id);
     $line_item_surcharge = false;
     $line_item_surcharge = apply_filters('egm__pp_exp__line_item_surcharge', $line_item_surcharge);
     $_totals = $this->erm->calculate_cart_totals();
     $amount = $cart_totals['money_totals']['grand_total'];
     $amount = epl_get_balance_due();
     $tax = epl_get_element_m('surcharge', 'money_totals', $cart_totals, 0);
     $subtotal = epl_get_element_m('subtotal', 'money_totals', $cart_totals, 0);
     $num_days_in_cart = array();
     $price_multiplier = array();
     $price_multiplier_label = array();
     $discount_amount = number_format(epl_get_element('discount_amount', $cart_totals['money_totals'], 0), 2, ".", "");
     //$subtotal = $discount_amount > 0 ? number_format( $subtotal - $discount_amount, 2 ) : $subtotal;
     $this->epl->load_file('libraries/gateways/paypal/paypal.php');
     $paypal = new EPL_Paypal();
     $gateway_info = $this->erm->get_gateway_info();
     $paypal->_credentials = array('USER' => $gateway_info['_epl_pp_exp_user'], 'PWD' => $gateway_info['_epl_pp_exp_pwd'], 'SIGNATURE' => $gateway_info['_epl_pp_exp_sig']);
     $requestParams = array('TOKEN' => $_GET['token'], 'PAYMENTACTION' => 'Sale', 'PAYERID' => $_GET['PayerID']);
     $orderParams = array('PAYMENTREQUEST_0_AMT' => $amount, 'PAYMENTREQUEST_0_ITEMAMT' => $amount - $tax, 'PAYMENTREQUEST_0_CURRENCYCODE' => epl_nz(epl_get_general_setting('epl_currency_code'), 'USD'), 'PAYMENTREQUEST_0_TAXAMT' => $line_item_surcharge === false ? $tax : 0);
     $counter = 0;
     $tickets = $_SESSION['__epl'][$regis_id]['_dates']['_att_quantity'];
     $dates = isset($_SESSION['__epl'][$regis_id]['_dates']['_epl_start_date']) ? $_SESSION['__epl'][$regis_id]['_dates']['_epl_start_date'] : array();
     $events = $_SESSION['__epl'][$regis_id]['_events'];
     $parallel_pay = epl_get_regis_setting('_epl_enable_PP_parallel_pay') == 10 && !epl_is_empty_array(epl_get_element('_epl_price_parallel_pay_email', $event_details, array()));
     $pp_email = epl_get_element('_epl_pp_exp_email', $gateway_info);
     if ($parallel_pay) {
         $orderParams = array();
         foreach ($tickets as $event_id => $ind_tickets) {
             $this->ecm->setup_event_details($event_id);
             foreach ($ind_tickets as $ticket_id => $ticket_qty) {
                 $ticket_name = epl_get_element($ticket_id, $event_details['_epl_price_name']);
                 $ticket_price = epl_get_element($ticket_id, $event_details['_epl_price']);
                 if (epl_is_eligible_for_member_price($ticket_id)) {
                     $ticket_price = epl_get_element_m($ticket_id, '_epl_member_price', $event_details, $ticket_price);
                 }
                 $qty = is_array($ticket_qty) ? array_sum($ticket_qty) : $ticket_qty;
                 if ($qty > 0) {
                     $orderParams['PAYMENTREQUEST_' . $counter . '_AMT'] = $ticket_price;
                     $orderParams['PAYMENTREQUEST_' . $counter . '_SELLERPAYPALACCOUNTID'] = epl_get_element_m($ticket_id, '_epl_price_parallel_pay_email', $event_details, $pp_email);
                     $orderParams['PAYMENTREQUEST_' . $counter . '_SHIPPINGAMT'] = 0;
                     $orderParams['PAYMENTREQUEST_' . $counter . '_CURRENCYCODE'] = epl_nz(epl_get_general_setting('epl_currency_code'), 'USD');
                     $orderParams['PAYMENTREQUEST_' . $counter . '_ITEMAMT'] = $ticket_price;
                     $orderParams['PAYMENTREQUEST_' . $counter . '_TAXAMT'] = 0;
                     $orderParams['PAYMENTREQUEST_' . $counter . '_DESC'] = substr($ticket_name, 0, 126);
                     $orderParams['PAYMENTREQUEST_' . $counter . '_PAYMENTREQUESTID'] = $post_ID . '-' . $counter;
                     $counter++;
                 }
             }
         }
     }
     $counter = 0;
     $item = array();
     foreach ($tickets as $event_id => $ind_tickets) {
         $this->ecm->setup_event_details($event_id);
         $num_days_in_cart[$event_id] = count(epl_get_element($event_id, $dates, array()));
         $price_multiplier[$event_id] = $event_details['_epl_price_per'] == 10 && !epl_is_date_level_price() ? $num_days_in_cart[$event_id] : 1;
         $price_multiplier_label[$event_id] = $price_multiplier[$event_id] > 1 ? ' - ' . $num_days_in_cart[$event_id] . ' ' . epl__('days') : '';
         foreach ($ind_tickets as $ticket_id => $ticket_qty) {
             $ticket_name = epl_get_element($ticket_id, $event_details['_epl_price_name']);
             $ticket_price = epl_get_element($ticket_id, $event_details['_epl_price']);
             if (epl_is_eligible_for_member_price($ticket_id)) {
                 $ticket_price = epl_get_element_m($ticket_id, '_epl_member_price', $event_details, $ticket_price);
             }
             $qty = is_array($ticket_qty) ? array_sum($ticket_qty) : $ticket_qty;
             if ($qty > 0) {
                 $item['L_PAYMENTREQUEST_0_NAME' . $counter] = substr($event_details['post_title'], 0, 126);
                 $item['L_PAYMENTREQUEST_0_DESC' . $counter] = $ticket_name . $price_multiplier_label[$event_id];
                 //$item['L_PAYMENTREQUEST_0_NUMBER' . $counter] = $ticket_id;
                 $item['L_PAYMENTREQUEST_0_AMT' . $counter] = $ticket_price;
                 $item['L_PAYMENTREQUEST_0_QTY' . $counter] = $qty * $price_multiplier[$event_id];
                 $counter++;
             }
         }
     }
     if ($parallel_pay) {
         $item = array();
         $counter = 0;
         $ticket_counter = 0;
         //this will be incremented if we do line item per ticket qty
         foreach ($tickets as $event_id => $ind_tickets) {
             $this->ecm->setup_event_details($event_id);
             foreach ($ind_tickets as $ticket_id => $ticket_qty) {
                 $ticket_name = epl_get_element($ticket_id, $event_details['_epl_price_name']);
                 $ticket_price = epl_get_element($ticket_id, $event_details['_epl_price']);
                 if (epl_is_eligible_for_member_price($ticket_id)) {
                     $ticket_price = epl_get_element_m($ticket_id, '_epl_member_price', $event_details, $ticket_price);
                 }
                 $qty = is_array($ticket_qty) ? array_sum($ticket_qty) : $ticket_qty;
                 if ($qty > 0) {
                     $item['L_PAYMENTREQUEST_' . $counter . '_NAME' . $ticket_counter] = substr($event_details['post_title'], 0, 126);
                     $item['L_PAYMENTREQUEST_' . $counter . '_DESC' . $ticket_counter] = $ticket_name . $price_multiplier_label[$event_id];
                     //$item['L_PAYMENTREQUEST_0_NUMBER' . $counter] = $ticket_id;
                     $item['L_PAYMENTREQUEST_' . $counter . '_AMT' . $ticket_counter] = $ticket_price;
                     $item['L_PAYMENTREQUEST_' . $counter . '_QTY' . $ticket_counter] = $qty * $price_multiplier[$event_id];
                     $counter++;
                 }
             }
         }
     }
     if (!$parallel_pay) {
         if ($tax > 0 && $line_item_surcharge !== false) {
             //$discount_description = epl_get_element( 'discount_description', $cart_totals['money_totals'], null );
             foreach ($_SESSION['__epl'][$regis_id]['_events'] as $event_id => $event_totals) {
                 $sc = epl_get_element_m('surcharge', 'money_totals', $event_totals, 0);
                 if ($sc == 0) {
                     continue;
                 }
                 $this->ecm->setup_event_details($event_id);
                 $surcharge_label = epl_get_element('_epl_surcharge_label', $event_details, epl__('Surcharge'));
                 $item['L_PAYMENTREQUEST_0_NAME' . $counter] = $surcharge_label;
                 //$item['L_PAYMENTREQUEST_0_DESC' . $counter] = $discount_description;
                 //$item['L_PAYMENTREQUEST_0_NUMBER' . $counter] = $ticket_id;
                 $item['L_PAYMENTREQUEST_0_AMT' . $counter] = $sc;
                 $item['L_PAYMENTREQUEST_0_QTY' . $counter] = 1;
                 $requestParams['PAYMENTREQUEST_0_ITEMAMT'] += $sc;
                 $counter++;
             }
         }
         if ($discount_amount > 0) {
             $discount_description = epl_get_element('discount_description', $cart_totals['money_totals'], null);
             $discount_description = substr($discount_description, 0, 126);
             $item['L_PAYMENTREQUEST_0_NAME' . $counter] = $discount_description;
             //$item['L_PAYMENTREQUEST_0_DESC' . $counter] = $discount_description;
             //$item['L_PAYMENTREQUEST_0_NUMBER' . $counter] = $ticket_id;
             $item['L_PAYMENTREQUEST_0_AMT' . $counter] = -1 * $discount_amount;
             $item['L_PAYMENTREQUEST_0_QTY' . $counter] = 1;
         }
         $alt_total_due = epl_get_element_m('pay_deposit', 'money_totals', $cart_totals) == 1;
         if ($alt_total_due > 0) {
             $counter++;
             $balance_due_desc = epl__('Deposit Offset.  Due at a later date.');
             $balance_due_desc = substr($balance_due_desc, 0, 126);
             $balance_offset = get_the_regis_total_amount(false) - $amount;
             $item['L_PAYMENTREQUEST_0_NAME' . $counter] = $balance_due_desc;
             //$item['L_PAYMENTREQUEST_0_DESC' . $counter] = $discount_description;
             //$item['L_PAYMENTREQUEST_0_NUMBER' . $counter] = $ticket_id;
             $item['L_PAYMENTREQUEST_0_AMT' . $counter] = -1 * $balance_offset;
             $item['L_PAYMENTREQUEST_0_QTY' . $counter] = 1;
         }
         $payment_data = epl_get_regis_payments();
         if (!empty($payment_data)) {
             if (count($payment_data) > 0) {
                 foreach ($payment_data as $time => $p) {
                     $counter++;
                     $payment_made_description = epl__('Offset for payment made on: ') . epl_formatted_date($p['_epl_payment_date']);
                     $payment_made_description = substr($payment_made_description, 0, 126);
                     $item['L_PAYMENTREQUEST_0_NAME' . $counter] = $payment_made_description;
                     //$item['L_PAYMENTREQUEST_0_DESC' . $counter] = $discount_description;
                     //$item['L_PAYMENTREQUEST_0_NUMBER' . $counter] = $ticket_id;
                     $item['L_PAYMENTREQUEST_0_AMT' . $counter] = -1 * $p['_epl_payment_amount'];
                     $item['L_PAYMENTREQUEST_0_QTY' . $counter] = 1;
                 }
             }
         }
         if (($donation_amount = epl_get_element_m('donation_amount', 'money_totals', $cart_totals, 0)) > 0) {
             $counter++;
             $item['L_PAYMENTREQUEST_0_NAME' . $counter] = epl__('Donation');
             $item['L_PAYMENTREQUEST_0_AMT' . $counter] = $donation_amount;
             $item['L_PAYMENTREQUEST_0_QTY' . $counter] = 1;
         }
         if (($original_total = epl_get_element_m('original_total', 'money_totals', $cart_totals, 0)) > 0) {
             $counter++;
             $item['L_PAYMENTREQUEST_0_NAME' . $counter] = epl__('Offset');
             $item['L_PAYMENTREQUEST_0_AMT' . $counter] = -1 * ($original_total - $orderParams['PAYMENTREQUEST_0_AMT']);
             $item['L_PAYMENTREQUEST_0_QTY' . $counter] = 1;
         }
     }
     $request = $requestParams + $item + $orderParams;
     $request = apply_filters('epl_express_checkout_do_payment_request_params', $request);
     $response = $paypal->request('DoExpressCheckoutPayment', $request);
     if (is_array($response) && $response['ACK'] == 'Success') {
         $payment_amount = $response['PAYMENTINFO_0_AMT'];
         $counter = 0;
         if ($parallel_pay) {
             $payment_amount = 0;
             foreach ($tickets as $event_id => $ind_tickets) {
                 $this->ecm->setup_event_details($event_id);
                 foreach ($ind_tickets as $ticket_id => $ticket_qty) {
                     $qty = is_array($ticket_qty) ? array_sum($ticket_qty) : $ticket_qty;
                     if ($qty > 0) {
                         $payment_amount += epl_get_element('PAYMENTINFO_' . $counter . '_AMT', $response, 0);
                         $counter++;
                     }
                 }
             }
         }
         $data['post_ID'] = $post_ID;
         $data['_epl_grand_total'] = $cart_totals['money_totals']['grand_total'];
         $data['_epl_payment_amount'] = $payment_amount;
         $data['_epl_payment_date'] = current_time('mysql');
         $data['_epl_payment_method'] = $this->erm->get_payment_profile_id();
         $data['_epl_transaction_id'] = $response['PAYMENTINFO_0_TRANSACTIONID'];
         $data['_epl_prediscount_total'] = epl_get_element('pre_discount_total', $cart_totals['money_totals'], 0);
         $data['_epl_discount_amount'] = epl_get_element('discount_amount', $cart_totals['money_totals'], 0);
         $data = apply_filters('epl_pp_exp_response_data', $data, $response);
         $this->erm->update_payment_data($data);
         return true;
         //echo "DONE";
     } else {
         $error = 'ERROR: ' . $response['L_SHORTMESSAGE0'] . '. ' . $response['L_LONGMESSAGE0'];
         echo EPL_Util::get_instance()->epl_invoke_error(0, $error, false);
     }
     return false;
 }
 function epl_daily_schedule($table = false, $email_only = false, $regis_post_id = null)
 {
     global $epl_fields;
     $event_id = (int) $_REQUEST['event_id'];
     $date_id = epl_get_element('date_id', $_REQUEST);
     $time_id = epl_get_element('time_id', $_REQUEST);
     $names_only = epl_get_element('names_only', $_REQUEST, 0) == 1;
     $email_list = array();
     //$regis_post_id = epl_get_element( 'post_ID', $_REQUEST, null );
     $this->setup_event_details($event_id);
     $_totals = $this->get_event_regis_snapshot($event_id);
     $this->set_event_regis_post_ids($event_id, $regis_post_id);
     global $event_details;
     $event_title = $event_details['post_title'];
     if (!$table) {
         $filename = str_replace(" ", "-", $event_title) . "_" . date_i18n("m-d-Y");
         //header( "Content-type: application/x-msdownload", true, 200 );
         /* header( 'Content-Type: application/csv' );
            header( "Content-Disposition: attachment; filename={$filename}.csv" );
            header( "Pragma: no-cache" );
            header( "Expires: 0" ); */
     } else {
     }
     //$this->setup_event_details( $event_id );
     //echo "<pre class='prettyprint'>" . print_r($event_details, true). "</pre>";
     //find the forms that the user has selected for this event
     $event_ticket_buyer_forms = array_flip((array) $event_details['_epl_primary_regis_forms']);
     $event_addit_forms = epl_get_element('_epl_addit_regis_forms', $event_details) ? array_flip($event_details['_epl_addit_regis_forms']) : array();
     /*
      * find price forms if any.
      */
     $price_forms = epl_get_element('_epl_price_forms', $event_details, array());
     $_price_forms = array();
     foreach ($price_forms as $k => $v) {
         $_price_forms += $v;
     }
     //find the list of all forms
     $available_forms = $this->get_list_of_available_forms();
     $available_fields = $this->get_list_of_available_fields();
     //isolate the ticket buyer forms that are selected inside the event
     $ticket_buyer_forms = array_intersect_key($available_forms, $event_ticket_buyer_forms);
     //isolate the additional forms for attendees.
     $addit_forms = array_intersect_key($available_forms, array_merge($event_addit_forms, $_price_forms));
     //This will combine all the fields in all the forms so that we can construct a header row.
     $tickey_buyer_fields = array();
     foreach ($ticket_buyer_forms as $_form_id => $_form_info) {
         $tickey_buyer_fields += $_form_info['epl_form_fields'];
     }
     //combine all the fields from the attendee forms
     $event_addit_fields = array();
     foreach ($addit_forms as $_form_id => $_form_info) {
         //$event_addit_fields += $_form_info['epl_form_fields'];
         $event_addit_fields = array_merge($event_addit_fields, $_form_info['epl_form_fields']);
     }
     $epl_fields_inside_form = array_flip($tickey_buyer_fields);
     //get the field ids inside the form
     $epl_addit_fields_inside_form = array_flip($event_addit_fields);
     //get the field ids inside the form
     //when creating a form in form manager, the user may rearrange fields.  Find their desired order
     $epl_fields_to_display = $this->epl_util->sort_array_by_array($available_fields, $epl_fields_inside_form);
     $epl_addit_fields_to_display = $this->epl_util->sort_array_by_array($available_fields, $epl_addit_fields_inside_form);
     //final list of all the fields to display
     $epl_fields_to_display = $epl_fields_to_display + $epl_addit_fields_to_display;
     $csv_row = '';
     $header_row = array();
     $header_pulled = false;
     $row = array();
     $form_data_header = array();
     $form_data = array();
     //$header_row[] = '';
     $header_row[] = epl__('Regis ID');
     $header_row[] = epl__('Regis Date');
     $header_row[] = epl__('Status');
     $header_row[] = epl__('Payment Method');
     $header_row[] = epl__('Total');
     $header_row[] = epl__('Amount Paid');
     $header_row[] = epl__('Discount Code');
     $form_data_header[] = epl__('Event Date');
     $form_data_header[] = epl__('Time');
     $form_data_header[] = epl__('Ticket');
     //get all the registration post ids for this event
     $regis_ids = $this->get_event_regis_post_ids(false, $regis_post_id);
     //as of 1.1, the dates are stored as timestamps.
     //This will format the date for display based on the settings admin date format.
     foreach ($event_details['_epl_start_date'] as $k => &$v) {
         //if ( $v >= EPL_DATE )
         // $v = epl_admin_date_display( $v );
         //else
         // unset( $event_details['_epl_start_date'][$k] );
     }
     $has_addit_att_forms = !epl_is_empty_array($event_details['_epl_addit_regis_forms']);
     $zebra = 'odd';
     //for each registration
     foreach ($regis_ids as $regis_id => $att_count) {
         //setup the registration details
         $regis_data = $this->setup_regis_details($regis_id);
         //echo "<pre class='prettyprint'>" . __LINE__ . "> " . print_r($regis_data, true). "</pre>";
         //Sometime there may be incomplete db records.  These will cause issues below.
         //In those cases, skip and move to the next item
         if (!isset($regis_data['_epl_dates']['_epl_start_date'][$event_id])) {
             continue;
         }
         if (get_the_regis_status(null, true) <= 1) {
             continue;
         }
         $zebra = $zebra == 'odd' ? 'even' : 'odd';
         //event times and prices
         //$event_times = $regis_data['_epl_dates']['_epl_start_time'][$event_id];
         //$event_prices = $regis_data['_epl_dates']['_epl_start_time'][$event_id];
         $disc_code_id = epl_get_element('discount_code_id', $regis_data['_epl_events'][$event_id]['money_totals']);
         $disc_code = epl_get_element_m($disc_code_id, '_epl_discount_code', $event_details);
         $reserved_dates = epl_get_element_m($event_id, '_epl_start_date', $regis_data['_epl_dates'], array());
         $reserved_times = epl_get_element_m($event_id, '_epl_start_time', $regis_data['_epl_dates'], array());
         if ($date_id && !in_array($date_id, $reserved_dates)) {
             continue;
         }
         if ($time_id && !in_array($time_id, $reserved_times)) {
             continue;
         }
         //this isolates the dates and times that the user has registered for
         //$reserved_dates = implode( ' & ', array_intersect_key( $event_details['_epl_start_date'], array_flip( $reserved_dates ) ) );
         $reserved_times_display = implode(' & ', array_intersect_key($event_details['_epl_start_time'], array_flip($reserved_times)));
         //init vars
         $date_labels = array();
         $date_labels[0] = '';
         $time_labels = array();
         $time_labels[0] = '';
         $ticket_labels = array();
         $ticket_labels[0] = $att_count;
         $purchased_tickets = (array) $regis_data['_epl_dates']['_att_quantity'][$event_id];
         //?????????
         $start = 1;
         foreach ($purchased_tickets as $price_id => $qty) {
             $_qty = is_array($qty) ? array_sum($qty) : $qty;
             //current( $qty );
             if ($_qty > 0) {
                 $date_label[] = current((array) $regis_data['_epl_dates']['_epl_start_date'][$event_id]);
                 if (epl_get_element('_epl_pricing_type', $event_details) == 10) {
                     if (in_array($event_details['_epl_price_parent_time_id'][$price_id], (array) $regis_data['_epl_dates']['_epl_start_time'][$event_id])) {
                         $time_labels = array_pad($time_labels, $start + $_qty, epl_get_element($event_details['_epl_price_parent_time_id'][$price_id], $event_details['_epl_start_time']));
                     } else {
                         $time_labels = array_pad($time_labels, $start + $_qty, '');
                     }
                 }
                 $ticket_labels = array_pad($ticket_labels, $start + $_qty, $event_details['_epl_price_name'][$price_id]);
                 $start += $_qty;
             }
         }
         $_r = array();
         $regis_status = isset($regis_data['_epl_regis_status']) ? $epl_fields['epl_regis_payment_fields']['_epl_regis_status']['options'][$regis_data['_epl_regis_status']] : '';
         $_pm_id = EPL_Registration_model::get_instance()->setup_current_data($regis_data)->get_payment_profile_id();
         $payment_method = isset($regis_data['_epl_payment_method']) && $regis_data['_epl_payment_method'] != '' ? $epl_fields['epl_regis_payment_fields']['_epl_payment_method']['options'][$_pm_id] : '';
         $grand_total = epl_get_formatted_curr(epl_nz($regis_data['_epl_grand_total'], 0.0));
         $amount_paid = epl_get_formatted_curr(epl_nz($regis_data['_epl_payment_amount'], 0.0));
         $attendee_info = $regis_data['_epl_attendee_info'];
         //################################### Ticket buyer Data ############################################
         //$row[] = epl__( 'Registrant' );
         if (!$has_addit_att_forms) {
             $form_data[] = '';
             //epl_escape_csv_val( $regis_date );
             $form_data[] = '';
             //$regis_time; //(epl_is_date_level_time ( ))?$regis_time:$time_labels[$i]; //
             $form_data[] = '';
             //epl_escape_csv_val( epl_get_element( $ticket_id, $event_details['_epl_price_name'] ) ); //$regis_price;
             foreach ($epl_fields_to_display as $field_id => $field_atts) {
                 $value = isset($attendee_info[$field_id]) ? epl_get_element(0, $attendee_info[$field_id][$event_id]) : '';
                 if ($field_atts['input_slug'] == 'email') {
                     $email_list[$regis_id] = $value;
                     if ($regis_post_id && $regis_post_id != $regis_id) {
                         unset($email_list[$regis_id]);
                     }
                 }
                 if ($field_atts['input_type'] == 'select' || $field_atts['input_type'] == 'radio') {
                     $value = isset($field_atts['epl_field_choice_text'][$value]) && $field_atts['epl_field_choice_text'][$value] !== '' ? $field_atts['epl_field_choice_text'][$value] : $value;
                 } elseif ($field_atts['input_type'] == 'checkbox') {
                     if (!epl_is_empty_array($field_atts['epl_field_choice_value'])) {
                         $value = implode(',', (array) $value);
                     } else {
                         if (is_array($value)) {
                             $value = implode(',', array_intersect_key($field_atts['epl_field_choice_text'], array_flip((array) $value)));
                         }
                     }
                 }
                 $form_data[] = epl_escape_csv_val(html_entity_decode(htmlspecialchars_decode($value, ENT_QUOTES)));
             }
             $row = !$names_only ? array_merge($row, $form_data) : $form_data;
             if ($table) {
                 $this->epl->epl_table->add_row($row, $zebra);
             }
             $csv_row .= implode(",", $row) . "\r\n";
             $row = array();
         }
         //###################  End Ticket Buyer Data #########################################
         $tickets_to_show = array_intersect_key($purchased_tickets, $event_details['_epl_price_name']);
         $counter = 1;
         $att_counter = 1;
         foreach ($tickets_to_show as $ticket_id => $ticket_qty) {
             if (is_array($ticket_qty)) {
                 $tmp_price_inner_keys = array_keys($ticket_qty);
                 $ticket_qty = array_sum($ticket_qty);
             }
             if ($ticket_qty == 0) {
                 continue;
             }
             for ($i = 0; $i < $ticket_qty; $i++) {
                 //$row[] = ''; //epl_get_element( '_epl_addit_regis_form_counter_label', $event_details, epl__( 'Attendee' ) ) . ' ' . $att_counter;
                 $grand_total = '';
                 $amount_paid = '';
                 $regis_status = get_the_regis_status();
                 $payment_method = '';
                 $ticket_label = epl_escape_csv_val(epl_get_element($ticket_id, $event_details['_epl_price_name']));
                 if (epl_is_date_level_price()) {
                     $reserved_date_key = $tmp_price_inner_keys[$i];
                     //echo "<pre class='prettyprint'>" . __LINE__ . "> " . print_r($reserved_date_key, true). "</pre>";
                     //$reserved_dates = epl_get_element_m( $reserved_date_key, '_epl_start_date', $event_details );
                 }
                 if (epl_is_date_level_time()) {
                     $reserved_time_key = $reserved_times[$reserved_date_key];
                     $reserved_times_display = epl_get_element_m($reserved_time_key, '_epl_start_time', $event_details);
                 }
                 $key = $regis_id . '_' . $counter;
                 $form_data[$key]['att_dates'] = array_flip($reserved_dates);
                 $form_data[$key]['att_times'] = $reserved_times_display;
                 //(epl_is_date_level_time ( ))?$regis_time:$time_labels[$i]; //
                 $form_data[$key]['ticket'] = $ticket_label;
                 //$regis_price;
                 $form_data[$key]['regis_status'] = $regis_status;
                 //$regis_price;
                 $form_data[$key]['regis_status_id'] = get_the_regis_status(null, true);
                 //$regis_price;
                 //$form_data[] = epl_get_element('_pack_attendance_dates_2035_' . $ticket_id . '_' . ($i+1) ); //$regis_price;
                 $pack_dates = epl_get_element("_pack_attendance_dates_{$event_id}_{$ticket_id}_" . ($i + 1), $regis_data);
                 //$regis_price;
                 if (!epl_is_empty_array($pack_dates)) {
                     $form_data[$key]['att_dates'] = $pack_dates;
                 }
                 $form_data[$key]['pack_size'] = epl_get_element_m($ticket_id, '_epl_price_pack_size', $event_details);
                 //$regis_price;
                 /* form data, if any */
                 foreach ($epl_fields_to_display as $field_id => $field_atts) {
                     if (!$header_pulled) {
                         $form_data_header[] = epl_escape_csv_val(html_entity_decode(htmlspecialchars_decode($field_atts['label'], ENT_QUOTES)));
                     }
                     $value = '';
                     if (isset($attendee_info[$field_id][$event_id][$ticket_id])) {
                         $value = epl_get_element($counter, $attendee_info[$field_id][$event_id][$ticket_id]);
                     } elseif (isset($attendee_info[$field_id][$event_id][$counter])) {
                         $value = $attendee_info[$field_id][$event_id][$counter];
                     }
                     if ($field_atts['input_slug'] == 'first_name' || $field_atts['input_slug'] == 'last_name') {
                         $form_data[$key][$field_atts['input_slug']] = epl_escape_csv_val(html_entity_decode(htmlspecialchars_decode($value, ENT_QUOTES)));
                     }
                 }
                 $header_pulled = true;
                 //decode special chars (Swedish, Nordic)
                 $row = !$names_only ? array_merge($row, $form_data) : $form_data;
                 array_walk($row, create_function('&$item', 'if(!is_array($item))$item = utf8_decode($item);'));
                 $csv_row .= implode(",", $row) . "\r\n";
                 $row = array();
                 //$form_data = array( );
                 $counter++;
                 $att_counter++;
             }
         }
     }
     $header_row = !$names_only ? array_merge($header_row, $form_data_header) : $form_data_header;
     array_walk($header_row, create_function('&$item', '$item = utf8_decode($item);'));
     $header_row = array();
     $header_row_pulled = false;
     //placeholders
     $header_row[] = '<div style="width:100px;">&nbsp;</div>';
     $header_row[] = '';
     $header_row[] = '';
     $header_row[] = '';
     $header_row[] = 'Status';
     if ($table) {
         $tmpl = array('table_open' => '<table border="1" cellpadding="0" cellspacing="0" class="" id="epl_daily_schedule_table">');
         $this->epl->epl_table->set_template($tmpl);
         //$this->epl->epl_table->set_heading( $header_row );
         $footer = array();
         $footer[] = 'Totals';
         $footer[] = '';
         $footer[] = '';
         $footer[] = '';
         $footer[] = '';
         $day_total = 0;
         foreach ($form_data as $regis_id => $reg_data) {
             $pack_counter = count($reg_data['att_dates']);
             $start_date_key = key($reg_data['att_dates']);
             $this_ticket_is_ok = false;
             $display_row = array();
             $display_row[] = $reg_data['ticket'];
             $display_row[] = $reg_data['att_times'];
             $display_row[] = $reg_data['first_name'];
             $display_row[] = $reg_data['last_name'];
             $display_row[] = $reg_data['regis_status'];
             $counter = 1;
             //if( $reg_data['regis_status'] == )
             foreach ($event_details['_epl_start_date'] as $date_key => $timestamp) {
                 if (!isset($footer[$date_key])) {
                     $footer[$date_key] = 0;
                 }
                 //if ( isset( $reg_data['att_dates'][$date_key] ) ) {
                 if (($date_key == $start_date_key || $this_ticket_is_ok == true) && $pack_counter > 0) {
                     if ($reg_data['regis_status_id'] == 5) {
                         $footer[$date_key] += 1;
                     }
                     if ($reg_data['pack_size'] != '') {
                         $this_ticket_is_ok = true;
                         //$display_row[] = "<img src='" . EPL_FULL_URL . "images/accept.png' /><br />" . $counter . '/' . $reg_data['pack_size'];
                         $renew = '';
                         if ($reg_data['pack_size'] - $counter == 1) {
                             $renew = "<img src='" . EPL_FULL_URL . "images/error.png' />";
                         }
                         $display_row[] = $counter . '/' . $reg_data['pack_size'] . $renew;
                         $counter++;
                         $pack_counter--;
                     } else {
                         $display_row[] = "<img src='" . EPL_FULL_URL . "images/accept.png' />";
                         $this_ticket_is_ok = false;
                     }
                 } else {
                     $display_row[] = '';
                     $this_ticket_is_ok = false;
                 }
                 if (!$header_row_pulled) {
                     $_d = epl_admin_date_display($timestamp);
                     if ($timestamp < EPL_DATE) {
                         $header_row[] = "<span style='color:#bbb'>{$_d}</span>";
                     } else {
                         $header_row[] = $_d;
                     }
                 }
             }
             //$footer[] = $day_total;
             //$day_total = 0;
             $header_row_pulled = true;
             $zebra = $reg_data['regis_status_id'] == 1 ? 'epl_incomplete' : '';
             $zebra_style = $reg_data['regis_status_id'] == 1 ? 'background-color:  #feffd4;' : '';
             $this->epl->epl_table->add_row($display_row, $zebra, $zebra_style);
         }
         $this->epl->epl_table->add_row($footer);
         $this->epl->epl_table->set_heading($header_row);
         $t = $this->epl->epl_table->generate();
         $url = admin_url("edit.php?post_type=epl_event&epl_action=epl_daily_schedule&table_view=1&epl_controller=epl_registration&event_id={$event_id}&print=1");
         $print_icon = !isset($_REQUEST['print']) ? '<div><a href="' . $url . '" target="_blank"><img src="' . EPL_FULL_URL . 'images/printer.png" /></a></div>' : '';
         return $print_icon . $t;
     } elseif ($email_only) {
         return $email_list;
     } else {
         echo implode(",", $header_row) . "\r\n";
         echo $csv_row;
         exit;
     }
 }
 /**
  * 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 get_the_event_dates_times_prices()
 {
     global $event_details, $event_snapshot;
     $_today = EPL_DATE;
     $_r = array();
     foreach ($event_details['_epl_start_date'] as $date_key => $date) {
         if (epl_is_ongoing_event() || true) {
             $_note = epl_get_element_m($date_key, '_epl_date_note', $event_details);
             $_location = '';
             if (epl_get_element($date_key, epl_get_element('_epl_date_location', $event_details))) {
                 $_location_id = epl_get_element($date_key, $event_details['_epl_date_location']);
                 $l = the_location_details($_location_id);
                 //sets up the location info
                 $_location = $l['post_title'];
                 //get_the_location_name();// . ' ' . get_the_location_gmap_icon();
                 //echo "<pre class='prettyprint'>" . __LINE__ . "> " . print_r( epl_formatted_date( $date ) . $_location_id, true ) . "</pre>";
             }
             $_end = $date != $event_details['_epl_end_date'][$date_key] ? ' - ' . epl_formatted_date($event_details['_epl_end_date'][$date_key]) : '';
             $_r[$date_key]['date'] = array('disp' => epl_formatted_date($date) . $_end . ' ' . $_location);
             foreach ($event_details['_epl_start_time'] as $time_key => $time) {
                 if (epl_is_date_level_time() && epl_is_date_specific_time($time_key) && !epl_get_element_m($date_key, $time_key, $event_details['_epl_date_specific_time'])) {
                     continue;
                 }
                 $_r[$date_key]['time'][$time_key] = array('disp' => $time . epl_prefix(' - ', epl_get_element_m($time_key, '_epl_time_note', $event_details)));
                 foreach ($event_details['_epl_price_name'] as $price_key => $price_name) {
                     if (epl_is_date_level_price() && epl_is_date_specific_price($price_key) && !epl_get_element_m($date_key, $price_key, $event_details['_epl_date_specific_price'])) {
                         continue;
                     }
                     //echo "<pre class='prettyprint'>" . __LINE__ . "> " . print_r($event_details['_epl_price_name'], true). "</pre>";
                     $_r[$date_key]['time'][$time_key]['price'][$price_key] = array('disp' => $price_name, 'price' => epl_get_formatted_curr($event_details['_epl_price'][$price_key], null, true));
                     if (epl_is_time_specific_price($price_key) && !epl_get_element_m($time_key, $price_key, epl_get_element('_epl_time_specific_price', $event_details))) {
                         unset($_r[$date_key]['time'][$time_key]['price'][$price_key]);
                     }
                     if (epl_is_date_specific_price($price_key) && !epl_get_element_m($date_key, $price_key, epl_get_element('_epl_date_specific_price', $event_details))) {
                         unset($_r[$date_key]['time'][$time_key]['price'][$price_key]);
                     }
                 }
             }
         }
     }
     return $this->epl->load_view('front/dates-times-prices', array('table_data' => $_r), true);
 }