-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddCase.php
349 lines (269 loc) · 11.4 KB
/
addCase.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
<?php include('partials/headerSection.php');
ob_start();
?>
<div class="main">
<?php include('partials/sideMenu.php')?>
<div class="mainContent">
<div class="topSection flex">
<div class="dashboardTitle">
<h1>New Case Page</h1>
</div>
<div class="userBox flex">
<a href="index.php">
<div class="adminImage">
<img src="./assets/images/pp.jpg" alt="Admin Image">
</div>
</a>
<div class="userName">
<span>Administrator</span>
<small><?php
if(isset($_SESSION['firstName'])){
echo $_SESSION['firstName'];
}
?></small>
</div>
<i class="uil uil-bell icon"></i>
</div>
</div>
<div class="body">
<div class="overViewDiv">
<div class="intro flex" >
<h3 class="title">Fill the fields to add a new case!</h3>
<?php
if(isset($_SESSION['addedCase'])){
echo $_SESSION['addedCase'];
unset($_SESSION['addedCase']);
}
?>
<div class="addBtn">
<a href="cases.php">
<span>View Cases</span>
</a>
</div>
</div>
</div>
<div class="mainItems">
<div class="addCaseContainer flex">
<div class="rowsDiv">
<form action="" method="POST" enctype="multipart/form-data">
<div class="row">
<label for="incType">Incident Type</label></label>
<select name="incType" id="incType" required>
<option value="Not Mentioned"> </option>
<?php
$sql = "SELECT * FROM incident_types";
$res = mysqli_query($conn, $sql);
if($res == TRUE){
$count = mysqli_num_rows($res);
echo $count;
if($count > 0){
while($row = mysqli_fetch_assoc($res)){
$typeName = $row['inctype_name'];
echo $typeName;
?>
<option value="<?php echo $typeName; ?>"><?php echo $typeName; ?></option>
<?php
}
}
}
else{
die('Failed to connect to the database');
}
?>
</select>
</div>
<div class="row">
<label for="location">Location</label>
<input type="text" name="location" id="location" >
</div>
<div class="row">
<label for="incDate">Date of Incident</label>
<input type="date" name="incDate" id="incDate">
</div>
<div class="row">
<label for="incTime">Time of Incident</label>
<input type="time" name="incTime" id="incTime">
</div>
<div class="row">
<label for="incDateReported">Date Reported</label>
<input type="date" name="incDateReported" id="incDateReported>
</div>
<div class="row">
<label for="reportTime">Time Reported</label>
<input type="time" name="reportTime" id="reportTime">
</div>
<div class="row">
<label for="reporterName">Reported By</label>
<input type="text" name="reporterName" id="reporterName">
</div>
<div class="row">
<label for="reporterID">Reporter ID</label>
<input type="number" name="atpID" id="reporterID">
</div>
<div class="row">
<label for="entrantName">OB Entry by</label>
<input type="text" name="entrantName" id="entrantName" required>
</div>
<div class="row">
<label for="desc">Incident Description</label>
<textarea name="desc" id="desc" required >
</textarea>
</div>
</div>
<div class="rowsDiv">
<div class="row">
<label for="desc2">Action taken</label>
<textarea name="action" id="desc2" required >
</textarea>
</div>
<div class="select_row">
<label for="file1">Select Image (1)</label>
<input type="file" name="image1" id="file1" placeholder="Select file (images)" style="cursor: pointer;" >
</div>
<div class="select_row">
<label for="file2">Select Image (2)</label>
<input type="file" name="image2" id="file2" placeholder="Select file (images)" style="cursor: pointer;">
</div>
<div class="select_row">
<label for="file3">Select Image (3)</label>
<input type="file" name="image3" id="file3" placeholder="Select file (images)" style="cursor: pointer;">
</div>
<div class="row">
<label for="category">Incident Category</label>
<select name="category" id="category" required>
<option value="Not Mentioned"></option>
<option value="Minor">Minor Incident</option>
<option value="Modorate">Modorate Incident</option>
<option value="Major">Major Incident</option>
</select>
</div>
<div class="row" >
<label class="container" id="status">Status
<input type="checkbox" name="status" value="Closed">
<span class="checkmark"></span>
</label>
</div>
<div class="row">
<input type="submit" name="submit" id="submitBtn" value="Submit Form">
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php include('partials/footer.php')?>
<?php
$incDateVariable = "";
$inc_reported_Date_Variable = "";
if(isset($_POST['submit'])){
// get input through variables
$incidentType = $_POST['incType'];
$location = $_POST['location'];
$incTime = $_POST['incTime'];
$reportTime = $_POST['reportTime'];
$reporterName = $_POST['reporterName'];
$reporterId = $_POST['atpID'];
$entrantName = $_POST['entrantName'];
$desc = $_POST['desc'];
$category = $_POST['category'];
$status = $_POST['status'];
$action = $_POST['action'];
if($status == "" ){
$status = 'Open';
}
// Format dates to dd/mm/yyyy ===================>
$incDateVariable = $_POST['incDate'];
$dateResult = explode('-',$incDateVariable);
$date = $dateResult['2'];
$month = $dateResult['1'];
$year = $dateResult['0'];
$incDate = $date.'/'.$month.'/'.$year;
$inc_reported_Date_Variable = $_POST['incDateReported'];
$dateResult = explode('-',$inc_reported_Date_Variable);
$report_date = $dateResult['2'];
$report_month = $dateResult['1'];
$report_year = $dateResult['0'];
$incDateReported = $report_date.'/'.$report_month.'/'.$report_year;
// Uploading Image 1 to the database =======================>
if(isset($_FILES['image1']['name'])){
//To upload the image we need the image name, source and destination.
$image1 = $_FILES['image1']['name'];
// Source ================>
$image1Source = $_FILES['image1']['tmp_name'];
// Destination ================>
$image1Destination = "./OB Images/ObImage".$image1;
// Finally upload the image ========>
$uploadInage1 = move_uploaded_file($image1Source, $image1Destination);
if($uploadInage1 == false){
$_SESSION['imgUpload'] = '<span class="fail">Failed to upload image!</span>';
header('location:' .SITEURL. 'addCase.php');
}
}else{
$image1 ="";
}
// Uploading Image 2 to the database =======================>
if(isset($_FILES['image2']['name'])){
// Get Image name ====>
$image2 = $_FILES['image2']['name'];
// Get Image source ====>
$image2Source = $_FILES['image2']['tmp_name'];
// Set Image destination ====>
$image2Destination = "./OB Images/ObImage".$image2;
// Upload image to the database ====>
$uploadImage2 = move_uploaded_file($image2Source, $image2Destination);
if($uploadImage2 == FALSE){
$_SESSION['imgUplaod'] = '<span class="fail">Rem!</span>';
header('location:' .SITEURL. 'addCase.php');
}
}else{
$image2 = "";
}
// Uploading Image 3 to the database =======================>
if(isset($_FILES['image3']['name'])){
// Get image name =======>
$image3 = $_FILES['image3']['name'];
// Get image Source =======>
$image3Source = $_FILES['image3']['tmp_name'];
// Set image Destination =======>
$image3Destination = "./OB Images/ObImage".$image3;
// Upload image to the database =======>
$uploadImage3 = move_uploaded_file($image3Source, $image3Destination);
if($uploadImage3 == false){
$_SESSION['imgUplaod'] = '<span class="fail">Failed to upload image!</span>';
header('location:' .SITEURL. 'addCase.php');
}
}
else{
$image3 = "";
}
$sql = "INSERT INTO cases_table SET
incident_type = '$incidentType',
location = '$location',
incident_date = '$incDate',
incident_time = '$incTime',
reported_date = '$incDateReported',
reported_time = '$reportTime',
reporter_name = '$reporterName',
reporter_emp_id = '$reporterId',
ob_entrant = '$entrantName',
incident_desc = '$desc',
action_taken = '$action',
case_category = '$category',
case_status = '$status',
image_one = '$image1',
image_two = '$image2',
image_three = '$image3'
";
$result = mysqli_query($conn, $sql);
if($result == TRUE){
$_SESSION['addedCase'] = '<span class="success">Case added Successfully!</span>';
header('location:'.SITEURL. 'addCase.php');
exit();
}
else{
die('Failed to connect to database!');
}
}
?>