Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit 8148afa

Browse files
author
Samuel Janda
committed
Correcting some introduced issues.
1 parent a908a56 commit 8148afa

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

controller/extract.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
$response->send();
3636
exit();
3737
}
38+
$data = str_replace(" ", "+", $_GET['data']);
3839

3940
if ($_SERVER['CONTENT_TYPE'] !== 'application/json') {
4041
$response = new Response();
@@ -73,7 +74,7 @@
7374
$extract = new Extract();
7475
$extract->location->setID(intval($_GET['id']));
7576
$extract->location->setAuthContact($json_data->authName);
76-
if (!$extract->detectMode($_GET['data'])) {
77+
if (!$extract->detectMode($data)) {
7778
$response = new Response();
7879
$response->setHttpStatusCode(400);
7980
$response->setSuccess(false);
@@ -112,7 +113,7 @@
112113

113114
if ($extract->getMode() === Extract::MODE_PHONE) {
114115
$visitor = new Visitor();
115-
$visitor->setPhoneNumber($_GET['data']);
116+
$visitor->setPhoneNumber($data);
116117

117118
$query_phone = $visitor->getPhoneNumber();
118119
$query = $writeDB->prepare("SELECT a.id as id, a.business_name as `location`, COUNT(c.phone) as `count` FROM accounts a, contacts c WHERE c.phone = :ph AND a.id = c.account_id GROUP BY `location`");
@@ -142,7 +143,7 @@
142143
$response->send();
143144
exit();
144145
}
145-
} else {
146+
} elseif ($extract->getMode() === Extract::MODE_DATE) {
146147
$query_date = $extract->getDate();
147148
$query = $writeDB->prepare("SELECT `name`, `phone`, `arr`, `dep` FROM contacts WHERE account_id =:id AND DATE(arr)=DATE(:d)");
148149
$query->bindParam(":id", $query_id, PDO::PARAM_STR);
@@ -171,6 +172,14 @@
171172
$response->setHttpStatusCode(200);
172173
$response->setSuccess(true);
173174
$response->addMessage("Request received successfully.");
175+
$response->addMessage("Data: {$data}");
176+
$response->send();
177+
exit();
178+
} else {
179+
$response = new Response();
180+
$response->setHttpStatusCode(401);
181+
$response->setSuccess(false);
182+
$response->addMessage("Error: extraction request type not identified.");
174183
$response->send();
175184
exit();
176185
}
@@ -195,6 +204,8 @@
195204
$response->setHttpStatusCode(400);
196205
$response->setSuccess(false);
197206
$response->addMessage("API Exception: " . $e->getMessage());
207+
$response->addMessage("Data: {$data} - length: " . strlen($data));
208+
$response->addMessage("Mode: " . $extract->getMode());
198209
$response->send();
199210
exit();
200211
} catch (Exception $e) {

model/Config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static function ValidatePhoneNumber(string $pn): bool
1616
if (strlen($pn) !== 12) return false; //Phone number length confirmed
1717
if (substr($pn, 0, 3) !== "+61") return false; //Australian telephone number confirmed
1818
$vb = intval(substr($pn, 4, 2)); //substring to be evaluated against valid number ranges
19+
if (in_array(substr($pn, 3, 1), ["0", "1", "5", "6", "9"])) return false; //Invalid area codes eliminated
1920
if (substr($pn, 3, 1) === "2" && ($vb < 37 && $vb !== 33)) return false; //NSW/ACT Number confirmed
2021
if (substr($pn, 3, 1) === "3" && ($vb < 32 || $vb > 34) && ($vb < 40 || $vb > 67 && ($vb !== 46 || $vb !== 60 || $vb !== 66)) && $vb < 70) return false; //VIC/TAS Number confirmed
2122
if (substr($pn, 3, 1) === "7" && ($vb < 20 && $vb > 58 && ($vb !== 50 || $vb !== 51)) && $vb !== 70 && ($vb < 75 || $vb > 77) && $vb !== 79) return false; //QLD Number confirmed

model/Extract.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getMode() {
3838
}
3939

4040
public function detectMode(string $data):bool {
41-
if (substr($data, 0, 1) === "+") {
41+
if (strlen($data) === 12) {
4242
$this->mode = self::MODE_PHONE;
4343
return true;
4444
}
@@ -59,9 +59,7 @@ public function getDate() {
5959

6060
public function addRow(string $name, string $phone, string $arr, string $dep):bool {
6161
$visitor = new Visitor();
62-
$visitor->setName($name);
63-
$visitor->setPhoneNumber($phone);
64-
array_push($this->data_table, new Visit($visitor->getName(), $visitor->getPhoneNumber(), $arr, $dep));
62+
array_push($this->data_table, new Visit($name, $phone, $arr, $dep));
6563
return true;
6664
}
6765

model/Visitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function setName(string $name):bool {
5151
}
5252

5353
public function setPhoneNumber(string $pn):bool {
54-
if (is_null($pn) || !Config::ValidatePhoneNumber($pn)) throw new APIException("Phone number must not be null and must be a string in the format +61xxxxxxxxx.");
54+
if (is_null($pn) || !Config::ValidatePhoneNumber($pn)) throw new APIException("Phone number must not be null and must be a string in the format +61xxxxxxxxx. For example, if your telephone number is 0412-123-987 you would enter +61412123987.");
5555
$this->_phone_number = $pn;
5656
return true;
5757
}

0 commit comments

Comments
 (0)