From 5957e05bf13ec9659f52a3c613abac09cacab8c6 Mon Sep 17 00:00:00 2001 From: msquare Date: Tue, 27 Sep 2016 17:59:28 +0200 Subject: finished rename settings to event config and added more date validation for event config --- includes/controller/event_config_controller.php | 45 +++++++++++++++++++------ includes/engelsystem_provider.php | 1 - includes/model/EventConfig_model.php | 14 ++++---- includes/sys_page.php | 2 +- includes/view/EventConfigView.php | 41 ---------------------- includes/view/EventConfig_view.php | 41 ++++++++++++++++++++++ 6 files changed, 84 insertions(+), 60 deletions(-) delete mode 100644 includes/view/EventConfigView.php create mode 100644 includes/view/EventConfig_view.php diff --git a/includes/controller/event_config_controller.php b/includes/controller/event_config_controller.php index 7e951214..f4564c18 100644 --- a/includes/controller/event_config_controller.php +++ b/includes/controller/event_config_controller.php @@ -17,16 +17,16 @@ function event_config_edit_controller() { $event_end_date = null; $teardown_end_date = null; - $settings_source = EventConfig(); - if ($settings_source === false) + $event_config = EventConfig(); + if ($event_config === false) engelsystem_error('Unable to load event config.'); - if ($settings_source != null) { - $event_name = $settings_source['event_name']; - $buildup_start_date = $settings_source['buildup_start_date']; - $event_start_date = $settings_source['event_start_date']; - $event_end_date = $settings_source['event_end_date']; - $teardown_end_date = $settings_source['teardown_end_date']; - $event_welcome_msg = $settings_source['event_welcome_msg']; + if ($event_config != null) { + $event_name = $event_config['event_name']; + $buildup_start_date = $event_config['buildup_start_date']; + $event_start_date = $event_config['event_start_date']; + $event_end_date = $event_config['event_end_date']; + $teardown_end_date = $event_config['teardown_end_date']; + $event_welcome_msg = $event_config['event_welcome_msg']; } if (isset($_REQUEST['submit'])) { @@ -58,6 +58,31 @@ function event_config_edit_controller() { $teardown_end_date = $result->getValue(); $ok &= $result->isOk(); + if ($buildup_start_date != null && $event_start_date != null && $buildup_start_date > $event_start_date) { + $ok = false; + error(_("The buildup start date has to be before the event start date.")); + } + + if ($event_start_date != null && $event_end_date != null && $event_start_date > $event_end_date) { + $ok = false; + error(_("The event start date has to be before the event end date.")); + } + + if ($event_end_date != null && $teardown_end_date != null && $event_end_date > $teardown_end_date) { + $ok = false; + error(_("The event end date has to be before the teardown end date.")); + } + + if ($event_start_date != null && $event_end_date != null && $event_start_date > $event_end_date) { + $ok = false; + error(_("The event start date has to be before the event end date.")); + } + + if ($buildup_start_date != null && $teardown_end_date != null && $buildup_start_date > $teardown_end_date) { + $ok = false; + error(_("The buildup start date has to be before the teardown end date.")); + } + if ($ok) { $result = EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg); @@ -66,7 +91,7 @@ function event_config_edit_controller() { engelsystem_log("Changed event config: $event_name, $event_welcome_msg, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date"); success(_("Settings saved.")); - redirect(page_link_to('admin_settings')); + redirect(page_link_to('admin_event_config')); } } diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php index 5e293366..d0f1cbff 100644 --- a/includes/engelsystem_provider.php +++ b/includes/engelsystem_provider.php @@ -79,7 +79,6 @@ require_once realpath(__DIR__ . '/../includes/pages/user_news.php'); require_once realpath(__DIR__ . '/../includes/pages/user_questions.php'); require_once realpath(__DIR__ . '/../includes/pages/user_settings.php'); require_once realpath(__DIR__ . '/../includes/pages/user_shifts.php'); -require_once realpath(__DIR__ . '/../includes/pages/admin_settings.php'); require_once realpath(__DIR__ . '/../vendor/parsedown/Parsedown.php'); diff --git a/includes/model/EventConfig_model.php b/includes/model/EventConfig_model.php index 57ba1d0f..0529c286 100644 --- a/includes/model/EventConfig_model.php +++ b/includes/model/EventConfig_model.php @@ -1,19 +1,19 @@ 0) - return $settings[0]; + if (count($event_config) > 0) + return $event_config[0]; return null; } /** - * Update Settings. + * Update event config. * * @param string $event_name * @param int $buildup_start_date @@ -23,7 +23,7 @@ function EventConfig() { * @param string $event_welcome_msg */ function EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg) { - if (Settings() == null) { + if (EventConfig() == null) { return sql_query("INSERT INTO `EventConfig` SET `event_name`=" . sql_null($event_name) . ", `buildup_start_date`=" . sql_null($buildup_start_date) . ", diff --git a/includes/sys_page.php b/includes/sys_page.php index 67da83c7..cbc18db8 100644 --- a/includes/sys_page.php +++ b/includes/sys_page.php @@ -50,7 +50,7 @@ function check_request_date($name, $error_message = null, $null_allowed = false) */ function check_date($input, $error_message = null, $null_allowed = false) { if (DateTime::createFromFormat("Y-m-d", trim($input))) - return new ValidationResult(true, DateTime::createFromFormat("Y-m-d", trim($input))); + return new ValidationResult(true, DateTime::createFromFormat("Y-m-d", trim($input))->getTimestamp()); if ($null_allowed) return new ValidationResult(true, null); diff --git a/includes/view/EventConfigView.php b/includes/view/EventConfigView.php deleted file mode 100644 index a00a26ed..00000000 --- a/includes/view/EventConfigView.php +++ /dev/null @@ -1,41 +0,0 @@ - \ No newline at end of file diff --git a/includes/view/EventConfig_view.php b/includes/view/EventConfig_view.php new file mode 100644 index 00000000..f6e20508 --- /dev/null +++ b/includes/view/EventConfig_view.php @@ -0,0 +1,41 @@ + \ No newline at end of file -- cgit v1.2.3-70-g09d2