최초 커밋
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__ . '/../skin/member/basic/descope_session.php';
|
||||
require_once __DIR__ . '/../bbs/admin_guard.php'; // ✅ 관리자 권한 함수 포함
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
|
||||
|
||||
$loginId = $_SESSION['user']['loginIds'][0] ?? '';
|
||||
|
||||
$commentId = (int)($_POST['commentId'] ?? 0);
|
||||
if ($commentId < 1) {
|
||||
echo json_encode(['status' => 'fail', 'message' => '잘못된 요청']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo = new PDO(
|
||||
"mysql:host=db;dbname=egbim;charset=utf8mb4",
|
||||
'egbim','baron3840!!',
|
||||
[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]
|
||||
);
|
||||
$pdo->exec("SET time_zone = '+09:00'");
|
||||
|
||||
// 댓글 소유자 확인
|
||||
$st = $pdo->prepare("SELECT commenter FROM qa_comments WHERE comment_id = ?");
|
||||
$st->execute([$commentId]);
|
||||
$row = $st->fetch();
|
||||
|
||||
if (!$row) {
|
||||
echo json_encode(['status'=>'fail','message'=>'존재하지 않는 댓글']);
|
||||
exit;
|
||||
}
|
||||
if ($row['commenter'] !== $loginId && !is_qna_admin()) {
|
||||
echo json_encode(['status'=>'fail','message'=>'본인 댓글만 삭제 가능']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 삭제
|
||||
$del = $pdo->prepare("DELETE FROM qa_comments WHERE comment_id = ?");
|
||||
$del->execute([$commentId]);
|
||||
|
||||
echo json_encode(['status'=>'ok']);
|
||||
} catch(Exception $e) {
|
||||
echo json_encode(['status'=>'fail','message'=>$e->getMessage()]);
|
||||
}
|
||||
Reference in New Issue
Block a user