-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.php
273 lines (230 loc) Β· 9.08 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
session_start();
require_once('API/sqlog.php');
if (!isset($_SESSION["loggedin"]) && !$_SESSION["loggedin"] === true) {
header("Location: index.php");
exit;
}
$username = $_SESSION['username'];
$searchData = htmlspecialchars($_GET['data']);
if($searchData == null || $searchData == " "){
$resultCheck = 0;
$searchData = '?';
}else
{
$sql = "select * from `cases` where `Casenumber` like '%$searchData%' or `clientName` like '%$searchData%' or `phoneNumber` like '%$searchData%' or `Address` like '%$searchData%' or `ReciptNumber` like '%$searchData%' or `ProductSKU` like '%$searchData%' or `ProductSerial` like '%$searchData%' or `ProductName` like '%$searchData%' or `CaseDescription` like '%$searchData%' or `CreatedAt` like '%$searchData%' or `Status` like '%$searchData%' or `Createdby` like '%$searchData%' or `Supplier` like '%$searchData%' ";
$result = mysqli_query($mysqli, $sql);
$resultCheck = mysqli_num_rows($result);
$cases = mysqli_fetch_all($result, MYSQLI_ASSOC);
}
?>
<!DOCTYPE html>
<html lang="en" class="has-aside-left has-aside-mobile-transition has-navbar-fixed-top has-aside-expanded">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>WarrantyTrack</title>
<link rel="stylesheet" href="css/main.min.css">
<!-- Fonts -->
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">
</head>
<body>
<div id="app">
<?php include ("include/header.php"); ?>
<section class="section is-title-bar">
<div class="level">
<div class="level-left">
<div class="level-item">
<ul>
<li>Search</li>
<li><?php echo "'$searchData'" ?></li>
</ul>
</div>
</div>
<div class="level-right">
<div class="level-item">
<div class="buttons is-right">
<a href="createcase.php"class="button is-primary">
<span class="icon"><i class="mdi mdi-plus"></i></span>
<span>New case</span>
</a>
</div>
</div>
</div>
</div>
</section>
<section class="hero is-hero-bar">
<div class="hero-body">
<div class="level">
<div class="level-left">
<div class="level-item"><h1 class="title">
Found <?php echo $resultCheck ?> cases
</h1></div>
</div>
<div class="level-right" style="display: none;">
<div class="level-item"></div>
</div>
</div>
</div>
</section>
<div class="card has-table">
<header class="card-header">
<p class="card-header-title">
<span class="icon"><i class="mdi mdi-account-multiple"></i></span>
Cases found
</p>
<a href="#" id="openCasesButton" class="card-header-icon">
<span class="icon mdi mdi-minus"></span>
</a>
</header>
<div class="card-content1">
<div class="b-table has-pagination">
<div class="table-wrapper has-mobile-cards">
<?php
if($resultCheck <= 0 || $resultCheck == null) { ?>
<section class="section">
<div class="content has-text-grey has-text-centered">
<p>
<span class="icon is-large"><i class="mdi mdi-emoticon-sad mdi-48px"></i></span>
</p>
<p>Nothing's hereβ¦</p></div>
</section>
</tr>
<?php } else { ?>
<table id="openCasesTable" class="table is-fullwidth is-striped is-hoverable is-fullwidth">
<script>
//if the screen is mobile
if (window.matchMedia("(max-width: 768px)").matches) {
document.write("<thead>");
}else
{
document.write("<tbody>");
}
</script>
<tr>
<th></th>
<th>Name</th>
<th>Product name</th>
<th>Receipt number</th>
<th>Status</th>
<th>Supplier</th>
<th>Created</th>
<th>Case ID</th>
<th>Agent</th>
<th></th>
</tr>
<script>
//if the screen is mobile
if (window.matchMedia("(max-width: 768px)").matches) {
document.write("</thead>");
document.write("<tbody>");
}else
{
//document.write("</tbody>");
}
</script>
<?php
foreach ($cases as $case) {
if ($case['Casenumber'] == "$searchData") {
echo "<script>window.location.href = 'caseinspect.php?caseID=$searchData'; </script>";
}
?>
<tr>
<td class="is-image-cell">
<div class="image">
<img
src="https://ui-avatars.com/api/?background=random&size=256&name=<?php echo $case['clientName'] ?>&format=svg"
class="is-rounded">
</div>
</td>
<td data-label="Name"><?php echo htmlspecialchars($case['clientName']); ?>
</td>
<td data-label="ProductName"><?php echo htmlspecialchars($case['ProductName']); ?>
</td>
<td data-label="ReceiptNumber"><?php echo htmlspecialchars($case['ReciptNumber']); ?>
</td>
<td data-label="Status"><?php echo htmlspecialchars($case['Status']); ?>
</td>
<td data-label="Supplier"><?php echo htmlspecialchars($case['Supplier']); ?>
</td>
<td data-label="Created">
<?php $date = $case['CreatedAt'];
//format date to dd/mm/yyyy
$date = date('d/m/Y', strtotime($date)); ?>
<small class="has-text-grey is-abbr-like" title="Oct 25, 2020"><?php echo htmlspecialchars($date); ?></small>
</td>
<td data-label="Case ID"><?php echo htmlspecialchars($case['Casenumber']); ?>
</td>
<td data-label="Case ID"><?php echo htmlspecialchars($case['Createdby']); ?>
</td>
<td class="is-actions-cell">
<div class="buttons is-right">
<a class="button is-rounded is-small is-primary"
href="caseinspect.php?caseID=<?php echo htmlspecialchars($case['Casenumber']); ?>">
<span class="icon"><i class="mdi mdi-eye"></i></span> Cases found >>
</a>
</div>
</td>
</tr>
<?php
}
} ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php include ('include/footer.php'); ?>
</div>
<!-- Scripts below are for demo only -->
<script type="text/javascript" src="js/main.min.js"></script>
<!-- Icons below are for demo only. Feel free to use any icon pack. Docs: https://bulma.io/documentation/elements/icon/ -->
<link rel="stylesheet" href="https://cdn.materialdesignicons.com/4.9.95/css/materialdesignicons.min.css">
<script>
//minify table if user pressed the button
var openTable = document.getElementById("openCasesTable");
//add listener to openCasesButton
var openCasesButton = document.getElementById("openCasesButton");
openCasesButton.addEventListener("click", function() {
//check if table is hidden
if (openTable.classList.contains("is-hidden")) {
//if hidden, show it
//change button child to close icon
//change icon for the child
openCasesButton.firstElementChild.classList.remove("mdi-plus");
openCasesButton.firstElementChild.classList.add("mdi-minus");
openTable.classList.remove("is-hidden");
} else {
//if visible, hide it
openCasesButton.firstElementChild.classList.add("mdi-plus");
openCasesButton.firstElementChild.classList.remove("mdi-minus");
openTable.classList.add("is-hidden");
}
});
//table.style.display = "none";
const getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent;
const comparer = (idx, asc) => (a, b) => ((v1, v2) =>
v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2)
)(getCellValue(asc ? a : b, idx), getCellValue(asc ? b : a, idx));
// do the work...
document.querySelectorAll('th').forEach(th => th.addEventListener('click', (() => {
var table = th.closest('tbody');
Array.from(table.querySelectorAll('tr:nth-child(n+2)'))
.sort(comparer(Array.from(th.parentNode.children).indexOf(th), this.asc = !this.asc))
.forEach(tr => table.appendChild(tr) );
})));
</script>
<style>
table, th, td {
border: 1px solid black;
}
th {
cursor: pointer;
user-select: none;
}
</style>
</body>
</html>