최초 커밋
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
// descope_qa_delete.php
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__ . '/../skin/member/basic/descope_session.php';
|
||||
|
||||
$me = $_SESSION['user']['loginIds'][0] ?? '';
|
||||
|
||||
// DB 연결
|
||||
$host = 'db';
|
||||
$dbname = 'egbim';
|
||||
$user = 'egbim';
|
||||
$pass = 'baron3840!!';
|
||||
$charset= 'utf8mb4';
|
||||
$pdo = new PDO(
|
||||
"mysql:host={$host};dbname={$dbname};charset={$charset}",
|
||||
$user, $pass,
|
||||
[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE=>PDO::FETCH_ASSOC]
|
||||
);
|
||||
$pdo->exec("SET time_zone = '+09:00'");
|
||||
|
||||
$postId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
if ($postId < 1) exit("잘못된 요청입니다.");
|
||||
|
||||
// 글 작성자 확인
|
||||
$stmt = $pdo->prepare("SELECT login_id, status FROM qa_posts WHERE post_id=:pid");
|
||||
$stmt->execute([':pid'=>$postId]);
|
||||
$post = $stmt->fetch();
|
||||
if (!$post) exit("존재하지 않는 글입니다.");
|
||||
|
||||
// 🚫 관리자 권한 제거 → 작성자만 삭제 가능
|
||||
if ($post['login_id'] !== $me) {
|
||||
exit("본인 작성 글만 삭제할 수 있습니다.");
|
||||
}
|
||||
|
||||
// 🚫 상태 확인 (검토중/답변완료는 삭제 금지)
|
||||
if (in_array($post['status'], ['검토중','답변완료'])) {
|
||||
exit("현재 상태('" . $post['status'] . "')에서는 삭제할 수 없습니다.");
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// 1) 첨부파일 실제 삭제
|
||||
$af = $pdo->prepare("SELECT save_path FROM qa_attachments WHERE post_id=:pid");
|
||||
$af->execute([':pid'=>$postId]);
|
||||
foreach ($af as $row) {
|
||||
$filePath = $_SERVER['DOCUMENT_ROOT'] . $row['save_path'];
|
||||
if (file_exists($filePath)) {
|
||||
unlink($filePath);
|
||||
}
|
||||
}
|
||||
|
||||
// 2) 첨부파일 DB 삭제
|
||||
$pdo->prepare("DELETE FROM qa_attachments WHERE post_id=:pid")->execute([':pid'=>$postId]);
|
||||
|
||||
// 3) 댓글 삭제
|
||||
$pdo->prepare("DELETE FROM qa_comments WHERE post_id=:pid")->execute([':pid'=>$postId]);
|
||||
|
||||
// 4) 글 삭제
|
||||
$pdo->prepare("DELETE FROM qa_posts WHERE post_id=:pid")->execute([':pid'=>$postId]);
|
||||
|
||||
$pdo->commit();
|
||||
|
||||
echo "<script>alert('글이 삭제되었습니다.');location.href='/egbim/bbs/descope_qa_list.php';</script>";
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
exit("삭제 중 오류: " . $e->getMessage());
|
||||
}
|
||||
Reference in New Issue
Block a user