-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelann.php
More file actions
71 lines (61 loc) · 3.36 KB
/
delann.php
File metadata and controls
71 lines (61 loc) · 3.36 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
<?php
session_start();
include "db_conn.php";
include 'db_pdo.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
function validate($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$id = validate($_POST['id']);
$stmt = $conn->prepare("SELECT Date FROM announcement WHERE ID = ?");
$stmt->bind_param("s", $id);
$stmt->execute();
$result = $stmt->get_result();
$dateRow = $result->fetch_assoc();
$date = $dateRow['Date'];
$formudate = DateTime::createFromFormat('F j, Y', $date);
$formattedDate = $formudate->format('Y-m-d');
$delRestrict = $conn->prepare("DELETE FROM restriction WHERE Date = ?");
$delRestrict->bind_param("s", $formattedDate);
$delRestrictexe = $delRestrict->execute();
$delAnnounce = $conn->prepare("DELETE FROM announcement WHERE ID = ?");
$delAnnounce->bind_param("s", $id);
$delAnnounceexe = $delAnnounce->execute();
if ($delAnnounceexe && $delRestrictexe) {
echo '<p class="success">Announcement Succesfully Deleted</p>';
$announcement = $ponn->query("SELECT * FROM announcement ORDER BY ID DESC");
if ($announcement->rowCount() <= 0) {
echo '<div class="todo-item">';
echo ' <a href="" id="remove-to-do" class="removee-to-do">N/A</a> <br>';
echo ' <div class="row-announce">';
echo ' <div class="empty">';
echo ' <img src="resources/default.jpeg">';
echo ' </div>';
echo ' <div class="post-ann">';
echo ' <h2>There is no announcement currently</h2>';
echo ' <small>Note: If you want to add announcement click the button "create announcement" in the upper right corner</small>';
echo ' </div>';
echo ' </div>';
echo '</div>';
} else {
while ($fetchannounce = $announcement->fetch(PDO::FETCH_ASSOC)) {
echo '<div class="todo-item">';
echo ' <button onclick="DeleteAnnouncement(' . $fetchannounce['ID'] . ')" id="remove-to-do" class="removee-to-do">' . $fetchannounce['Date'] . '</button> <br>';
echo ' <div class="row-announce">';
echo ' <div class="empty">';
echo ' <img src="resources/cedlogo.png">';
echo ' </div>';
echo ' <div class="post-ann">';
echo ' <h2 style="font-weight: 700; font-size: 18px;">' . $fetchannounce['Title'] . '</h2>';
echo ' <h2>' . $fetchannounce['Description'] . '</h2>';
echo ' <small>- ' . $fetchannounce['Author'] . '</small>';
echo ' </div>';
echo ' </div>';
echo '</div>';
}
}
}
}