-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_generic_edit.php
More file actions
115 lines (103 loc) · 5.39 KB
/
config_generic_edit.php
File metadata and controls
115 lines (103 loc) · 5.39 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
<?php
// config_generic_edit.php
include 'header.php';
include 'sidebar.php';
$config_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$update_message = '';
// Handle form submission for updating the configuration
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['config_id'])) {
$config_id = intval($_POST['config_id']);
$video = $_POST['video'];
$image = $_POST['image'];
$data_sheet = $_POST['data_sheet'];
$certificate = $_POST['certificate'];
$green_tick = $_POST['green_tick'];
$share_link = $_POST['share_link'];
$stmt = $conn->prepare("UPDATE config_generic SET video=?, image=?, data_sheet=?, certificate=?, green_tick=?, share_link=? WHERE id=?");
$stmt->bind_param("ssssssi", $video, $image, $data_sheet, $certificate, $green_tick, $share_link, $config_id);
if ($stmt->execute()) {
$update_message = "<div class='bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4'>Configuration updated successfully!</div>";
} else {
$update_message = "<div class='bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4'>Error updating record: " . $conn->error . "</div>";
}
$stmt->close();
}
// Fetch the current configuration data
$config = null;
if ($config_id > 0) {
$stmt = $conn->prepare("SELECT * FROM config_generic WHERE id = ?");
$stmt->bind_param("i", $config_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 1) {
$config = $result->fetch_assoc();
}
$stmt->close();
}
$conn->close();
?>
<!-- Main Content -->
<div class="bg-white p-8 rounded-lg shadow-md w-full">
<h4 class="text-2xl font-bold text-gray-700 mb-6">Edit Generic Configuration</h4>
<?php echo $update_message; ?>
<?php if ($config): ?>
<form action="config_generic_edit.php?id=<?php echo $config_id; ?>" method="post">
<input type="hidden" name="config_id" value="<?php echo $config['id']; ?>">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<!-- Form fields will go here -->
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Video</label>
<select name="video" class="shadow border rounded w-full py-2 px-3 text-gray-700">
<option value="Yes" <?php echo ($config['video'] == 'Yes') ? 'selected' : ''; ?>>Yes</option>
<option value="No" <?php echo ($config['video'] == 'No') ? 'selected' : ''; ?>>No</option>
</select>
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Image</label>
<select name="image" class="shadow border rounded w-full py-2 px-3 text-gray-700">
<option value="Yes" <?php echo ($config['image'] == 'Yes') ? 'selected' : ''; ?>>Yes</option>
<option value="No" <?php echo ($config['image'] == 'No') ? 'selected' : ''; ?>>No</option>
</select>
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Data Sheet</label>
<select name="data_sheet" class="shadow border rounded w-full py-2 px-3 text-gray-700">
<option value="Yes" <?php echo ($config['data_sheet'] == 'Yes') ? 'selected' : ''; ?>>Yes</option>
<option value="No" <?php echo ($config['data_sheet'] == 'No') ? 'selected' : ''; ?>>No</option>
</select>
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Certificate</label>
<select name="certificate" class="shadow border rounded w-full py-2 px-3 text-gray-700">
<option value="Yes" <?php echo ($config['certificate'] == 'Yes') ? 'selected' : ''; ?>>Yes</option>
<option value="No" <?php echo ($config['certificate'] == 'No') ? 'selected' : ''; ?>>No</option>
</select>
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Green Tick</label>
<input type="text" name="green_tick" value="<?php echo htmlspecialchars($config['green_tick']); ?>"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700">
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Share Link</label>
<input type="text" name="share_link" value="<?php echo htmlspecialchars($config['share_link']); ?>"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700">
</div>
</div>
<div class="mt-8 flex justify-end">
<a href="config_generic.php"
class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded mr-2">
Back to List
</a>
<button type="submit" class="bg-pink-600 hover:bg-pink-700 text-white font-bold py-2 px-4 rounded">
Save Changes
</button>
</div>
</form>
<?php else: ?>
<p class="text-red-500">Configuration not found.</p>
<?php endif; ?>
</div>
<?php
include 'footer.php';
?>