summaryrefslogtreecommitdiff
path: root/includes/sys_page.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-06-20 16:50:21 +0200
committermsquare <msquare@notrademark.de>2017-06-20 16:50:21 +0200
commit56814fa2fdf58b4013f4d57c5ea87619c7122957 (patch)
tree640945769b7e9626cdf43162c786147f5c962029 /includes/sys_page.php
parenta5fc5bd0979e8de1fce8a8addd351a6e7bd6aeb8 (diff)
parentcd30017b97afc3c7001fbb9eb14b54dbb980b7b6 (diff)
Merge branch 'pr/316' into feature-igel-rewrite
Diffstat (limited to 'includes/sys_page.php')
-rw-r--r--includes/sys_page.php232
1 files changed, 124 insertions, 108 deletions
diff --git a/includes/sys_page.php b/includes/sys_page.php
index 82ce9896..b2199988 100644
--- a/includes/sys_page.php
+++ b/includes/sys_page.php
@@ -8,184 +8,200 @@ use Engelsystem\ValidationResult;
/**
* 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
+ * @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
+ * @return int|null
*/
-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);
+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
- * The date pattern (i.e. Y-m-d H:i)
- * @param string $value
- * The string to parse
- * @return The parsed unix timestamp
+ * @param string $pattern The date pattern (i.e. Y-m-d H:i)
+ * @param string $value The string to parse
+ * @return int|null The parsed unix timestamp
*/
-function parse_date($pattern, $value) {
- $datetime = DateTime::createFromFormat($pattern, trim($value));
- if ($datetime == null) {
- return null;
- }
- return $datetime->getTimestamp();
+function parse_date($pattern, $value)
+{
+ $datetime = DateTime::createFromFormat($pattern, trim($value));
+ if ($datetime == null) {
+ return null;
+ }
+ return $datetime->getTimestamp();
}
/**
* Leitet den Browser an die übergebene URL weiter und hält das Script an.
+ *
+ * @param string $url
*/
-function redirect($url) {
- header("Location: " . $url, true, 302);
- raw_output("");
+function redirect($url)
+{
+ header('Location: ' . $url, true, 302);
+ raw_output('');
}
/**
* Echoes given output and dies.
*
- * @param String $output
- * String to display
+ * @param String $output String to display
*/
-function raw_output($output) {
- echo $output;
- die();
+function raw_output($output = '')
+{
+ echo $output;
+ die();
}
/**
* Helper function for transforming list of entities into array for select boxes.
*
- * @param array $data
- * The data array
- * @param string $key_name
- * name of the column to use as id/key
- * @param string $value_name
- * name of the column to use as displayed value
+ * @param array $data The data array
+ * @param string $key_name name of the column to use as id/key
+ * @param string $value_name name of the column to use as displayed value
+ *
+ * @return array
*/
-function select_array($data, $key_name, $value_name) {
- $ret = [];
- foreach ($data as $value) {
- $ret[$value[$key_name]] = $value[$value_name];
- }
- return $ret;
+function select_array($data, $key_name, $value_name)
+{
+ $return = [];
+ foreach ($data as $value) {
+ $return[$value[$key_name]] = $value[$value_name];
+ }
+ return $return;
}
/**
* Returns an int[] from given request param name.
*
- * @param String $name
- * Name of the request param
- * @param array<int> $default
- * Default return value, if param is not set
+ * @param string $name Name of the request param
+ * @param array $default Default return value, if param is not set
+ * @return array
*/
-function check_request_int_array($name, $default = []) {
- if (isset($_REQUEST[$name]) && is_array($_REQUEST[$name])) {
- return array_filter($_REQUEST[$name], 'is_numeric');
- }
- return $default;
+function check_request_int_array($name, $default = [])
+{
+ if (isset($_REQUEST[$name]) && is_array($_REQUEST[$name])) {
+ return array_filter($_REQUEST[$name], 'is_numeric');
+ }
+ return $default;
}
/**
* Checks if given request item (name) can be parsed to a date.
* If not parsable, given error message is put into msg() and null is returned.
*
- * @param string $input
- * String to be parsed into a date.
- * @param string $error_message
- * the error message displayed if $input is not parsable
- * @param boolean $null_allowed
- * is a null value allowed?
+ * @param string $name to be parsed into a date.
+ * @param string $error_message the error message displayed if $input is not parsable
+ * @param boolean $null_allowed is a null value allowed?
* @return ValidationResult containing the parsed date
*/
-function check_request_date($name, $error_message = null, $null_allowed = false) {
- if (! isset($_REQUEST[$name])) {
- return new ValidationResult($null_allowed, null);
- }
- return check_date($_REQUEST[$name], $error_message, $null_allowed);
+function check_request_date($name, $error_message = null, $null_allowed = false)
+{
+ if (!isset($_REQUEST[$name])) {
+ return new ValidationResult($null_allowed, null);
+ }
+ return check_date($_REQUEST[$name], $error_message, $null_allowed);
}
/**
* Checks if given string can be parsed to a date.
* If not parsable, given error message is put into msg() and null is returned.
*
- * @param string $input
- * String to be parsed into a date.
- * @param string $error_message
- * the error message displayed if $input is not parsable
- * @param boolean $null_allowed
- * is a null value allowed?
+ * @param string $input String to be parsed into a date.
+ * @param string $error_message the error message displayed if $input is not parsable
+ * @param boolean $null_allowed is a null value allowed?
* @return ValidationResult containing the parsed date
*/
-function check_date($input, $error_message = null, $null_allowed = false) {
- if ($tmp = parse_date("Y-m-d H:i", trim($input) . " 00:00")) {
- return new ValidationResult(true, $tmp);
- }
- if ($null_allowed) {
- return new ValidationResult(true, null);
- }
-
- error($error_message);
- return new ValidationResult(false, null);
+function check_date($input, $error_message = null, $null_allowed = false)
+{
+ if ($tmp = parse_date('Y-m-d H:i', trim($input) . ' 00:00')) {
+ return new ValidationResult(true, $tmp);
+ }
+ if ($null_allowed) {
+ return new ValidationResult(true, null);
+ }
+
+ error($error_message);
+ return new ValidationResult(false, null);
}
/**
* Returns REQUEST value filtered or default value (null) if not set.
+ *
+ * @param string $name
+ * @param string $default_value
+ * @return mixed|null
*/
-function strip_request_item($name, $default_value = null) {
- if (isset($_REQUEST[$name])) {
- return strip_item($_REQUEST[$name]);
- }
- return $default_value;
+function strip_request_item($name, $default_value = null)
+{
+ if (isset($_REQUEST[$name])) {
+ return strip_item($_REQUEST[$name]);
+ }
+ return $default_value;
}
/**
* Testet, ob der angegebene REQUEST Wert ein Integer ist, bzw.
* eine ID sein könnte.
+ *
+ * @param string $name
+ * @return int|false
*/
-function test_request_int($name) {
- if (isset($_REQUEST[$name])) {
- return preg_match("/^[0-9]*$/", $_REQUEST[$name]);
- }
- return false;
+function test_request_int($name)
+{
+ if (isset($_REQUEST[$name])) {
+ return preg_match('/^\d*$/', $_REQUEST[$name]);
+ }
+ return false;
}
/**
* Gibt den gefilterten REQUEST Wert mit Zeilenumbrüchen zurück
+ *
+ * @param string $name
+ * @param mixed $default_value
+ * @return mixed
*/
-function strip_request_item_nl($name, $default_value = null) {
- if (isset($_REQUEST[$name])) {
- return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+\n]{1,})/ui", '', strip_tags($_REQUEST[$name]));
- }
- return $default_value;
+function strip_request_item_nl($name, $default_value = null)
+{
+ if (isset($_REQUEST[$name])) {
+ return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+\n]{1,})/ui", '', strip_tags($_REQUEST[$name]));
+ }
+ return $default_value;
}
/**
* Entfernt unerwünschte Zeichen
+ *
+ * @param string $item
+ * @return string
*/
-function strip_item($item) {
- return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+]{1,})/ui", '', strip_tags($item));
+function strip_item($item)
+{
+ return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+]{1,})/ui", '', strip_tags($item));
}
/**
* Überprüft eine E-Mail-Adresse.
+ *
+ * @param string $email
+ * @return bool
*/
-function check_email($email) {
- return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
+function check_email($email)
+{
+ return (bool)filter_var($email, FILTER_VALIDATE_EMAIL);
}
-
-?>