false, 'error' => 'Unauthorized']); exit; } if ($sys_comp_code === '') { http_response_code(401); echo json_encode(['success' => false, 'error' => 'sys_comp_code_missing']); exit; } // content_id: JSON body 또는 POST 폼 데이터 모두 허용 $rawBody = file_get_contents('php://input'); $jsonBody = (is_string($rawBody) && $rawBody !== '') ? json_decode($rawBody, true) : null; $content_id = trim((string)( (is_array($jsonBody) ? ($jsonBody['content_id'] ?? '') : '') ?: ($_POST['content_id'] ?? '') ?: ($_GET['content_id'] ?? '') )); if ($content_id === '') { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Invalid content_id']); exit; } try { require_once __DIR__ . '/../db_conn.php'; $pdo = db_conn(); // edu_learning_histories 에서 watch_tm / content_tm 조회 $stmt = $pdo->prepare( "SELECT watch_tm, content_tm FROM edu_learning_histories WHERE member_id = ? AND sys_comp_code = ? AND content_id = ? LIMIT 1" ); $stmt->execute([$member_id, $sys_comp_code, $content_id]); $row = $stmt->fetch(PDO::FETCH_ASSOC); $watch_tm = (int)($row['watch_tm'] ?? 0); $content_tm = (int)($row['content_tm'] ?? 0); echo json_encode([ 'success' => true, 'content_id' => $content_id, 'watch_tm' => $watch_tm, 'content_tm' => $content_tm, ], JSON_UNESCAPED_UNICODE); } catch (Throwable $e) { error_log('[get_video_time.php] Error: ' . $e->getMessage()); http_response_code(500); echo json_encode(['success' => false, 'error' => 'server_error']); } ?>