-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdispatch.php
187 lines (152 loc) · 4.3 KB
/
dispatch.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
<!DOCTYPE HTML>
<html>
<head>
<title>Police Emergency Service System</title>
<?php
if (!isset($_POST["btnProcessCall"]) && !isset($_POST["btnDispatch"]))
header("Location: logcall.php");
?>
<?php
if (isset($_POST["btnDispatch"]))
{
$con = mysql_connect("localhost","Aliah","Asdfghjkl1234");
if(!$con)
{
die('Cannot connect to database :'.mysql_error());
}
mysql_select_db("22_aliah_pessdb",$con);
$patrolcarDispatched = $_POST["chkPatrolcar"];
$numOfPatrocarDispatched = count($patrolcarDispatched);
$incidentStatus;
if ($numOfPatrocarDispatched > 0) {
$incidentStatus='2';
} else {
$incidentStatus='1';
}
$sql="INSERT INTO incident (callerName,phoneNumber,incidentTypeId," .
"incidentLocation,incidentDesc, incidentStatusId) " .
"VALUES('".$_POST['callerName'] . "','" . $_POST['contactNo'] .
"','" . $_POST['incidentType']. "','" . $_POST['location'] .
"','" . $_POST['incidentDesc'] ."','" . $incidentStatus . "')";
if(!mysql_query($sql,$con))
{
die("Error1:".mysql_error());
}
//retrieve new incremental key for incidentId
$incidentId=mysql_insert_id($con);
for($i=0; $i < $numOfPatrocarDispatched; $i++)
{
$sql= "UPDATE patrolcar SET patrolcarStatusId='1' WHERE patrolcarId='" . $patrolcarDispatched[$i] . "'";
if(!mysql_query($sql,$con))
{
die("Error2:".mysql_error());
}
$sql="INSERT INTO dispatch(incidentId,patrolcarId,timeDispatched) VALUES " .
"('" . $incidentId . "','" . $patrolcarDispatched[$i] . "',NOW())";
if(!mysql_query($sql,$con))
{
die("Error3:".mysql_error());
}
}
mysql_close($con);
?>
<?php } ?>
</head>
<body>
<?php require_once 'header.php'; ?>
<br><br>
<form name="form1" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?> ">
<fieldset>
<legend>Incident Detail</legend>
<table class="ContentStyle">
<tr>
<td>Caller's Name :</td>
<td><?php echo $_POST['callerName'] ?>
<input type="hidden" name="callerName" id="callerName"
value="<?php echo $_POST['callerName'] ?>"></td>
</tr>
<tr>
<td>Contact No :</td>
<td><?php echo $_POST['contactNo']?> <input
type="hidden" name="contactNo" id="contactNo"
value="<?php echo $_POST['contactNo']?>"></td>
</tr>
<tr>
<td>Location :</td>
<td><?php echo $_POST['location'] ?> <input
type="hidden" name="location" id="location"
value="<?php echo $_POST['location'] ?>"></td>
</tr>
<tr>
<td>Incident Type :</td>
<td><?php echo $_POST['incidentType'] ?> <input
type="hidden" name="incidentType" id="incidentType"
value="<?php echo $_POST['incidentType'] ?>"></td>
<tr>
<td>Description :</td>
<td><textarea name="incidentDesc" cols="45"
rows="5" readonly id="incidentDesc"><?php echo $_POST['incidentDesc'] ?></textarea>
<input name="incidentDesc" type="hidden"
id="incidentDesc" value="<?php echo $_POST['incidentDesc'] ?>"></td>
</tr>
</table>
<br><br>
<?php
$con=mysql_connect("localhost","Aliah","Asdfghjkl1234");
if(!$con)
{
die('Cannot connect to database:'.mysql_error());
}
//select a table in the database
mysql_select_db("22_aliah_pessdb",$con);
$sql ="SELECT patrolcarId,statusDesc FROM patrolcar JOIN patrolcar_status
ON patrolcar.patrolcarStatusId=patrolcar_status.statusId
WHERE patrolcar.patrolcarStatusId='2' OR patrolcar.patrolcarStatusId='3'";
$result = mysql_query($sql,$con);
$incidentArray;
$count=0;
while($row=mysql_fetch_array($result))
{
$patrolcarArray[$count]=$row;
$count++;
}
if(!mysql_query($sql,$con))
{
die('Error:'.mysql_error());
}
mysql_close($con);
?>
<table width="40%" border="1" align="center" cellpadding="4"
cellspacing="8">
<tr>
<td width="20%"> </td>
<td width="51%">Patrol Car ID</td>
<td width="29%">Status</td>
<tr>
<?php
$i=0;
while($i<$count){
?>
<tr>
<td class="td_label"><input type="checkbox" name="chkPatrolcar[]" value="<?php echo
$patrolcarArray[$i]['patrolcarId']?>"></td>
<td><?php echo $patrolcarArray[$i]['patrolcarId']?></td>
<td><?php echo $patrolcarArray[$i]['statusDesc']?></td>
</tr>
<?php $i++;
} ?>
</table>
<table width="80%" border="0" align="center" cellpadding="4"
cellspacing="4">
<tr>
<td><input type="reset"
name="btnCancel" id="btnCancel" value="Reset"></td>
<td colspan="2"> <input
type="submit" name="btnDispatch" id="btnDispatch" value="Dispatch">
</td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>