-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmessaging.php
More file actions
461 lines (423 loc) · 27.2 KB
/
Copy pathmessaging.php
File metadata and controls
461 lines (423 loc) · 27.2 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
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
<?php
/**
* NewUI v4.0 - Internal Messaging & HAS Broadcast
*
* Three-tab interface: Inbox, Sent, Compose.
* Supports direct messages, multi-recipient, and "All" broadcast.
* Unread count badge updates via SSE events.
*/
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/inc/i18n.php';
require_once __DIR__ . '/inc/rbac.php';
// 2026-07-04 (GH #13) — pick the session profile matching the
// client's cookie (TCADMOBILE vs PHPSESSID). Without this, a
// browser holding a mobile cookie opens an empty desktop session
// here and bounces to login -> redirect loop.
require_once __DIR__ . '/inc/session-bootstrap.php';
sess_bootstrap_auto();
session_start();
if (empty($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
require_once __DIR__ . '/inc/force-pw-change.php';
force_pw_change_redirect();
$user = e($_SESSION['user']);
$level = current_role_name();
$theme = $_SESSION['day_night'] ?? 'Day';
$bs_theme = ($theme === 'Night') ? 'dark' : 'light';
$csrf = csrf_token();
$active_page = 'messaging';
?>
<!DOCTYPE html>
<html lang="<?php echo e(i18n_lang()); ?>" data-bs-theme="<?php echo $bs_theme; ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="<?php echo $csrf; ?>">
<title><?php echo e(t('page.messaging', 'Messaging')); ?> — <?php echo e(t('login.title', 'Tickets NewUI')); ?> <?php echo newui_version(); ?></title>
<!-- Vendor CSS -->
<link rel="stylesheet" href="assets/vendor/bootstrap/bootstrap.min.css">
<link rel="stylesheet" href="assets/vendor/bootstrap/bootstrap-icons.min.css">
<!-- App CSS -->
<link rel="stylesheet" href="assets/css/dashboard.css?v=<?php echo newui_version(); ?>">
<link rel="stylesheet" href="assets/css/messaging.css?v=<?php echo asset_v('assets/css/messaging.css'); ?>">
</head>
<body>
<?php include_once NEWUI_ROOT . '/inc/navbar.php'; ?>
</header>
<!-- Page Content -->
<div class="container-fluid p-3">
<!-- Page title -->
<div class="d-flex align-items-center justify-content-between mb-3">
<h5 class="mb-0">
<i class="bi bi-envelope text-primary me-2"></i><?php echo e(t('nav.menu.messages', 'Messages')); ?>
</h5>
<div class="d-flex gap-2">
<a href="index.php" class="btn btn-sm btn-outline-secondary">
<i class="bi bi-arrow-left me-1"></i><?php echo e(t('profile.back_to_dashboard', 'Dashboard')); ?>
</a>
</div>
</div>
<!-- Tab Navigation -->
<ul class="nav nav-tabs mb-3" id="msgTabs" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="tab-inbox" data-bs-toggle="tab"
data-bs-target="#pane-inbox" type="button" role="tab"
aria-controls="pane-inbox" aria-selected="true">
<i class="bi bi-inbox me-1"></i>Inbox
<span class="badge bg-danger rounded-pill ms-1 d-none" id="inboxBadge">0</span>
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="tab-sent" data-bs-toggle="tab"
data-bs-target="#pane-sent" type="button" role="tab"
aria-controls="pane-sent" aria-selected="false">
<i class="bi bi-send me-1"></i>Sent
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="tab-compose" data-bs-toggle="tab"
data-bs-target="#pane-compose" type="button" role="tab"
aria-controls="pane-compose" aria-selected="false">
<i class="bi bi-pencil-square me-1"></i>Compose
</button>
</li>
</ul>
<!-- Tab Content -->
<div class="tab-content" id="msgTabContent">
<!-- ═══ INBOX TAB ═══ -->
<div class="tab-pane fade show active" id="pane-inbox" role="tabpanel" aria-labelledby="tab-inbox">
<!-- Bulk actions -->
<div class="d-flex align-items-center gap-2 mb-2">
<div class="form-check form-check-sm">
<input class="form-check-input" type="checkbox" id="inboxSelectAll" title="Select all" aria-label="Select all messages">
</div>
<button type="button" class="btn btn-sm btn-outline-primary d-none" id="inboxBulkMarkRead" title="Mark selected as read">
<i class="bi bi-envelope-open me-1"></i>Mark Read
</button>
<button type="button" class="btn btn-sm btn-outline-danger d-none" id="inboxBulkDelete" title="Delete selected">
<i class="bi bi-trash me-1"></i>Delete Selected
</button>
<span class="text-body-secondary small ms-auto" id="inboxInfo"></span>
</div>
<div class="table-responsive">
<table class="table table-sm table-hover align-middle mb-0" id="inboxTable">
<thead>
<tr>
<th style="width:30px"></th>
<th style="width:22px"></th>
<th style="width:140px">From</th>
<th>Subject</th>
<th style="width:80px" class="text-center">Priority</th>
<th style="width:150px">Date</th>
</tr>
</thead>
<tbody id="inboxBody">
<tr><td colspan="6" class="text-center text-body-secondary py-4">Loading...</td></tr>
</tbody>
</table>
</div>
<div id="inboxPagination" class="d-flex justify-content-center mt-2"></div>
</div>
<!-- ═══ SENT TAB ═══ -->
<div class="tab-pane fade" id="pane-sent" role="tabpanel" aria-labelledby="tab-sent">
<div class="table-responsive">
<table class="table table-sm table-hover align-middle mb-0" id="sentTable">
<thead>
<tr>
<th style="width:200px">To</th>
<th>Subject</th>
<th style="width:80px" class="text-center">Priority</th>
<th style="width:150px">Date</th>
</tr>
</thead>
<tbody id="sentBody">
<tr><td colspan="4" class="text-center text-body-secondary py-4">Loading...</td></tr>
</tbody>
</table>
</div>
<div id="sentPagination" class="d-flex justify-content-center mt-2"></div>
</div>
<!-- ═══ COMPOSE TAB ═══ -->
<div class="tab-pane fade" id="pane-compose" role="tabpanel" aria-labelledby="tab-compose">
<div class="card">
<div class="card-body">
<form id="composeForm" autocomplete="off">
<div class="row g-3">
<!-- Phase 99a-v2 (2026-06-28) — restructured per Eric beta:
dynamic per-channel fields, target-bridge picker for
mesh, two-stage Send-To, hide-irrelevant-fields.
The form reshapes as the user picks Channel / Send-To. -->
<div class="col-md-4">
<label class="form-label small text-body-secondary mb-1" for="composeChannel">Protocol / Channel</label>
<select class="form-select form-select-sm" id="composeChannel">
<option value="inbox" selected>TicketsCAD Inbox (internal)</option>
<option value="smtp">Email (SMTP)</option>
<option value="sms">SMS</option>
<option value="meshtastic">Meshtastic (mesh radio)</option>
<option value="meshcore">MeshCore (mesh radio)</option>
<option value="aprs">APRS-IS (amateur radio)</option>
<option value="dmr">DMR (digital radio)</option>
</select>
<div class="form-text" id="composeChannelHelp">
Internal — message lands in recipient's TicketsCAD inbox.
</div>
</div>
<!-- Target bridge — mesh channels only. Defaults to the
bridge most recently online OR (when a target node is
chosen) the bridge that most recently heard that node. -->
<div class="col-md-4" id="composeBridgeCol" style="display:none;">
<label class="form-label small text-body-secondary mb-1" for="composeBridge">
Target bridge
<i class="bi bi-question-circle text-body-secondary" tabindex="0"
data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="top"
data-bs-html="true"
data-bs-content="Which mesh bridge should claim this send. <b>Any</b> lets the system pick the bridge that most recently heard the target node (or the most-recently-online bridge for a broadcast). Pick a specific bridge to force routing through it (useful when one bridge is having issues)."
title="Bridge picker help"></i>
</label>
<select class="form-select form-select-sm" id="composeBridge">
<option value="0">Any (heard-by default)</option>
</select>
</div>
<!-- Send To — second-level discriminator. Options reshape
per channel. Mesh: Broadcast slot / Direct node / Direct
unit. SMTP+SMS: Direct email/phone. APRS: Direct callsign. -->
<div class="col-md-4" id="composeSendToCol" style="display:none;">
<label class="form-label small text-body-secondary mb-1" for="composeSendTo">Send to</label>
<select class="form-select form-select-sm" id="composeSendTo">
<!-- options populated by JS per channel -->
</select>
</div>
<!-- ── Recipient row — exactly one of these is visible at a time -->
<div class="col-12" id="composeRecipRow">
<!-- Inbox: user multi-select -->
<div id="composeRecipInbox">
<label class="form-label small text-body-secondary mb-1" for="composeTo">To</label>
<select class="form-select form-select-sm" id="composeTo" multiple size="4">
<option value="all">-- All Users (Broadcast) --</option>
</select>
<div class="form-text">Hold Ctrl to select multiple recipients. Select "All Users" to message everyone.</div>
</div>
<!-- Channel slot (mesh broadcast / zello channel name) -->
<div id="composeRecipChannel" style="display:none;">
<label class="form-label small text-body-secondary mb-1" id="composeRecipChannelLabel" for="composeChannelSlot">Channel</label>
<select class="form-select form-select-sm" id="composeChannelSlot">
<option value="channel:0">Slot 0 (Primary)</option>
<option value="channel:1">Slot 1</option>
<option value="channel:2">Slot 2</option>
<option value="channel:3">Slot 3</option>
<option value="channel:4">Slot 4</option>
<option value="channel:5">Slot 5</option>
<option value="channel:6">Slot 6</option>
<option value="channel:7">Slot 7</option>
</select>
</div>
<!-- Text address (SMTP / SMS / APRS / direct mesh node) +
personnel/node picker autocomplete -->
<div id="composeRecipText" style="display:none;">
<label class="form-label small text-body-secondary mb-1" id="composeRecipTextLabel" for="composeToText">To</label>
<div class="position-relative">
<input type="text" class="form-control form-control-sm" id="composeToText"
placeholder="" autocomplete="off">
<div id="composeToDropdown" class="list-group position-absolute w-100 shadow-sm"
style="display:none; z-index:1050; max-height:240px; overflow-y:auto;"></div>
</div>
<div class="form-text" id="composeRecipTextHelp">
Separate multiple recipients with commas. Start typing to search.
</div>
</div>
<!-- DMR talkgroup picker — appears when channel=dmr AND
sendTo=talkgroup. Populated from /api/talkgroups.php?enabled=1.
Each option shows "TG XXXX — Name [call_type]". -->
<div id="composeRecipTalkgroup" style="display:none;">
<label class="form-label small text-body-secondary mb-1" for="composeTalkgroup">Talkgroup</label>
<select class="form-select form-select-sm" id="composeTalkgroup">
<option value="">— loading talkgroups —</option>
</select>
<div class="form-text" id="composeTalkgroupHelp">
Enabled talkgroups from Settings → Communications & Integrations → Voice → DMR Talkgroups.
</div>
</div>
<!-- Unit / personnel picker (future: resolves to channel-
appropriate address via comm_identifiers) -->
<div id="composeRecipUnit" style="display:none;">
<label class="form-label small text-body-secondary mb-1" for="composeUnitPick">To unit / person</label>
<select class="form-select form-select-sm" id="composeUnitPick">
<option value="">— select —</option>
</select>
<div class="form-text" id="composeRecipUnitHelp">
Direct messages to a TicketsCAD personnel record — resolved to the channel-appropriate address.
</div>
</div>
</div>
<!-- Speak on channel (TTS) — only for channels that support
voice (Zello, DMR — DMR currently future). Hidden for
the rest. -->
<div class="col-md-4" id="composeSpeakCol" style="display:none;">
<label class="form-label small text-body-secondary mb-1"> </label>
<div class="form-check mt-1">
<input class="form-check-input" type="checkbox" id="composeSpeak">
<label class="form-check-label small" for="composeSpeak">
<i class="bi bi-megaphone me-1"></i>Speak on channel (TTS audio)
<i class="bi bi-question-circle text-body-secondary" tabindex="0"
data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="top"
data-bs-content="When checked, the system synthesizes the message body to voice and transmits it as audio on the channel. Available for Zello and DMR (voice-supporting channels)."
title="Speak help"></i>
</label>
</div>
</div>
<!-- Priority — only meaningful for inbox/SMTP/SMS where
high-priority is a deliverable header or visible
prefix. Hidden for mesh/APRS where it has no effect. -->
<div class="col-md-3" id="composePriorityCol">
<label class="form-label small text-body-secondary mb-1" for="composePriority">Priority</label>
<select class="form-select form-select-sm" id="composePriority">
<option value="normal">Normal</option>
<option value="high">High</option>
<option value="urgent">Urgent</option>
</select>
</div>
<!-- Send As — SMTP only (when user has personal email). -->
<div class="col-md-3" id="composeSendAsCol" style="display:none;">
<label class="form-label small text-body-secondary mb-1" for="composeSendAs">
Send As
<i class="bi bi-question-circle text-body-secondary" tabindex="0"
data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="top"
data-bs-html="true"
data-bs-content="<b>Dispatch (system)</b> — message from the org's configured SMTP sender.<br><br><b>As yourself</b> — message from your personal email address. Useful when liability lives with you personally."
title="Send As help"></i>
</label>
<select class="form-select form-select-sm" id="composeSendAs">
<option value="system">Dispatch (system)</option>
</select>
</div>
<!-- Subject — only shown for channels that have subjects
(inbox + smtp). Hidden for SMS where it doesn't apply. -->
<div class="col-12" id="composeSubjectCol">
<label class="form-label small text-body-secondary mb-1" for="composeSubject">Subject</label>
<input type="text" class="form-control form-control-sm" id="composeSubject"
placeholder="Subject (optional)" maxlength="255">
</div>
<!-- Attach to incident — applies to inbox only.
External channels don't have a clean way to
link delivered messages back to incidents. -->
<div class="col-md-4" id="composeIncidentCol">
<label class="form-label small text-body-secondary mb-1" for="composeIncident">Attach to Incident #</label>
<input type="number" class="form-control form-control-sm" id="composeIncident"
placeholder="(optional)" min="1">
</div>
<!-- Body. Char counter shown for length-limited
channels (SMS 160) — hidden otherwise. -->
<div class="col-12">
<label class="form-label small text-body-secondary mb-1 d-flex justify-content-between" for="composeBody">
<span>Message</span>
<span class="text-body-secondary small font-monospace" id="composeCharCounter" style="display:none;">0/160</span>
</label>
<textarea class="form-control form-control-sm" id="composeBody" rows="8"
placeholder="Type your message here..."></textarea>
</div>
<!-- Send -->
<div class="col-12 d-flex justify-content-end gap-2">
<button type="button" class="btn btn-sm btn-outline-secondary" id="composeClear">
<i class="bi bi-x-lg me-1"></i>Clear
</button>
<button type="submit" class="btn btn-sm btn-primary" id="composeSend">
<i class="bi bi-send me-1"></i>Send Message
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div><!-- /tab-content -->
</div><!-- /container -->
<!-- ═══ Message Detail Modal ═══ -->
<div class="modal fade" id="msgDetailModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header py-2">
<h6 class="modal-title" id="msgDetailTitle">Message</h6>
<button type="button" class="btn-close btn-close-sm" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row g-2 mb-3 small text-body-secondary">
<div class="col-sm-6"><strong>From:</strong> <span id="msgDetailFrom"></span></div>
<div class="col-sm-6"><strong>Date:</strong> <span id="msgDetailDate"></span></div>
<div class="col-sm-6"><strong>To:</strong> <span id="msgDetailTo"></span></div>
<div class="col-sm-3"><strong>Priority:</strong> <span id="msgDetailPriority"></span></div>
<div class="col-sm-3"><strong>Incident:</strong> <span id="msgDetailIncident"></span></div>
</div>
<hr class="my-2">
<div id="msgDetailBody" class="msg-detail-body"></div>
</div>
<div class="modal-footer py-1">
<button type="button" class="btn btn-sm btn-outline-primary" id="msgReplyBtn">
<i class="bi bi-reply me-1"></i>Reply
</button>
<button type="button" class="btn btn-sm btn-outline-danger" id="msgDeleteBtn">
<i class="bi bi-trash me-1"></i>Delete
</button>
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- ═══ HAS Broadcast Modal ═══ -->
<div class="modal fade" id="hasBroadcastModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content border-danger">
<div class="modal-header bg-danger text-white py-2">
<h6 class="modal-title"><i class="bi bi-megaphone-fill me-2"></i>HAS Broadcast — All Stations</h6>
<button type="button" class="btn-close btn-close-white btn-close-sm" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="alert alert-warning py-2 small mb-3">
<i class="bi bi-exclamation-triangle-fill me-1"></i>
This will send an <strong>URGENT</strong> message to ALL logged-in users and trigger an audio alert on every station.
</div>
<div class="mb-3">
<label class="form-label small text-body-secondary mb-1" for="hasSubject">Subject</label>
<input type="text" class="form-control form-control-sm" id="hasSubject" value="HAS Broadcast" maxlength="255">
</div>
<div>
<label class="form-label small text-body-secondary mb-1" for="hasBody">Message</label>
<textarea class="form-control form-control-sm" id="hasBody" rows="4"
placeholder="Enter broadcast message..."></textarea>
</div>
</div>
<div class="modal-footer py-1">
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-sm btn-danger" id="hasSendBtn">
<i class="bi bi-megaphone-fill me-1"></i>Broadcast to All Stations
</button>
</div>
</div>
</div>
</div>
<!-- ═══ HAS Alert Toast (for incoming broadcasts) ═══ -->
<div class="position-fixed top-0 start-50 translate-middle-x p-3" style="z-index:9999" id="hasAlertWrap">
<div class="toast has-alert-toast border-danger" role="alert" aria-live="assertive" aria-atomic="true"
data-bs-autohide="false" id="hasAlertToast">
<div class="toast-header bg-danger text-white">
<i class="bi bi-megaphone-fill me-2"></i>
<strong class="me-auto">HAS BROADCAST</strong>
<small id="hasAlertTime"></small>
<button type="button" class="btn-close btn-close-white btn-close-sm ms-2" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body" id="hasAlertBody"></div>
</div>
</div>
<!-- Vendor JS -->
<script src="assets/vendor/bootstrap/bootstrap.bundle.min.js"></script>
<!-- App JS -->
<script>
var USER_ID = <?php echo (int) $_SESSION['user_id']; ?>;
var CSRF_TOKEN = '<?php echo $csrf; ?>';
</script>
<script src="assets/js/event-bus.js?v=<?php echo asset_v('assets/js/event-bus.js'); ?>"></script>
<script src="assets/js/audio-alerts.js?v=<?php echo asset_v('assets/js/audio-alerts.js'); ?>"></script>
<script src="assets/js/messaging.js?v=<?php echo asset_v('assets/js/messaging.js'); ?>"></script>
</body>
</html>