Added position to equipment

This commit is contained in:
2026-09-20 09:19:18 +02:00
parent 2fc74c0677
commit 5fd6c68b4f
8 changed files with 74 additions and 26 deletions
+19 -6
View File
@@ -8,17 +8,31 @@
*/
function db_get_setting($sno, $default=NULL) {
// TODO WIP
function db_get_setting($sno, $userid, $autocreate=false, $default=NULL) {
global $pdo;
$sql = "SELECT valint, valstr FROM settings WHERE userid=0 AND sno=?";
global $g_error;
global $g_warning;
$sql = "SELECT valint, valstr FROM settings WHERE userid=? AND sno=?";
$sth = $pdo->prepare($sql);
try {
$sth->execute([$sno]);
$sth->execute([$userid, $sno]);
} catch (Exception $e) {
$g_error->Add('SQL-Error: '. $e->getMessage());
$g_error->Add($sql);
$g_error->Add("userid=$userid, sno=$sno", true));
return $default;
}
$row = $sth->fetch();
if ($row === false) {
if ($autocreate) {
// create empty settings record if it not exists
$p[':userid'] = $userid;
$p[':sno'] = $sno;
db_exec_insert('settings', $p);
$g_warning->Add("Added missing settings record with id=$sno");
}
return $default;
}
$row = $sth->fetchOne();
return $row;
}
@@ -61,7 +75,6 @@ function db_lock_refresh($token) {
return $sth->rowCount() === 1;
}
function db_lock_release($token) {
global $pdo;
$sql = "DELETE FROM recordlock WHERE token=?";
+9 -9
View File
@@ -13,7 +13,7 @@
function gpc_get_string(&$GPC, $varname, $maxlen = NULL, $default = NULL) {
// TODO Parameter nullval: single value or array of values which considered as null
// Default value for nullval is "-1"
if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) {
if (!isset($GPC[$varname]) || (strlen(trim($GPC[$varname])) == 0)) {
return $default;
}
$s = trim($GPC[$varname]);
@@ -24,14 +24,14 @@ function gpc_get_string(&$GPC, $varname, $maxlen = NULL, $default = NULL) {
}
function gpc_get_int(&$GPC, $varname, $default = NULL) {
if (!isset($GPC[$varname])) {
if (!isset($GPC[$varname]) || $GPC[$varname] === '') {
return $default;
}
return (int)$GPC[$varname];
}
function gpc_get_uint(&$GPC, $varname, $default = NULL) {
if (!isset($GPC[$varname])) {
if (!isset($GPC[$varname]) || $GPC[$varname] === '') {
return $default;
}
$val = (int)$GPC[$varname];
@@ -43,7 +43,7 @@ function gpc_get_uint(&$GPC, $varname, $default = NULL) {
function gpc_get_float(&$GPC, $varname, $default = NULL) {
global $g_lconv;
if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) {
if (!isset($GPC[$varname]) || (strlen(trim($GPC[$varname])) == 0)) {
return $default;
}
$var = str_replace($g_lconv['thousands_sep'], '', $GPC[$varname]);
@@ -55,7 +55,7 @@ function gpc_get_float(&$GPC, $varname, $default = NULL) {
function gpc_get_currency(&$GPC, $varname, $default = NULL) {
global $g_lconv;
if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) {
if (!isset($GPC[$varname]) || (strlen(trim($GPC[$varname])) == 0)) {
return $default;
}
$var = str_replace($g_lconv['thousands_sep'], '', $GPC[$varname]);
@@ -132,21 +132,21 @@ function gpc_get_datetime(&$GPC, $varname, $default = NULL) {
}
function gpc_get_color(&$GPC, $varname, $default = NULL) {
if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) {
if (!isset($GPC[$varname]) || (strlen(trim($GPC[$varname])) == 0)) {
return $default;
}
$color = $GPC[$varname];
if ((strlen($color) == 7) and (substr($color, 0, 1) == '#')) {
if ((strlen($color) == 7) && (substr($color, 0, 1) == '#')) {
$color = substr($color, 1);
}
if ((strlen($color) != 6) or (! ctype_xdigit($color))) {
if ((strlen($color) != 6) || (! ctype_xdigit($color))) {
return $default;
}
return strtoupper($color);
}
function gpc_get_enum(&$GPC, $varname, $values, $default = NULL) {
if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) {
if (!isset($GPC[$varname]) || (strlen(trim($GPC[$varname])) == 0)) {
return $default;
}
if (! in_array($GPC[$varname], $values)) {