This repository has been archived by the owner on Jan 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
143 lines (103 loc) · 3.46 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
require_once('sys/functions/general.php');
require_once('sys/functions/fetchers.php');
if (isset($_GET['search']))
$pagetitle = 'Suchergebnisse';
else
$pagetitle = 'Suche';
returnHeader($pagetitle, 'Suchen');
?>
<h1><?php echo $pagetitle ?></h1>
<?php
$search_name = (isset($_GET['name']) ? $_GET['name'] : '');
$search_cats = (isset($_GET['cats']) ? json_decode($_GET['cats']) : array());
$search_user = (isset($_GET['user']) ? $_GET['user'] : '');
if (!$search_user == '')
$search_own = ($_SESSION['user_name'] == $search_user ? true : false);
else
$search_own = false;
?>
<div class="search-topbar need-clearfix">
<form action="search_send.php" method="post">
<div class="option-group">
Suchbegriff
<input type="text" name="name" required="required" value="<?php echo (isset($_GET['name']) ? $_GET['name'] : '') ?>">
</div>
<div class="option-group">
Kategorie
<div class="search-cats">
<label>
<input type="checkbox" id="allcats" name="cats[]" value="0">Alle Kategorien
</label>
<?php
$cats = fetch_categories();
foreach ($cats as $this_cat) {
?>
<label>
<input type="checkbox" name="cats[]" value="<?php echo $this_cat['id'] . '"' . (in_array($this_cat['id'], $search_cats) ? ' checked="checked"' : '') . '>' . $this_cat['name'] ?>
</label>
<?php
}
?>
</div>
</div>
<div class="option-group">
<button>Suchen</button>
</div>
</form>
</div>
<?php
$products = fetch_products($search_name, $search_cats, $search_user);
echo count($products) . ' Ergebnisse für <b>' . (empty($search_name) ? '<em>alles</em>' : $search_name) . '</b> in <b>';
$search_cats_out = '';
$a = 0;
if (!empty($search_cats)) {
foreach ($cats as $this_cat) {
if (in_array($this_cat['id'], $search_cats)) {
if ($a != 0) {
$search_cats_out .= ', ';
}
$search_cats_out .= $this_cat['name'];
$a++;
}
}
}
echo (empty($search_cats_out) ? '<em>überall</em>' : $search_cats_out) . '</b>';
if (!empty($search_user)) {
echo ' von <b>' . fetch_user($search_user)['name'] . '</b>';
}
?>
<button type="button" onclick="$('#debug').slideToggle('fast');">Show/hide Debugging Infos</button>
<div id="debug" style="display: none;">
<textarea readonly="readonly" style="width: 100%; height: 500px">
<?php echo json_encode($products, JSON_PRETTY_PRINT); ?>
</textarea>
</div>
<ul class="productlist">
<?php
foreach ($products as $this_product) {
?>
<li class="need-clearfix">
<div class="prod_imgbox">
<a href="product.php?id=<?php echo $this_product['id'] ?>">
<img src="sys/img/products/<?php echo $this_product['id'] ?>.png">
</a>
</div>
<div class="prod_detailbox">
<a class="prod-name" href="product.php?id=<?php echo $this_product['id'] ?>"><?php echo $this_product['name'] ?></a>
<span class="prod-price"><?php echo number_format($this_product['price'], 2, ',', '.') ?> €</span>
<div class="prod-infos">
<?php
echo 'von <a href=\'search.php?search&user=' . $this_product['user_id'] . '\'>' . $this_product['user_name'] . '</a> / ';
echo 'in <a href=\'search.php?search&cats=["' . $this_product['cat_id'] . '"]\'>' . $this_product['cat_name'] . '</a>'?>
</div>
<div class="prod-desc"><?php echo $this_product['description'] ?></div>
</div>
</li>
<?php
}
?>
</ul>
<?php
returnFooter();
?>