-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhealthblock.php
More file actions
129 lines (115 loc) · 5.58 KB
/
healthblock.php
File metadata and controls
129 lines (115 loc) · 5.58 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
<?php include("assets/head/h.php"); ?>
<div class="pcoded-main-container">
<div class="pcoded-content">
<div class="pagetitle">
<h5 class="fw-bold text-primary">
Health Block Setup
</h5>
</div>
<div class="row">
<div class="col-sm-12">
<div class="card">
<div class="card-body">
<form class="row align-items-center" enctype="multipart/form-data" method="post" action="">
<!-- Select District -->
<div class="col-auto">
<select id="District1" name="District1" required class="form-control">
<option value="">-- Select District --</option>
<?php
$call_q1 = "SELECT dist_id, Dist_name FROM dist_master";
$q22 = mysqli_query($con, $call_q1);
while ($row = mysqli_fetch_array($q22)) {
echo "<option value=\"{$row['dist_id']}-{$row['Dist_name']}\">{$row['Dist_name']}</option>";
}
mysqli_free_result($q22);
$con->next_result();
?>
</select>
</div>
<!-- Health Block Input -->
<div class="col-auto">
<input type="text" class="form-control" id="healthblock1" name="healthblock1" placeholder="Write Health block name" required>
<div id="block-message" style="color: red; font-size: 0.9rem;"></div>
</div>
<!-- Submit Button -->
<div class="col-auto">
<button type="submit" id="postsubmit" name="postsubmit" class="btn btn-primary w-100">Add Health Block</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="card">
<h6>Block Rectification</h6>
<div class="card-body">
</div>
</div>
</div>
</div>
<?php
if (isset($_POST['postsubmit'])) {
// Get the posted values
$dist = $_POST["District1"];
$block = $_POST["healthblock1"];
// Separate the district ID and name
list($dist_id1, $dist_name1) = explode('-', $dist);
$dist = $dist_id1;
$disname = $dist_name1;
// Check if the Health Block already exists
$check_query = "SELECT COUNT(*) AS block_count FROM block_master WHERE block_name = '$block' and dist_id=$dist";
$check_result = mysqli_query($con, $check_query);
$row = mysqli_fetch_assoc($check_result);
if ($row['block_count'] > 0) {
// Block name already exists, show a message
echo "<div class='alert alert-danger'>Error: The Health Block '$block' already exists.</div>";
} else {
// Block name doesn't exist, proceed with insertion
$query_insert = "INSERT INTO block_master (block_id, block_name, dist_name, dist_id)
SELECT IFNULL(MAX(block_id), 0) + 1, '$block', '$disname', $dist
FROM block_master";
$insertresult = $con->query($query_insert);
if ($insertresult) {
echo "<div class='alert alert-success'>Health block added successfully!</div>";
} else {
echo "<div class='alert alert-danger'>Error: Could not add Health Block. Please try again.</div>";
}
}
}
?>
<!-- AJAX check block name -->
<script>
$(document).ready(function() {
$('#healthblock1').on('keyup', function() {
var blockName = $(this).val().trim();
var districtId = $('#District1').val().split('-')[0];
if (blockName !== '' && districtId !== '') {
$.ajax({
url: 'assets/get/check_block.php',
type: 'POST',
data: {
block_name: blockName,
district_id: districtId
},
success: function(response) {
if (response === 'exists') {
$('#block-message').text('This health block name already exists in the selected district.');
} else {
$('#block-message').text('');
}
},
error: function() {
alert('An error occurred while checking the health block name.');
}
});
} else {
$('#block-message').text('');
}
});
});
</script>
</div>
</div>
<?php include("assets/head/f.php"); ?>