add date/datetime input fields to relevant formfields

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-05-15 10:07:25 +02:00
parent 4d5473ff14
commit 07a1ad8c58
9 changed files with 27 additions and 21 deletions

View File

@@ -26,6 +26,7 @@
namespace Froxlor\Ajax; namespace Froxlor\Ajax;
use Exception; use Exception;
use DateTime;
use Froxlor\Config\ConfigDisplay; use Froxlor\Config\ConfigDisplay;
use Froxlor\Config\ConfigParser; use Froxlor\Config\ConfigParser;
use Froxlor\CurrentUser; use Froxlor\CurrentUser;
@@ -233,7 +234,7 @@ class Ajax
{ {
$keyid = isset($_POST['id']) ? (int)$_POST['id'] : 0; $keyid = isset($_POST['id']) ? (int)$_POST['id'] : 0;
$allowed_from = isset($_POST['allowed_from']) ? $_POST['allowed_from'] : ""; $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 // validate allowed_from
if (!empty($allowed_from)) { if (!empty($allowed_from)) {
@@ -260,8 +261,10 @@ class Ajax
$allowed_from = implode(",", array_unique($ip_list)); $allowed_from = implode(",", array_unique($ip_list));
} }
if ($valid_until <= 0 || !is_numeric($valid_until)) { if (!empty($valid_until)) {
$valid_until = -1; $valid_until_db = DateTime::createFromFormat('Y-m-d\TH:i', $valid_until)->format('U');
} else {
$valid_until_db = -1;
} }
$upd_stmt = Database::prepare(" $upd_stmt = Database::prepare("
@@ -277,7 +280,7 @@ class Ajax
Database::pexecute($upd_stmt, [ Database::pexecute($upd_stmt, [
'keyid' => $keyid, 'keyid' => $keyid,
'af' => $allowed_from, 'af' => $allowed_from,
'vu' => $valid_until, 'vu' => $valid_until_db,
'aid' => $this->userinfo['adminid'], 'aid' => $this->userinfo['adminid'],
'cid' => $cid 'cid' => $cid
]); ]);

View File

@@ -403,7 +403,7 @@ class Domains extends ApiCommand implements ResourceEntity
$documentroot = $_documentroot; $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', '0000-00-00',
'0', '0',
'' ''
@@ -412,7 +412,7 @@ class Domains extends ApiCommand implements ResourceEntity
$registration_date = null; $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', '0000-00-00',
'0', '0',
'' ''
@@ -1291,7 +1291,7 @@ class Domains extends ApiCommand implements ResourceEntity
$adminid = $result['adminid']; $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', '0000-00-00',
'0', '0',
'' ''
@@ -1299,7 +1299,7 @@ class Domains extends ApiCommand implements ResourceEntity
if ($registration_date == '0000-00-00' || empty($registration_date)) { if ($registration_date == '0000-00-00' || empty($registration_date)) {
$registration_date = null; $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', '0000-00-00',
'0', '0',
'' ''

View File

@@ -43,6 +43,8 @@ class Validate
const REGEX_DESC_TEXT = '/^[^\0\r\n<>]*$/'; 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 * Validates the given string by matching against the pattern, prints an error on failure and exits
* *

View File

@@ -75,19 +75,20 @@ return [
'add_date' => [ 'add_date' => [
'label' => lng('domains.add_date'), 'label' => lng('domains.add_date'),
'desc' => lng('panel.dateformat'), 'desc' => lng('panel.dateformat'),
'type' => 'label', 'type' => 'date',
'readonly' => true,
'value' => date('Y-m-d') 'value' => date('Y-m-d')
], ],
'registration_date' => [ 'registration_date' => [
'label' => lng('domains.registration_date'), 'label' => lng('domains.registration_date'),
'desc' => lng('panel.dateformat'), 'desc' => lng('panel.dateformat'),
'type' => 'text', 'type' => 'date',
'size' => 10 'size' => 10
], ],
'termination_date' => [ 'termination_date' => [
'label' => lng('domains.termination_date'), 'label' => lng('domains.termination_date'),
'desc' => lng('panel.dateformat'), 'desc' => lng('panel.dateformat'),
'type' => 'text', 'type' => 'date',
'size' => 10 'size' => 10
] ]
] ]

View File

@@ -86,20 +86,21 @@ return [
'add_date' => [ 'add_date' => [
'label' => lng('domains.add_date'), 'label' => lng('domains.add_date'),
'desc' => lng('panel.dateformat'), 'desc' => lng('panel.dateformat'),
'type' => 'label', 'type' => 'date',
'readonly' => true,
'value' => date('Y-m-d', (int)$result['add_date']) 'value' => date('Y-m-d', (int)$result['add_date'])
], ],
'registration_date' => [ 'registration_date' => [
'label' => lng('domains.registration_date'), 'label' => lng('domains.registration_date'),
'desc' => lng('panel.dateformat'), 'desc' => lng('panel.dateformat'),
'type' => 'text', 'type' => 'date',
'value' => $result['registration_date'], 'value' => $result['registration_date'],
'size' => 10 'size' => 10
], ],
'termination_date' => [ 'termination_date' => [
'label' => lng('domains.termination_date'), 'label' => lng('domains.termination_date'),
'desc' => lng('panel.dateformat'), 'desc' => lng('panel.dateformat'),
'type' => 'text', 'type' => 'date',
'value' => $result['termination_date'], 'value' => $result['termination_date'],
'size' => 10 'size' => 10
] ]

View File

@@ -58,9 +58,8 @@ return [
'title' => lng('apikeys.valid_until'), 'title' => lng('apikeys.valid_until'),
'description' => lng('apikeys.valid_until_help') 'description' => lng('apikeys.valid_until_help')
], ],
/** @TODO datetime-picker */ 'type' => 'datetime-local',
'type' => 'text', 'value' => $result['valid_until'] < 0 ? "" : date('Y-m-d\TH:i', $result['valid_until'])
'value' => $result['valid_until'] < 0 ? "" : $result['valid_until']
] ]
] ]
] ]

View File

@@ -465,7 +465,7 @@ return [
'allowed_from' => 'Erlaube Zugriff von', 'allowed_from' => 'Erlaube Zugriff von',
'allowed_from_help' => 'Komma getrennte Liste von IPs oder Netzen.<br>Standard ist leer (von überall erlaubt).', 'allowed_from_help' => 'Komma getrennte Liste von IPs oder Netzen.<br>Standard ist leer (von überall erlaubt).',
'valid_until' => 'Gültig bis', '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' => [ 'changepassword' => [
'old_password' => 'Altes Passwort', 'old_password' => 'Altes Passwort',
@@ -1104,7 +1104,7 @@ Vielen Dank, Ihr Administrator',
'send' => 'Versenden', 'send' => 'Versenden',
'nosslipsavailable' => 'Für diesen Server wurden noch keine SSL IP/Port Kombinationen eingetragen', 'nosslipsavailable' => 'Für diesen Server wurden noch keine SSL IP/Port Kombinationen eingetragen',
'backtooverview' => 'Zurück zur Übersicht', 'backtooverview' => 'Zurück zur Übersicht',
'dateformat' => 'JJJJ-MM-TT', 'dateformat' => 'TT.MM.JJJJ',
'dateformat_function' => 'd.m.Y', 'dateformat_function' => 'd.m.Y',
'timeformat_function' => 'H:i:s', 'timeformat_function' => 'H:i:s',
'default' => 'Standard', 'default' => 'Standard',

View File

@@ -506,7 +506,7 @@ return [
'allowed_from' => 'Allowed from', 'allowed_from' => 'Allowed from',
'allowed_from_help' => 'Comma separated list of ip addresses / networks.<br>Default is empty (allow from all).', 'allowed_from_help' => 'Comma separated list of ip addresses / networks.<br>Default is empty (allow from all).',
'valid_until' => 'Valid until', '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' => [ 'changepassword' => [
'old_password' => 'Old password', 'old_password' => 'Old password',

View File

@@ -29,7 +29,7 @@
{% endif %} {% endif %}
<div class="col-sm-8"> <div class="col-sm-8">
{% 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) }} {{ _self.input(id, field) }}
{% elseif field.type == 'textul' %} {% elseif field.type == 'textul' %}
{{ _self.input_ul(id, field) }} {{ _self.input_ul(id, field) }}