-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_sermon.php
319 lines (283 loc) · 11.8 KB
/
admin_sermon.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
include 'connections/db.php'; // Include your database connection file
session_start();
// Initialize variables
$modal_message = "";
$modal_status = false;
// Handle form submissions
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['add'])) {
// Create
$title = $_POST['title'];
$description = $_POST['description'];
$bible_verse = $_POST['bible_verse'];
// Handle image uploads
$image_folder = 'uploads/';
$main_image = '';
$thumbnail_image = '';
$secondary_image = '';
// Upload main image
if (isset($_FILES['main_image']) && $_FILES['main_image']['error'] == 0) {
$main_image_name = $_FILES['main_image']['name'];
$main_image_tmp_name = $_FILES['main_image']['tmp_name'];
$main_image_path = $image_folder . basename($main_image_name);
if (move_uploaded_file($main_image_tmp_name, $main_image_path)) {
$main_image = $main_image_path;
} else {
$modal_message = "Error uploading the main image.";
$modal_status = true;
}
}
// Upload thumbnail image
if (isset($_FILES['thumbnail_image']) && $_FILES['thumbnail_image']['error'] == 0) {
$thumbnail_image_name = $_FILES['thumbnail_image']['name'];
$thumbnail_image_tmp_name = $_FILES['thumbnail_image']['tmp_name'];
$thumbnail_image_path = $image_folder . basename($thumbnail_image_name);
if (move_uploaded_file($thumbnail_image_tmp_name, $thumbnail_image_path)) {
$thumbnail_image = $thumbnail_image_path;
} else {
$modal_message = "Error uploading the thumbnail image.";
$modal_status = true;
}
}
// Upload secondary image
if (isset($_FILES['secondary_image']) && $_FILES['secondary_image']['error'] == 0) {
$secondary_image_name = $_FILES['secondary_image']['name'];
$secondary_image_tmp_name = $_FILES['secondary_image']['tmp_name'];
$secondary_image_path = $image_folder . basename($secondary_image_name);
if (move_uploaded_file($secondary_image_tmp_name, $secondary_image_path)) {
$secondary_image = $secondary_image_path;
} else {
$modal_message = "Error uploading the secondary image.";
$modal_status = true;
}
}
// Insert into database if all images are uploaded successfully
if ($main_image && $thumbnail_image && $secondary_image) {
$stmt = $pdo->prepare("INSERT INTO sermons (title, description, bible_verse, main_image, thumbnail_image, secondary_image) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->execute([$title, $description, $bible_verse, $main_image, $thumbnail_image, $secondary_image]);
$modal_message = "Sermon added successfully!";
$modal_status = true;
}
} elseif (isset($_POST['delete'])) {
// Delete
$id = $_POST['sermon_id'];
$stmt = $pdo->prepare("DELETE FROM sermons WHERE id = ?");
$stmt->execute([$id]);
$modal_message = "Sermon deleted successfully!";
$modal_status = true;
}
}
// Fetch sermons for display
$stmt = $pdo->query("SELECT * FROM sermons");
$sermons = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Living One Young Lifers</title>
<link rel="icon" href="images/l1-removebg-preview.png"
type="image/x-icon" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link rel="stylesheet" href="assets/css/main.css" />
<noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript>
<style>
<style>
body {
font-family: Arial, sans-serif;
}
.video-link {
max-width: 150px; /* Set a max width for the link column */
overflow: hidden; /* Hide overflow */
white-space: nowrap; /* Prevent line breaks */
text-overflow: ellipsis; /* Add ellipsis for overflowed text */
display: inline-block; /* Allow the text overflow properties to work */
color: black;
}
.video-link a {
color: #007BFF; /* Change to a color that contrasts well */
text-decoration: none; /* Remove underline for better readability */
}
.video-link a:hover {
text-decoration: underline; /* Add underline on hover for emphasis */
color: #0056b3; /* Darker shade on hover */
}
.video-link:hover {
overflow: visible; /* Show full link on hover */
white-space: normal; /* Allow text to wrap */
background-color: #f9f9f9; /* Optional: Background for better visibility */
position: relative; /* Allow positioning */
border: 1px solid #ddd; /* Optional: Border for clarity */
}
/* Modal Styles */
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
padding-top: 100px;
}
.modal-content {
background-color: white;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 50%;
max-width: 400px;
text-align: center;
border-radius: 8px;
}
.modal-content p {
color: #333;
font-size: 18px;
padding-top: 40px;
}
.modal-button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
margin: 10px;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
}
.modal-button:hover {
background-color: #45a049;
}
.modal-button.cancel {
background-color: #f44336; /* Red color for cancel button */
}
.modal-button.cancel:hover {
background-color: #e53935; /* Darker red on hover */
}
</style>
</head>
<body class="landing is-preload">
<div id="page-wrapper">
<!-- Header -->
<header id="header" class="alt">
<h1><a href="index.html">L1</a></h1>
<nav id="nav">
<ul>
<li class="special">
<a href="#menu" class="menuToggle"><span>Menu</span></a>
<div id="menu">
<ul>
<li><a href="admin.php">Update Link</a></li>
<li><a href="ministry_edit.php">Edit Ministry</a></li>
<li><a href="admin_youth.php">Edit Youth</a></li>
<li><a href="organizational/edit.php">Edit Organizational</a></li>
<li><a href="logout.php">Log Out</a></li> <!-- Link to logout.php -->
</ul>
</div>
</li>
</ul>
</nav>
</header>
<!-- Admin Form to Add New Sermon -->
<section id="banner">
<div class="inner">
<h2>Admin - Add Testimony</h2>
</div>
</section>
<section>
<form method="POST" enctype="multipart/form-data">
<label for="title">Name:</label>
<input type="text" name="title" required />
<label for="description">Testimony of life:</label>
<textarea name="description" required></textarea>
<label for="bible_verse">Bible Verse:</label>
<input type="text" name="bible_verse" />
<label for="main_image">Upload Main Image:</label>
<input type="file" name="main_image" accept="image/*" required />
<label for="thumbnail_image">Upload Thumbnail Image:</label>
<input type="file" name="thumbnail_image" accept="image/*" required />
<label for="secondary_image">Upload Secondary Image:</label>
<input type="file" name="secondary_image" accept="image/*" required />
<button type="submit" name="add">Add Testimony</button>
</form>
</section>
<!-- Display List of Sermons for Admin Management -->
<section id="two" class="wrapper alt style2">
<table>
<thead>
<tr>
<th>Name</th>
<th>Testimony of life</th>
<th>Video Link</th>
<th>Bible Verse</th>
<th>Main Image</th>
<th>Thumbnail</th>
<th>Secondary Image</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($sermons)): ?>
<tr>
<td colspan="8" style="text-align: center; color: #e85154;">No sermons yet.</td>
</tr>
<?php else: ?>
<?php foreach ($sermons as $sermon): ?>
<tr>
<td><?php echo htmlspecialchars($sermon['title']); ?></td>
<td><?php echo htmlspecialchars($sermon['description']); ?></td>
<td class="video-link"><a href="<?php echo htmlspecialchars($sermon['video_link']); ?>"><?php echo htmlspecialchars($sermon['video_link']); ?></a></td>
<td><?php echo htmlspecialchars($sermon['bible_verse']); ?></td>
<td><img src="<?php echo htmlspecialchars($sermon['main_image']); ?>" alt="" width="50" /></td>
<td><img src="<?php echo htmlspecialchars($sermon['thumbnail_image']); ?>" alt="" width="50" /></td>
<td><img src="<?php echo htmlspecialchars($sermon['secondary_image']); ?>" alt="" width="50" /></td>
<td>
<form method="POST" style="display:inline;">
<input type="hidden" name="sermon_id" value="<?php echo $sermon['id']; ?>" />
<button type="submit" name="delete">Delete</button>
</form>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</section>
</div>
<!-- Modal Structure -->
<div id="modal" class="modal" style="<?php echo $modal_status ? 'display: flex;' : 'display: none;'; ?>">
<div class="modal-content">
<p><?php echo $modal_message; ?></p>
<button class="modal-button" onclick="this.parentElement.parentElement.style.display='none';">OK</button>
</div>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/jquery.scrolly.min.js"></script>
<script src="assets/js/browser.min.js"></script>
<script src="assets/js/breakpoints.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
<script>
// Handle modal display logic
var modal = document.getElementById('modal');
if ("<?php echo $modal_status ? 'true' : 'false'; ?>" === 'true') {
modal.style.display = 'flex';
}
// Close modal on click of any close button or OK button
document.querySelector('.modal-button').onclick = function() {
modal.style.display = 'none';
};
// Close modal if user clicks outside of the modal
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = 'none';
}
}
</script>
</body>
</html>