Files
YMS/webgui/search.php
T
2025-04-01 14:49:03 +02:00

138 lines
5.1 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>
<?php
if ($g_referrer != $g_scriptname) {
echo '<a class="btn btn-secondary" href="', $g_referrer, '">', _('Back'), "</a>\n";
}
echo "</form>\n";
if (isset($needle)) {
$sqlneedle = '%'.$needle.'%';
// equipment
$remarks = isset($_POST['ck_remarks']) ? ' OR remarks LIKE :needle' : '';
$sql = "SELECT eid, ename, model, remarks "
. "FROM equipment "
. "WHERE vid=:vid AND (ename LIKE :needle OR model LIKE :needle)" . $remarks;
$sth = $pdo->prepare($sql);
$sth->execute([':vid' => $user->vid, ':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 = stripos($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, '&nbsp;';
echo '<a href="equipment.php?f=view&id=', $row['eid'], '"><i class="bi-eye"></i></a>';
echo "</p>\n";
}
}
// inventory
$remarks = isset($_POST['ck_remarks']) ? 'OR i.remarks LIKE :needle ' : '';
$sql = "SELECT invid, invname, i.remarks "
. "FROM inventory AS i JOIN storage AS s ON (i.conttype='storage' AND i.sid=s.sid) "
. "WHERE s.vid=:vid AND i.invname LIKE :needle " . $remarks
. "UNION "
. "SELECT invid, invname, i.remarks "
. "FROM inventory AS i JOIN box AS b ON (i.conttype='box' AND i.boxid=b.boxid) "
. " JOIN storage AS s ON (i.sid=s.sid) "
. "WHERE s.vid=:vid AND i.invname LIKE :needle " . $remarks;
$sth = $pdo->prepare($sql);
$sth->execute([':vid' => $user->vid, ':needle' => $sqlneedle]);
if ($sth->rowCount() > 0) {
echo '<h3>', _('Inventory'), "</h3>\n";
foreach ($sth->fetchAll() as $row) {
$out = rtrim($row['invname'] . ' ' . $row['model']);
// mark needle in result
$p0 = stripos($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, '&nbsp;';
echo '<a href="inventory.php?f=view&id=', $row['invid'], '"><i class="bi-eye"></i></a>';
echo "</p>\n";
}
}
// notes
$sql = "SELECT taskid, taskname "
. "FROM task "
. "WHERE taskname LIKE :needle AND (vid IS NULL OR vid=:vid)";
$sth = $pdo->prepare($sql);
$sth->execute([':needle' => $sqlneedle, ':vid' => $user->vid]);
if ($sth->rowCount() > 0) {
echo '<h3>', _('Tasks'), "</h3>\n";
foreach ($sth->fetchAll() as $row) {
// mark needle in result
$out = $row['taskname'];
$p0 = stripos($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, '&nbsp;';
echo '<a href="task.php?f=view&id=', $row['taskid'], '"><i class="bi-eye"></i></a>';
echo "</p>\n";
}
}
// notes
$sql = "SELECT noteid, annotation "
. "FROM note "
. "WHERE annotation LIKE :needle";
$sth = $pdo->prepare($sql);
$sth->execute([':needle' => $sqlneedle]);
if ($sth->rowCount() > 0) {
echo '<h3>', _('Annotations'), "</h3>\n";
foreach ($sth->fetchAll() as $row) {
// mark needle in result
$out = $row['annotation'];
$p0 = stripos($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, '&nbsp;';
echo '<a href="note.php?f=view&id=', $row['noteid'], '"><i class="bi-eye"></i></a>';
echo "</p>\n";
}
}
}
include 'footer.php';