23 lines
855 B
PHP
23 lines
855 B
PHP
<?php
|
|
require_once '../includes/db.php';
|
|
require_once '../includes/auth.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isLoggedIn()) {
|
|
$video_id = (int)$_POST['video_id'];
|
|
$timestamp = (float)($_POST['timestamp'] ?? 0);
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
$stmt = $pdo->prepare("SELECT id FROM bookmarks WHERE user_id = ? AND video_id = ?");
|
|
$stmt->execute([$user_id, $video_id]);
|
|
$bookmark = $stmt->fetch();
|
|
|
|
if ($bookmark) {
|
|
$pdo->prepare("DELETE FROM bookmarks WHERE id = ?")->execute([$bookmark['id']]);
|
|
echo json_encode(['success' => true, 'action' => 'removed']);
|
|
} else {
|
|
$pdo->prepare("INSERT INTO bookmarks (user_id, video_id, video_timestamp) VALUES (?, ?, ?)")->execute([$user_id, $video_id, $timestamp]);
|
|
echo json_encode(['success' => true, 'action' => 'added']);
|
|
}
|
|
}
|
|
?>
|