-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperator_dashboard.php
355 lines (317 loc) · 12 KB
/
operator_dashboard.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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<?php
session_start();
require_once 'db_connection.php';
require_once 'Message.php';
use App\Message;
// Authentication check for operators
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'operator') {
header("Location: login.php?error=access_denied");
exit();
}
// Handle message sending
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['send_message'])) {
$receiver_id = $_POST['receiver_id'];
$message_text = $_POST['message'];
$message = new Message($conn);
if ($message->sendMessage($_SESSION['user_id'], $receiver_id, $message_text)) {
$success_message = "Message sent successfully!";
} else {
$error_message = "Failed to send message.";
}
}
$message = new Message($conn);
$operatorId = $_SESSION['user_id'];
$messages = $message->getMessages($operatorId);
// Pagination Setup
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$limit = 10;
$offset = ($page - 1) * $limit;
$page_title = 'Operator Dashboard';
include 'templates/operator_header.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $page_title; ?></title>
<style>
.dashboard-content {
padding: 20px;
max-width: 1200px;
margin: 0 auto;
}
.dashboard-section {
background: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
margin-bottom: 20px;
padding: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin: 15px 0;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f5f5f5;
font-weight: bold;
}
.message-form {
margin-top: 20px;
}
.message-form select,
.message-form textarea {
width: 100%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 4px;
}
.message-form textarea {
min-height: 100px;
resize: vertical;
}
.message-form button {
background-color: #007bff;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.message-form button:hover {
background-color: #0056b3;
}
@media (max-width: 768px) {
.dashboard-section {
overflow-x: auto;
}
}
.message-form-container {
margin-bottom: 20px;
}
.messages-display {
margin-top: 20px;
border-top: 1px solid #ddd;
padding-top: 20px;
}
.messages-list {
max-height: 400px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;
padding: 10px;
}
.message-item {
margin-bottom: 15px;
padding: 10px;
border-radius: 4px;
}
.message-item.sent {
background-color: #e3effd;
margin-left: 20px;
}
.message-item.received {
background-color: #f5f5f5;
margin-right: 20px;
}
.message-header {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
font-size: 0.9em;
color: #666;
}
.message-content {
word-break: break-word;
}
.alert {
padding: 10px;
margin-bottom: 15px;
border-radius: 4px;
}
.alert-error {
background-color: #fee2e2;
color: #dc2626;
border: 1px solid #fecaca;
}
.alert-success {
background-color: #dcfce7;
color: #16a34a;
border: 1px solid #bbf7d0;
}
.message-form textarea {
width: 100%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 4px;
min-height: 100px;
resize: vertical;
}
.message-form select {
width: 100%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 4px;
}
.message-form button {
background-color: #007bff;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.message-form button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="dashboard-content">
<h1>Welcome, Operator <?php echo htmlspecialchars($_SESSION['username']); ?></h1>
<!-- All Jobs Section -->
<div class="dashboard-section">
<h2>All Jobs</h2>
<?php
$jobs_sql = "SELECT
jobs.job_name,
machines.machine_name,
users.username AS operator_name,
jobs.start_date,
jobs.end_date,
jobs.priority
FROM jobs
JOIN machines ON jobs.machine_id = machines.id
JOIN users ON jobs.operator_id = users.id
ORDER BY jobs.priority ASC, jobs.start_date DESC";
$jobs_result = $conn->query($jobs_sql);
if ($jobs_result && $jobs_result->num_rows > 0) {
echo "<table>";
echo "<tr>
<th>Job Name</th>
<th>Machine</th>
<th>Operator</th>
<th>Start Date</th>
<th>End Date</th>
<th>Priority</th>
</tr>";
while($row = $jobs_result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . htmlspecialchars($row["job_name"]) . "</td>";
echo "<td>" . htmlspecialchars($row["machine_name"]) . "</td>";
echo "<td>" . htmlspecialchars($row["operator_name"]) . "</td>";
echo "<td>" . htmlspecialchars($row["start_date"]) . "</td>";
echo "<td>" . htmlspecialchars($row["end_date"]) . "</td>";
echo "<td>" . htmlspecialchars($row["priority"]) . "</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "<p>No jobs available.</p>";
}
?>
</div>
<!-- Messaging Section -->
<div class="dashboard-section">
<h2>Messaging</h2>
<div class="messaging-pane">
<div class="send-message-form">
<h3>Send Message</h3>
<form action="" method="post">
<div class="form-group">
<label for="receiver_id">Recipient:</label>
<select name="receiver_id" id="receiver_id" required>
<option value="">Select Recipient</option>
<?php
$sql = "SELECT id, username FROM users WHERE role IN ('manager', 'operator', 'auditor')";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
echo "<option value=\"" . $row['id'] . "\">" . htmlspecialchars($row['username']) . "</option>";
}
?>
</select>
</div>
<div class="form-group">
<label for="machine_id">Regarding Machine (optional):</label>
<select name="machine_id" id="machine_id">
<option value="">Select Machine</option>
<?php
$sql = "SELECT id, machine_name FROM machines";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
echo "<option value=\"" . $row['id'] . "\">" . htmlspecialchars($row['machine_name']) . "</option>";
}
?>
</select>
</div>
<div class="form-group">
<label for="job_id">Regarding Job (optional):</label>
<select name="job_id" id="job_id">
<option value="">Select Job</option>
<?php
$sql = "SELECT job_id, job_name FROM jobs";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
echo "<option value=\"" . $row['job_id'] . "\">" . htmlspecialchars($row['job_name']) . "</option>";
}
?>
</select>
</div>
<div class="form-group">
<label for="message">Message:</label>
<textarea name="message" id="message" required placeholder="Type your message here..."></textarea>
</div>
<button type="submit" name="send_message" class="button">Send Message</button>
</form>
</div>
<div class="inbox">
<h3>Inbox</h3>
<?php
if (empty($messages)) {
echo "<p>No messages in your inbox.</p>";
} else {
foreach ($messages as $msg) {
?>
<div class="message-container">
<div class="message-header">
<span class="message-sender">From: <?php echo htmlspecialchars($msg['sender_name']); ?></span>
<span class="message-timestamp"><?php echo htmlspecialchars($msg['sent_at']); ?></span>
</div>
<div class="message-body">
<?php echo htmlspecialchars($msg['message']); ?>
</div>
<?php if (isset($msg['machine_name'])): ?>
<div class="message-details">
Regarding Machine: <?php echo htmlspecialchars($msg['machine_name']); ?>
</div>
<?php endif; ?>
<?php if (isset($msg['job_name'])): ?>
<div class="message-details">
Regarding Job: <?php echo htmlspecialchars($msg['job_name']); ?>
</div>
<?php endif; ?>
<div class="message-footer">
<?php if ($msg['read_at'] === null): ?>
<button class="button mark-as-read-button" data-message-id="<?php echo $msg['id']; ?>">Mark as Read</button>
<?php endif; ?>
</div>
</div>
<?php
}
}
?>
</div>
</div>
</div>
</div>
</body>
</html>