diff options
author | msquare <msquare@notrademark.de> | 2016-09-27 17:59:28 +0200 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2016-09-27 17:59:28 +0200 |
commit | 5957e05bf13ec9659f52a3c613abac09cacab8c6 (patch) | |
tree | 4c926f5f2497c5955ad03594b0ee907652c1a51e /includes | |
parent | 031fc3057c46245cd62fc39f2d11ee3f0a393e06 (diff) |
finished rename settings to event config and added more date validation for event config
Diffstat (limited to 'includes')
-rw-r--r-- | includes/controller/event_config_controller.php | 45 | ||||
-rw-r--r-- | includes/engelsystem_provider.php | 1 | ||||
-rw-r--r-- | includes/model/EventConfig_model.php | 14 | ||||
-rw-r--r-- | includes/sys_page.php | 2 | ||||
-rw-r--r-- | includes/view/EventConfig_view.php (renamed from includes/view/EventConfigView.php) | 2 |
5 files changed, 44 insertions, 20 deletions
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 @@ <?php /** - * Get settings. + * Get event config. */ function EventConfig() { - $settings = sql_select("SELECT * FROM `EventConfig` LIMIT 1"); - if ($settings === false) + $event_config = sql_select("SELECT * FROM `EventConfig` LIMIT 1"); + if ($event_config === false) return false; - if (count($settings) > 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/EventConfig_view.php index a00a26ed..f6e20508 100644 --- a/includes/view/EventConfigView.php +++ b/includes/view/EventConfig_view.php @@ -10,7 +10,7 @@ * @param date $teardown_end_date */ function EventConfig_edit_view($event_name, $event_welcome_msg, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date) { - return page_with_title(admin_settings_title(), [ + return page_with_title(event_config_title(), [ msg(), form([ div('row', [ |