commit
This commit is contained in:
233
kngil/bbs/qa_detail.php
Normal file
233
kngil/bbs/qa_detail.php
Normal file
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
// kngil/bbs/qa_detail.php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
/* ===============================
|
||||
1. 세션 & 로그인 체크
|
||||
=============================== */
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
if (empty($_SESSION['login'])) {
|
||||
echo "<script>
|
||||
alert('로그인 후 이용 가능합니다.');
|
||||
location.href = '/kngil/skin/qa_list.skin.php';
|
||||
</script>";
|
||||
exit;
|
||||
}
|
||||
|
||||
$login = $_SESSION['login'];
|
||||
$me = $login['user_id'] ?? '';
|
||||
$auth = $login['auth_bc'] ?? '';
|
||||
|
||||
$isAdmin = in_array($auth, ['BS100100', 'BS100200']); // 개발자/관리자
|
||||
|
||||
/* ===============================
|
||||
2. DB 연결 (PostgreSQL)
|
||||
=============================== */
|
||||
require_once $_SERVER['DOCUMENT_ROOT'].'/kngil/bbs/db_conn.php';
|
||||
|
||||
/* ===============================
|
||||
4. 삭제 처리
|
||||
=============================== */
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'delete') {
|
||||
|
||||
$postId = (int)($_POST['post_id'] ?? 0);
|
||||
if ($postId < 1) {
|
||||
die('잘못된 요청입니다.');
|
||||
}
|
||||
|
||||
// 글 조회
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT post_id, user_id, stat_bc
|
||||
FROM kngil.qa_posts
|
||||
WHERE post_id = :pid
|
||||
");
|
||||
$stmt->execute([':pid' => $postId]);
|
||||
$post = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$post) {
|
||||
die('존재하지 않는 글입니다.');
|
||||
}
|
||||
|
||||
// 상태 제한 (검토중 / 완료면 삭제 불가)
|
||||
if (in_array($post['stat_bc'], ['REVIEW', 'DONE']) && !$isAdmin) {
|
||||
die('검토중이거나 답변 완료된 글은 삭제할 수 없습니다.');
|
||||
}
|
||||
|
||||
// 권한 체크 (본인 or 관리자)
|
||||
if (!$isAdmin && $post['user_id'] !== $loginUser['user_id']) {
|
||||
die('삭제 권한이 없습니다.');
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// 1️⃣ 첨부파일 삭제
|
||||
$fs = $pdo->prepare("
|
||||
SELECT save_path
|
||||
FROM kngil.qa_attachments
|
||||
WHERE post_id = :pid
|
||||
");
|
||||
$fs->execute([':pid' => $postId]);
|
||||
|
||||
foreach ($fs->fetchAll() as $f) {
|
||||
$file = $_SERVER['DOCUMENT_ROOT'] . $f['save_path'];
|
||||
if (is_file($file)) unlink($file);
|
||||
}
|
||||
|
||||
$pdo->prepare("DELETE FROM kngil.qa_attachments WHERE post_id = ?")
|
||||
->execute([$postId]);
|
||||
|
||||
// 2️⃣ 댓글 삭제
|
||||
$pdo->prepare("DELETE FROM kngil.qa_comments WHERE post_id = ?")
|
||||
->execute([$postId]);
|
||||
|
||||
// 3️⃣ 본문 삭제
|
||||
$pdo->prepare("DELETE FROM kngil.qa_posts WHERE post_id = ?")
|
||||
->execute([$postId]);
|
||||
|
||||
$pdo->commit();
|
||||
|
||||
header("Location: /kngil/skin/qa_list.skin.php");
|
||||
exit;
|
||||
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
die('삭제 중 오류 발생: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/* ===============================
|
||||
3. post_id 검증
|
||||
=============================== */
|
||||
$postId = (int)($_GET['id'] ?? 0);
|
||||
if ($postId < 1) {
|
||||
exit('잘못된 접근입니다.');
|
||||
}
|
||||
|
||||
|
||||
/* ===============================
|
||||
5. 글 조회
|
||||
=============================== */
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT
|
||||
p.post_id,
|
||||
p.user_id,
|
||||
p.user_nm,
|
||||
p.tel_no,
|
||||
p.category,
|
||||
p.co_nm,
|
||||
p.dept_nm,
|
||||
p.title,
|
||||
p.content,
|
||||
p.attachment,
|
||||
p.stat_bc,
|
||||
p.is_secret,
|
||||
p.complete_form,
|
||||
p.cdt_dt,
|
||||
p.mid_dt,
|
||||
p.is_read_admin,
|
||||
|
||||
u.email
|
||||
|
||||
FROM kngil.qa_posts p
|
||||
LEFT JOIN kngil.users u
|
||||
ON p.user_id = u.user_id
|
||||
WHERE p.post_id = :pid
|
||||
");
|
||||
$stmt->execute([':pid' => $postId]);
|
||||
$post = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$post) {
|
||||
exit('존재하지 않는 글입니다.');
|
||||
}
|
||||
|
||||
/* ===============================
|
||||
6. 비밀글 접근 제어
|
||||
=============================== */
|
||||
if ($post['is_secret'] === 'Y' && $post['user_id'] !== $me && !$isAdmin) {
|
||||
exit('⚠️ 비밀글은 작성자 또는 관리자만 확인할 수 있습니다.');
|
||||
}
|
||||
|
||||
/* ===============================
|
||||
7. 관리자 열람 처리
|
||||
=============================== */
|
||||
if ($isAdmin && $post['is_read_admin'] === 'N') {
|
||||
$pdo->prepare("
|
||||
UPDATE kngil.qa_posts
|
||||
SET is_read_admin = 'Y'
|
||||
WHERE post_id = :pid
|
||||
")->execute([':pid' => $postId]);
|
||||
}
|
||||
|
||||
/* ===============================
|
||||
8. 라벨 매핑
|
||||
=============================== */
|
||||
$STATUS_LABELS = [
|
||||
'WAIT' => '문의접수',
|
||||
'REVIEW'=> '검토중',
|
||||
'DONE' => '답변완료'
|
||||
];
|
||||
|
||||
$CATEGORY_LABELS = [
|
||||
'general' => '일반문의',
|
||||
'improvement' => '개선문의',
|
||||
'error' => '오류문의',
|
||||
'notice' => '공지사항'
|
||||
];
|
||||
|
||||
$post['status_label'] = $STATUS_LABELS[$post['stat_bc']] ?? $post['stat_bc'];
|
||||
$post['category_label'] = $CATEGORY_LABELS[$post['category']] ?? $post['category'];
|
||||
$post['display_name'] = $post['user_nm'];
|
||||
|
||||
/* ===============================
|
||||
9. 첨부파일 조회
|
||||
=============================== */
|
||||
$af = $pdo->prepare("
|
||||
SELECT
|
||||
id,
|
||||
ori_name,
|
||||
save_path,
|
||||
file_size,
|
||||
uploaded_at
|
||||
FROM kngil.qa_attachments
|
||||
WHERE post_id = :pid
|
||||
ORDER BY id ASC
|
||||
");
|
||||
$af->execute([':pid' => $postId]);
|
||||
$attachments = $af->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
/* ===============================
|
||||
10. 댓글 조회 (일단 구조만)
|
||||
=============================== */
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT
|
||||
comment_id,
|
||||
post_id,
|
||||
commenter,
|
||||
content,
|
||||
user_nm,
|
||||
cdt_dt
|
||||
FROM kngil.qa_comments
|
||||
WHERE post_id = :post_id
|
||||
ORDER BY cdt_dt ASC
|
||||
");
|
||||
$stmt->execute([
|
||||
':post_id' => $postId
|
||||
]);
|
||||
|
||||
$comments = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
/* ===============================
|
||||
11. 소유자 여부 (수정 버튼용)
|
||||
=============================== */
|
||||
$isOwner = ($post['user_id'] === $me);
|
||||
|
||||
/* ===============================
|
||||
12. 스킨 렌더링
|
||||
=============================== */
|
||||
include $_SERVER['DOCUMENT_ROOT'].'/kngil/skin/qa_detail.skin.php';
|
||||
Reference in New Issue
Block a user