-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathedit-unit.php
716 lines (622 loc) · 26.9 KB
/
edit-unit.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
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
<?php
$subsys="unit";
require_once('db-open.php');
include('local-dls.php');
require_once('session.inc');
require_once('functions.php');
SessionErrorIfReadonly();
if (isset($_POST['unit'])) {
$unit = strtoupper(MysqlClean($_POST,'unit',20));
// TODO: validate data.
if (isset($_POST['status'])) {
$status = MysqlClean($_POST,'status',30);
syslog(LOG_INFO, "Posted unit $unit with status seen [$status]");
}
else {
$status="In Service";
syslog(LOG_INFO, "Posted unit $unit with status defaulting to [$status]");
}
// if (isset($_POST['status_comment'])) $status_comment = MysqlClean($_POST,'status_comment',255); else $status_comment="";
if (isset($_POST['type'])) $type = MysqlClean($_POST,'type',20); else $type="Unit";
if (isset($_POST['assignment'])) $assignment = MysqlClean($_POST,'assignment',20); else $assignment="";
if (isset($_POST['role'])) $role = MysqlClean($_POST,'role',20); else $role="Other";
if (isset($_POST['location'])) $location = MysqlClean($_POST,'location',100); else $location="";
if (isset($_POST['notes'])) $notes = MysqlClean($_POST,'notes',100); else $notes="";
if (isset($_POST['personnel'])) $personnel = MysqlClean($_POST,'personnel',100); else $personnel="";
}
if (isset($_POST['saveunit']) || isset($_POST['saveunit_closewin'])) {
if (isset($_POST['new-unit-entered'])) {
$unit = strtoupper(MysqlClean($_POST,'unit',20));
$pattern = "/[\\/[\]'!@#$\^%&*()+=,;:{}|<>~`?\"]/";
$replacement = "";
if ($unit == "") {
die('Cannot create unit with empty name.');
}
if (preg_match($pattern, $unit)) {
die('Bad characters in name: '.$unit. "\n Only letters, numbers, space, dash or underscore are valid characters.\n Use your browser Back feature to resolve the problem and try again.");
}
// update status
if ($personnel != "")
MysqlQuery("INSERT INTO messages (ts, unit, message) VALUES (NOW(), '$unit', 'Unit created - personnel: $personnel')");
else
MysqlQuery("INSERT INTO messages (ts, unit, message) VALUES (NOW(), '$unit', 'Unit created.')");
syslog(LOG_INFO, $_SESSION['username'] . " created unit [$unit]");
// update units
// TODO: sanity check $unit input characters here?
MysqlQuery("INSERT INTO units (unit, status, status_comment, type, role, personnel, update_ts, assignment, personnel_ts, location, location_ts, notes, notes_ts) VALUES ('$unit', '$status', '$status_comment', '$type', '$role', '$personnel', NOW(), '$assignment', NOW(), '$location', NOW(), '$notes', NOW())");
}
else {
// update status
if ($_POST['status'] <> $_POST['previous_status']) {
$fragment = "status='$status', status_comment='Status changed to: $status', update_ts=NOW(),";
if ($_POST['previous_status'] <> "")
MysqlQuery("INSERT INTO messages (ts, unit, message) VALUES (NOW(), '$unit', 'Status change: $status (was: ".MysqlClean($_POST, 'previous_status', 200).")')");
else
MysqlQuery("INSERT INTO messages (ts, unit, message) VALUES (NOW(), '$unit', 'Status change: $status')");
if ($_POST['previous_status'] == 'Attached to Incident') {
MysqlQuery("UPDATE incident_units SET cleared_time=NOW() WHERE unit='$unit' AND cleared_time IS NULL");
}
}
else {
$fragment="";
}
// update location
// not implimented yet
// update notes
// not implimented yet
// update personnel
if ($_POST['personnel'] <> $_POST['previous_personnel']) {
MysqlQuery("INSERT INTO messages (ts, unit, message) VALUES (NOW(), '$unit', 'Personnel change logged: $personnel')");
}
syslog(LOG_INFO, $_SESSION['username'] . " edited unit [$unit]");
// update units
MysqlQuery("UPDATE units SET $fragment type='$type', role='$role', assignment='$assignment', location='$location', notes='$notes', personnel='$personnel' WHERE unit='$unit'");
}
if (isset($_POST['saveunit_closewin'])) {
print "<SCRIPT LANGUAGE=\"JavaScript\">if (window.opener){window.opener.location.reload()} self.close()</SCRIPT>";
die("(Error: JavaScript not enabled or not present) Action completed. Close this window to continue.");
}
else {
header("Location: edit-unit.php?unit=".$_POST['unit']);
exit;
}
}
elseif (isset($_POST["abortdelete"])) {
// Noop, just reload
}
elseif (isset($_POST["deleteunit"])) {
if (!CheckAuthByLevel('delete_units',$_SESSION['access_level'])) {
print "Access level (". $_SESSION['access_level'] . ") too low to delete unit.\n";
exit;
}
elseif (isset($_POST['deleteforsure'])) {
syslog(LOG_INFO, $_SESSION['username'] . ' deleted unit [' . $_POST['unit'] . ']');
MysqlQuery("DELETE FROM units WHERE unit='".MysqlClean($_POST,"unit",20)."'");
MysqlQuery("INSERT INTO messages (ts, unit, message) VALUES (NOW(), '$unit', 'Unit deleted.')");
print "<SCRIPT LANGUAGE=\"JavaScript\">if (window.opener){window.opener.location.reload()} self.close()</SCRIPT>";
die("(Error: JavaScript not enabled or not present) Action completed. Close this window to continue.");
}
else {
$_GET['unit'] = MysqlClean($_POST,'unit',20);
$unit = $_GET['unit'];
$newunit = 0;
$unitresult = MysqlQuery("SELECT * from units where unit = '$unit'");
$unitline = mysql_fetch_array($unitresult, MYSQL_ASSOC) or die ("Unit $unit not found in table!");
mysql_free_result($unitresult);
}
}
elseif (isset($_GET["new-unit"])) {
$unitline["unit"] = "";
$unit = "";
$newunit = 1;
$unitline["status"] = "In Service";
$unitline["role"] = "Other";
$unitline["type"] = "Unit";
$unitline["assignment"] = "";
$unitline["status_comment"] = "";
$unitline["personnel"] = "";
$unitline["update_ts"] = "";
}
elseif (isset($_GET["unit"])) {
$unit = MysqlClean($_GET,"unit",20);
$newunit = 0;
$unitresult = MysqlQuery("SELECT * from units where unit = '$unit'");
$unitline = mysql_fetch_array($unitresult, MYSQL_ASSOC) or die ("unit not found in table");
mysql_free_result($unitresult);
}
elseif (isset($_POST['add_pageout'])) {
if (!CheckAuthByLevel('create_unitpaging',$_SESSION['access_level'])) {
print "Access level (". $_SESSION['access_level'] . ") too low to create autopaging link.\n";
exit;
}
$newval = MysqlClean($_POST, 'newpageout', 20);
if ($newval != '0') {
syslog(LOG_INFO, $_SESSION['username'] . " added page-out of pager ID $newval to unit [$unit]");
MysqlQuery("INSERT INTO unit_incident_paging (unit, to_person_id) VALUES ('$unit', $newval)");
}
header("Location: edit-unit.php?unit=".$_POST['unit']);
exit;
}
elseif (isset($_POST['pageunit']) && # manual unit paging
isset($DB_PAGING_NAME) &&
isset($USE_PAGING_LINK) && $USE_PAGING_LINK) {
if (!isset($ALLOW_MANUAL_PAGE) || !$ALLOW_MANUAL_PAGE) {
die ('Manual paging is disabled.');
}
$paginglink = mysql_connect($DB_PAGING_HOST, $DB_PAGING_USER, $DB_PAGING_PASS)
or die("Could not connect : " . mysql_error());
$ipaddr = $_SERVER['REMOTE_ADDR'];
$to_person_id = MysqlClean($_POST,'to_person_id',30);
$unit = MysqlClean($_POST,'unit',40);
$pagetext = MysqlClean($_POST,'pagetext',80);
$message = "[CAD] FR " . $_SESSION['username'] . " TO $unit: " . $_POST['pagetext'];
$success = 1; // unless overridden below:
if (strlen($message) >= 128) {
# TODO: try to work around this limitation? reimplement part of paging... or wait for API?
$message = substr($message, 0, 127);
}
# TODO 1.7: replace this with api call
#
if (!mysql_query("INSERT into $DB_PAGING_NAME.batches (from_user_id, from_ipaddr, orig_message, entered) ".
" VALUES (0, '$ipaddr', '$message', NOW() )", $paginglink) ||
mysql_affected_rows() != 1) {
syslog(LOG_WARNING, "Error inserting row into database $DB_PAGING_NAME.batches as [$DB_PAGING_HOST/$DB_PAGING_USER]");
$success = 0;
}
else {
$batch_id = mysql_insert_id();
if (!mysql_query("INSERT into $DB_PAGING_NAME.messages (from_user_id, to_person_id, message) VALUES ".
"(0, $to_person_id, '$message')", $paginglink) ||
mysql_affected_rows() != 1) {
syslog(LOG_WARNING, "Error inserting row into $DB_PAGING_NAME.messages as [$DB_PAGING_HOST/$DB_PAGING_USER]");
$success = 0;
}
$msg_id = mysql_insert_id();
if (!mysql_query("INSERT into $DB_PAGING_NAME.batch_messages (batch_id, msg_id) VALUES ".
"($batch_id, $msg_id)", $paginglink) ||
mysql_affected_rows() != 1) {
syslog(LOG_WARNING, "Error inserting row into $DB_PAGING_NAME.batch_messages as [$DB_PAGING_HOST/$DB_PAGING_USER]");
$success = 0;
}
if (!mysql_query("INSERT into $DB_PAGING_NAME.send_queue (status, msg_id, queued) VALUES ".
"('Queued', $msg_id, NOW())", $paginglink) ||
mysql_affected_rows() != 1) {
syslog(LOG_WARNING, "Error inserting row into $DB_PAGING_NAME.send_queue as [$DB_PAGING_HOST/$DB_PAGING_USER]");
$success = 0;
}
}
if ($success) {
syslog(LOG_INFO, $_SESSION['username'] . " sent a manual page to unit [$unit], person_id [$to_person_id].");
}
mysql_close($paginglink);
header("Location: edit-unit.php?unit=".$_POST['unit']."&pagesent=".$success);
exit;
}
// TODO: In future, replace this handler when you replace the method
else {
$action = 0;
foreach (array_keys($_POST) as $postkey) {
if (preg_match("/delete_pageout_(\d+)_(\d+)/", $postkey, $matches)) {
if (!CheckAuthByLevel('delete_unitpaging',$_SESSION['access_level'])) {
print "Access level (". $_SESSION["access_level"] . ") too low to delete autopaging link.\n";
exit;
}
syslog(LOG_INFO, $_SESSION['username'] . ' deleted page-out of pager ID ' . $matches[2] . ' from unit [' . $_POST['unit'].']');
MysqlQuery("DELETE FROM unit_incident_paging WHERE row_id=" . $matches[1] );
if (mysql_affected_rows() != 1) {
syslog(LOG_WARNING, "Error while deleting row_id " . $matches[1] . " from unit_incident_paging");
}
$action = 1;
header("Location: edit-unit.php?unit=".$_POST['unit']);
exit;
}
}
// If no row was found in the pattern match case
if (!$action) {
die ('Unknown options to edit-unit.php page load.');
}
}
header_html(
"Dispatch :: Unit Details",
" <script src=\"js/jquery-1.7.2.min.js\" type=\"text/javascript\"></script>\n"
);
if (isset($_POST["deleteunit"]) || isset($_POST['deleteforsure']))
$disabledp = ' disabled ';
else
$disabledp = '';
/*-------------------------------------------------------------------------*/
?>
<body vlink="blue" link="blue" alink="cyan">
<form name="myform" action="edit-unit.php" method="post">
<!-- Begin Outer Table -->
<table cellspacing="3" cellpadding="0">
<!-- Begin Outer Table Row 1 -->
<tr>
<td colspan="3" bgcolor="darkblue" class="text">
<!-- Title Bar Table -->
<table width=100%>
<tr>
<td><font color="white" size="+1"><b><?php if (!$newunit) print "Unit: $unit"; else print "Creating a New Unit"; ?></b></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3" bgcolor="#bbbbbb">
<!-- Begin Unit Form Outer Table -->
<table cellpadding="0" cellspacing="0" border="1" width="100%">
<tr>
<td>
<script type="text/javascript">
$(document).ready(function() {
$("input[name='unit']").first().focus();
});
</script>
<!-- Begin Unit Form Inner Table -->
<table cellpadding="2" cellspacing="0" width="100%">
<!-- Begin Unit Form Row: Unit Name -->
<?php
if ($newunit) {
print "<tr>";
print "<td class=\"label\" align=\"right\"><b>Unit name</b></td>\n";
print "<td colspan=\"5\" class=\"text\"><input type=\"text\" style=\"text-transform: uppercase\" maxlength=\"20\" name=\"unit\"><input type=\"hidden\" name=\"new-unit-entered\"></td>\n";
print "</tr>\n";
}
else {
print "<input type=\"hidden\" name=\"unit\" value=\"".$unit."\" />\n";
}
?>
<!-- Begin Unit Form Row: Branch / Type / Assignment -->
<tr>
<td class="label" align="right">B<u>r</u>anch</td>
<td class="text" width="100%">
<label for="role" accesskey="role">
<select name="role" <?php print $disabledp ?> id="role">
<?php
$roles = MysqlQuery("SELECT role FROM unit_roles");
print "<option value=\"\"></option>\n";
while ($role_row = mysql_fetch_object($roles)) {
$role = $role_row->role;
if ($unitline["role"] == $role)
print "<option selected value=\"$role\">$role</option>\n";
else
print "<option value=\"$role\">$role</option>\n";
}
?>
</select>
</label>
</td>
<td class="label" align="right">T<u>y</u>pe</td>
<td class="text" width="100%">
<label for="type" accesskey="y">
<select name="type" <?php print $disabledp ?> id="type">
<?php
$avail_types = array('Unit', 'Individual', 'Generic');
if (array_search($unitline["type"], $avail_types) === FALSE)
print "<option selected value=\"\">(none)</option>\n";
foreach ($avail_types as $type) {
print "<option ";
if ($unitline["type"] == $type)
print "selected ";
print "value=\"$type\">$type</option>\n";
}
?>
</select>
</label>
</td>
<td class="label" align="right"><u>A</u>ssignment</td>
<td class="text" width="100%">
<label for="assignment" accesskey="a">
<select name="assignment" <?php print $disabledp ?> id="assignment">
<?php
$avail_asses = MysqlQuery('SELECT * FROM unit_assignments');
print "<option value=\"\">(none)</option>\n";
while ($avail_assignment = mysql_fetch_object ($avail_asses)) {
print "<option ";
if ($unitline["assignment"] == $avail_assignment->assignment)
print "selected ";
print "value=\"".$avail_assignment->assignment."\">".
$avail_assignment->description."</option>\n";
}
?>
</select>
</td>
</tr>
<!-- Begin Unit Form Row: Spacer -->
<tr>
<td colspan="6"></td>
</tr>
<!-- Begin Unit Form Row: Status -->
<tr>
<td class="label" align="right"><u>S</u>tatus</td>
<td class="text" width="100%">
<label for="status" accesskey="s">
<?php
// Can't set away from these two status options manually:
if ($unitline["status"] == 'Attached to Incident') {
print "<select name=\"status\" disabled id=\"status\">\n";
print "<option selected value=\"Attached to Incident\">Attached to Incident</option>\n";
print "</select>\n";
print "<input type=hidden id=status name=status value=\"Attached to Incident\">\n";
print "<br><font size=\"-2\"><b>(change via Incidents screen)</b></font>\n";
}
elseif ($unitline["status"] == 'Staged At Location') {
print "<select name=\"status\" disabled id=\"status\">\n";
print "<option selected value=\"Staged At Location\">Staged at Location</option>\n";
print "</select>\n";
print "<input type=hidden id=status name=status value=\"Staged at Location\">\n";
print "<font size=\"-2\"><br><b>(change via Incidents > Staging Locations screen)</b></font>\n";
}
else {
print "<select name=\"status\" <?php print $disabledp ?> id=\"status\">\n";
$statusset=0;
$statusresult = MysqlQuery("SELECT * from status_options");
while ($line = mysql_fetch_array($statusresult, MYSQL_ASSOC)) {
// Can't set to these two status options manually:
if ($line["status"] != 'Attached to Incident' &&
$line["status"] != 'Staged At Location') {
echo " <option ";
if (!strcmp($line["status"], $unitline["status"])) {
$statusset=1;
echo "selected ";
}
echo "value=\"". MysqlUnClean($line["status"])."\">". $line["status"]."</option>\n";
}
}
if (!$statusset) {
echo " <option selected value=\"\">\n";
}
mysql_free_result($statusresult);
print "</select>\n";
}
?>
</label>
<input type="hidden" name="previous_status" value="<?php print MysqlUnClean($unitline["status"]);?>" />
</td>
<td colspan="2"> </td>
<td class="label" align="right">Updated</td>
<td class="text"><?php print dls_utime($unitline["update_ts"]);?></td>
</tr>
<!-- Begin Unit Form Row: Status Redux -->
<tr>
<td> </td>
<td class="label" colspan="5" nowrap>Comment: <?php print MysqlUnClean($unitline["status_comment"])?></td>
</tr>
<!-- Begin Unit Form Row: Spacer -->
<tr>
<td colspan="6"></td>
</tr>
<!-- Begin Unit Form Row: Last Location -->
<tr>
<td class="label" align="right" nowrap>Last <u>L</u>ocation</td>
<td class="text" colspan="5">
<label for="location" accesskey="l">
<input name="location" id="location" <?php print $disabledp ?> type="text" maxlength="250" size="80"
value="<?php print MysqlUnClean($unitline["location"])?>" />
</label>
<input type="hidden" name="previous_location" value="<?php print $unitline["location"];?>" />
</td>
</tr>
<!-- Begin Unit Form Row: Personnel -->
<tr>
<td class="label" align="right"><u>P</u>ersonnel</td>
<td class="text" colspan="5">
<label for="personnel" accesskey="p">
<input name="personnel" id="personnel" <?php print $disabledp ?> type="text" maxlength="250" size="80"
value="<?php print MysqlUnClean($unitline["personnel"]);?>" />
</label>
<input type="hidden" name="previous_personnel" value="<?php print $unitline["personnel"];?>" />
</td>
</tr>
<!-- Begin Unit Form Row: Notes -->
<tr>
<td class="label" align="right">N<u>o</u>tes</td>
<td class="text" colspan="5">
<label for="notes" accesskey="o">
<input name="notes" id="notes" <?php print $disabledp ?> type="text" maxlength="250" size="80"
value="<?php print MysqlUnClean($unitline["notes"])?>" />
</label>
<input type="hidden" name="previous_notes" value="<?php print $unitline["notes"];?>" />
</td>
</tr>
<?php
// Begin Unit Form Row: Generic Notice
if ($unitline["type"] == "Generic")
print "<tr>\n<td class=\"label\" colspan=\"6\"><b>Note: As a generic unit, multiple instances of this unit may be simultaneously assigned to separate incidents.</b></td></tr>"
?>
<!-- Begin Unit Form Row: Buttons -->
<tr>
<td> </td>
<td class="label" colspan="5">
<button type="submit" id="saveunit" name="saveunit" <?php print $disabledp ?> tabindex="41" accesskey="1"><u>1</u> Save</button>
<button type="submit" id="saveunit_closewin" name="saveunit_closewin" <?php print $disabledp ?> tabindex="42" value="Save & Return" accesskey="2"><u>2</u> Save & Return</button>
<button type="button" id="cancel" name="cancel" <?php print $disabledp ?> tabindex="43" accesskey="3"
onClick='if (window.opener){window.opener.location.reload()} self.close()'><u>3</u> Cancel</button>
<?php
if (CheckAuthByLevel('delete_units', $_SESSION['access_level'])) {
if (isset($_POST["deleteunit"]) || isset($_POST['deleteforsure'])) {
?>
<button type="submit" id="abortdelete" name="abortdelete" tabindex="44" accesskey="4"><u>4</u> Abort Deletion</button>
<?php
}
?>
<noscript><b>Warning</b>: Javascript disabled. Close popup to cancel changes.</noscript>
</td>
</tr>
<?php
// Begin Unit Form Row: If Existing Unit, possible to delete it...
if(!$newunit) {
print "<tr>\n";
print "<td colspan=\"6\" class=\"label\" align=\"right\">";
if (isset($_POST["deleteunit"])) {
print "<input type=\"checkbox\" name=\"deleteforsure\" /> ";
print "<span style=\"color: red; font-weight: bold; text-decoration: blink;\">Confirm</span> " .
"you want to delete this unit? ";
}
print "<input type=\"submit\" id=\"deleteunit\" name=\"deleteunit\" value=\"Delete Unit\" /></td>\n";
print "</tr>\n";
}
}
?>
</table>
<!-- End Unit Form Inner Table -->
</td>
</tr>
</table>
<!-- End Unit Form Outer Table -->
</td>
</tr>
<!-- End Outer Table Row 1 -->
<!-- Outer Table Spacer Row -->
<tr><td></td></tr>
<?php
if (isset($USE_PAGING_LINK) && $USE_PAGING_LINK) {
if ($newunit) {
print "<tr><td colspan=3>Save unit in order to edit auto-paging links.</td></tr>";
}
else {
$paginglink = mysql_connect($DB_PAGING_HOST, $DB_PAGING_USER, $DB_PAGING_PASS)
or die("Could not connect : " . mysql_error());
if (isset($ALLOW_MANUAL_PAGE) && $ALLOW_MANUAL_PAGE) {
?>
<!-- Begin Outer Table Row 2 -->
<tr>
<td colspan="3" bgcolor="#bbbbbb">
<!-- Begin Page Now Form Outer Table -->
<table cellpadding="0" cellspacing="0" border="1" width="100%">
<tr>
<td>
<!-- Begin Page Now Form Inner Table -->
<table cellpadding="2" cellspacing="0" width="100%">
<?php
$querytext = "SELECT person_id,name FROM $DB_PAGING_NAME.people ".
" WHERE UPPER(REPLACE(name, ' ', '')) = '" . strtoupper(str_replace(' ', '', $unit)) . "'";
$pager_query = mysql_query($querytext, $paginglink) or die ("<b>Problem with query: </b><font color=red> $querytext </font>");
if (mysql_num_rows($pager_query)) {
$pager = mysql_fetch_object($pager_query);
print "<tr><td class=label>Send page to <b>$unit</b>: \n";
print "<INPUT type=hidden name=\"to_person_id\" value=\"" . $pager->person_id."\">\n";
print "<INPUT type=text onfocus=\"focusPaging(true)\" name=\"pagetext\" size=\"30\" maxlength=\"80\">\n";
print "<BUTTON type=submit name=\"pageunit\" tabindex=\"42\" accesskey=\"4\"><u>4</u> Send Page</button>\n";
print "<BUTTON type=button onfocus =\"focusPaging(false)\" name=\"cancelpageunit\" tabindex=\"43\" accesskey=\"5\"><u>5</u> Cancel Page</button>\n";
print "</td></tr>\n";
//print "<tr><td><span class=\"label\" style=\"color:blue\" id=\"pagehelp\"> ";
}
else {
print "<tr><td class=label style=\"color:blue\">Cannot page this unit directly from CAD: No pager defined for "<b>$unit</b>".<br>";
print "<font size=-1> If this unit has a pager, try the Paging system directly, as the pager may be named differently.</font></td></tr>\n";
}
if ($_GET['pagesent'] == 1) {
print "Your page was sent.";
}
elseif (isset($_GET['pagesent']) && $_GET['pagesent'] == 0) {
print "Error sending page.";
}
print "</span></td></tr>\n";
?>
</table>
</td>
</tr>
</table>
</td>
</tr>
<!-- End Outer Table Row 2 -->
<!-- Outer Table Spacer Row -->
<tr><td></td></tr>
<?php
}
?>
<!-- Begin Outer Table Row 3 -->
<tr>
<td colspan="3" bgcolor="#bbbbbb">
<!-- Begin AutoPage Form Outer Table -->
<table cellpadding="0" cellspacing="0" border="1" width="100%">
<tr>
<td>
<!-- Begin AutoPage Form Inner Table -->
<table cellpadding="0" cellspacing="0" >
<?php
$pplquery = "SELECT * FROM $DB_PAGING_NAME.people WHERE is_active=1 ORDER BY name";
$options_query = mysql_query($pplquery, $paginglink) or die ("<b>Problem with query</b>: <font color=red> $pplquery</font>");
$Pagers = array();
while ($pager_option = mysql_fetch_object($options_query)) {
$Pagers[$pager_option->person_id] = $pager_option->name;
}
$pageout_qty = MysqlGrabData("SELECT COUNT(*) FROM unit_incident_paging WHERE unit='$unit'");
$pageout_query = MysqlQuery("SELECT * FROM unit_incident_paging WHERE unit='$unit'");
// TODO: set access level dynamically
if (mysql_num_rows($pageout_query) || CheckAuthByLevel('create_unitpaging',$_SESSION['access_level'])) {
?>
<!-- Begin Unit AutoPage Row: Labels -->
<tr>
<td colspan=4 class="label">
<b>Automatic Paging Notification</b><br>
When <?php print $unit?> is assigned to an incident, CAD will page a notification to each of the pagers listed below.<br>
<div style="text-align:right; color:blue"><b>CLARIFICATION:</b> This <u>does not</u> page <?php print $unit?> when <u>the units listed below</u> are assigned to an incident.<br> This list contains pagers, not units; and this Unit Details window is about a unit, not <?php print $unit?>'s pager.</div>
<font size=-3> <center><img src="Images/bluespacer.gif" width=600 height=1></center> </font>
</td>
</tr>
<!-- Begin Unit AutoPage Row: Current List / Add -->
<tr>
<td valign="top" class="label" nowrap>
Pagers being notified about <?php print $unit?> dispatches:
<table >
<?php
if (mysql_num_rows($pageout_query)) {
while ($pageout_rcpt = mysql_fetch_object($pageout_query)) {
// TODO: set access level dynamically
if ($pageout_rcpt->to_person_id == 0) {
print "<font color=red>Bad data needs conversion</font></td>";
}
else {
print "<tr><td class=\"label\"> <b>". $Pagers[$pageout_rcpt->to_person_id] . "</b> ";
if (CheckAuthByLevel('delete_unitpaging',$_SESSION['access_level'])) {
print "<input type=image title=\"Remove this pager from the notification list\" src=\"Images/cross-16.png\" name=\"delete_pageout_".
$pageout_rcpt->row_id . '_' . $pageout_rcpt->to_person_id . "\" alt=\"Delete\"></td></tr>";
}
// TODO: In future, replace this submit button with a red "X", and replace the handler appropriately.
unset($Pagers[$pageout_rcpt->to_person_id]);
}
}
}
else {
print "<tr><td class=label style=\"color:blue\">No pagers are being notified.</td></tr>";
}
print "</table></td>\n";
}
print "</td>\n";
if ($_SESSION['access_level'] >= 5) {
print "<td valign=middle>\n";
print "<img src=\"Images/bluespacer.gif\" width=1 height=".(int)(20*($pageout_qty+2)).">\n";
print "</td>\n";
print "<td valign=top class=\"label\" nowrap>\n";
print "Add notify about $unit to pager:\n";
print "<table cellpadding=\"2\" cellspacing=\"1\" width=\"100%\">\n";
print "<tr><td class=\"label\"><SELECT name=newpageout>\n";
print "<option value=\"0\"> -select a pager below- </option>\n";
foreach (array_keys($Pagers) as $pager) {
print "<option value=$pager>" . $Pagers[$pager] . "</option>\n";
}
print "</SELECT></td><td class=\"label\"><input type=submit value=\"Add\" name=\"add_pageout\"></td>\n";
}
mysql_close($paginglink);
?>
</tr>
</table>
</td>
</tr>
</table>
<!-- End Unit AutoPage Inner Table -->
</td>
</tr>
</table>
<!-- End Unit AutoPage Outer Table -->
</td>
</tr>
<!-- End Outer Table Row 2 -->
<?php } } ?>
</table>
<!-- End Outer Table -->
</form>
</body>
</html>