-
Notifications
You must be signed in to change notification settings - Fork 0
/
registerservicecenters.php
48 lines (45 loc) · 1.69 KB
/
registerservicecenters.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
<?php
/**
* Created by PhpStorm.
* User: root
* Date: 6/5/17
* Time: 10:58 PM
*/
require_once 'include/DB_Function.php';
$db = new DB_Functions();
// response array
$response = array("error" => false);
if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['phone']) && isset($_POST['address']) && isset($_POST['company'])) {
// receiving post parameters
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$company = $_POST['company'];
$latitude = $_POST['lat'];
$longitude = $_POST['lon'];
// check if a registration already exists with that registration number
if ($db->isServiceCenter($name, $phone, $email)){
// service center already registered
$response["error"] = true;
$response["error-msg"] = "A service center is already registered with that name, phone and email.";
echo json_encode($response);
} else {
// register the service center
if ($service_center = $db->createServiceCenter($name, $email, $phone, $address, $company, $latitude, $longitude)) {
// successfully registered
$response["error"] = false;
$response["service_center"] = $service_center;
$response["message"] = "The service center was registered successfully.";
echo json_encode($response);
} else {
// some error registering the car
$response["error"] = true;
$response["error-msg"] = "Error! Please try again later.";
echo json_encode($response);
}
}
} else {
$response["error"] = true;
$response["error-msg"] = "Please enter all the details!";
}