-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue_types.php
More file actions
245 lines (226 loc) · 10.9 KB
/
queue_types.php
File metadata and controls
245 lines (226 loc) · 10.9 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
<?php
include("includes/header.php");
/*
* ===================== Getting queue type Data =====================
*/
//DB Connect
$dbconn = new Database;
//Create a query - Get queue types
$query = " SELECT patient_attendance_queue_id, patient_attendance_queue_name, patient_attendance_queue_description, patient_attendance_queue_color, patient_attendance_queue_color
FROM `patient_attendance_queue`
WHERE is_deleted = 0
ORDER BY patient_attendance_queue_id ASC";
//Run query
$queue_types = $dbconn->select($query);
?>
<?php
/*
* ===================== Insert form data into Database =====================
*/
if (isset($_POST["submit"])) {
//Insert new queue type into database
//Prepare values
$patient_attendance_queue_name = mysqli_real_escape_string($dbconn->link, $_POST["patient_attendance_queue_name"]);
$patient_attendance_queue_description = mysqli_real_escape_string($dbconn->link, $_POST["patient_attendance_queue_description"]);
$patient_attendance_queue_color = mysqli_real_escape_string($dbconn->link, $_POST["patient_attendance_queue_color"]);
//Basic validation - Empty fields check
if ($patient_attendance_queue_name == "") {
$error = "Please fill out all the required fields!";
//Redirect
header("Location:queue_types.php?msgtype=error&msg=" . urlencode($error));
} else {
//Create a query
$query = " INSERT INTO `patient_attendance_queue` (`patient_attendance_queue_name`, `patient_attendance_queue_description`,`patient_attendance_queue_color`)
VALUES ('$patient_attendance_queue_name', '$patient_attendance_queue_description', '$patient_attendance_queue_color')";
//Run query
$insert_status = $dbconn->insert($query);
//Validate insertion (The Database class return 1 on success, error on failure)
if ($insert_status == 1) {
//Redirect
header("Location:queue_types.php?msgtype=info&msg=" . urlencode("New queue type '$patient_attendance_queue_name' successfully added to the system"));
} else {
header("Location:queue_types.php?msgtype=error&msg=" . urlencode($insert_status));
}
}
}
?>
<?php
/*
* ===================== Delete a queue type if requested =====================
*/
if (isset($_POST["delete"])) {
//Assign vars
$deletable_patient_attendance_queue_id = intval(mysqli_real_escape_string($dbconn->link, $_POST["deletable_patient_attendance_queue_id"]));
$deletable_patient_attendance_queue_name = (mysqli_real_escape_string($dbconn->link, $_POST["deletable_patient_attendance_queue_name"]));
//Delete
if ($deletable_patient_attendance_queue_id <= 3) {
$error = "The queue type '" . $deletable_patient_attendance_queue_name . "' can't be deleted since it's a system default queue.";
header("Location:queue_types.php?msg=" . urlencode($error) . "&msgtype=error");
} else {
//Delete queue type (Instead of deleting, make is_deleted = true. Affect historical data!)
$query = " UPDATE patient_attendance_queue
SET is_deleted = 1
WHERE patient_attendance_queue_id = '$deletable_patient_attendance_queue_id'";
var_dump($query);
$delete_status = $dbconn->update($query);
if ($delete_status == 1) {
$info = "The queue type '" . $deletable_patient_attendance_queue_name . "' successfully removed.";
header("Location:queue_types.php?msg=" . urlencode($info) . "&msgtype=info");
} else {
$error = $dbconn->error;
header("Location:queue_types.php?msg=" . urlencode($error) . "&msgtype=error");
}
}
}
?>
<?php
/*
* ===================== Update a queue type if requested =====================
*/
if (isset($_POST["update"])) {
//Assign vars
$updatable_patient_attendance_queue_id = intval(mysqli_real_escape_string($dbconn->link, $_POST["updatable_patient_attendance_queue_id"]));
$updatable_patient_attendance_queue_name = (mysqli_real_escape_string($dbconn->link, $_POST["updatable_patient_attendance_queue_name"]));
$patient_attendance_queue_color = (mysqli_real_escape_string($dbconn->link, $_POST["patient_attendance_queue_color"]));
//Get default form data
$query = " SELECT *
FROM patient_attendance_queue
WHERE patient_attendance_queue_id = '$updatable_patient_attendance_queue_id' ";
$updatable_details = $dbconn->select($query);
$updatable_details = $updatable_details->fetch_assoc();
}
if (isset($_POST["submit_update"])) {
//Proceed to updation
//update role
$updatable_patient_attendance_queue_id = mysqli_real_escape_string($dbconn->link, $_POST["updatable_patient_attendance_queue_id"]);
$patient_attendance_queue_name = mysqli_real_escape_string($dbconn->link, $_POST["patient_attendance_queue_name"]);
$patient_attendance_queue_description = mysqli_real_escape_string($dbconn->link, $_POST["patient_attendance_queue_description"]);
$patient_attendance_queue_color = mysqli_real_escape_string($dbconn->link, $_POST["patient_attendance_queue_color"]);
$query = " UPDATE patient_attendance_queue
SET patient_attendance_queue_name = '$patient_attendance_queue_name',
patient_attendance_queue_description = '$patient_attendance_queue_description',
patient_attendance_queue_color = '$patient_attendance_queue_color'
WHERE patient_attendance_queue_id = $updatable_patient_attendance_queue_id";
echo $query;
$update_status = $dbconn->update($query);
if ($update_status == 1) {
$info = "The queue type '" . $patient_attendance_queue_name . "' successfully edited.";
header("Location:queue_types.php?msg=" . urlencode($info) . "&msgtype=info");
} else {
$error = $dbconn->error;
header("Location:queue_types.php?msg=" . urlencode($error) . "&msgtype=error");
}
}
?>
<!-- Title -->
<div class="container my-5 box-white">
<h1>Queue types</h1>
<p>Add and manage queue types here.</p>
<p><?php print_url_message() ?></p>
</div>
<?php if (isset($updatable_details)) : ?>
<!--Edit queue type form-->
<div class="container my-5">
<div class="row">
<div class="col-lg-5 col-md-8 box-white ">
<h2>Edit queue type: <?php echo $updatable_details["patient_attendance_queue_name"] ?> </h2>
<form class="mb-3" method="post" action="queue_types.php">
<div class="mb-3">
<label class="form-label">Queue name<span class="form-required">*</span></label>
<input name="patient_attendance_queue_name" type="text" class="form-control" placeholder="Enter new queue type name" value="<?php echo $updatable_details["patient_attendance_queue_name"] ?>">
</div>
<div class="mb-3">
<label class="form-label">Queue description</label>
<textarea name="patient_attendance_queue_description" class="form-control" rows="3" placeholder="Describe queue type"><?php echo $updatable_details["patient_attendance_queue_description"] ?></textarea>
</div>
<div class="mb-3">
<label class="form-label">Queue type color <span type="button" class="badge text-bg-primary rounded-pill" data-toggle="tooltip" data-placement="top" title="in the 'Queue' management section, this color will be displayed to easily identify the patients assigned to this queue.">?</span></label>
<input name="patient_attendance_queue_color" type="color" class="form-control form-control-color" value="<?php echo $updatable_details["patient_attendance_queue_color"] ?>">
</div>
<div>
<p><span class="form-required">* Required</span></p>
</div>
<div class="my-4">
<input type="hidden" name="updatable_patient_attendance_queue_id" value="<?php echo $updatable_patient_attendance_queue_id ?>">
<input class="me-2 btn btn-outline-primary" name="submit_update" type="submit" value="Change">
<a class="me-2 btn btn-outline-secondary" href="queue_types.php">Cancel</a>
</div>
</form>
</div>
</div>
</div>
<?php endif; ?>
<!-- queue type list -->
<div class="container my-5 box-white">
<div class="row">
<div class="col-lg-8">
<h2>Queue types</h2>
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Queue type</th>
<th scope="col">Description</th>
<th scope="col">Color</th>
<th scope="col">Edit queue</th>
<th scope="col">Delete queue</th>
</tr>
</thead>
<tbody>
<?php while ($row = $queue_types->fetch_assoc()) : ?>
<tr>
<td><?php echo $row["patient_attendance_queue_name"] ?></td>
<td><?php echo $row["patient_attendance_queue_description"] ?></td>
<td><span style="background-color:<?php echo $row["patient_attendance_queue_color"] ?>;width:50px" class="badge rounded-pill"> </span></td>
<td>
<form action="queue_types.php" method="POST">
<input type="hidden" name="updatable_patient_attendance_queue_id" value="<?php echo $row["patient_attendance_queue_id"] ?>">
<input type="hidden" name="updatable_patient_attendance_queue_name" value="<?php echo $row["patient_attendance_queue_name"] ?>">
<input type="hidden" name="patient_attendance_queue_color" value="<?php echo $row["patient_attendance_queue_color"] ?>">
<input class="btn btn-outline-secondary btn-table" type="submit" name="update" value="Edit">
</form>
</td>
<td>
<form action="queue_types.php" method="POST" onsubmit="return confirm('Are you sure you want to delete this queue type?');">
<input type="hidden" name="deletable_patient_attendance_queue_id" value="<?php echo $row["patient_attendance_queue_id"] ?>">
<input type="hidden" name="deletable_patient_attendance_queue_name" value="<?php echo $row["patient_attendance_queue_name"] ?>">
<input class="btn btn-outline-danger btn-table" type="submit" name="delete" value="Remove">
</form>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
<!--Add queue types form-->
<div class="container my-5">
<div class="row">
<div class="col-lg-5 col-md-8 box-white ">
<h2>Add new queue types</h2>
<form class="mb-3" method="post" action="queue_types.php">
<div class="mb-3">
<label class="form-label">Queue type <span class="form-required">*</span></label>
<input name="patient_attendance_queue_name" type="text" class="form-control" placeholder="Enter new Queue type">
</div>
<div class="mb-3">
<label class="form-label">Queue type description</label>
<textarea name="patient_attendance_queue_description" class="form-control" rows="3" placeholder="Describe Queue type"></textarea>
</div>
<div class="mb-3">
<label class="form-label">Queue type color <span type="button" class="badge text-bg-primary rounded-pill" data-toggle="tooltip" data-placement="top" title="in the 'Queue' management section, this color will be displayed to easily identify the patients assigned to this queue.">?</span></label>
<input name="patient_attendance_queue_color" type="color" class="form-control form-control-color" value="#d9d9d9">
</div>
<div>
<p><span class="form-required">* Required</span></p>
</div>
<div class="my-4">
<input class="me-2 btn btn-outline-primary" name="submit" type="submit" value="Add Type">
</div>
</form>
</div>
</div>
</div>
<?php
include("includes/footer.php");
?>