function find_errors($values = array()) { if (empty($values) && !empty($this->disco_form)) { $values = $this->disco_form->get_values(); } if (empty($values)) { $values = $this->get_event_values(); } if (empty($values)) { trigger_error('Programmer error: no event values available for reasonEvent::find_errors()'); } static $required_fields = array('name', 'datetime', 'recurrence', 'show_hide'); $errors = array(); foreach ($required_fields as $field) { if (empty($values[$field])) { $errors[$field][] = 'The ' . $field . ' field is required.'; } } if (empty($errors)) { if ($values['recurrence'] != 'none') { if (empty($values['frequency'])) { static $repeat_vals = array('daily' => 'day', 'weekly' => 'week', 'monthly' => 'month', 'yearly' => 'year'); $errors['frequency'][] = 'How often should this event repeat? If it repeats every ' . $repeat_vals[$values['recurrence']] . ', enter a 1.'; } if (empty($values['term_only'])) { $errors['term_only'][] = 'Please indicate whether this event should occur only while classes are in session.'; } } $d = parse_mysql_date($values['datetime']); if ($values['recurrence'] == 'weekly') { // there must be at least 1 day of the week the event recurs on static $days = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); foreach ($days as $day) { if (!empty($values[$day])) { $day_set = true; break; } } if (empty($day_set)) { $errors['sunday'][] = 'Please enter which day(s) of the week this event will occur.'; } // the date of the event must be on one of those days of the week $day_o_week = carl_date('l', $d['timestamp']); if (empty($values[strtolower($day_o_week)])) { $errors['sunday'][] = 'This event starts on a ' . $day_o_week . ', which is not one of the repeating days of week provided.'; } } elseif ($values['recurrence'] == 'monthly') { // don't allow repetition on days that don't occur in every month if ($d['day'] > 28) { $errors['datetime'][] = 'Dates after the 28th do not occur in all months, so they are not available for monthly repeats.'; } } elseif ($values['recurrence'] == 'yearly') { if ($d['month'] == 2 and $d['day'] == 29) { $errors['datetime'][] = 'February 29th only occurs on leap-years, so it is not an acceptable date for yearly repeating events.'; } } } if (!empty($this->disco_form)) { foreach ($errors as $field => $errs) { foreach ($errs as $err_txt) { $this->disco_form->set_error($field, $err_txt); } } } return $errors; }
function set_values($values) { $this->dates = array(); if (!empty($values['frequency'])) { $this->frequency = $values['frequency']; } else { $this->frequency = 1; } if (!empty($values['recurrence'])) { $this->recurrence = $values['recurrence']; } else { $this->recurrence = 'none'; } if (!empty($values['monthly_repeat'])) { $this->monthly_repeat = $values['monthly_repeat']; } else { $this->monthly_repeat = 'numeric'; } if (!empty($values['datetime'])) { $this->datetime = $values['datetime']; $s = parse_mysql_date($this->datetime); $this->ystart = $s['year']; $this->mstart = $s['month']; $this->dstart = $s['day']; $this->ustart = $s['timestamp']; } else { trigger_error('A datetime value must be given in reasonEventRepeater::set_values()'); return false; } if (!empty($values['end_date']) && $values['end_date'] != '0000-00-00 00:00:00') { $end_date = $values['end_date']; } else { $end_year = max(carl_date('Y'), $this->ystart) + $this->years_out; $end_date = $end_year . '-' . $this->mstart . '-' . $this->dstart; } $e = parse_mysql_date($end_date); if (!empty($e)) { $this->end_date = $end_date; $this->yend = $e['year']; $this->mend = $e['month']; $this->dend = $e['day']; $this->uend = $e['timestamp']; } else { trigger_error('Problem determining end date'); return false; } if (!empty($values['month_day_of_week']) && !empty($values['week_of_month'])) { $this->month_day_of_week = $values['month_day_of_week']; $this->week_of_month = $values['week_of_month']; } elseif ($this->recurrence == 'monthly' and $this->monthly_repeat == 'semantic') { $this->month_day_of_week = carl_date('l', $this->ustart); $this->week_of_month = floor($this->dstart / 7) + 1; } else { $this->month_day_of_week = ''; $this->week_of_month = ''; } if (!empty($values['month_day_of_week']) && $values['month_day_of_week'] != $this->month_day_of_week) { trigger_error('Month day of week mismatch'); } if (!empty($values['week_of_month']) && $values['week_of_month'] != $this->week_of_month) { trigger_error('Week of month mismatch'); } $this->days_of_week = array(); if (!empty($values['sunday'])) { $this->days_of_week[] = 'Sunday'; } if (!empty($values['monday'])) { $this->days_of_week[] = 'Monday'; } if (!empty($values['tuesday'])) { $this->days_of_week[] = 'Tuesday'; } if (!empty($values['wednesday'])) { $this->days_of_week[] = 'Wednesday'; } if (!empty($values['thursday'])) { $this->days_of_week[] = 'Thursday'; } if (!empty($values['friday'])) { $this->days_of_week[] = 'Friday'; } if (!empty($values['saturday'])) { $this->days_of_week[] = 'Saturday'; } }