49 lines
1.8 KiB
PHP
49 lines
1.8 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
$response = ['success' => false, 'message' => 'An error occurred.'];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$type = $_POST['type'] ?? '';
|
|
$title = $_POST['title'] ?? '';
|
|
|
|
if (empty($title)) {
|
|
$response['message'] = 'Title is required.';
|
|
echo json_encode($response);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$pdo = db();
|
|
if ($type === 'meeting') {
|
|
$stmt = $pdo->prepare("INSERT INTO meetings (title, description, purpose, date, attendees, summary) VALUES (?, ?, ?, ?, ?, ?)");
|
|
$stmt->execute([
|
|
$title,
|
|
$_POST['description'] ?? '',
|
|
$_POST['purpose'] ?? '',
|
|
$_POST['date'] ?? null,
|
|
$_POST['attendees'] ?? '',
|
|
$_POST['summary'] ?? ''
|
|
]);
|
|
$response['entry'] = ['id' => $pdo->lastInsertId(), 'title' => $title, 'description' => $_POST['description'] ?? ''];
|
|
} elseif ($type === 'event') {
|
|
$stmt = $pdo->prepare("INSERT INTO events (title, description, date, purpose, notes) VALUES (?, ?, ?, ?, ?)");
|
|
$stmt->execute([
|
|
$title,
|
|
$_POST['description'] ?? '',
|
|
$_POST['date'] ?? null,
|
|
$_POST['purpose'] ?? '',
|
|
$_POST['notes'] ?? ''
|
|
]);
|
|
$response['entry'] = ['id' => $pdo->lastInsertId(), 'title' => $title, 'description' => $_POST['description'] ?? ''];
|
|
}
|
|
$response['success'] = true;
|
|
$response['message'] = ucfirst($type) . ' added successfully.';
|
|
} catch (PDOException $e) {
|
|
$response['message'] = 'Database error: ' . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
header('Content-Type: application/json');
|
|
echo json_encode($response);
|