-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarcode.php
More file actions
executable file
·129 lines (108 loc) · 3.65 KB
/
carcode.php
File metadata and controls
executable file
·129 lines (108 loc) · 3.65 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
<?php
$conn = require __DIR__ . "/database.php";
session_start();
if (!isset($_SESSION["email"])) {
// Redirect to the login page if the user is not logged in
header('Location: index.php');
exit();
}
$email = mysqli_real_escape_string($conn, $_SESSION['email']);
$query = "SELECT * FROM account WHERE email='$email'";
$result = mysqli_query($conn, $query);
if ($row = mysqli_fetch_assoc($result)) {
$name = $row['userName'];
$password = $row['password'];
$phone = $row['phoneNum'];
$role = $row['role'];
} else {
// Handle case where email is not found in the database
$name = '';
$password = '';
$phone = '';
$role = '';
}
if (isset($_GET['car_number'])) {
$car_number = mysqli_real_escape_string($conn, $_GET['car_number']);
$query = "SELECT * FROM car WHERE number='$car_number'";
$query_run = mysqli_query($conn, $query);
if (mysqli_num_rows($query_run) == 1) {
$car = mysqli_fetch_array($query_run);
$res = [
'status' => 200,
'message' => 'הרכב/ הכלי נשלף בהצלחה דרך מספרו',
'data' => $car
];
echo json_encode($res);
return;
} else {
$res = [
'status' => 404,
'message' => 'מ.ז הרכב לא נמצא'
];
echo json_encode($res);
return;
}
}
if (isset($_POST['update_car'])) {
$car_number = mysqli_real_escape_string($conn, $_POST['car_number']);
$type = mysqli_real_escape_string($conn, $_POST['type']);
$year = mysqli_real_escape_string($conn, $_POST['year']);
$color = mysqli_real_escape_string($conn, $_POST['color']);
$testDate = mysqli_real_escape_string($conn, $_POST['testDate']);
$insuranceDate = mysqli_real_escape_string($conn, $_POST['insuranceDate']);
$careDate = mysqli_real_escape_string($conn, $_POST['careDate']);
$fuelType = mysqli_real_escape_string($conn, $_POST['fuelType']);
if ($type == NULL || $year == NULL || $color == NULL || $testDate == NULL || $insuranceDate == NULL || $careDate == NULL || $fuelType == NULL) {
$res = [
'status' => 422,
'message' => 'שדה חובה ריק'
];
echo json_encode($res);
return;
} else if ((!is_numeric($year)) || $year < 1900 || $year > date("Y")) {
$res = [
'status' => 422,
'message' => 'שנת ייצור לא חוקית'
];
echo json_encode($res);
return;
}
$query = "UPDATE car SET type='$type', year='$year', color='$color', testDate='$testDate', insuranceDate='$insuranceDate', careDate='$careDate', fuelType='$fuelType'
WHERE number='$car_number'";
$query_run = mysqli_query($conn, $query);
if ($query_run) {
$res = [
'status' => 200,
'message' => 'הרכב עודכן בהצלחה'
];
echo json_encode($res);
return;
} else {
$res = [
'status' => 500,
'message' => 'הרכב לא עודכן'
];
echo json_encode($res);
return;
}
}
if (isset($_POST['delete_car'])) {
$car_number = mysqli_real_escape_string($conn, $_POST['car_number']);
$query = "DELETE FROM car WHERE number='$car_number'";
$query_run = mysqli_query($conn, $query);
if ($query_run) {
$res = [
'status' => 200,
'message' => 'הרכב נמחק בהצלחה'
];
echo json_encode($res);
return;
} else {
$res = [
'status' => 500,
'message' => 'הרכב לא נמחק'
];
echo json_encode($res);
return;
}
}