Selaa lähdekoodia

Add online store search ( issue #8 )

master
Skylar Ittner 1 vuosi sitten
vanhempi
commit
d180061bf8
3 muutettua tiedostoa jossa 56 lisäystä ja 2 poistoa
  1. 3
    0
      public/index.php
  2. 7
    2
      public/parts/nav.php
  3. 46
    0
      public/parts/search.php

+ 3
- 0
public/index.php Näytä tiedosto

@@ -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";

+ 7
- 2
public/parts/nav.php Näytä tiedosto

@@ -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>

+ 46
- 0
public/parts/search.php Näytä tiedosto

@@ -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>

Loading…
Peruuta
Tallenna