Settings page finished, filter gui improved

This commit is contained in:
2026-07-07 11:23:16 +02:00
parent 42df35f1a0
commit 2177834b39
12 changed files with 241 additions and 51 deletions
+101 -4
View File
@@ -364,11 +364,28 @@ function db_exec_insert($table, $params) {
}
function db_exec_update($table, $params, $pk) {
// TODO primary key with multiple fields: $pk is an array
// primary key can be a single field name or multiple fields: $pk is an array
global $pdo;
global $g_error;
$fields = join(',', array_map(function($s) { return ltrim($s, ':') . '=' . $s; }, array_keys($params)));
$sql = "UPDATE $table SET $fields WHERE $pk=:$pk";
// remove primary key fields from list of fields to update
if (is_array($pk)) {
if (count($pk) == 1) {
$pk = $pk[0];
$fields = $params;
unset($fields[':'.$pk]);
$where = "$pk=:$pk";
} else {
$pkparams = array_map(fn($value) => ':' . $value, $pk);
$fields = array_diff_key($params, array_flip($pkparams));
$where = join(' AND ', array_map(fn($s) => "$s=:$s", $pk));
}
} else {
$fields = $params;
unset($fields[':'.$pk]);
$where = "$pk=:$pk";
}
$fieldlist = join(',', array_map(fn($s) => ltrim($s, ':') . '=' . $s, array_keys($fields)));
$sql = "UPDATE $table SET $fieldlist WHERE $where";
$sth = $pdo->prepare($sql);
try {
$sth->execute($params);
@@ -503,6 +520,7 @@ function db_load_enum($table, $column, $lookup=false, $as_dict=false, $check_nul
// if lookup is true the name lookup and translaton is applied
// if as_dict is true the enum value is returned as the array key
// if check_null is true the nullable-check is applied and returned
// works also for set datatype
global $pdo;
$sql = "SELECT TRIM(TRAILING ')' FROM SUBSTRING(column_type,6)), is_nullable "
. "FROM information_schema.columns "
@@ -903,6 +921,7 @@ function form_create_checks($fieldname, $label, $optlist, $selected) {
echo "</div>\n";
}
// TODO DEPRECATED for touch multiple adjacent buttuns are not well suited.
function form_action_buttons($script, $id) {
echo "<td>";
echo '<a title="', _('View'), '" href="', $script, '?f=view&id=', $id, '"><i class="bi-eye"></i></a>', "\n";
@@ -980,7 +999,7 @@ function filter_create_select($fieldname, $label, $optlist, $selval=NULL, $multi
} */
echo '<div class="d-flex flex-nowrap gap-2">', "\n";
echo '<label for="', $fieldname,'">', $label,'</label>', "\n";
echo '<select id="', $fieldname, '" name="', $fieldname, '"', $multiple ? ' multiple' : '', ">\n";
echo '<select class="form-select" id="', $fieldname, '" name="', $fieldname, '"', $multiple ? ' multiple' : '', ">\n";
foreach ($optlist as $k => $v) {
echo '<option value="', $k, '"';
if ($k == $selval) {
@@ -992,6 +1011,24 @@ function filter_create_select($fieldname, $label, $optlist, $selval=NULL, $multi
echo "</div>";
}
function filter_create_checks($fieldname, $label, $optlist, $selected = []) {
// TODO WIP
echo '<fieldset class="mb-3">';
echo '<legend class="fs-6 mb-1 border-bottom pb-1">', $label, "</legend>\n";
echo '<div class="d-flex flex-wrap gap-3">';
foreach ($optlist as $k => $v) {
echo '<div class="form-check">';
$checked = in_array($k, $selected, true) ? ' checked' : '';
echo '<label class="form-check-label">';
echo '<input type="checkbox" class="form-check-input" name="', $fieldname, '[', $k, ']"', $checked, '>';
echo $v;
echo '</label>';
echo '</div>';
}
echo '</div>';
echo '</fieldset>';
}
// ========== FORMAT FUNCTIONS ================================================
function format_float($val, $decimals = 2, $suffix = '') {
@@ -1202,6 +1239,66 @@ function pdf_get_preview($docid) {
}
function make_weblink($dest) {
$dest = trim($dest);
if ($dest === '') {
return '';
}
$scheme = strtolower((string) parse_url($dest, PHP_URL_SCHEME));
if ($scheme === '') {
$dest = 'https://' . $dest;
} elseif (!in_array($scheme, ['http', 'https'], true)) {
return '';
}
return '<a href="' . $dest . '"><i class="bi-globe"></i></a>';
}
function make_maillink($dest) {
$dest = trim($dest);
if ($dest === '') {
return '';
}
$scheme = strtolower((string) parse_url($dest, PHP_URL_SCHEME));
if ($scheme === '') {
$dest = 'mailto:' . $dest;
} elseif ($scheme !== 'mailto') {
return '';
}
return '<a href="' . $dest . '"><i class="bi-envelope"></i></a>';
}
function make_phonelink($dest) {
$dest = normalize_phone_e164($dest);
if ($dest === '') {
return '';
}
$scheme = strtolower((string) parse_url($dest, PHP_URL_SCHEME));
if ($scheme === '') {
$dest = 'tel:' . $dest;
} elseif ($scheme !== 'tel') {
return '';
}
return '<a href="' . $dest . '"><i class="bi-telephone"></i></a>';
}
function normalize_phone_e164($phone) {
$phone = trim($phone);
if ($phone === '') {
return '';
}
$phone = preg_replace('/[^\d+]/', '', $phone);
if (str_starts_with($phone, '+')) {
return $phone;
}
if (str_starts_with($phone, '00')) {
return '+' . substr($phone, 2);
}
if (str_starts_with($phone, '0')) {
$phone = substr($phone, 1);
}
return '+49' . $phone;
}
// ========== MENU FUNCTIONS ==================================================
$g_menu = Array (