-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_notices.php
More file actions
164 lines (141 loc) · 4.46 KB
/
send_notices.php
File metadata and controls
164 lines (141 loc) · 4.46 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
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
<?php
session_start();
// Check if fname and lname are set in the session
if (isset($_SESSION['fname']) && isset($_SESSION['lname'])) {
$fname = $_SESSION['fname'];
$lname = $_SESSION['lname'];
} else {
// Redirect to login if session variables are not set
header("Location: login.php");
exit();
}
// Database connection
$conn = new mysqli("localhost", "root", "", "erp");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Verify user status
$status = '';
$sql = "SELECT status FROM login_details WHERE fname = ? AND lname = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss", $fname, $lname);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$status = $row['status'];
} else {
echo "User not found.";
exit();
}
$stmt->close();
// Handle form submission for sending notices
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$topic = $_POST['topic'];
$content = $_POST['content'];
$date_time = date("Y-m-d H:i:s"); // Current date and time
if (!empty($topic) && !empty($content)) {
// Insert notice into the database
$sql = "INSERT INTO notices (fname, lname, status, topic, content, date_time) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssssss", $fname, $lname, $status, $topic, $content, $date_time);
if ($stmt->execute()) {
echo "<p class='success'>Notice sent successfully.</p>";
} else {
echo "<p class='error'>Error: " . $stmt->error . "</p>";
}
$stmt->close();
} else {
echo "<p class='error'>Please fill out all fields.</p>";
}
}
// Close database connection
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>::: Send Notice :::</title>
<style>
/* Frutiger Aero Styling */
body {
font-family: 'Segoe UI', Tahoma, sans-serif;
background: url("notices.png");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
color: #333;
margin: 0;
padding: 0;
}
h1 {
text-align: center;
color: #0078D7;
text-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
margin-top: 20px;
}
form {
background: rgba(255, 255, 255, 0.85);
margin: 30px auto;
padding: 20px;
border-radius: 12px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
max-width: 500px;
color: #246b9c;
}
form label {
font-weight: bold;
display: block;
margin-bottom: 8px;
}
form input, form textarea, form button {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #bcd4e6;
border-radius: 8px;
font-size: 16px;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}
form textarea {
resize: none;
}
form button {
background-color: #4fa3d5;
color: white;
font-weight: bold;
cursor: pointer;
transition: background-color 0.3s ease;
}
form button:hover {
background-color: #246b9c;
}
.success {
text-align: center;
color: #28a745;
font-weight: bold;
}
.error {
text-align: center;
color: #dc3545;
font-weight: bold;
}
</style>
</head>
<body>
<br>
<br>
<h1>Send Notice</h1>
<form method="POST" action="">
<label for="topic">Notice Topic:</label>
<input type="text" style="width: 474px;" id="topic" name="topic" placeholder="Enter the notice topic" required>
<label for="content">Notice Content:</label>
<textarea id="content" style="width: 474px;" name="content" rows="5" placeholder="Enter the notice content" required></textarea>
<button type="submit">Send Notice</button>
</form>
</body>
</html>