-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeleteStep.php
More file actions
executable file
·60 lines (48 loc) · 1.86 KB
/
deleteStep.php
File metadata and controls
executable file
·60 lines (48 loc) · 1.86 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
<?php
// Connect to the database
$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($_POST['deleteStepId'])) {
$deleteStepId = $_POST['deleteStepId'];
// Fetch the paymentPercent for the step
$paymentPercentQuery = "SELECT paymentPercent FROM projectstep WHERE id='$deleteStepId'";
$paymentPercentResult = mysqli_query($conn, $paymentPercentQuery);
if ($paymentPercentResult) {
$row = mysqli_fetch_assoc($paymentPercentResult);
$paymentPercent = $row['paymentPercent'];
if ($paymentPercent == 0) {
// Perform the deletion query
$deleteQuery = "DELETE FROM projectstep WHERE id='$deleteStepId'";
if (mysqli_query($conn, $deleteQuery)) {
$response = array('status' => 200, 'message' => 'השלב נמחק בהצלחה');
} else {
$response = array('status' => 500, 'message' => 'שגיאה במחיקת השלב');
}
} else {
$response = array('status' => 422, 'message' => 'אי אפשר למחוק שלב שיש עבורו תשלום קיים');
}
} else {
$response = array('status' => 500, 'message' => 'שגיאה בשליפת אחוז תשלום');
}
echo json_encode($response);
}