36776-vm/log_progress.php
Flatlogic Bot 3be446013d Initialv1
2025-12-09 00:59:40 +00:00

35 lines
952 B
PHP

<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) {
http_response_code(401); // Unauthorized
exit('You must be logged in to log progress.');
}
$data = json_decode(file_get_contents('php://input'), true);
$theme = $data['theme'] ?? null;
if (empty($theme)) {
http_response_code(400); // Bad Request
exit('Theme is required.');
}
$user_id = $_SESSION['user_id'];
$completion_date = date('Y-m-d');
try {
$pdo = db();
$stmt = $pdo->prepare("INSERT INTO progress (user_id, theme, completion_date) VALUES (?, ?, ?)");
$stmt->execute([$user_id, $theme, $completion_date]);
http_response_code(200); // OK
echo json_encode(['success' => true]);
} catch (PDOException $e) {
http_response_code(500); // Internal Server Error
error_log('Failed to log progress: ' . $e->getMessage());
echo json_encode(['success' => false, 'message' => 'Could not save progress.']);
}