39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
// Test saving a jalan feature via save.php logic
|
|
$_POST = null;
|
|
$input = [
|
|
'tipe' => 'jalan',
|
|
'status' => 'Nasional',
|
|
'nilai' => 1234.56,
|
|
'geom' => [
|
|
'type' => 'Feature',
|
|
'geometry' => [
|
|
'type' => 'LineString',
|
|
'coordinates' => [[109.3490, -0.0550],[109.3500,-0.0560]]
|
|
],
|
|
'properties' => []
|
|
]
|
|
];
|
|
// Simulate php://input by writing to a temp file and modifying save.php to read from it isn't necessary; instead include save.php after setting $GLOBALS
|
|
|
|
// We'll directly call save.php code by including and setting $data
|
|
$data = $input;
|
|
|
|
include 'db.php';
|
|
|
|
$tipe = $data['tipe'];
|
|
$status = $data['status'] ?? '';
|
|
$nilai = $data['nilai'] ?? 0;
|
|
$geom = json_encode($data['geom']);
|
|
|
|
if($tipe == "jalan"){
|
|
$panjang = $nilai ? $nilai : 0;
|
|
$sql = "INSERT INTO data_unified (tipe, status, panjang, geom)\n VALUES ('jalan', '$status', $panjang, '$geom')";
|
|
}
|
|
|
|
if ($conn->query($sql) === TRUE) {
|
|
echo "Inserted jalan id=" . $conn->insert_id . "\n";
|
|
} else {
|
|
echo "Error: " . $conn->error . "\n";
|
|
}
|
|
?>
|