/** * Returns an array of days in a certain week * * When a date is passed to the function, the weekday number of that day is calculated. * Then, looping from 0-6 (Sun - Sat), the dates of that week are calculated. * * @since 1.0.0 * @param date $date Ex. 2011-01-01 * @param date $startdate If passed, will only return dates after that day. Ex. 2011-01-01 * @param array $weekdays From the recurrence form, the checkboxes corresponding to the weekdays. * @return string */ function get_days_of_a_week($date, $start_date = 0, $end_date = 0, $weekdays = array()) { $date = strtotime(epl_dmy_convert($date)); $start_date = strtotime(epl_dmy_convert($start_date)); $end_date = strtotime(epl_dmy_convert($end_date)); //usingn this method instead of date("W") since the latter method uses Monday as start of week $year = date("Y", $date); $jan1 = gmmktime(0, 0, 0, 1, 1, $year); $mydate = gmmktime(0, 0, 0, 11, 30, $year); $week_number = (int) (($date - $jan1) / (7 * 24 * 60 * 60)) + 1; // below, in the loop, for $n_d, the week number that is below 10 needs to be represented in 0# format if ($week_number < 10) { $week_number = "0" . $week_number; } //$week_number = date( "W", $date ); //Note that this number is derived with Monday as start of the week $_d = array(); for ($day = 0; $day <= 6; $day++) { $n_d = strtotime($year . "W" . $week_number . $day); $newdate_year = date("Y", $n_d); $newdate_month = date("n", $n_d); $j = date("j", $n_d); //day 1-31 $w = date("w", $n_d); //day of the week 0-6 if ($n_d >= $start_date && $n_d <= $end_date && in_array($w, $weekdays)) { $this->dates[$newdate_year][$newdate_month][$j] = date('Y-m-d', $n_d); } else { unset($this->dates[$newdate_year][$newdate_month][$j]); } } }
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 construct_date_display_table($args) { extract($args); global $event_details; $tmpl = array('table_open' => '<table cellpadding="0" cellspacing="0" class="event_dates_table">'); $this->epl->epl_table->set_template($tmpl); //$this->epl->epl_table->set_heading( epl__( 'Start Date' ), epl__( 'End Date' ), '' ); foreach ($meta['_epl_start_date'] as $key => $date) { $end_date = $meta['_epl_end_date'][$key]; $date = epl_dmy_convert($date); $end_date = epl_dmy_convert($end_date); if (strtotime($date) >= strtotime(date("Y-m-d"))) { $t_row = array(date(get_option('date_format'), strtotime($date)), ' ' . epl__('to') . ' ', date(get_option('date_format'), strtotime($end_date))); if ($date == $end_date) { unset($t_row[1]); unset($t_row[2]); } $this->epl->epl_table->add_row($t_row); } } $r = $this->epl->epl_table->generate(); $this->epl->epl_table->clear(); return $r; }
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 get_the_regis_payment_date() { global $regis_details, $event_details; if ($regis_details['_epl_payment_date'] != '') { return date_i18n(get_option('date_format'), strtotime(epl_dmy_convert($regis_details['_epl_payment_date']))); } return ''; }