menambahkan data jumlah rumah prasejahtera yang tercakup bantuan dari rumah ibadah pada popup
This commit is contained in:
@@ -1,8 +1,38 @@
|
|||||||
<?php
|
<?php
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
$conn = new mysqli('localhost', 'root', '', 'webgis');
|
$conn = new mysqli("localhost", "root", "", "webgis");
|
||||||
|
|
||||||
$result = $conn->query("SELECT * FROM rumah_ibadah");
|
$result = $conn->query("SELECT * FROM rumah_ibadah");
|
||||||
$data = [];
|
$data = [];
|
||||||
while ($row = $result->fetch_assoc()) $data[] = $row;
|
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$id = $row['id'];
|
||||||
|
$lat = $row['lat'];
|
||||||
|
$lng = $row['lng'];
|
||||||
|
$radius_m = $row['radius_m'];
|
||||||
|
|
||||||
|
// Hitung jumlah rumah prasejahtera dalam radius
|
||||||
|
// menggunakan formula Haversine langsung di SQL
|
||||||
|
$stmt = $conn->prepare("
|
||||||
|
SELECT COUNT(*) as total
|
||||||
|
FROM rumah_prasejahtera
|
||||||
|
WHERE (
|
||||||
|
6371000 * acos(
|
||||||
|
cos(radians(?)) * cos(radians(lat)) *
|
||||||
|
cos(radians(lng) - radians(?)) +
|
||||||
|
sin(radians(?)) * sin(radians(lat))
|
||||||
|
)
|
||||||
|
) <= ?
|
||||||
|
");
|
||||||
|
$stmt->bind_param("dddd", $lat, $lng, $lat, $radius_m);
|
||||||
|
$stmt->execute();
|
||||||
|
$hitungResult = $stmt->get_result()->fetch_assoc();
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
$row['jumlah_tercakup'] = (int) $hitungResult['total'];
|
||||||
|
$data[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
echo json_encode($data);
|
echo json_encode($data);
|
||||||
|
$conn->close();
|
||||||
?>
|
?>
|
||||||
@@ -183,27 +183,73 @@ function loadIbadah() {
|
|||||||
fillColor: '#8e44ad', fillOpacity: 0.1, weight: 1, dashArray: '5,5'
|
fillColor: '#8e44ad', fillOpacity: 0.1, weight: 1, dashArray: '5,5'
|
||||||
}).addTo(layerIbadah);
|
}).addTo(layerIbadah);
|
||||||
|
|
||||||
marker.bindPopup(`<b>${ib.nama_ibadah}</b><br>
|
const totalPrasejahtera = Object.keys(dataPrasejahtera).length;
|
||||||
Jenis Rumah Ibadah: ${ib.jenis}<br>
|
const persen = totalPrasejahtera > 0
|
||||||
Jangkauan Bantuan: ${ib.radius_m} m
|
? Math.round((ib.jumlah_tercakup / totalPrasejahtera) * 100)
|
||||||
<hr>
|
: 0;
|
||||||
<div style="display:flex; gap:6px;">
|
|
||||||
${ROLE === 'admin' || ROLE === 'operator' ? `
|
marker.bindPopup(`
|
||||||
<button onclick="editIbadah(${ib.id})"
|
<div style="font-size:13px; min-width:200px;">
|
||||||
style="flex:1; padding:6px; background:#2980b9; color:white;
|
<b style="font-size:15px;">
|
||||||
border:none; border-radius:4px; cursor:pointer; font-size:12px;">
|
<i class="fa-solid fa-place-of-worship"></i> ${ib.nama_ibadah}
|
||||||
<i class="fa-solid fa-pen-to-square"></i> Edit
|
</b>
|
||||||
</button>
|
<hr style="margin:6px 0;">
|
||||||
` : ''}
|
<b>Jenis:</b> ${ib.jenis}<br>
|
||||||
${ROLE === 'admin' ? `
|
<b>Jangkauan Bantuan:</b> ${ib.radius_m} m<br>
|
||||||
<button onclick="hapusIbadah(${ib.id})"
|
<hr style="margin:6px 0;">
|
||||||
style="flex:1; padding:6px; background:none; color:red;
|
|
||||||
border:1px solid red; border-radius:4px; cursor:pointer; font-size:12px;">
|
<div style="
|
||||||
<i class="fa-solid fa-trash"></i> Hapus
|
background:#f0f4f8;
|
||||||
</button>
|
border-radius:8px;
|
||||||
` : ''}
|
padding:10px;
|
||||||
</div>`
|
margin:6px 0;
|
||||||
);
|
text-align:center;
|
||||||
|
">
|
||||||
|
<div style="font-size:22px; font-weight:700; color:#1B2A4A;">
|
||||||
|
${ib.jumlah_tercakup}
|
||||||
|
</div>
|
||||||
|
<div style="font-size:11px; color:#666; margin-bottom:6px;">
|
||||||
|
rumah tercakup dari ${totalPrasejahtera} total
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Progress bar -->
|
||||||
|
<div style="
|
||||||
|
background:#dde3ea;
|
||||||
|
border-radius:20px;
|
||||||
|
height:6px;
|
||||||
|
overflow:hidden;
|
||||||
|
">
|
||||||
|
<div style="
|
||||||
|
background: ${persen > 0 ? '#27ae60' : '#dde3ea'};
|
||||||
|
width:${persen}%;
|
||||||
|
height:100%;
|
||||||
|
border-radius:20px;
|
||||||
|
transition: width 0.3s;
|
||||||
|
"></div>
|
||||||
|
</div>
|
||||||
|
<div style="font-size:11px; color:#888; margin-top:4px;">
|
||||||
|
${persen}% dari total prasejahtera
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display:flex; gap:6px; margin-top:4px;">
|
||||||
|
${ROLE === 'admin' || ROLE === 'operator' ? `
|
||||||
|
<button onclick="editIbadah(${ib.id})"
|
||||||
|
style="flex:1; padding:6px; background:#2980b9; color:white;
|
||||||
|
border:none; border-radius:4px; cursor:pointer; font-size:12px;">
|
||||||
|
<i class="fa-solid fa-pen-to-square"></i> Edit
|
||||||
|
</button>
|
||||||
|
` : ''}
|
||||||
|
${ROLE === 'admin' ? `
|
||||||
|
<button onclick="hapusIbadah(${ib.id})"
|
||||||
|
style="flex:1; padding:6px; background:none; color:red;
|
||||||
|
border:1px solid red; border-radius:4px; cursor:pointer; font-size:12px;">
|
||||||
|
<i class="fa-solid fa-trash"></i> Hapus
|
||||||
|
</button>
|
||||||
|
` : ''}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
|
||||||
marker.on('dragend', function(e) {
|
marker.on('dragend', function(e) {
|
||||||
let pos = e.target.getLatLng();
|
let pos = e.target.getLatLng();
|
||||||
|
|||||||
Reference in New Issue
Block a user