50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
require_once 'config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
try {
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
|
|
// Validate required fields
|
|
if (!isset($data['name']) || !isset($data['latitude']) || !isset($data['longitude'])) {
|
|
http_response_code(400);
|
|
echo json_encode(['error' => 'Missing required fields: name, latitude, or longitude']);
|
|
exit;
|
|
}
|
|
|
|
// Validate coordinates are numeric
|
|
if (!is_numeric($data['latitude']) || !is_numeric($data['longitude'])) {
|
|
http_response_code(400);
|
|
echo json_encode(['error' => 'Latitude and longitude must be numeric values']);
|
|
exit;
|
|
}
|
|
|
|
$db = getDB();
|
|
$stmt = $db->prepare('INSERT INTO markers (name, latitude, longitude, open_24_hours) VALUES (?, ?, ?, ?)');
|
|
$open_24_hours = isset($data['open_24_hours']) ? (int)$data['open_24_hours'] : 0;
|
|
|
|
$stmt->execute([
|
|
$data['name'],
|
|
(float)$data['latitude'],
|
|
(float)$data['longitude'],
|
|
$open_24_hours
|
|
]);
|
|
|
|
echo json_encode([
|
|
'success' => true,
|
|
'id' => $db->lastInsertId(),
|
|
'name' => $data['name'],
|
|
'latitude' => (float)$data['latitude'],
|
|
'longitude' => (float)$data['longitude'],
|
|
'open_24_hours' => $open_24_hours
|
|
]);
|
|
} catch (Exception $e) {
|
|
http_response_code(500);
|
|
echo json_encode(['error' => $e->getMessage()]);
|
|
}
|
|
} else {
|
|
http_response_code(405);
|
|
echo json_encode(['error' => 'Method not allowed']);
|
|
}
|
|
?>
|