-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeptask copy.php
More file actions
319 lines (278 loc) · 15.5 KB
/
deptask copy.php
File metadata and controls
319 lines (278 loc) · 15.5 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
<?php
include("assets/head/h.php");
$facid = $_SESSION['u_facilityid'];
$factype = $_SESSION['f_type_id'];
$assid = $_SESSION['assperiod'];
$facname = $_SESSION['facname'];
$factypename1 = $_SESSION['factypename'];
// Handle form submission
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['submit_form2'])) {
$_SESSION['dept_id1'] = $_POST['department_id'];
// echo "<div class='alert alert-success'>Department selected successfully!</div>";
}
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['submit_form1'])) {
$_SESSION['assperiod'] = $_POST['assis'];
// echo "<div class='alert alert-success'>Department selected successfully!</div>";
}
?>
<div class="pcoded-main-container">
<div class="pcoded-content">
<div class="pagetitle mb-2">
<?php
$assessmentName = '';
if (!empty($_SESSION['assperiod'])) {
$stmt = $con->prepare("SELECT ass_name FROM assessment_desc WHERE id = ?");
$stmt->bind_param("i", $_SESSION['assperiod']);
$stmt->execute();
$result = $stmt->get_result();
if ($row = $result->fetch_assoc()) {
$assessmentName = $row['ass_name'];
}
$stmt->close();
}
?>
<h5 class="fw-bold text-primary mb-1">
<i class="bi bi-question-circle-fill me-2"></i>
Facility setup for assessment. Current Assessment is
<span class="text-warning"><?= htmlspecialchars($assessmentName) ?></span>
</h5>
</div>
<div class="row">
<div class="col-sm-6">
<div class="card">
<div class="card-header bg-primary text-white fw-bold">
Current assessment setup
</div>
<div class="card-body">
<form method="POST" action="">
<p>
<strong>Switch Assesment</strong>
<select class="mb-3 form-control form-control-sm" id="assis" name="assis" required>
<option value="">-- Select --</option>
<?php
$query = "SELECT ass_name,id
FROM assessment_desc
WHERE fac_id_fk = ?";
$stmt = $con->prepare($query);
$stmt->bind_param("i", $facid);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
echo "<option value='{$row['id']}'>{$row['ass_name']}</option>";
}
?>
</strong> departments. Please select the department for which the assessment will be carried out.
</select>
</p>
<button type="submit" name="submit_form1" class="btn btn-primary">Update current assessment</button>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['submit_form1'])) {
$_SESSION['assperiod'] = $_POST['assis'];
$selectedId = $_POST['assis'];
$stmt = $con->prepare("SELECT ass_name FROM assessment_desc WHERE id = ?");
$stmt->bind_param("i", $selectedId);
$stmt->execute();
$result = $stmt->get_result();
if ($row = $result->fetch_assoc()) {
echo "<div class='alert alert-success'>You have selected <strong>" . htmlspecialchars($row['ass_name']) . "</strong> for current assessment.</div>";
}
$stmt->close();
}
?>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card">
<div class="card-header bg-primary text-white fw-bold">
Department/Assesment package Setup for Current Assessment
</div>
<div class="card-body">
<form method="POST" action="">
<?php
if ($factype == 8) {
?>
<strong>select the assessment package. </strong>
<?php } else {
?>
<strong>select the Department. </strong>
<?php } ?>
<select class="mb-3 form-control form-control-sm" id="department_id" name="department_id" required>
<option value="">-- Select --</option>
<?php
$query = "SELECT DISTINCT a.fac_dept_id_fk, b.dept_name
FROM concern_subtype_chklist AS a
JOIN fac_department AS b ON a.fac_dept_id_fk = b.fac_dept_id
WHERE a.fac_type_id_fk = ? AND a.fac_dept_id_fk IN (
SELECT fac_dept_id FROM fac_dept_map WHERE fac_id = ? AND acc_id = ?
)";
$stmt = $con->prepare($query);
$stmt->bind_param("iii", $factype, $facid, $assid);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
echo "<option value='{$row['fac_dept_id_fk']}'>{$row['dept_name']}</option>";
}
$stmt->close();
// $con->close();
?>
</select>
<button type="submit" name="submit_form2" class="btn btn-primary">Submit</button>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['submit_form2'])) {
$_SESSION['dept_id1'] = $_POST['department_id'];
$selectedId = $_POST['department_id'];
$stmt = $con->prepare("SELECT dept_name FROM fac_department WHERE fac_dept_id = ?");
$stmt->bind_param("i", $selectedId);
$stmt->execute();
$result = $stmt->get_result();
if ($row = $result->fetch_assoc()) {
echo "<div class='alert alert-success'>You have selected <strong>" . htmlspecialchars($row['dept_name']) . "</strong> for current assessment.</div>";
}
$stmt->close();
}
?>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="card">
<?php if ($factype == 8) { ?>
<div class="card-header bg-primary text-white fw-bold">
Assessment package setup for current assessment
</div>
<?php } else { ?>
<div class="card-header bg-primary text-white fw-bold">
Department setup for current assessment
</div>
<?php } ?>
<div class="card-body">
<?php
// Handle single activation
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['activate_department_id'])) {
$deptId = intval($_POST['activate_department_id']);
$facilityId = $_SESSION['u_facilityid'];
$assessmentPeriod = $_SESSION['assperiod'];
// Prevent duplicate
$check = $con->prepare("SELECT 1 FROM fac_dept_map WHERE fac_id = ? AND acc_id = ? AND fac_dept_id = ?");
$check->bind_param("iii", $facilityId, $assessmentPeriod, $deptId);
$check->execute();
$check->store_result();
if ($check->num_rows === 0) {
$insert = $con->prepare("INSERT INTO fac_dept_map (fac_id, acc_id, fac_dept_id) VALUES (?, ?, ?)");
$insert->bind_param("iii", $facilityId, $assessmentPeriod, $deptId);
$insert->execute();
echo "<div class='alert alert-success'>Department activated successfully!</div>";
$insert->close();
} else {
echo "<div class='alert alert-info'>Department already activated.</div>";
}
$check->close();
}
?>
<?php
// Handle deactivation
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['disable_department_id'])) {
$deptId = intval($_POST['disable_department_id']);
$facilityId = $_SESSION['u_facilityid'];
$assessmentPeriod = $_SESSION['assperiod'];
$delete = $con->prepare("DELETE FROM fac_dept_map WHERE fac_id = ? AND acc_id = ? AND fac_dept_id = ?");
$delete->bind_param("iii", $facilityId, $assessmentPeriod, $deptId);
if ($delete->execute()) {
echo "<div class='alert alert-warning'>Department disabled successfully!</div>";
}
$delete->close();
}
?>
<table class="table table-bordered table-sm">
<thead class="table-light">
<tr>
<th>Department Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT DISTINCT a.fac_dept_id_fk, b.dept_name
FROM concern_subtype_chklist AS a
JOIN fac_department AS b ON a.fac_dept_id_fk = b.fac_dept_id
WHERE a.fac_type_id_fk = ? and b.active_status=1";
$stmt = $con->prepare($query);
$stmt->bind_param("i", $factype);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$deptId = $row['fac_dept_id_fk'];
// Check if this department is already active
$checkQuery = $con->prepare("SELECT 1 FROM fac_dept_map WHERE fac_id = ? AND acc_id = ? AND fac_dept_id = ?");
$checkQuery->bind_param("iii", $facid, $assid, $deptId);
$checkQuery->execute();
$checkQuery->store_result();
$alreadyActive = $checkQuery->num_rows > 0;
$checkQuery->close();
echo "<tr>";
echo "<td>{$row['dept_name']}</td>";
echo "<td>";
if ($alreadyActive) {
echo "<form method='POST' style='display:inline; margin-right:5px;'>
<input type='hidden' name='disable_department_id' value='{$deptId}'>
<button type='submit' class='btn btn-sm btn-danger'>Disable</button>
</form>
<button class='btn btn-sm btn-success' disabled>Activated</button>";
} else {
echo "<form method='POST' style='display:inline;'>
<input type='hidden' name='activate_department_id' value='{$deptId}'>
<button type='submit' class='btn btn-sm btn-primary'>Activate</button>
</form>";
}
echo "</td>";
echo "</tr>";
}
$stmt->close();
?>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card shadow-sm">
<div class="card-header bg-primary text-white fw-bold">
Begin New Assessment Cycle
</div>
<div class="card-body">
<form method="post" action="assets/get/create_assessment.php">
<div class="mb-3">
<label for="ass_name" class="form-label fw-semibold text-primary small">
Name of New Assessment Cycle
</label>
<input type="text" id="ass_name" name="ass_name" class="form-control form-control-sm" required>
</div>
<div class="text-center">
<button type="submit" name="save_assessor" class="btn btn-sm btn-primary px-4">
<i class="bi bi-save2-fill me-1"></i> Submit
</button>
</div>
</form>
</div>
<?php if (!empty($_SESSION['ass_create_success'])): ?>
<div class="alert alert-success">
<?= htmlspecialchars($_SESSION['success']) ?>
</div>
<?php unset($_SESSION['ass_create_success'], $_SESSION['success']); ?>
<?php elseif (!empty($_SESSION['error'])): ?>
<div class="alert alert-danger">
<?= htmlspecialchars($_SESSION['error']) ?>
</div>
<?php unset($_SESSION['error']); ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<?php include("assets/head/f.php"); ?>