Webgui: improve box, maintenance and date handling

This commit is contained in:
2026-09-16 06:12:50 +02:00
parent a76848e1da
commit 9b45fd3700
10 changed files with 116 additions and 31 deletions
+14
View File
@@ -8,6 +8,20 @@
*/
function db_get_setting($sno, $default=NULL) {
// TODO WIP
global $pdo;
$sql = "SELECT valint, valstr FROM settings WHERE userid=0 AND sno=?";
$sth = $pdo->prepare($sql);
try {
$sth->execute([$sno]);
} catch (Exception $e) {
return $default;
}
$row = $sth->fetchOne();
return $row;
}
function db_lock_acquire($table, $key, $userid) {
global $pdo;
$token = bin2hex(random_bytes(8));
+36 -3
View File
@@ -83,11 +83,44 @@ function gpc_get_bool(&$GPC, $varname, $default = FALSE) {
}
function gpc_get_date(&$GPC, $varname, $default = NULL) {
// TODO improve
if (!isset($GPC[$varname]) || $GPC[$varname] == '') {
global $g_opt_datefmt;
if (!isset($GPC[$varname]) || !is_scalar($GPC[$varname])) {
return $default;
}
return $GPC[$varname];
$value = trim((string)$GPC[$varname]);
if ($value === '') {
return $default;
}
foreach (array_keys($g_opt_datefmt) as $format) {
if (preg_match_all('/[Ymd]/', $format, $tokens) !== 3) {
continue;
}
$regex = preg_quote($format, '/');
$regex = str_replace('d', '(\d{2})', $regex);
$regex = str_replace('m', '(\d{2})', $regex);
$regex = str_replace('Y', '(\d{4})', $regex);
if (!preg_match('/^' . $regex . '$/', $value, $matches)) {
continue;
}
$year = $month = $day = NULL;
foreach ($tokens[0] as $i => $token) {
switch ($token) {
case 'Y':
$year = (int)$matches[$i + 1];
break;
case 'm':
$month = (int)$matches[$i + 1];
break;
case 'd':
$day = (int)$matches[$i + 1];
break;
}
}
if (checkdate($month, $day, $year)) {
return sprintf('%04d-%02d-%02d', $year, $month, $day);
}
}
return $default;
}
function gpc_get_datetime(&$GPC, $varname, $default = NULL) {