-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.php
More file actions
235 lines (211 loc) · 9.84 KB
/
Copy pathdata.php
File metadata and controls
235 lines (211 loc) · 9.84 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
<?php
include("assets/head/h.php");
?>
<!-- [ Main Content ] start -->
<div class="pcoded-main-container">
<div class="pcoded-content">
<!-- [ breadcrumb ] start -->
<div class="page-header">
<div class="page-block">
<div class="row align-items-center">
<div class="col-md-12">
<div class="page-header-title">
<h5 class="m-b-10">Record Operations </h5>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="card">
<div class="card-body pt-3">
<!-- Facility Addition Form -->
<form enctype="multipart/form-data" method="POST" action="#">
<!-- Select District -->
<div class="row mb-3">
<label for="District1" class="col-md-4 col-lg-3 col-form-label">Select District</label>
<div class="col-md-8 col-lg-9">
<select class="form-control" id="District1" name="District1" required>
<option value="">- Select District -</option>
<?php
$districtQuery = "SELECT dist_id, Dist_name FROM dist_master";
$result = mysqli_query($con, $districtQuery);
while ($row = mysqli_fetch_array($result)) {
echo "<option value='{$row['dist_id']}'>{$row['Dist_name']}</option>";
}
mysqli_free_result($result);
?>
</select>
</div>
</div>
<!-- Select Health Block -->
<div class="row mb-3">
<label for="block" class="col-md-4 col-lg-3 col-form-label">Select Health Block</label>
<div class="col-md-8 col-lg-9">
<select class="form-control" id="block" name="block" required>
<option value="0">- Select Health Block -</option>
</select>
</div>
</div>
<!-- Select Facility Type -->
<div class="row mb-3">
<label for="facility1234" class="col-md-4 col-lg-3 col-form-label">Select Facility</label>
<div class="col-md-8 col-lg-9">
<select class="form-control" id="facility" name="facility" required>
<option value="0">- Select Facility -</option>
</select>
</div>
</div>
<div class="row mb-3">
<label for="dataop" class="col-md-4 col-lg-3 col-form-label">Record Operations</label>
<div class="col-md-8 col-lg-9">
<select class="form-control" id="dataop1" name="dataop1" required>
<option value="1">Delete Outcome</option>
</select>
</div>
</div>
<div class="row mb-3">
<label for="date1" class="col-md-4 col-lg-3 col-form-label">Select Month</label>
<div class="col-md-8 col-lg-9">
<input type="month" class="form-control" name="date1" id="date1" required>
</div>
</div>
<input type="hidden" id="fac_id" name="fac_id">
<input type="hidden" id="dist_id" name="dist_id">
<input type="hidden" id="block_id" name="block_id">
<input type="hidden" id="nin_no2" name="nin_no2">
<input type="hidden" id="Health_facilty_type" name="Health_facilty_type">
<!-- Submit Button -->
<div class="text-center">
<button type="submit" id="postsubmit" name="postsubmit" class="btn btn-primary">Delete Data</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
// Handle Form Submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['postsubmit'])) {
$district = $_POST['District1'] ?? '';
$block = $_POST['block'] ?? '';
$facility = $_POST['facility'] ?? '';
$dataOp = $_POST['dataop1'] ?? '';
$selectedMonth = $_POST['date1'] ?? '';
if (empty($district) || empty($block) || empty($facility) || empty($dataOp) || empty($selectedMonth)) {
echo "<script>alert('Please fill all required fields.');</script>";
exit;
}
if ($dataOp == '2') { // Delete Outcome for selected month
$formattedMonth = date("Y/m", strtotime($selectedMonth));
mysqli_query($con, "SET SQL_SAFE_UPDATES = 0");
$deleteQuery = "DELETE FROM outcome_values_in_old
WHERE institute_id = '$facility'
AND month_in = '$formattedMonth'";
if (mysqli_query($con, $deleteQuery)) {
echo "<script>alert('Outcome data deleted successfully for $formattedMonth.');</script>";
} else {
echo "<script>alert('Error deleting outcome data.');</script>";
}
}
else {
echo "<script>alert('Only Delete Outcome logic implemented currently.');</script>";
}
}
?>
<script>
$(document).ready(function() {
// Fetch blocks based on selected district
$("#District1").on('change', function() {
var districtId = $(this).val();
if (districtId) {
$.ajax({
method: "POST",
url: "assets/get/response_dist_create.php",
data: {
cid: districtId
},
dataType: "html",
success: function(data) {
$("#block").html(data);
$("#facility").html('<option value="">Select Facility</option>');
},
error: function(xhr, status, error) {
console.error("Error fetching blocks:", error);
}
});
} else {
$("#block").html('<option value="">Select Block</option>');
$("#facility").html('<option value="">Select Facility</option>');
}
});
// Fetch facilities based on selected block
$("#block").on('change', function() {
var districtId = $("#District1").val();
var blockId = $(this).val();
if (districtId && blockId) {
$.ajax({
method: "POST",
url: "assets/get/get_facilities_by_block1.php",
data: {
distid: districtId,
block_id: blockId
},
dataType: "html",
success: function(data) {
$("#facility").html(data);
},
error: function(xhr, status, error) {
console.error("Error fetching facilities:", error);
}
});
} else {
$("#facility").html('<option value="">Select Facility</option>');
}
});
// Fetch facility details and populate hidden fields
$("#facility").on('change', function() {
var facilityId = $(this).val();
if (facilityId) {
$.ajax({
method: "POST",
url: "assets/get/get_facility_details.php",
data: {
facility_id: facilityId
},
dataType: "json",
success: function(data) {
if (data.error) {
console.error(data.error);
clearFacilityFields();
} else {
$("#fac_id").val(data.fac_id);
$("#dist_id").val(data.dist_id);
$("#block_id").val(data.block_id);
$("#nin_no2").val(data.nin_no);
$("#Health_facilty_type").val(data.Health_facilty_type);
}
},
error: function(xhr, status, error) {
console.error("Error fetching facility details:", error);
clearFacilityFields();
}
});
} else {
clearFacilityFields();
}
});
// Helper function to clear hidden fields
function clearFacilityFields() {
$("#fac_id").val('');
$("#dist_id").val('');
$("#block_id").val('');
$("#nin_no2").val('');
$("#Health_facilty_type").val('');
}
});
</script>
<?php include("assets/head/f.php"); ?>