Webgui: More mobile friendly touch and much more improvements
This commit is contained in:
+69
-23
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/******************************************************************************
|
||||
* YMS - Yacht Management Software
|
||||
* Copyright (C) 2024, 2025 Thomas Hooge
|
||||
* Copyright (C) 2024-2026 Thomas Hooge
|
||||
*
|
||||
* SPDX-License-Identifier: WTFPL
|
||||
******************************************************************************/
|
||||
@@ -222,6 +222,9 @@ if (strlen($flt->txt) > 1) {
|
||||
$w[] = '(ename LIKE :txt OR model LIKE :txt OR remarks LIKE :txt)';
|
||||
$p[':txt'] = '%'.$flt->txt.'%';
|
||||
}
|
||||
// TODO flags (ordered, removed, deleted)
|
||||
// if (strlen($flt->flags) > 0) {
|
||||
// }
|
||||
$where = join(' AND ', $w);
|
||||
$order = ' ORDER BY ename';
|
||||
|
||||
@@ -233,19 +236,22 @@ try {
|
||||
$g_error->Add($e->getMessage());
|
||||
$g_error->Add($sql);
|
||||
$g_error->Add(print_r($p, true));
|
||||
$g_error->PrintOut();
|
||||
}
|
||||
$numrows = $sth->fetchColumn();
|
||||
$lastpage = ceil($numrows/$g_rows_pp);
|
||||
$page = gpc_get_int($_REQUEST, 'p', 1);
|
||||
// TODO check against allowed values for rows per page
|
||||
$rows_pp = gpc_get_int($_REQUEST, 'n', $g_rows_pp);
|
||||
|
||||
$sql = "SELECT eid, ename, manufacturer, model, serial, remarks,"
|
||||
$sql = "SELECT eid, ename, manufacturer, model, serial, remarks, flags,"
|
||||
. " TIMESTAMPDIFF(MONTH, purchdate, NOW()) AS age_mon "
|
||||
. "FROM equipment";
|
||||
$sql .= ' WHERE ' . $where;
|
||||
$sql .= $order;
|
||||
|
||||
// if pagination:
|
||||
$sql .= ' LIMIT ' . ($page - 1) * $g_rows_pp . ',' . $g_rows_pp;
|
||||
$sql .= ' LIMIT ' . ($page - 1) * $rows_pp . ',' . $rows_pp;
|
||||
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute($p);
|
||||
@@ -260,18 +266,28 @@ $opt_none_male = array(-1 => pgettext('male', '― none ―'));
|
||||
?>
|
||||
<form method="post" action="<?=$g_scriptname?>">
|
||||
<div id="filter" class="card">
|
||||
<div class="card-header">Filter</div>
|
||||
<div class="card-body">
|
||||
<div class="card-header"><i class="bi bi-funnel me-2"></i>Filter</div>
|
||||
<div class="card-body d-flex flex-wrap gap-3">
|
||||
<?php
|
||||
filter_create_select('flt_category', _('Category'), $g_opt_all + $g_opt_none + $opt_ecat, $flt->cat);
|
||||
filter_create_select('flt_manuf', _('Manufacturer'), $g_opt_all + $opt_none_male + $opt_manufacturer, $flt->manuf);
|
||||
filter_create_select('flt_supp', _('Supplier'), $g_opt_all + $opt_none_male + $opt_supplier, $flt->supp);
|
||||
?>
|
||||
<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>
|
||||
<button name="submit[freset]" class="btn btn-sm btn-secondary float-end" title="<?=_('Reset filter to defaults')?>"><?=_('Clear')?></button>
|
||||
</div>
|
||||
<div class="d-flex flex-nowrap gap-2">
|
||||
<label for="flt_txt"><?=_('Text')?></label>
|
||||
<input type="text" name="flt_txt" size="15" maxlength="30" value="<?=$flt->txt ?>">
|
||||
</div>
|
||||
<div class="d-flex flex-nowrap gap-2">
|
||||
<?php
|
||||
$enum_data = db_load_enum('equipment', 'flags', true, true, false);
|
||||
form_create_checks('flags', _('Flags'), $enum_data, []);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
|
||||
<button name="submit[freset]" class="btn btn-sm btn-secondary float-end" title="<?=_('Reset filter to defaults')?>"><?=_('Clear')?></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -284,6 +300,7 @@ echo $pagination;
|
||||
echo '<table class="table table-striped">', "\n";
|
||||
echo "<thead>\n";
|
||||
echo '<tr>';
|
||||
echo '<th>#</th>';
|
||||
echo '<th>', _('Description'), "</th>";
|
||||
echo '<th>', _('Manufacturer'), "</th>";
|
||||
echo '<th>', _('Model'), "</th>";
|
||||
@@ -293,6 +310,8 @@ echo '<th>', _('Remarks'), "</th>";
|
||||
echo "<th> </th>";
|
||||
echo "</tr>\n";
|
||||
echo "</thead>\n";
|
||||
$i = ($page - 1) * $rows_pp;
|
||||
$i0 = $i + 1;
|
||||
foreach ($res as $row) {
|
||||
// calc nice age display
|
||||
if (!isset($row['age_mon'])) {
|
||||
@@ -302,19 +321,26 @@ foreach ($res as $row) {
|
||||
} else {
|
||||
$age = sprintf(_('%dy'), intdiv($row['age_mon'], 12));
|
||||
}
|
||||
$i++; // record number
|
||||
echo "<tr>\n";
|
||||
echo "<td>", $i;
|
||||
echo '<a class="text-nowrap" title="', _('View'), '" href="', $g_scriptname, '?f=view&id=', $row['eid'], '"><i class="bi bi-eye ms-2"></i></a>', "\n";
|
||||
echo "</td>\n";
|
||||
echo "<td>", $row['ename'], "</td>\n";
|
||||
echo "<td>", ($opt_manufacturer[$row['manufacturer']] ?? ''), "</td>\n";
|
||||
echo "<td>", $row['model'], "</td>\n";
|
||||
echo "<td>", $row['serial'], "</td>\n";
|
||||
echo "<td>", $age, "</td>\n";
|
||||
echo "<td>", $row['remarks'], "</td>\n";
|
||||
// Action buttons
|
||||
form_action_buttons($g_scriptname, $row['eid']);
|
||||
// Edit current record button
|
||||
echo "<td>";
|
||||
echo '<a title="', _('Edit'), '" href="', $g_scriptname, '?f=edit&id=', $row['eid'], '"><i class="bi-pencil"></i></a>', "\n";
|
||||
echo "</td>\n";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
?>
|
||||
<tfoot>
|
||||
<tr><td colspan="6"><?php printf(_('%d records of %d'), count($res), $numrows); ?></td></tr>
|
||||
<tr><td colspan="8"><?php printf(_('Records %d to %d of %d'), $i0, $i, $numrows); ?></td></tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<?php
|
||||
@@ -344,7 +370,7 @@ form_create_select('manufacturer', _('Manufacturer'), $opt_manufacturer, $flt->m
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
|
||||
<textarea class="form-control" id="remarks" name="remarks" rows="3"></textarea>
|
||||
<textarea class="form-control" id="remarks" name="remarks" rows="3" maxlength="150"></textarea>
|
||||
</div>
|
||||
<div class="container-fluid px-0 my-3">
|
||||
<button type="submit" name="submit[insert]" class="btn btn-primary"><?=_('Save')?></button>
|
||||
@@ -356,7 +382,7 @@ elseif ($action == ACT_VIEW):
|
||||
// ========== VARIANT: view single record =====================================
|
||||
|
||||
$sql = "SELECT eid, ename, model, serial, purchdate, price, weight, "
|
||||
. " supplier, manufacturer, ecat, shortname, remarks "
|
||||
. " supplier, manufacturer, ecat, shortname, remarks, flags "
|
||||
. "FROM equipment "
|
||||
. "WHERE eid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
@@ -371,7 +397,9 @@ echo '<div class="col">';
|
||||
|
||||
echo '<table class="table">', "\n";
|
||||
echo '<tr><th>', _('Short name'),"</th><td>", $equipment->shortname, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Manufacturer'),"</th><td>", $opt_manufacturer[$equipment->manufacturer], "</td></tr>\n";
|
||||
echo '<tr><th>', _('Manufacturer'),"</th><td>", $opt_manufacturer[$equipment->manufacturer];
|
||||
echo ' <a title="', _('View'), '" href="company.php?f=view&id=', $equipment->manufacturer, '"><i class="bi-eye"></i></a>';
|
||||
echo "</td></tr>\n";
|
||||
echo '<tr><th>', _('Model'),"</th><td>", $equipment->model, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Serial'),"</th><td>", $equipment->serial, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Weight'),"</th><td>", format_float($equipment->weight, 2, 'kg'), "</td></tr>\n";
|
||||
@@ -379,14 +407,17 @@ echo '<tr><th>', _('Price'),"</th><td>", format_currency($equipment->price), "</
|
||||
echo '<tr><th>', _('Purchase date'),"</th><td>", $equipment->purchdate, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Supplier'),"</th><td>", $equipment->supplier ? $opt_supplier[$equipment->supplier] : 'n/a', "</td></tr>\n";
|
||||
echo '<tr><th>', _('Category'),"</th><td>", $opt_ecat[$equipment->ecat], "</td></tr>\n";
|
||||
echo '<tr><th>', _('Remarks'),"</th><td>", $equipment->remarks, "</td></tr>\n";
|
||||
echo '<tr><th>', _('Remarks'),"</th><td>", nl2br($equipment->remarks), "</td></tr>\n";
|
||||
echo '<tr><th>', _('Flags'),"</th><td>", $equipment->flags, "</td></tr>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
echo '</div>'; // Column break
|
||||
echo '<div class="col">';
|
||||
?>
|
||||
<p>Images and documents go here</p>
|
||||
<?php
|
||||
echo '<div class="col">', "\n";
|
||||
|
||||
echo '<div class="card">', "\n";
|
||||
echo '<div class="card-header">', _('Images and documents'), "</div>\n";
|
||||
echo '<div class="card-body">', "\n";
|
||||
|
||||
$sql = "SELECT d.docid, d.doctype, d.title "
|
||||
. "FROM docref AS r INNER JOIN document AS d using (docid) "
|
||||
. "WHERE r.reftype='equipment' AND r.refid=? "
|
||||
@@ -394,31 +425,46 @@ $sql = "SELECT d.docid, d.doctype, d.title "
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([$id]);
|
||||
$res = $sth->fetchAll();
|
||||
// TODO hübsche Darstellung
|
||||
$doccount = 0;
|
||||
foreach ($res as $row) {
|
||||
$doccount += 1;
|
||||
if ($row['doctype'] == 'picture') {
|
||||
echo '<a href="dl.php?id=', $row['docid'], '">';
|
||||
// echo '<img width="120" src="doc/pic-', $row['hash'], '.', $row['extension'],'">';
|
||||
echo '<img width="120" src="dl.php?id=', $row['docid'], '" alt="', $row['title'], '">';
|
||||
echo "</a>\n";
|
||||
} elseif ($row['doctype'] == 'drawing') {
|
||||
echo "<p>Drawing: ", $row['title'], "<br>";
|
||||
echo '<a href="dl.php?id=', $row['docid'], '">';
|
||||
echo '<img width="180" src="dl.php?id=', $row['docid'], '">';
|
||||
echo "</a>";
|
||||
echo "</p>\n";
|
||||
} elseif ($row['doctype'] == 'generic') {
|
||||
echo '<a href="dl.php?id=', $row['docid'], '">';
|
||||
echo '<img width="120" src="dl.php?id=', $row['docid'], '&t=s" alt="', $row['title'], '">';
|
||||
// echo $row['title'];
|
||||
echo "</a>\n";
|
||||
} elseif ($row['doctype'] == 'manual') {
|
||||
echo "Manual: ";
|
||||
echo "<p>Manual: ";
|
||||
echo '<a href="documents.php?f=view&id=', $row['docid'], '">';
|
||||
echo $row['title'];
|
||||
echo "</a>\n";
|
||||
echo "</a></p>\n";
|
||||
} else {
|
||||
// unknown document type
|
||||
echo "<span>Unknown document type:", $row['doctype'], "</span>\n";
|
||||
}
|
||||
}
|
||||
if ($doccount == 0) {
|
||||
echo _('No referenced documents'), "\n";
|
||||
}
|
||||
echo "</div>\n"; // card-body
|
||||
echo "</div>\n"; // card
|
||||
?>
|
||||
<form method="post" enctype="multipart/form-data" action="<?=$g_scriptname?>">
|
||||
<input type="hidden" name="id" value="<?=$id?>">
|
||||
<div class="card">
|
||||
<div class="card-header"><?=_('Add Image');?></div>
|
||||
<div class="card-body">
|
||||
<input type="file" name="files[]" multiple accept="image/*" capture="camera">
|
||||
<input type="submit" name="submit[upload]" value="Upload">
|
||||
|
||||
Reference in New Issue
Block a user