-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckcode.php
More file actions
executable file
·125 lines (104 loc) · 3.13 KB
/
checkcode.php
File metadata and controls
executable file
·125 lines (104 loc) · 3.13 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['id'])) {
$id = mysqli_real_escape_string($conn, $_GET['id']);
$query = "SELECT * FROM checks WHERE id='$id'";
$query_run = mysqli_query($conn, $query);
if (mysqli_num_rows($query_run) == 1) {
$check = mysqli_fetch_array($query_run);
$res = [
'status' => 200,
'message' => 'הציק נשלף בהצלחה דרך המספר',
'data' => $check
];
echo json_encode($res);
return;
} else {
$res = [
'status' => 404,
'message' => 'מספר הציק לא נמצא'
];
echo json_encode($res);
return;
}
}
if (isset($_POST['update_check'])) {
$id = mysqli_real_escape_string($conn, $_POST['id']);
$forName = mysqli_real_escape_string($conn, $_POST['forName']);
$price = mysqli_real_escape_string($conn, $_POST['price']);
$checkDate = mysqli_real_escape_string($conn, $_POST['checkDate']);
if ($id == NULL || $forName == NULL || $price == NULL || $checkDate == 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 checks SET forName='$forName', price='$price', checkDate='$checkDate'
WHERE id='$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_check'])) {
$id = mysqli_real_escape_string($conn, $_POST['id']);
$query = "DELETE FROM checks WHERE id='$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;
}
}