diff --git a/scheduler.module b/scheduler.module index 48b22d1..08322c9 100644 --- a/scheduler.module +++ b/scheduler.module @@ -1,6 +1,8 @@ t("If the Date module's Date Popup module is enabled you may use the popup calendar for your field type."), ); + + // Textfield for setting default time + $form['scheduler_time_default'] = array( + '#type' => 'textfield', + '#title' => t('Default time'), + '#default_value' => variable_get('scheduler_time_default', SCHEDULER_TIME_DEFAULT), + '#size' => 20, + '#maxlength' => 20, + '#description' => t('This is the default time to use on all scheduler inputs if no time is entered. This must be in a H:i:s format.'), + ); if (!module_exists('date_popup')) { $form['scheduler_field_type']['#default_value'] = 'textfield'; @@ -179,6 +191,11 @@ function scheduler_admin_validate($form, &$form_state) { if (!in_array($time_format, $acceptable)) { form_set_error('scheduler_date_format', t('The Date Popup module only accepts the following formats: !formats', array('!formats' => implode($acceptable, ', ')))); } + + //Check if a valid time was entered. + if(!preg_match('/^[0-2][0-9]:[0-5][0-9]:[0-5][0-9]$/', $form_state['values']['scheduler_time_default'])){ + form_set_error('scheduler_time_default', t('A valid time if the format of 00:00:00 is required')); + } } } @@ -316,6 +333,7 @@ function scheduler_form_alter(&$form, $form_state) { $form['scheduler_settings'] = array( '#type' => 'fieldset', '#title' => t('Scheduling options'), + '#description' => t('Leave time blank to use default time of !time', array('!time' => variable_get('scheduler_time_default', SCHEDULER_TIME_DEFAULT))), '#collapsible' => TRUE, '#collapsed' => !$fieldset_extended, '#weight' => 35, @@ -1016,3 +1034,12 @@ function scheduler_set_target($source, $node, $target, $value) { } } } + +/** + * Function to set default time to if no time entered. + */ +function scheduler_date_popup_pre_validate_alter($element, $form_state, &$input) { + if ($element['#array_parents'][0] == 'scheduler_settings' && $input['date'] != '' && $input['time'] == '') { + $input['time'] = variable_get('scheduler_time_default', SCHEDULER_TIME_DEFAULT); + } +}