first commit
This commit is contained in:
68
sales_manager_scenario/get_consultation_files.php
Normal file
68
sales_manager_scenario/get_consultation_files.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// 출력 버퍼링 시작 및 에러 리포팅 비활성화
|
||||
error_reporting(0);
|
||||
ob_start();
|
||||
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
||||
|
||||
// 출력 버퍼 비우기
|
||||
ob_clean();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
// 1. 권한 및 세션 체크
|
||||
if (!isset($user_id) || $level > 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, file_paths_json,
|
||||
file_expiry_date, created_at
|
||||
FROM manager_consultation_files
|
||||
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]);
|
||||
$files = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// JSON 파싱 및 날짜 포맷팅
|
||||
foreach ($files as &$file) {
|
||||
$file['files'] = json_decode($file['file_paths_json'], true) ?: [];
|
||||
$file['created_at_formatted'] = date('Y-m-d H:i', strtotime($file['created_at']));
|
||||
$file['file_count'] = count($file['files']);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'data' => $files,
|
||||
'count' => count($files)
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log('조회 오류: ' . $e->getMessage());
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => '조회 실패: ' . $e->getMessage(),
|
||||
'data' => []
|
||||
]);
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user