Files
YMS/webgui/search.php
T
2024-04-30 19:38:28 +02:00

83 lines
2.6 KiB
PHP

<?php
/******************************************************************************
* YMS - Yacht Management Software
* Copyright (C) 2024 Thomas Hooge
*
* SPDX-License-Identifier: WTFPL
******************************************************************************/
require 'globals.inc';
$pagetitle = _('Search');
$needle = gpc_get_string($_REQUEST, 'needle', 40);
require 'header.php';
echo "<h1>$pagetitle</h1>\n";
?>
<form method="post" action="<?=$g_scriptname?>">
<div>
<label for="needle">Suche nach:</label>
<input type="text" id="needle" name="needle" value="<?=$needle?>" autofocus>
</div>
<div>
<input type="checkbox" id="remarks" name="ck_remarks"<?php if (isset($_POST['ck_remarks'])) echo ' checked'; ?>>
<label for="remarks">Bemerkungsfelder berücksichtigen</label>
</div>
<button type="submit" class="btn btn-primary" name="submit[search]"><?=_('Search')?></button>
</form>
<?php
if (isset($needle)) {
$sqlneedle = '%'.$needle.'%';
$remarks = isset($_POST['ck_remarks']) ? ' OR remarks LIKE :needle' : '';
// equipment
$sql = "SELECT eid, ename, model, remarks "
. "FROM equipment "
. "WHERE ename LIKE :needle OR model LIKE :needle" . $remarks;
$sth = $pdo->prepare($sql);
$sth->execute([':needle' => $sqlneedle]);
if ($sth->rowCount() > 0) {
echo '<h3>', _('Equipment'), "</h3>\n";
foreach ($sth->fetchAll() as $row) {
$out = $row['ename'] . ' ' . $row['model'];
// mark needle in result
$p0 = strpos($out, $needle);
if ($p0 > 0) {
$out = substr_replace($out, '</span>', $p0 + strlen($needle), 0);
$out = substr_replace($out, '<span style="background:#ffef00;">', $p0, 0);
}
echo '<p>', $out;
echo '';
echo "</p>\n";
}
}
// inventory
$sql = "SELECT invid, invname, remarks "
. "FROM inventory "
. "WHERE invname LIKE :needle" . $remarks;
$sth = $pdo->prepare($sql);
$sth->execute([':needle' => $sqlneedle]);
if ($sth->rowCount() > 0) {
echo '<h3>', _('Inventory'), "</h3>\n";
foreach ($sth->fetchAll() as $row) {
$out = $row['invname'] . ' ' . $row['model'];
// mark needle in result
$p0 = strpos($out, $needle);
if ($p0 > 0) {
$out = substr_replace($out, '</span>', $p0 + strlen($needle), 0);
$out = substr_replace($out, '<span style="background:#ffef00;">', $p0, 0);
}
echo '<p>', $out;
echo '';
echo "</p>\n";
}
}
}
include 'footer.php';