Ongoing webgui work

This commit is contained in:
2025-04-01 14:49:03 +02:00
parent 0c09ce2916
commit c293ca1caa
20 changed files with 572 additions and 166 deletions
+33 -5
View File
@@ -87,6 +87,8 @@ require 'header.php';
if ($action == ACT_DEFAULT):
// ========== VARIANT: default behavior =======================================
page_caption_search($pagetitle);
// load filter from db
$flt = db_get_filter($user->id, 208);
@@ -103,10 +105,34 @@ if (strlen($flt->txt) > 1) {
$where = join(' AND ', $w);
$order = ' ORDER BY comptype, compname';
// grand total of records for current vessel
$grandtotal = $pdo->query("SELECT COUNT(*) FROM company")->fetchColumn();
// get total record count for pagination and limit
$sql = "SELECT COUNT(*) FROM company";
if ($where) {
$sql .= " WHERE $where";
}
$sth = $pdo->prepare($sql);
try {
$sth->execute($p);
} catch(PDOException $e) {
$g_error->Add($e->getMessage());
$g_error->Add($sql);
$g_error->Add(print_r($p, true));
}
$numrows = $sth->fetchColumn();
$lastpage = ceil($numrows/$g_rows_pp);
$page = gpc_get_int($_REQUEST, 'p', 1);
$sql = "SELECT compid, compname, comptype, remarks "
. "FROM company";
if ($where) $sql .= ' WHERE ' . $where;
$sql .= $order;
// if pagination:
$sql .= ' LIMIT ' . ($page - 1) * $g_rows_pp . ',' . $g_rows_pp;
$sth = $pdo->prepare($sql);
try {
$sth->execute($p);
@@ -117,8 +143,6 @@ try {
}
$res = $sth->fetchAll();
echo '<h1>', $pagetitle , "</h1>\n";
// Filter
$opt_special = array(
-2 => _('&horbar; all &horbar;'),
@@ -149,6 +173,9 @@ foreach ($opt_special + $opt_comptype as $k => $v) {
<?php
// Pagination on top
$pagination = get_pagination($g_scriptname, '', $page, $lastpage);
echo $pagination;
echo '<table class="table table-striped">', "\n";
echo "<thead>\n";
@@ -173,10 +200,12 @@ foreach ($res as $row) {
}
// Table summary
echo "<tfoot>\n";
echo '<tr><td colspan="6">', sprintf(_('%d records'), count($res)), '</td></tr>', "\n";
echo '<tr><td colspan="6">', sprintf(_('%d records out of total %d'), count($res), $grandtotal), '</td></tr>', "\n";
echo "</tfoot>\n";
echo "</table>\n";
echo $pagination;
form_add_button($g_scriptname);
@@ -230,8 +259,7 @@ form_view_buttons($g_scriptname, $id);
// show referenced equipment
$sql = "SELECT eid, ename FROM equipment WHERE supplier=:id OR manufacturer=:id";
$sth = $pdo->prepare($sql);
$sth->bindValue(':id', $id, PDO::PARAM_INT);
$sth->execute();
$sth->execute([':id' => $id]);
if ($sth->rowCount() > 0) {
echo "<p>Referenced in equipment:</p>\n";
echo "<ul>\n";