61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* API Endpoint: Delete Transmission
|
|
* Deletes a transmission from the schedule
|
|
*/
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
require_once __DIR__ . '/../helpers.php';
|
|
|
|
use Dotenv\Dotenv;
|
|
|
|
$dotenv = Dotenv::createImmutable(__DIR__ . '/..');
|
|
$dotenv->load();
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
try {
|
|
$db = getDbConnection();
|
|
|
|
// Get POST data
|
|
$input = json_decode(file_get_contents('php://input'), true);
|
|
|
|
if (!$input) {
|
|
$input = $_POST;
|
|
}
|
|
|
|
// Validate required fields
|
|
if (empty($input['id'])) {
|
|
jsonResponse([
|
|
'success' => false,
|
|
'error' => 'Missing transmission ID'
|
|
], 400);
|
|
}
|
|
|
|
// Check if transmission exists
|
|
$stmt = $db->prepare("SELECT id FROM transmissions WHERE id = ?");
|
|
$stmt->execute([$input['id']]);
|
|
|
|
if (!$stmt->fetch()) {
|
|
jsonResponse([
|
|
'success' => false,
|
|
'error' => 'Transmission not found'
|
|
], 404);
|
|
}
|
|
|
|
// Delete transmission
|
|
$stmt = $db->prepare("DELETE FROM transmissions WHERE id = ?");
|
|
$stmt->execute([$input['id']]);
|
|
|
|
jsonResponse([
|
|
'success' => true,
|
|
'message' => 'Transmission deleted successfully'
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
jsonResponse([
|
|
'success' => false,
|
|
'error' => $e->getMessage()
|
|
], 500);
|
|
}
|