function construct_table_array($dates, $return_raw = false)
 {
     $r = array();
     $date_format = epl_nz(epl_get_general_setting('epl_admin_date_format'), get_option('date_format'));
     /*
      * need to know registration start and end dates
      * need to know the constructed dates
      *
      */
     //epl_log( "debug", "<pre>" . print_r( $dates, true ) . "</pre>" );
     foreach ($dates as $year => $month) {
         foreach ($month as $_month => $_days) {
             foreach ($_days as $k => $v) {
                 $_dd = strtotime(epl_admin_dmy_convert($v));
                 $_d = $return_raw ? $_dd : date_i18n($date_format, $_dd);
                 //$_d =date_i18n( $date_format, $_dd );
                 //preserving the keys for dates that have already been saved.
                 //Just in case there may be a registration that has been assigned to that date id
                 $_u_k = array_search($_dd, epl_get_element('_epl_start_date', $this->values, array()));
                 if ($_u_k === FALSE) {
                     $_u_k = $this->epl_util->make_unique_id();
                 }
                 $data['_epl_start_date'][$_u_k] = $_d;
                 //$data['_epl_end_date'][$_u_k] =date_i18n( $date_format, strtotime( "+{$this->ind_event_length} day", $_dd ) );
                 $data['_epl_end_date'][$_u_k] = $return_raw ? strtotime("+{$this->ind_event_length} day", $_dd) : date_i18n($date_format, strtotime("+{$this->ind_event_length} day", $_dd));
                 if (isset($_POST['_epl_rec_regis_start_date']) && $_POST['_epl_rec_regis_start_date'] != '') {
                     $data['_epl_regis_start_date'][$_u_k] = date_i18n($date_format, strtotime(epl_admin_dmy_convert($_POST['_epl_rec_regis_start_date'])));
                 } elseif (isset($_POST['_epl_rec_regis_start_days_before_start_date']) && $_POST['_epl_rec_regis_start_days_before_start_date'] != '') {
                     $data['_epl_regis_start_date'][$_u_k] = date_i18n($date_format, strtotime("-" . (int) $_POST['_epl_rec_regis_start_days_before_start_date'] . " day", $_dd));
                 }
                 if (isset($_POST['_epl_rec_regis_end_date']) && $_POST['_epl_rec_regis_end_date'] != '') {
                     $data['_epl_regis_end_date'][$_u_k] = date_i18n($date_format, strtotime(epl_admin_dmy_convert($_POST['_epl_rec_regis_end_date'])));
                 } elseif (isset($_POST['_epl_rec_regis_end_days_before_start_date']) && $_POST['_epl_rec_regis_end_days_before_start_date'] != '') {
                     $data['_epl_regis_end_date'][$_u_k] = date_i18n($date_format, strtotime("-" . (int) $_POST['_epl_rec_regis_end_days_before_start_date'] . " day", $_dd));
                 }
                 if (isset($_POST['_epl_recurrence_capacity']) && $_POST['_epl_recurrence_capacity'] != '') {
                     $data['_epl_date_capacity'][$_u_k] = (int) $_POST['_epl_recurrence_capacity'];
                 }
             }
         }
     }
     if ($return_raw) {
         return $data;
     }
     //epl_log( "debug", "<pre>" . print_r($data, true ) . "</pre>" );
     /* $rows_to_display = count( $data['_epl_start_date'] );
               $fields_to_display = array_keys( $this->fields['epl_date_fields'] );
     
               $_field_args = array(
               'section' => $this->fields['epl_date_fields'],
               'fields_to_display' => $fields_to_display,
               'meta' => array( '_view' => 1, '_type' => 'row', '_rows' => $rows_to_display, 'value' => $data )
               ); */
     $rows_to_display = count($data['_epl_start_date']);
     $epl_fields_to_display = array_keys($this->fields['epl_date_fields']);
     $_field_args = array('section' => $this->fields['epl_date_fields'], 'fields_to_display' => $epl_fields_to_display, 'meta' => array('_view' => 'raw', '_type' => 'row', '_rows' => $rows_to_display, 'value' => $data));
     $data['date_fields'] = $this->epl_util->render_fields($_field_args);
     $data['date_field_labels'] = $this->epl_util->extract_labels($this->fields['epl_date_fields']);
     //epl_log( "<pre>" . print_r($data['date_fields'], true ) . "</pre>", 1 );
     //echo "<pre class='prettyprint'>" . print_r($data['date_fields'], true). "</pre>";
     $r = $this->epl->load_view('admin/events/dates-section', $data, true);
     return $r;
 }
 function stripe_process()
 {
     global $event_details, $cart_totals;
     $event_id = $event_details['ID'];
     $regis_id = $this->erm->get_regis_id();
     $post_ID = $this->erm->get_regis_post_id();
     $this->epl->load_file('libraries/gateways/stripe/Stripe.php');
     $this->ecm->setup_event_details($event_id);
     $_totals = $this->erm->calculate_cart_totals(true);
     $gateway_info = $this->erm->get_gateway_info();
     $secret_key = $gateway_info['_epl_secret_key'];
     $publishable_key = $gateway_info['_epl_publishable_key'];
     $data['stripe'] = array("secret_key" => $secret_key, "publishable_key" => $publishable_key);
     Stripe::setApiKey($data['stripe']['secret_key']);
     // Get the credit card details submitted by the form
     $token = $_POST['stripeToken'];
     // Create the charge on Stripe's servers - this will charge the user's card
     try {
         $charge = Stripe_Charge::create(array("amount" => epl_get_balance_due() * 100, "currency" => strtolower(epl_nz(epl_get_general_setting('epl_currency_code'), 'USD')), "card" => $token, "description" => $event_details['post_title'], "metadata" => array("regis_id" => $post_ID)));
         $data['post_ID'] = $post_ID;
         $data['_epl_grand_total'] = $cart_totals['money_totals']['grand_total'];
         $data['_epl_payment_amount'] = $cart_totals['money_totals']['grand_total'];
         $data['_epl_payment_date'] = current_time('mysql');
         $data['_epl_payment_method'] = $this->erm->get_payment_profile_id();
         $data['_epl_transaction_id'] = $charge->id;
         $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_stripe_response_data', $data);
         $this->erm->update_payment_data($data);
         return true;
     } catch (Stripe_CardError $e) {
         $body = $e->getJsonBody();
         $err = $body['error'];
         return '<div class="epl_error">Error: ' . $err['message'] . '</div>';
     }
 }
 function _exp_checkout_do_payment()
 {
     global $event_details;
     $event_id = $event_details['ID'];
     if (is_null($event_id)) {
         return false;
     }
     $regis_id = $this->erm->get_regis_id();
     $post_ID = $_SESSION['__epl']['post_ID'];
     $this->ecm->setup_event_details($event_id);
     $_totals = $this->erm->calculate_totals();
     $this->epl->load_file('libraries/gateways/paypal/paypal.php');
     $paypal = new EPL_Paypal();
     $requestParams = array('TOKEN' => $_GET['token'], 'PAYMENTACTION' => 'Sale', 'PAYERID' => $_GET['PayerID'], 'PAYMENTREQUEST_0_AMT' => $_totals['money_totals']['grand_total'], 'PAYMENTREQUEST_0_CURRENCYCODE' => epl_nz(epl_get_general_setting('epl_currency_code'), 'USD'));
     $response = $paypal->request('DoExpressCheckoutPayment', $requestParams);
     if (is_array($response) && $response['ACK'] == 'Success') {
         $data['post_ID'] = $post_ID;
         $data['_epl_regis_status'] = '5';
         $data['_epl_grand_total'] = $_totals['money_totals']['grand_total'];
         $data['_epl_payment_amount'] = $response['PAYMENTINFO_0_AMT'];
         $data['_epl_payment_date'] = current_time('mysql');
         $data['_epl_payment_method'] = '_pp_exp';
         $data['_epl_transaction_id'] = $response['PAYMENTINFO_0_TRANSACTIONID'];
         $data = apply_filters('epl_pp_exp_response_data', $data, $response);
         $this->erm->update_payment_data($data);
         return true;
         //echo "DONE";
     } else {
         //display error message
         return 'ERROR: ' . $response['L_SHORTMESSAGE0'] . '. ' . $response['L_LONGMESSAGE0'];
     }
 }
function epl_fc_date_format()
{
    $_format = epl_nz(epl_get_general_setting('epl_admin_date_format'), 'm/d/Y');
    $_format = str_replace(array('Y', 'm', 'd'), array('yyyy', 'MM', 'dd'), $_format);
    return $_format;
}
 function common_js_files()
 {
     global $epl_wp_localize_script_args;
     $_f = array('F', 'm', 'Y', 'j', 'l', 'd', 'S');
     $_r = array('MM', 'mm', 'yy', 'd', 'DD', 'dd', '');
     //$date_format_for_dp = (strpos('F', get_option( 'date_format' ) === false))?str_ireplace('Y','yy',get_option( 'date_format' )):'m/d/yy';
     $date_format_for_dp = str_replace($_f, $_r, epl_nz(epl_get_general_setting('epl_admin_date_format'), get_option('date_format')));
     wp_enqueue_script('jquery');
     wp_enqueue_script('jquery-migrate-js', "//code.jquery.com/jquery-migrate-1.2.1.min.js", array('jquery'));
     if (EPL_IS_ADMIN || epl_user_is_admin()) {
         wp_enqueue_script('select2', $this->epl->load_asset('js/select2.min.js'), array('jquery'));
     }
     wp_enqueue_script('events_planner_js', $this->epl->load_asset('js/events-planner.js'), array('jquery'));
     wp_enqueue_script('tipsy-js', EPL_FULL_URL . 'js/tipsy.js', array('jquery'));
     wp_enqueue_script('full-calendar-js', $this->epl->load_asset('js/fullcalendar.min.js'), array('jquery'));
     wp_enqueue_script('jquery-form-js', $this->epl->load_asset('js/jquery.validate.min.js'), array('jquery'));
     //wp_enqueue_script( 'datatables-js', epl_get_protocol() . '://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js' );
     wp_enqueue_script('datatables-js', $this->epl->load_asset('js/jquery.dataTables.min.js'), array('jquery'));
     $epl_wp_localize_script_args = array('ajaxurl' => admin_url('admin-ajax.php', epl_get_protocol()), 'plugin_url' => EPL_FULL_URL, 'date_format' => $date_format_for_dp, 'time_format' => get_option('time_format'), 'firstDay' => get_option('start_of_week'), 'yearRange' => 'c-10:c+10', 'sc' => epl_sc_is_enabled() ? 1 : 0, 'debug' => EPL_DEBUG ? 1 : 0, 'cart_added_btn_txt' => epl__('In the cart (View)'));
     $epl_wp_localize_script_args = apply_filters('epl_wp_localize_script_args', $epl_wp_localize_script_args);
     wp_localize_script('events_planner_js', 'EPL', $epl_wp_localize_script_args);
     do_action('epl_init_common_js_files', $this);
     return $this;
 }