Closed (fixed)
Project:
Event
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
4 Feb 2007 at 21:54 UTC
Updated:
21 May 2008 at 21:34 UTC
Hi,
I've just added a couple of lines of code in order to verify that the event has valid dates (in the original version you can enter 35 January and it gets transformed to 4 of February).
This is the reworked event_validate_form_date
/**
* Validates the start and end times in a node form submission.
* - Changes 24 hour time to 12 hour time (if the module is configured to do this).
* - Adjusts times for time zone offsets.
*
* @ingroup event_support
* @param $node The submitted node with form data.
* @param $date The name of the event's date ('start' or 'end') to validate and set.
*/
function event_validate_form_date(&$node, $date) {
$prefix = $date .'_';
/**
* If using javascript pop-up calendar, convert input date back to individual date parts expected by the validator
*/
if (module_exists('jscalendar')) {
$get = $prefix . 'date';
$this_date = $node->$get;
$timestamp = mktime(substr($this_date, 11, 2), substr($this_date, 14, 2), substr($this_date, 17, 2), substr($this_date, 5, 2), substr($this_date, 8, 2), substr($this_date, 0, 4));
$node->{$prefix . 'year'} = date('Y', $timestamp);
$node->{$prefix . 'month'} = date('n', $timestamp);
$node->{$prefix . 'day'} = date('d', $timestamp);
$node->{$prefix . 'hour'} = variable_get('event_ampm', '0') ? date('H', $timestamp) : date('g', $timestamp);
$node->{$prefix . 'minute'} = date('i', $timestamp);
}
// If we have all the parameters, re-calculate $node->event_$date .
if (isset($node->{$prefix . 'year'}) && isset($node->{$prefix . 'month'}) && isset($node->{$prefix . 'day'}) && isset($node->{$prefix . 'hour'}) && isset($node->{$prefix . 'minute'})) {
$hour = $node->{$prefix . 'hour'};
if (variable_get('event_ampm', '0')) {
if (($node->{$prefix . 'ampm'} == 'pm') && ($hour != 12)) {
$hour += 12;
}
elseif (($node->{$prefix . 'ampm'} == 'am') && ($hour == 12)) {
$hour -= 12;
}
}
if (!checkdate($node->{$prefix . 'month'},$node->{$prefix . 'day'},$node->{$prefix . 'year'}))
{
form_set_error($prefix.'date', t($prefix.'date is invalid, please check.'));
}
// translate the input values to GMT and set the node property value
$offset = event_get_offset($node->timezone, gmmktime($hour, $node->{$prefix . 'minute'}, 0, $node->{$prefix . 'month'}, $node->{$prefix . 'day'}, $node->{$prefix . 'year'}));
$node->{'event_'. $date} = _event_mktime($hour, $node->{$prefix . 'minute'}, 0, $node->{$prefix . 'month'}, $node->{$prefix . 'day'}, $node->{$prefix . 'year'}, $offset);
}
elseif (!$node->$date) {
// Round to nearest hour:
$now = _event_user_time();
$node->$date = $now - ($now % (60 * 60));
}
}
Comments
Comment #1
killes@www.drop.org commentednot a patch
Comment #2
killes@www.drop.org commentedSuch checking is now in place.
Comment #3
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.