Repository navigation
Expand file tree
/
Copy pathapi.php
More file actions
60 lines (53 loc) · 2.06 KB
/
Copy pathapi.php
File metadata and controls
60 lines (53 loc) · 2.06 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
<?php
header('Content-Type: application/json');
require_once "classes/Binocom.php";
$binocom = new Binocom();
$action = $_GET['action'] ?? $_POST['action'] ?? '';
switch($action) {
case 'get_wards':
$lga_id = isset($_GET['lga_id']) ? (int)$_GET['lga_id'] : 0;
$wards = $binocom->getWardsByLga($lga_id);
echo json_encode(['status' => 'success', 'data' => $wards]);
break;
case 'get_polling_units':
$lga_id = isset($_GET['lga_id']) ? (int)$_GET['lga_id'] : 0;
$ward_id = isset($_GET['ward_id']) && $_GET['ward_id'] !== '' ? (int)$_GET['ward_id'] : null;
if ($ward_id !== null && $ward_id > 0) {
$pus = $binocom->getPollingUnitsByWard($lga_id, $ward_id);
} else if ($lga_id > 0) {
$pus = $binocom->getPollingUnitsByLga($lga_id);
} else {
$pus = $binocom->getAllPollingUnits();
}
echo json_encode(['status' => 'success', 'data' => $pus]);
break;
case 'get_pu_results':
$pu_id = isset($_GET['pu_id']) ? (int)$_GET['pu_id'] : 0;
$details = $binocom->getPollingUnitDetails($pu_id);
$results = $binocom->getPollingUnitResults($pu_id);
echo json_encode([
'status' => 'success',
'details' => $details,
'results' => $results
]);
break;
case 'get_lga_results':
$lga_id = isset($_GET['lga_id']) ? (int)$_GET['lga_id'] : 0;
$lgaDetails = $binocom->getLgaDetails($lga_id);
$summedResults = $binocom->getLgaSummedResults($lga_id);
$announcedResults = [];
if ($lgaDetails && isset($lgaDetails['lga_name'])) {
$announcedResults = $binocom->getAnnouncedLgaResults($lgaDetails['lga_name']);
}
echo json_encode([
'status' => 'success',
'lga' => $lgaDetails,
'summed_results' => $summedResults,
'announced_results' => $announcedResults
]);
break;
default:
echo json_encode(['status' => 'error', 'message' => 'Invalid action']);
break;
}
?>