94 lines
2.9 KiB
PHP
94 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* 영상 시청 시간 저장 API
|
|
* POST /bbs/api/save_video_time.php
|
|
*
|
|
* Parameters:
|
|
* - content_id (필수): 영상 content ID
|
|
* - current_seconds (필수): 현재 시청 시간 (초 단위)
|
|
*/
|
|
|
|
session_start();
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
// 세션 체크
|
|
if (!isset($_SESSION['member_id'])) {
|
|
http_response_code(401);
|
|
echo json_encode(['success' => false, 'error' => 'Unauthorized']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
require $_SERVER['DOCUMENT_ROOT'] . '/www/baroncs/dbconfig.php';
|
|
require $_SERVER['DOCUMENT_ROOT'] . '/www/baroncs/head.php';
|
|
|
|
$member_id = intval($_SESSION['member_id']);
|
|
$content_id = intval($_POST['content_id'] ?? 0);
|
|
$current_seconds = intval($_POST['current_seconds'] ?? 0);
|
|
|
|
if ($content_id <= 0) {
|
|
http_response_code(400);
|
|
echo json_encode(['success' => false, 'error' => 'Invalid content_id']);
|
|
exit;
|
|
}
|
|
|
|
// 마이클래스 영상인지 확인 (CA10001 카테고리)
|
|
$sql = "SELECT id, category_code FROM edu_contents WHERE id = ?";
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->bind_param("i", $content_id);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$content = $result->fetch_assoc();
|
|
$stmt->close();
|
|
|
|
if (!$content) {
|
|
http_response_code(404);
|
|
echo json_encode(['success' => false, 'error' => 'Content not found']);
|
|
exit;
|
|
}
|
|
|
|
$is_myclass = ($content['category_code'] === 'CA10001');
|
|
|
|
// 시청 시간 저장 (마이클래스만)
|
|
if ($is_myclass) {
|
|
// edu_video_playback 테이블에 저장
|
|
$check_sql = "SELECT id FROM edu_video_playback WHERE member_id = ? AND content_id = ?";
|
|
$check_stmt = $conn->prepare($check_sql);
|
|
$check_stmt->bind_param("ii", $member_id, $content_id);
|
|
$check_stmt->execute();
|
|
$check_result = $check_stmt->get_result();
|
|
$exists = $check_result->fetch_assoc();
|
|
$check_stmt->close();
|
|
|
|
if ($exists) {
|
|
// 기존 레코드 업데이트
|
|
$update_sql = "UPDATE edu_video_playback SET current_seconds = ?, updated_at = NOW() WHERE member_id = ? AND content_id = ?";
|
|
$update_stmt = $conn->prepare($update_sql);
|
|
$update_stmt->bind_param("iii", $current_seconds, $member_id, $content_id);
|
|
$update_stmt->execute();
|
|
$update_stmt->close();
|
|
} else {
|
|
// 새 레코드 생성
|
|
$insert_sql = "INSERT INTO edu_video_playback (member_id, content_id, current_seconds) VALUES (?, ?, ?)";
|
|
$insert_stmt = $conn->prepare($insert_sql);
|
|
$insert_stmt->bind_param("iii", $member_id, $content_id, $current_seconds);
|
|
$insert_stmt->execute();
|
|
$insert_stmt->close();
|
|
}
|
|
}
|
|
|
|
echo json_encode([
|
|
'success' => true,
|
|
'content_id' => $content_id,
|
|
'current_seconds' => $current_seconds,
|
|
'is_myclass' => $is_myclass
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
error_log('[save_video_time.php] Error: ' . $e->getMessage());
|
|
http_response_code(500);
|
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
|
}
|
|
?>
|