More webgui work. Filters e.g.

This commit is contained in:
2024-04-19 13:25:56 +02:00
parent 851f7e13a2
commit c3b5ef95a9
20 changed files with 853 additions and 585 deletions
+81 -9
View File
@@ -23,6 +23,14 @@ switch ($submit = form_get_action()) {
case 'edit': $action = ACT_EDIT; break;
case 'del': $action = ACT_DELETE; break;
case 'filter':
$flt = array();
$flt['type'] = gpc_get_int($_POST, 'flt_type');
$flt['txt'] = gpc_get_string($_POST, 'flt_txt');
db_save_filter($flt, 208);
$action = ACT_DEFAULT;
break;
case 'insert':
$p[':compname'] = gpc_get_string($_POST, 'compname');
$p[':comptype'] = gpc_get_int($_POST, 'comptype');
@@ -33,6 +41,7 @@ switch ($submit = form_get_action()) {
case 'update':
$p[':compid'] = $id;
$p[':compname'] = gpc_get_string($_POST, 'compname');
$p[':shortname'] = gpc_get_string($_POST, 'shortname', 20);
$p[':comptype'] = gpc_get_int($_POST, 'comptype');
$p[':street'] = gpc_get_string($_POST, 'street', 30);
$p[':zip'] = gpc_get_string($_POST, 'zip', 10);
@@ -78,13 +87,69 @@ require 'header.php';
if ($action == ACT_DEFAULT):
// ========== VARIANT: default behavior =======================================
echo '<h1>', $pagetitle , "</h1>\n";
// load filter from db
$flt = db_get_filter($user->id, 208);
$w = array();
$p = array();
if ($flt->type > 0) {
$w[] = 'comptype=:comptype';
$p[':comptype'] = $flt->type;
}
if (strlen($flt->txt) > 1) {
$w[] = '(compname LIKE :txt OR remarks LIKE :txt)';
$p[':txt'] = '%'.$flt->txt.'%';
}
$where = join(' AND ', $w);
$order = ' ORDER BY comptype, compname';
$sql = "SELECT compid, compname, comptype, remarks "
. "FROM company "
. "ORDER BY comptype, compname";
$sth = $pdo->query($sql);
. "FROM company";
if ($where) $sql .= ' WHERE ' . $where;
$sql .= $order;
$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));
}
$res = $sth->fetchAll();
echo '<h1>', $pagetitle , "</h1>\n";
// Filter
$opt_special = array(
-2 => _('&horbar; all &horbar;'),
);
?>
<form method="post" action="<?=$g_scriptname?>">
<div id="filter" class="card">
<div class="card-header">Filter</div>
<div class="card-body">
<label for="flt_type">Type</label>
<select id="flt_type" name="flt_type">
<?php
foreach ($opt_special + $opt_comptype as $k => $v) {
echo '<option value="', $k,'"';
if ($k == $flt->type) {
echo ' selected';
}
echo '>', $v, '</option>';
}
?>
</select>
<label for="flt_txt">Text</label>
<input type="text" name="flt_txt" size="15" maxlength="30" value="<?=$flt->txt?>">
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
</div>
</div>
</form>
<?php
echo '<table class="table table-striped">', "\n";
echo "<thead>\n";
echo "<tr>";
@@ -134,7 +199,7 @@ echo '<h2>', _('Add Company'), "</h2>\n";
elseif ($action == ACT_VIEW):
// ========== VARIANT: view single record =====================================
$sql = "SELECT compname, comptype, street, zip, city, country,"
$sql = "SELECT compname, comptype, shortname, street, zip, city, country,"
. " contact, phone, email, web, customerno, contractno, remarks "
. "FROM company "
. "WHERE compid=?";
@@ -145,7 +210,8 @@ $company = $sth->fetch(PDO::FETCH_OBJ);
echo "<h2>", $company->compname, "</h2>\n";
echo '<table class="table">', "\n";
echo '<tr><th scope="row">', _('Name'),"</th><td>", $company->compname, "</td></tr>\n";
echo '<tr><th scope="row" style="width:20%">', _('Name'),"</th><td>", $company->compname, "</td></tr>\n";
echo '<tr><th scope="row">', _('Short name'),"</th><td>", $company->shortname, "</td></tr>\n";
echo '<tr><th scope="row">', _('Type'),"</th><td>", $opt_comptype[$company->comptype], "</td></tr>\n";
echo '<tr><th scope="row">', _('Street'),"</th><td>", $company->street, "</td></tr>\n";
echo '<tr><th scope="row">', _('Zip, City'),"</th><td>", $company->zip, ' ', $company->city, "</td></tr>\n";
@@ -162,15 +228,17 @@ echo "</table>\n";
form_view_buttons($g_scriptname, $id);
// show referenced equipment
$sql = "SELECT ename FROM equipment WHERE supplier=:id OR manufacturer=:id";
$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();
if ($sth->rowCount > 0) {
if ($sth->rowCount() > 0) {
echo "<p>Referenced in equipment:</p>\n";
echo "<ul>\n";
foreach ($sth->fetchAll() as $row) {
echo "<li>", $row['ename'], "</li>\n";
echo "<li>", $row['ename'], ' ';
echo '<a title="', _('View'), '" href="equipment.php?f=view&id=', $row['eid'], '"><i class="bi-eye"></i></a>';
echo "</li>\n";
}
echo "</ul>\n";
} else {
@@ -197,6 +265,10 @@ $company = $sth->fetch(PDO::FETCH_OBJ);
<label for="compname" class="form-label"><?=_('Name')?></label>
<input type="text" class="form-control" id="compname" name="compname" value="<?=$company->compname ?>">
</div>
<div class="mb-3">
<label for="shortname" class="form-label"><?=_('Short name')?></label>
<input type="text" class="form-control" id="shortname" name="shortname" value="<?=$company->shortname ?>">
</div>
<div class="mb-3">
<label for="comptype" class="form-label"><?=_('Company type')?></label>
<select name="comptype" class="form-control">