Add online store search ( issue #8 )

master
Skylar Ittner 6 лет назад
Родитель 819ce856a4
Коммит d180061bf8

@ -32,6 +32,9 @@ if (isset($_GET['page'])) {
$page = "404";
}
break;
case "search":
$page = "search";
break;
case "item":
if (isset($_GET['id']) && $binstack->has('items', ['itemid' => $_GET['id']])) {
$page = "item";

@ -36,9 +36,14 @@ foreach ($cats as $c) {
</div>
</li>
</ul>
<form class="form-inline ml-3">
<form class="form-inline ml-3" method="GET">
<div class="input-group">
<input class="form-control" type="search" placeholder="Search" aria-label="Search">
<input type="hidden" name="page" value="search" />
<input name="q" class="form-control" type="search" placeholder="Search" aria-label="Search" value="<?php
if (isset($_GET['q'])) {
echo htmlspecialchars($_GET['q']);
}
?>">
<div class="input-group-addon">
<button class="btn btn-success" type="submit"><i class="fas fa-search"></i> <span class="d-none d-md-inline">Search</span></button>
</div>

@ -0,0 +1,46 @@
<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
if (!defined('NICKELBOX')) {
die("Direct access denied.");
}
$query = $_GET['q'];
$dbitems = $binstack->select('items', 'itemid', [
'AND' => [
'price[>]' => 0,
'OR' => [
'name[~]' => $query,
'code1' => $query,
'code2' => $query,
'text1[~]' => $query
]
], 'LIMIT' => 20]);
$items = [];
foreach ($dbitems as $i) {
$items[] = new Item($i);
}
?>
<div class="container mt-4">
<h1 class="display-4">Search <span class="h3 ml-3 d-none"><?php echo htmlspecialchars($query); ?></span></h1>
<div class="list-group list-group-flush">
<?php
if (count($items) > 0) {
foreach ($items as $i) {
echo RenderItem::line($i);
}
} else {
?>
<p>No results found for <?php echo htmlspecialchars($query); ?>.</p>
<?php
}
?>
</div>
</div>
Загрузка…
Отмена
Сохранить