-
Notifications
You must be signed in to change notification settings - Fork 0
/
Report-List.php
125 lines (104 loc) · 4.36 KB
/
Report-List.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
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
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
include 'db.php';
// Handle POST request for updating or deleting a report
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$reportId = $_POST['id_Report'];
if (isset($_POST['action']) && $_POST['action'] == 'delete') {
// SQL to delete report
$deleteSQL = "DELETE FROM Reports WHERE id_Report = $reportId";
if ($conn->query($deleteSQL) === TRUE) {
echo "<p>Report deleted successfully!</p>";
} else {
echo "<p>Error deleting report: " . $conn->error . "</p>";
}
} else {
// Update logic
$customer_name = $conn->real_escape_string($_POST['customer_name']);
$date_time = $_POST['date_time']; // Format and sanitize
$bill_amount = $_POST['bill_amount'];
$services = $conn->real_escape_string($_POST['services']);
$updateSQL = "UPDATE Reports SET customer_name = '$customer_name', date_time = '$date_time', bill_amount = '$bill_amount', services = '$services'
WHERE id_Report = $reportId";
if ($conn->query($updateSQL) === TRUE) {
echo "<p>Report updated successfully!</p>";
} else {
echo "<p>Error updating report: " . $conn->error . "</p>";
}
}
}
// Fetch all reports
$query = "SELECT * FROM Reports"; // Adjust the query as needed
$result = $conn->query($query);
?>
<!DOCTYPE html>
<html>
<head>
<title>View Reports</title>
<link rel="stylesheet" href="stylos.css">
<script>
function showEditForm(id) {
var form = document.getElementById('editForm-' + id);
form.style.display = form.style.display === 'none' ? 'block' : 'none';
}
function confirmUpdate() {
return confirm("Are you sure you want to update this report?");
}
function confirmDelete() {
return confirm("Are you sure you want to delete this report?");
}
</script>
</head>
<body>
<h2>All Reports</h2>
<button onclick="window.location.href='Report-form.php'">Back to Form</button>
<table>
<tr>
<th>Customer Name</th>
<th>Date Time</th>
<th>Bill Amount</th>
<th>Services</th>
<th>Actions</th>
</tr>
<?php
while ($row = $result->fetch_assoc()) {
$reportId = $row['id_Report'];
echo "<tr>";
echo "<td>" . htmlspecialchars($row['customer_name']) . "</td>";
echo "<td>" . htmlspecialchars($row['date_time']) . "</td>";
echo "<td>" . htmlspecialchars($row['bill_amount']) . "</td>";
echo "<td>" . htmlspecialchars($row['services']) . "</td>";
echo "<td>";
echo "<button onclick='showEditForm($reportId)'>Edit</button>";
echo "<form method='post' action='Report-List.php' onsubmit='return confirmDelete()' style='display:inline;'>";
echo "<input type='hidden' name='id_Report' value='$reportId'>";
echo "<input type='hidden' name='action' value='delete'>";
echo "<input type='submit' value='Remove'>";
echo "</form>";
echo '<form method="POST" action="Report-List.php">';
echo "<input type='hidden' name='id_Report' value='$reportId'>";
echo "</td>";
echo "</tr>";
// Inline Edit Form
echo "<tr id='editForm-$reportId' style='display:none;'>";
echo "<td colspan='5'>";
echo "<form action='Report-List.php' method='post' onsubmit='return confirmUpdate()'>";
echo "<input type='hidden' name='id_Report' value='$reportId'>";
echo "<input type='text' name='customer_name' value='" . htmlspecialchars($row['customer_name']) . "'>";
echo "<input type='datetime-local' name='date_time' value='" . htmlspecialchars($row['date_time']) . "'>";
echo "<input type='number' name='bill_amount' value='" . htmlspecialchars($row['bill_amount']) . "'>";
echo "<input type='text' name='services' value='" . htmlspecialchars($row['services']) . "'>";
echo "<input type='submit' value='Update'>";
echo "</form>";
echo "</td>";
echo "</tr>";
}
?>
</table>
<?php $conn->close(); ?>
</body>
</html>