-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_assign.php
More file actions
195 lines (166 loc) · 7.48 KB
/
Copy pathtask_assign.php
File metadata and controls
195 lines (166 loc) · 7.48 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
<?php
include "header_intern.php";
$cno = $_COOKIE['case_id'];
// echo "$cno";
if (isset($_REQUEST["save"])) {
$tid = $_COOKIE["assign_id"];
$intern = $_REQUEST['intern'];
$remark = $_REQUEST['remark'];
$alloted_by = $_SESSION["intern_id"];
$alloted_date = $_REQUEST["rmk_date"];
$new_status = "reassign";
$old_status="re_alloted";
$action_by="intern";
// Fetching the instruction from the task table based on case_id
$stmt = $obj->con1->prepare("SELECT * FROM `task` WHERE `case_id` = ?");
$stmt->bind_param('i', $cno); // Changed $con to $cno
$stmt->execute();
$Resp = $stmt->get_result();
if ($row = mysqli_fetch_array($Resp)) {
$instruction = $row["instruction"];
} else {
// Handle case where no rows were returned
setcookie("sql_error", "No task found for this case ID.", time() + 3600, "/");
header("location:task_intern.php");
exit();
}
try {
// Prepare insert statement
$stmt = $obj->con1->prepare("INSERT INTO task(`case_id`, `alloted_to`, `instruction`, `alloted_by`,`action_by`, `alloted_date`, `status`, `remark`) VALUES (?, ?, ?, ?, ?, ?, ?,?)");
// Bind parameters
$stmt->bind_param("iisissss", $cno, $intern, $instruction, $alloted_by,$action_by, $alloted_date, $new_status, $remark);
// Execute and check response
if (!$stmt->execute()) {
throw new Exception("Problem in adding! " . strtok($obj->con1->error, "("));
}
$stmt->close();
// Update the status of the associated task in the task table
$updateStmt = $obj->con1->prepare("UPDATE `task` SET `status` = ? WHERE `id` = ?");
$updateStmt->bind_param("si", $old_status, $tid);
$updateResp = $updateStmt->execute();
if (!$updateResp) {
throw new Exception("Problem in updating task status! " . strtok($obj->con1->error, "("));
}
$updateStmt->close();
} catch (\Exception $e) {
setcookie("sql_error", urlencode($e->getMessage()), time() + 3600, "/");
}
if ($Resp && $updateResp) {
setcookie("msg", "data", time() + 3600, "/");
header("location:task_intern.php");
} else {
setcookie("msg", "fail", time() + 3600, "/");
header("location:task_intern.php");
}
}
if (isset($_REQUEST["update"])) {
$e_id = $_COOKIE['edit_id'];
$tid = $_REQUEST['taskid'];
$stage = $_REQUEST['stage'];
$remark = $_REQUEST['remark'];
$date = $_REQUEST['dos'];
$new_status = "reassign";
$old_status="re_alloted";
$action_by="intern";
try {
$stmt = $obj->con1->prepare("UPDATE case_hist SET task_id=?, stage=?,remarks=?,dos=?,`status`=? WHERE id=?");
$stmt->bind_param("issssi", $tid,$stage,$remark,$date, $status, $e_id);
$Resp = $stmt->execute();
if (!$Resp) {
throw new Exception(
"Problem in updating! " . strtok($obj->con1->error, "(")
);
}
$stmt->close();
} catch (\Exception $e) {
setcookie("sql_error", urlencode($e->getMessage()), time() + 3600, "/");
}
if ($Resp) {
setcookie("edit_id", "", time() - 3600, "/");
setcookie("msg", "update", time() + 3600, "/");
} else {
setcookie("msg", "fail", time() + 3600, "/");
}
header("location:case_hist.php");
header("location:case_hist.php");
}
?>
<!-- <a href="javascript:go_back();"><i class="bi bi-arrow-left"></i></a> -->
<div class="pagetitle">
<h1>Task Assign</h1>
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="index.php">Home</a></li>
<li class="breadcrumb-item">Task Assign</li>
<li class="breadcrumb-item active">
<?php echo (isset($mode)) ? (($mode == 'view') ? 'View' : 'Edit') : 'Add' ?>-
<strong><?= $cno ?></strong>
</li>
</ol>
</nav>
</div><!-- End Page Title -->
<section class="section">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<!-- Multi Columns Form -->
<form class="row g-3 pt-3" method="post" enctype="multipart/form-data">
<div class="col-md-12">
<label for="intern" class="form-label">Interns</label>
<select class="form-control" id="intern" name="intern"
<?php echo isset($mode) && $mode === 'view' ? 'disabled' : '' ?>>
<option value="">Select an Intern</option>
<?php
$signedInInternId = $_SESSION['intern_id'];
// Update the query to exclude the signed-in intern
$intern = "SELECT * FROM `interns` WHERE id != ?";
$stmt = $obj->con1->prepare($intern);
$stmt->bind_param("i", $signedInInternId);
$stmt->execute();
$result = $stmt->get_result();
while ($row = mysqli_fetch_array($result)) { ?>
<option value="<?= htmlspecialchars($row["id"]) ?>">
<?= htmlspecialchars($row["name"]) ?>
</option>
<?php } ?>
</select>
</div>
<div class="col-md-12">
<label for="title" class="form-label">Remark</label>
<input type="text" class="form-control" id="remark" name="remark"
value="<?php echo (isset($mode) && isset($data['remarks'])) ? $data['remarks'] : ''; ?>"
<?php echo isset($mode) && $mode == 'view' ? 'readonly' : ''; ?>>
</div>
<div class="col-md-12">
<label for="title" class="form-label">Remark Date</label>
<input type="date" class="form-control" id="rmk_date" name="rmk_date"
value="<?php echo (isset($mode) && isset($data['remark'])) ? $data['remark'] : date('Y-m-d'); ?>"
<?php echo isset($mode) && $mode == 'view' ? 'readonly' : ''; ?>>
</div>
<div class="text-left mt-4">
<button type="submit"
name="<?php echo isset($mode) && $mode == 'edit' ? 'update' : 'save' ?>" id="save"
class="btn btn-success <?php echo isset($mode) && $mode == 'view' ? 'd-none' : '' ?>"><?php echo isset($mode) && $mode == 'edit' ? 'Update' : 'Save' ?>
</button>
<button type="button" class="btn btn-danger" onclick="javascript: go_back();">
Close</button>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<script>
function go_back() {
eraseCookie("edit_id");
eraseCookie("view_id");
eraseCookie("add_id");
eraseCookie("case_no");
window.location = "task_intern.php";
}
</script>
<?php
include "footer_intern.php";
?>