function capacity_table($table = true) { /* * if id exists, update meta * */ //epl_log( "debug", "<pre> META FOR DB " . print_r( $meta, true ) . "</pre>" ); //echo "<pre class='prettyprint'>CAPACITY PER" . print_r( $this->capacity_per(), true ) . "</pre>"; global $event_details, $capacity, $current_att_count, $multi_time, $multi_price, $available_space_arr; if ($this->mode == 'overview') { return null; } $tmpl = array('table_open' => '<table border="0" cellpadding="2" cellspacing="1" class="epl_avail_spaces_table">'); $this->epl_table->set_template($tmpl); $this->epl_table->set_heading('Date', '#'); $_table = ''; //get the attendee and money totals $_totals = $this->calculate_totals(); $grand_total = $_totals['money_totals']['grand_total']; $grand_total_key = "_grand_total"; $available_space_arr = array(); //$this->epl_table->set_heading( 'Available Spaces', '', '' ); switch ($this->capacity_per()) { case 'date': //per date //need the total attendees //need to apply the total attendees to every day. $qty_meta_key = "_total_att_" . $event_details['ID']; //$total_att = array_sum( ( array ) $meta[$this->regis_id]['_dates']['_att_quantity'][$event_details['ID']] ); $total_att = $_totals['_att_quantity']['total'][$event_details['ID']]; $dates = $event_details['_epl_start_date']; foreach ($dates as $_date_key => $_date_id) { $_date = $event_details['_epl_start_date'][$_date_key]; $_date = epl_dmy_convert($event_details['_epl_start_date'][$_date_key]); if (!epl_compare_dates(EPL_TIME, $_date, '>')) { $qty_meta_key = "_total_att_" . $event_details['ID'] . '_date_' . $_date_key; $cap = $capacity['date'][$_date_key]; $num_att = $current_att_count[$qty_meta_key]; $avail = $this->avail_spaces($cap, $num_att); if ($avail == 0) { $avail = epl__('Sold Out'); } $available_space_arr[$_date_key] = array($event_details['_epl_start_date'][$_date_key], $avail); } //$this->epl_table->add_row( '', $event_details['_epl_start_date'][$_date_key], $avail ); } break; } if ($table) { $data['available_spaces_table'] = $this->epl_table->generate($available_space_arr); $this->epl_table->clear(); return $this->epl->load_view('front/cart/cart-available-spaces', $data, true); } return $available_space_arr; }
function epl_is_ok_to_register($event_data, $current_key) { /* * the event is marked as open for registration * registration start date is <= today -done * registration end date is >= today * there are available spaces * */ global $event_details, $capacity, $current_att_count, $available_space_arr; $event_status = epl_get_element('_epl_event_status', $event_details); //echo "<pre class='prettyprint'>$current_key" . print_r( $current_att_count, true ) . "</pre>"; $today = date_i18n('Y-m-d H:i:s', EPL_TIME); $regis_start_date = epl_get_date_timestamp(epl_admin_dmy_convert(epl_get_element_m($current_key, '_epl_regis_start_date', $event_details, $today))); $regis_end_date = epl_get_date_timestamp(epl_admin_dmy_convert(epl_get_element_m($current_key, '_epl_regis_end_date', $event_details, $today))); $ok = epl_compare_dates($today, $regis_start_date, ">="); if (!$ok) { return epl__("Available for registration on") . ' ' . epl_formatted_date($event_details['_epl_regis_start_date'][$current_key]); } $ok = epl_compare_dates($today, strtotime('23:59:59', $regis_end_date), "<="); if (!$ok) { return epl__(' Registration Closed'); } $avail_spaces = 0; if (is_array($available_space_arr) && !epl_is_empty_array($available_space_arr)) { if (array_key_exists($current_key, $available_space_arr) && $available_space_arr[$current_key][1]) { $avail_spaces = $available_space_arr[$current_key][1]; $ok = is_numeric($avail_spaces); } } if (!$ok) { return epl__('Sold Out'); } return true; }
/** * 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 epl_is_ok_to_register($event_data, $current_key) { global $event_details; /* * the event is marked as open for registration * registration start date is <= today -done * registration end date is >= today * there are available spaces * */ global $event_details, $capacity, $current_att_count, $available_space_arr; //echo "<pre class='prettyprint'>$current_key" . print_r( $current_att_count, true ) . "</pre>"; $today = date('m/d/Y H:i:s', EPL_TIME); $regis_start_date = $event_details['_epl_regis_start_date'][$current_key]; $regis_end_date = $event_details['_epl_regis_end_date'][$current_key]; $regis_start_date = epl_dmy_convert($regis_start_date); $regis_end_date = epl_dmy_convert($regis_end_date); $ok = epl_compare_dates($today, $regis_start_date, ">="); if (!$ok) { return epl__("Available for registration on ") . $event_details['_epl_regis_start_date'][$current_key]; } $ok = epl_compare_dates($today, $regis_end_date, "<="); if (!$ok) { return epl__(' Registration Closed'); } $avail_spaces = 0; if (is_array($available_space_arr) && !empty($available_space_arr)) { if (array_key_exists($current_key, $available_space_arr) && $available_space_arr[$current_key][1]) { $avail_spaces = $available_space_arr[$current_key][1]; $ok = is_numeric($avail_spaces); } } if (!$ok) { return epl__('Sold Out'); } /* $erm = EPL_Base::get_instance()->load_model( 'EPL_registration_model' ); $totals = $erm->calculate_totals(); echo "<pre class='prettyprint'>" . print_r( $totals, true ) . "</pre>"; if ( is_array( $totals ) && !empty( $totals ) ) { $total_att = $_totals['_att_quantity']['total'][$event_details['ID']]; if ( $total_att > $avail_spaces ) { return epl__('Sorry, the number of attendees selected exceeds number of avaialable spaces. Available spaces:' . $avail_spaces); } } */ return true; }
function epl_get_regis_status($date_key = null) { global $event_details, $capacity, $current_att_count, $available_space_arr; $today = date_i18n('m/d/Y H:i:s', EPL_TIME); $regis_start_date = epl_get_date_timestamp(epl_admin_dmy_convert(epl_get_element($date_key, $event_details['_epl_regis_start_date'], $today))); $regis_end_date = epl_get_date_timestamp(epl_admin_dmy_convert(epl_get_element($date_key, $event_details['_epl_regis_end_date'], $today))); $ok = epl_compare_dates($today, $regis_start_date, ">="); if (!$ok) { return epl__("Opens on") . ' ' . epl_formatted_date($event_details['_epl_regis_start_date'][$date_key]); } $ok = epl_compare_dates($today, strtotime('23:59:59', $regis_end_date), "<="); if (!$ok) { return epl__('Closed'); } return epl__('Open'); }
$go = true; if ($_from_date && epl_compare_dates($date, $_from_date, '<')) { $go = false; } if ($_to_date && epl_compare_dates($date, $_to_date, '>')) { $go = false; } if (!$go) { continue; } foreach ($event_details['_epl_start_time'] as $time_id => $time) { if (epl_is_date_level_time() && !epl_is_empty_array($date_specifc_time) && (!isset($date_specifc_time[$time_id]) || !isset($date_specifc_time[$time_id][$date_id]))) { continue; } $regis_end_time = epl_get_element_m($time_id, '_epl_regis_endtime', $event_details, null); if ($regis_end_time && epl_compare_dates(strtotime($regis_end_time, $date), EPL_TIME, '<')) { continue; } $register_button = get_the_register_button(null, false, $register_button_url + array('_time_id' => $time_id)); $event_link = ''; if (isset($event_details['_epl_link']) && $event_details['_epl_link'] != '') { $event_link = epl_anchor($event_details['_epl_link'], 'Learn More', '_self', 'class="event_link"') . ' ' . $register_button; } else { $event_link = $register_button; } //removed per Jessi //if (!$regis_end_time && epl_compare_dates( strtotime($time, $date), EPL_TIME, '<' )) //continue; $event_id = get_the_ID(); $event_excerpt = get_the_excerpt(); $event_tooltip = '';
function is_code_expired($_code) { global $event_details; $_code_expiration_date = epl_get_element($_code, epl_get_element('_epl_discount_end_date', $this->discount_configs), null); if (!$_code_expiration_date) { return false; } $_code_expiration_date = epl_formatted_date($_code_expiration_date, 'Y-m-d', 'date'); $_expired = epl_compare_dates(EPL_TIME, $_code_expiration_date . ' 23:59:59', ">"); if ($_expired) { return true; } return false; }