5) { echo json_encode(['success' => false, 'message' => '접근 권한이 없습니다.']); exit; } $manager_id = $user_id; $step_id = isset($_GET['step_id']) ? intval($_GET['step_id']) : 2; $limit = isset($_GET['limit']) ? intval($_GET['limit']) : 20; try { $pdo = db_connect(); if (!$pdo) { throw new Exception('데이터베이스 연결 실패'); } // 저장된 녹음 파일 목록 조회 $sql = "SELECT id, manager_id, step_id, audio_file_path, transcript_text, file_expiry_date, created_at FROM manager_consultations WHERE manager_id = ? AND step_id = ? ORDER BY created_at DESC LIMIT ?"; $stmt = $pdo->prepare($sql); if (!$stmt) { throw new Exception('SQL 준비 실패'); } $stmt->execute([$manager_id, $step_id, $limit]); $consultations = $stmt->fetchAll(PDO::FETCH_ASSOC); // 날짜 포맷팅 foreach ($consultations as &$consultation) { $consultation['created_at_formatted'] = date('Y-m-d H:i', strtotime($consultation['created_at'])); $consultation['is_gcs'] = strpos($consultation['audio_file_path'], 'gs://') === 0; } echo json_encode([ 'success' => true, 'data' => $consultations, 'count' => count($consultations) ]); } catch (Exception $e) { error_log('조회 오류: ' . $e->getMessage()); echo json_encode([ 'success' => false, 'message' => '조회 실패: ' . $e->getMessage(), 'data' => [] ]); } ?>