finished rename settings to event config and added more date validation for event config

main
msquare 8 years ago
parent 031fc3057c
commit 5957e05bf1

@ -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'));
}
}

@ -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');

@ -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) . ",

@ -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);

@ -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', [
Loading…
Cancel
Save