From 07a1ad8c584b310c73798a8a59a3d207075dbc82 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Sun, 15 May 2022 10:07:25 +0200 Subject: [PATCH] add date/datetime input fields to relevant formfields Signed-off-by: Michael Kaufmann --- lib/Froxlor/Ajax/Ajax.php | 11 +++++++---- lib/Froxlor/Api/Commands/Domains.php | 8 ++++---- lib/Froxlor/Validate/Validate.php | 2 ++ .../admin/domains/formfield.domains_add.php | 7 ++++--- .../admin/domains/formfield.domains_edit.php | 7 ++++--- lib/formfields/formfield.api_key.php | 5 ++--- lng/de.lng.php | 4 ++-- lng/en.lng.php | 2 +- templates/Froxlor/form/formfields.html.twig | 2 +- 9 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lib/Froxlor/Ajax/Ajax.php b/lib/Froxlor/Ajax/Ajax.php index d6f8b3ab..4fa57aee 100644 --- a/lib/Froxlor/Ajax/Ajax.php +++ b/lib/Froxlor/Ajax/Ajax.php @@ -26,6 +26,7 @@ namespace Froxlor\Ajax; use Exception; +use DateTime; use Froxlor\Config\ConfigDisplay; use Froxlor\Config\ConfigParser; use Froxlor\CurrentUser; @@ -233,7 +234,7 @@ class Ajax { $keyid = isset($_POST['id']) ? (int)$_POST['id'] : 0; $allowed_from = isset($_POST['allowed_from']) ? $_POST['allowed_from'] : ""; - $valid_until = isset($_POST['valid_until']) ? (int)$_POST['valid_until'] : -1; + $valid_until = isset($_POST['valid_until']) ? $_POST['valid_until'] : ""; // validate allowed_from if (!empty($allowed_from)) { @@ -260,8 +261,10 @@ class Ajax $allowed_from = implode(",", array_unique($ip_list)); } - if ($valid_until <= 0 || !is_numeric($valid_until)) { - $valid_until = -1; + if (!empty($valid_until)) { + $valid_until_db = DateTime::createFromFormat('Y-m-d\TH:i', $valid_until)->format('U'); + } else { + $valid_until_db = -1; } $upd_stmt = Database::prepare(" @@ -277,7 +280,7 @@ class Ajax Database::pexecute($upd_stmt, [ 'keyid' => $keyid, 'af' => $allowed_from, - 'vu' => $valid_until, + 'vu' => $valid_until_db, 'aid' => $this->userinfo['adminid'], 'cid' => $cid ]); diff --git a/lib/Froxlor/Api/Commands/Domains.php b/lib/Froxlor/Api/Commands/Domains.php index 87a1d302..3aa08bb8 100644 --- a/lib/Froxlor/Api/Commands/Domains.php +++ b/lib/Froxlor/Api/Commands/Domains.php @@ -403,7 +403,7 @@ class Domains extends ApiCommand implements ResourceEntity $documentroot = $_documentroot; } - $registration_date = Validate::validate($registration_date, 'registration_date', '/^(19|20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/', '', [ + $registration_date = Validate::validate($registration_date, 'registration_date', Validate::REGEX_YYYY_MM_DD, '', [ '0000-00-00', '0', '' @@ -412,7 +412,7 @@ class Domains extends ApiCommand implements ResourceEntity $registration_date = null; } - $termination_date = Validate::validate($termination_date, 'termination_date', '/^(19|20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/', '', [ + $termination_date = Validate::validate($termination_date, 'termination_date', Validate::REGEX_YYYY_MM_DD, '', [ '0000-00-00', '0', '' @@ -1291,7 +1291,7 @@ class Domains extends ApiCommand implements ResourceEntity $adminid = $result['adminid']; } - $registration_date = Validate::validate($registration_date, 'registration_date', '/^(19|20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/', '', [ + $registration_date = Validate::validate($registration_date, 'registration_date', Validate::REGEX_YYYY_MM_DD, '', [ '0000-00-00', '0', '' @@ -1299,7 +1299,7 @@ class Domains extends ApiCommand implements ResourceEntity if ($registration_date == '0000-00-00' || empty($registration_date)) { $registration_date = null; } - $termination_date = Validate::validate($termination_date, 'termination_date', '/^(19|20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/', '', [ + $termination_date = Validate::validate($termination_date, 'termination_date', Validate::REGEX_YYYY_MM_DD, '', [ '0000-00-00', '0', '' diff --git a/lib/Froxlor/Validate/Validate.php b/lib/Froxlor/Validate/Validate.php index bd0fc555..dc0a44e6 100644 --- a/lib/Froxlor/Validate/Validate.php +++ b/lib/Froxlor/Validate/Validate.php @@ -43,6 +43,8 @@ class Validate const REGEX_DESC_TEXT = '/^[^\0\r\n<>]*$/'; + const REGEX_YYYY_MM_DD = '/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/'; + /** * Validates the given string by matching against the pattern, prints an error on failure and exits * diff --git a/lib/formfields/admin/domains/formfield.domains_add.php b/lib/formfields/admin/domains/formfield.domains_add.php index ac20fb70..37cfc39e 100644 --- a/lib/formfields/admin/domains/formfield.domains_add.php +++ b/lib/formfields/admin/domains/formfield.domains_add.php @@ -75,19 +75,20 @@ return [ 'add_date' => [ 'label' => lng('domains.add_date'), 'desc' => lng('panel.dateformat'), - 'type' => 'label', + 'type' => 'date', + 'readonly' => true, 'value' => date('Y-m-d') ], 'registration_date' => [ 'label' => lng('domains.registration_date'), 'desc' => lng('panel.dateformat'), - 'type' => 'text', + 'type' => 'date', 'size' => 10 ], 'termination_date' => [ 'label' => lng('domains.termination_date'), 'desc' => lng('panel.dateformat'), - 'type' => 'text', + 'type' => 'date', 'size' => 10 ] ] diff --git a/lib/formfields/admin/domains/formfield.domains_edit.php b/lib/formfields/admin/domains/formfield.domains_edit.php index 5a93987c..ea1c72bc 100644 --- a/lib/formfields/admin/domains/formfield.domains_edit.php +++ b/lib/formfields/admin/domains/formfield.domains_edit.php @@ -86,20 +86,21 @@ return [ 'add_date' => [ 'label' => lng('domains.add_date'), 'desc' => lng('panel.dateformat'), - 'type' => 'label', + 'type' => 'date', + 'readonly' => true, 'value' => date('Y-m-d', (int)$result['add_date']) ], 'registration_date' => [ 'label' => lng('domains.registration_date'), 'desc' => lng('panel.dateformat'), - 'type' => 'text', + 'type' => 'date', 'value' => $result['registration_date'], 'size' => 10 ], 'termination_date' => [ 'label' => lng('domains.termination_date'), 'desc' => lng('panel.dateformat'), - 'type' => 'text', + 'type' => 'date', 'value' => $result['termination_date'], 'size' => 10 ] diff --git a/lib/formfields/formfield.api_key.php b/lib/formfields/formfield.api_key.php index 63d5ee72..ec7bfe31 100644 --- a/lib/formfields/formfield.api_key.php +++ b/lib/formfields/formfield.api_key.php @@ -58,9 +58,8 @@ return [ 'title' => lng('apikeys.valid_until'), 'description' => lng('apikeys.valid_until_help') ], - /** @TODO datetime-picker */ - 'type' => 'text', - 'value' => $result['valid_until'] < 0 ? "" : $result['valid_until'] + 'type' => 'datetime-local', + 'value' => $result['valid_until'] < 0 ? "" : date('Y-m-d\TH:i', $result['valid_until']) ] ] ] diff --git a/lng/de.lng.php b/lng/de.lng.php index a2004b9d..c037fd10 100644 --- a/lng/de.lng.php +++ b/lng/de.lng.php @@ -465,7 +465,7 @@ return [ 'allowed_from' => 'Erlaube Zugriff von', 'allowed_from_help' => 'Komma getrennte Liste von IPs oder Netzen.
Standard ist leer (von überall erlaubt).', 'valid_until' => 'Gültig bis', - 'valid_until_help' => 'Datum Gültigkeitsende, Format JJJJ-MM-TT', + 'valid_until_help' => 'Datum Gültigkeitsende, Format YYYY-MM-DDThh:mm', ], 'changepassword' => [ 'old_password' => 'Altes Passwort', @@ -1104,7 +1104,7 @@ Vielen Dank, Ihr Administrator', 'send' => 'Versenden', 'nosslipsavailable' => 'Für diesen Server wurden noch keine SSL IP/Port Kombinationen eingetragen', 'backtooverview' => 'Zurück zur Übersicht', - 'dateformat' => 'JJJJ-MM-TT', + 'dateformat' => 'TT.MM.JJJJ', 'dateformat_function' => 'd.m.Y', 'timeformat_function' => 'H:i:s', 'default' => 'Standard', diff --git a/lng/en.lng.php b/lng/en.lng.php index e825c1b8..3530fbcc 100644 --- a/lng/en.lng.php +++ b/lng/en.lng.php @@ -506,7 +506,7 @@ return [ 'allowed_from' => 'Allowed from', 'allowed_from_help' => 'Comma separated list of ip addresses / networks.
Default is empty (allow from all).', 'valid_until' => 'Valid until', - 'valid_until_help' => 'Date until valid, format YYYY-MM-DD', + 'valid_until_help' => 'Date until valid, format YYYY-MM-DDThh:mm', ], 'changepassword' => [ 'old_password' => 'Old password', diff --git a/templates/Froxlor/form/formfields.html.twig b/templates/Froxlor/form/formfields.html.twig index 198d7b93..eae300a0 100644 --- a/templates/Froxlor/form/formfields.html.twig +++ b/templates/Froxlor/form/formfields.html.twig @@ -29,7 +29,7 @@ {% endif %}
{% endif %} - {% if field.type == 'text' or field.type == 'password' or field.type == 'number' or field.type == 'file' or field.type == 'email' or field.type == 'url' or field.type == 'hidden' %} + {% if field.type == 'text' or field.type == 'password' or field.type == 'number' or field.type == 'file' or field.type == 'email' or field.type == 'url' or field.type == 'hidden' or field.type == 'date' or field.type == 'datetime-local' %} {{ _self.input(id, field) }} {% elseif field.type == 'textul' %} {{ _self.input_ul(id, field) }}