Webgui: filter and pagination working

This commit is contained in:
2026-07-15 19:42:55 +02:00
parent 2177834b39
commit a183a4725f
33 changed files with 2088 additions and 750 deletions
+137
View File
@@ -0,0 +1,137 @@
<?php
/******************************************************************************
* YMS - Yacht Management Software
* Copyright (C) 2024-2026 Thomas Hooge
*
* SPDX-License-Identifier: WTFPL
******************************************************************************/
require 'globals.inc';
require 'lib/gpc.inc';
$pagetitle = _('Settings');
// ========== ACTIONS START ===================================================
switch ($submit = form_get_action()) {
case NULL: break;
case 'update':
$pk = ['userid', 'sno'];
// global settings
if ($user->role == 'captain') {
$p[':userid'] = 0;
$p[':sno'] = 20;
$p[':valint'] = gpc_get_int($_POST, 'maximgx');
db_exec_update('settings', $p, $pk);
$p[':sno'] = 21;
$p[':valint'] = gpc_get_int($_POST, 'maximgy');
db_exec_update('settings', $p, $pk);
}
// user settings
$p[':userid'] = $user->id;
$p[':sno'] = 2; // date format
$p[':valint'] = NULL;
$p[':valstr'] = gpc_get_string($_POST, 'datefmt');
db_exec_update('settings', $p, $pk);
$p[':sno'] = 10; // rows pp
$p[':valstr'] = NULL;
$p[':valint'] = gpc_get_int($_POST, 'rowspp');
db_exec_update('settings', $p, $pk);
break;
default:
$g_error->Add(sprintf(_("Unknown function '%s'!"), $submit));
$valid = FALSE;
}
// ========== ACTIONS END =====================================================
require 'header.php';
// ========== PAGE CONTENT ====================================================
if ($action == ACT_DEFAULT):
// ========== VARIANT: default behavior =======================================
echo '<h1>', $pagetitle, "</h1>\n";
$datefmt = 'Y-m-d';
$sql = "SELECT valstr FROM settings WHERE userid=? AND sno=2";
$sth = $pdo->prepare($sql);
$sth->execute([$user->id]);
if ($res = $sth->fetch(PDO::FETCH_NUM)) {
$datefmt = $res[0];
} else {
// create missing record in settings table
$sql = "INSERT INTO settings (userid, sno, valstr) VALUES (?, 2, ?)";
$sth = $pdo->prepare($sql);
$sth->execute([$user->id, $datefmt]);
}
$curdate = new DateTime();
$opt_datefmt = array(
'Y-m-d' => _('YYYY-MM-DD'). $curdate->format(' - Y-m-d'),
'Y/m/d' => _('YYYY/MM/DD'). $curdate->format(' - Y/m/d'),
'd.m.Y' => _('DD.MM.YYYY'). $curdate->format(' - d.m.Y'),
'd/m/Y' => _('DD/MM/YYYY'). $curdate->format(' - d/m/Y'),
'm-d-Y' => _('MM/DD/YYYY'). $curdate->format(' - m-d-Y')
);
$rowspp = 10;
$sql = "SELECT valint FROM settings WHERE userid=? AND sno=10";
$sth = $pdo->prepare($sql);
$sth->execute([$user->id]);
if ($res = $sth->fetch(PDO::FETCH_NUM)) {
$rowspp = $res[0];
} else {
// create missing record in settings table
$sql = "INSERT INTO settings (userid, sno, valint) VALUES (?, 10, ?)";
$sth = $pdo->prepare($sql);
$sth->execute([$user->id, $rowspp]);
}
$maximgx = $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=20")->fetchColumn();
$maximgy = $pdo->query("SELECT valint FROM settings WHERE userid=0 AND sno=21")->fetchColumn();
?>
<form method="post" action="<?=$g_scriptname?>">
<h2>for current user</h2>
<?php
form_create_select('datefmt', _('Date format'), $opt_datefmt, $datefmt);
?>
<div class="mb-3">
<label for="rowspp" class="form-label"><?=_('Number of rows per page')?></label>
<input type="text" class="form-control" id="rowspp" name="rowspp" maxlength="3" value=<?=$rowspp?>>
</div>
<?php
// limit global settings for captain only
if ($user->role == 'captain'):
?>
<h2>global for all users</h2>
<div class="mb-3">
<label for="maximgx" class="form-label"><?=_('Maximal image width')?></label>
<input type="text" class="form-control" id="maximgx" name="maximgx" maxlength="4" value=<?=$maximgx?>>
</div>
<div class="mb-3">
<label for="maximgy" class="form-label"><?=_('Maximal image height')?></label>
<input type="text" class="form-control" id="maximgy" name="maximgy" maxlength="4" value=<?=$maximgy?>>
</div>
<?php
endif;
?>
<div class="container-fluid px-0 my-3">
<button type="submit" name="submit[update]" class="btn btn-primary"><?=_('Save')?></button>
<a href="index.php" class="btn btn-secondary"><?=_('Back')?></a>
</div>
</form>
<?php
else:
// ========== ERROR UNKNOWN VARIANT ===========================================
echo '<p>', _('Unknown function call: Please report to system development!'), "</p>\n";
endif; // $action == ...
// ========== END OF VARIANTS =================================================
include 'footer.php';