summaryrefslogtreecommitdiff
path: root/includes/sys_page.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2016-10-04 18:52:52 +0200
committermsquare <msquare@notrademark.de>2016-10-04 18:52:52 +0200
commita50b26490cf3c76d6dae293cb34b4cbff01133b6 (patch)
treec2c21eb042aa4c61d96cc439957a0137f8319372 /includes/sys_page.php
parentaa628208ec6b4f484b37df44b3126fb28ab3f68e (diff)
reduce complexity of shiftsfilter update
Diffstat (limited to 'includes/sys_page.php')
-rw-r--r--includes/sys_page.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/includes/sys_page.php b/includes/sys_page.php
index f20a791c..3c548bab 100644
--- a/includes/sys_page.php
+++ b/includes/sys_page.php
@@ -5,6 +5,32 @@
*/
/**
+ * Parse a date from da day and a time textfield.
+ *
+ * @param string $date_name
+ * Name of the textfield containing the day (format Y-m-d)
+ * @param string $time_name
+ * Name of the textfield containing the time (format H:i)
+ * @param string[] $allowed_days
+ * List of allowed days in format Y-m-d
+ * @param int $default_value
+ * Default value unix timestamp
+ */
+function check_request_datetime($date_name, $time_name, $allowed_days, $default_value) {
+ $time = date("H:i", $default_value);
+ $day = date("Y-m-d", $default_value);
+
+ if (isset($_REQUEST[$time_name]) && preg_match('#^\d{1,2}:\d\d$#', trim($_REQUEST[$time_name]))) {
+ $time = trim($_REQUEST[$time_name]);
+ }
+ if (isset($_REQUEST[$date_name]) && in_array($_REQUEST[$date_name], $allowed_days)) {
+ $day = $_REQUEST[$date_name];
+ }
+
+ return parse_date("Y-m-d H:i", $day . " " . $time);
+}
+
+/**
* Parse a date into unix timestamp
*
* @param string $pattern