-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
158 lines (136 loc) · 4.32 KB
/
index.php
File metadata and controls
158 lines (136 loc) · 4.32 KB
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
<?php
date_default_timezone_set('America/Chicago');
require __DIR__ . '/vendor/autoload.php';
$klein = new \Klein\Klein();
$klein->respond(function ($request, $response, $service, $app) {
$loader = new Twig_Loader_Filesystem(__DIR__ . '/templates');
$twig = new Twig_Environment($loader);
$service->twig = $twig;
$app->register('db', function () {
return new PDO('mysql:host=127.0.0.1;dbname=globalhackv', 'globalhackv', 'globalhack');
});
});
$klein->respond('GET', '/', function ($request, $response, $service, $app) {
return $service->twig->render('home.twig');
});
$klein->respond('GET', '/resources', function ($request, $response, $service, $app) {
return $service->twig->render('resources.twig');
});
$klein->respond('GET', '/averages', function ($request, $response, $service, $app) {
return $service->twig->render('averages.twig');
});
$klein->respond('GET', '/averages.json', function ($request, $response, $service, $app) {
$db = $app->db;
$stmt = $db->prepare('select `Municipali`, `X`, `Y`, avg(`waiting_time`) as `avg`
from citations
inner join locations on citations.court_location = upper(locations.`Municipali`)
where court_location <> \'\'
group by court_location
order by `avg` asc');
$stmt->execute();
return $response->json($stmt->fetchAll(PDO::FETCH_ASSOC));
});
$klein->respond('POST', '/search', function ($request, $response, $service, $app) {
if (!$request->first_name || !$request->last_name) {
return $response->redirect('/');
}
$birthday = "{$request->birth['year']}-{$request->birth['month']}-{$request->birth['day']}";
$date = strtotime($birthday);
$db = $app->db;
$stmt = $db->prepare('SELECT
violations.citation_number,
violation_number,
citation_date,
first_name,
last_name,
date_of_birth,
defendant_address,
defendant_city,
defendant_state,
drivers_license_number,
court_date,
court_location,
court_address,
violation_description,
warrant_status,
warrant_number,
status,
status_date,
fine_amount,
court_cost,
X,
Y,
`Municipal Website` AS `website`,
`Court Clerk Phone Number` AS `phone`,
`Online Payment System Provider` AS `payment`
FROM
citations
INNER JOIN
violations ON
citations.citation_number = violations.citation_number
INNER JOIN
locations ON
court_address = locations.address
JOIN
munipality ON
court_location = UPPER(Municipality)
WHERE
`last_name` LIKE :name AND
`date_of_birth` = :birthday AND
(`drivers_license_number` = \'\' OR `drivers_license_number` LIKE :license)
HAVING
`defendant_city` != \'\' AND
`defendant_state` != \'\' AND
`drivers_license_number` != \'\' AND
`court_address` != \'\' AND
`defendant_address` != \'\'
ORDER BY
`status_date` DESC');
$name = "%{$request->last_name}%";
$stmt->bindParam(':name', $name);
$stmt->bindParam(':birthday', date('Y-m-d', $date));
$license = $request->drivers_license_id;
$stmt->bindParam(':license', $license);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($results) === 0) {
return $service->twig->render('noresults.twig', array(
'first' => $request->first_name,
'last' => $request->last_name,
'birthday' => date('Y-m-d', $date),
'drivers_license_id' => $request->drivers_license_id
));
}
$info = new stdClass();
foreach ($results as $row) {
if ($row['status'] == 'FTA WARRANT ISSUED') {
if (!property_exists($info, 'warrant')) $info->warrant = array();
$info->warrant[] = array(
'violation' => $row['violation_number'],
'citation' => $row['citation_number']
);
}
if ($row['status'] == 'CONT FOR PAYMENT') {
if (!property_exists($info, 'fine')) $info->fine = array();
$info->fine[] = array(
'amount' => $row['fine_amount'],
'violation' => $row['violation_number'],
'citation' => $row['citation_number'],
'violation_description' => $row['violation_description'],
'fine_amount' => $row['fine_amount'],
'court_cost' => $row['court_cost']
);
}
if ($row['fine_amount'] != '') {
if (!property_exists($info, 'fines_owed')) $info->fines_owed = 0.0;
if (!property_exists($info, 'fees_owed')) $info->fees_owed = 0.0;
$info->fines_owed = ((float) substr($row['fine_amount'], 1)) + $info->fines_owed;
$info->fees_owed = ((float) substr($row['court_cost'], 1)) + $info->fees_owed;
}
}
return $service->twig->render('search.twig', array(
'results' => $results,
'info' => $info
));
});
$klein->dispatch();