-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptioncode.php
More file actions
executable file
·125 lines (104 loc) · 3.27 KB
/
exceptioncode.php
File metadata and controls
executable file
·125 lines (104 loc) · 3.27 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
<?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['exception_id'])) {
$exception_id = mysqli_real_escape_string($conn, $_GET['exception_id']);
$query = "SELECT * FROM exception WHERE id='$exception_id'";
$query_run = mysqli_query($conn, $query);
if (mysqli_num_rows($query_run) == 1) {
$exception = mysqli_fetch_array($query_run);
$res = [
'status' => 200,
'message' => 'החריגה נשלפה בהצלחה דרך מ.ז',
'data' => $exception
];
echo json_encode($res);
return;
} else {
$res = [
'status' => 404,
'message' => 'מ.ז החריגה לא נמצא'
];
echo json_encode($res);
return;
}
}
if (isset($_POST['update_exception'])) {
$exception_id = mysqli_real_escape_string($conn, $_POST['exception_id']);
$name = mysqli_real_escape_string($conn, $_POST['projectName']);
$description = mysqli_real_escape_string($conn, $_POST['description']);
$price = mysqli_real_escape_string($conn, $_POST['price']);
if ($name == NULL || $description == NULL || $price == NULL) {
$res = [
'status' => 422,
'message' => 'שדה חובה ריק'
];
echo json_encode($res);
return;
} else if (!is_numeric($price)) {
$res = [
'status' => 422,
'message' => 'המחיר חייב להיות מספר'
];
echo json_encode($res);
return;
}
$query = "UPDATE exception SET projectName='$name', description='$description', price='$price'
WHERE id='$exception_id'";
$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_exception'])) {
$exception_id = mysqli_real_escape_string($conn, $_POST['exception_id']);
$query = "DELETE FROM exception WHERE id='$exception_id'";
$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;
}
}