-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared_links_edit.php
More file actions
126 lines (113 loc) · 5.9 KB
/
shared_links_edit.php
File metadata and controls
126 lines (113 loc) · 5.9 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
126
<?php
// shared_links_edit.php
include 'header.php';
include 'sidebar.php';
$link_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$update_message = '';
// Handle form submission for updating the link
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['link_id'])) {
$link_id = intval($_POST['link_id']);
$customer_id = $_POST['customer_id'];
$video = $_POST['video'];
$image = $_POST['image'];
$sheet = $_POST['sheet'];
$certificate = $_POST['certificate'];
$status = $_POST['status'];
$stmt = $conn->prepare("UPDATE shared_links SET customer_id=?, video=?, image=?, sheet=?, certificate=?, status=? WHERE id=?");
$stmt->bind_param("isssssi", $customer_id, $video, $image, $sheet, $certificate, $status, $link_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'>Link 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 link data
$link = null;
if ($link_id > 0) {
$stmt = $conn->prepare("SELECT * FROM shared_links WHERE id = ?");
$stmt->bind_param("i", $link_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 1) {
$link = $result->fetch_assoc();
}
$stmt->close();
}
// Fetch all customers for the dropdown
$customers_result = $conn->query("SELECT id, customer_name FROM customers WHERE status = 'Enable' ORDER BY customer_name");
?>
<!-- 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 Shared Link</h4>
<?php echo $update_message; ?>
<?php if ($link): ?>
<form action="shared_links_edit.php?id=<?php echo $link_id; ?>" method="post">
<input type="hidden" name="link_id" value="<?php echo $link['id']; ?>">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Customer</label>
<select name="customer_id" class="shadow border rounded w-full py-2 px-3 text-gray-700">
<?php while ($customer = $customers_result->fetch_assoc()): ?>
<option value="<?php echo $customer['id']; ?>" <?php echo ($link['customer_id'] == $customer['id']) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($customer['customer_name']); ?>
</option>
<?php endwhile; ?>
</select>
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Status</label>
<select name="status" class="shadow border rounded w-full py-2 px-3 text-gray-700">
<option value="ENABLED" <?php echo ($link['status'] == 'ENABLED') ? 'selected' : ''; ?>>Enabled
</option>
<option value="DISABLED" <?php echo ($link['status'] == 'DISABLED') ? 'selected' : ''; ?>>Disabled
</option>
</select>
</div>
<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 ($link['video'] == 'YES') ? 'selected' : ''; ?>>Yes</option>
<option value="NO" <?php echo ($link['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 ($link['image'] == 'YES') ? 'selected' : ''; ?>>Yes</option>
<option value="NO" <?php echo ($link['image'] == 'NO') ? 'selected' : ''; ?>>No</option>
</select>
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Sheet</label>
<select name="sheet" class="shadow border rounded w-full py-2 px-3 text-gray-700">
<option value="YES" <?php echo ($link['sheet'] == 'YES') ? 'selected' : ''; ?>>Yes</option>
<option value="NO" <?php echo ($link['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 ($link['certificate'] == 'YES') ? 'selected' : ''; ?>>Yes</option>
<option value="NO" <?php echo ($link['certificate'] == 'NO') ? 'selected' : ''; ?>>No</option>
</select>
</div>
</div>
<div class="mt-8 flex justify-end">
<a href="shared_links.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">Shared link not found.</p>
<?php endif; ?>
</div>
<?php
$conn->close();
include 'footer.php';
?>