-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.php
81 lines (66 loc) · 1.77 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
<?php
require 'includes/header.php';
$template = new Smarty;
$browser_title = 'Virginia Businesses';
$query = filter_var($_GET['q'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
/*
* If no search query has been passed in the URL
*/
if (!isset($query) || empty($query))
{
header($_SERVER['SERVER_PROTOCOL'] . " 400 Bad Request", true, 400);
exit();
}
/*
* Query our own API
*/
$api_url = API_URL . '/api/search/' . $query;
$results_json = get_content($api_url);
$results = json_decode($results_json);
if ($results === FALSE)
{
header($_SERVER['SERVER_PROTOCOL'] . " 500 Internal Server Error", true, 500);
exit();
}
if ( !is_array($results) || count($results) == 0 )
{
$page_body = '
<div class="row">
<div class="card warning">
<h3>No results found</h3>
<p>Please try another search</p>
</div>
</div>';
}
else
{
$page_body = '
<article>
<table>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Inc. Date</th>
<th scope="col">Status</th>
</tr>
</thead>
<tbody>';
/*
* Display a table of all results values
*/
foreach ($results as $business)
{
$page_body .= '<tr>
<td><a href="/business/' . $business->EntityID . '">' . $business->Name . '</a></td>
<td>' . $business->IncorpDate . '</td>
<td>' . $business->Status . '</td>
</tr>';
}
$page_body .= '
</tbody>
</table>';
}
$template->assign('page_body', $page_body);
$template->assign('page_title', $page_title);
$template->assign('browser_title', $browser_title);
$template->display('includes/templates/simple.tpl');