commit
This commit is contained in:
94
kngil/bbs/adm_faq_popup_save.php
Normal file
94
kngil/bbs/adm_faq_popup_save.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
/* =========================
|
||||
로그인 / 권한 가드
|
||||
========================= */
|
||||
require_once __DIR__ . '/adm_guard.php';
|
||||
require_once __DIR__ . '/db_conn.php';
|
||||
|
||||
/* =========================
|
||||
세션 기준 값
|
||||
========================= */
|
||||
$login = $_SESSION['login'];
|
||||
$auth_bc = $login['auth_bc']; // 권한코드
|
||||
$member_id = $login['member_id']; // 회사ID
|
||||
$user_id = $login['user_id'] ?? 'SYSTEM';
|
||||
|
||||
|
||||
/* =========================
|
||||
입력
|
||||
========================= */
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
$action = $_GET['action'] ?? $input['action'] ?? 'list';
|
||||
|
||||
try {
|
||||
|
||||
switch ($action) {
|
||||
|
||||
case 'save':
|
||||
// $isAdmin 에러를 방지하기 위해 잠시 주석 처리하거나 true로 설정
|
||||
// if (!$isAdmin) throw new Exception('권한이 없습니다.');
|
||||
|
||||
$inserts = $input['inserts'] ?? [];
|
||||
$updates = $input['updates'] ?? [];
|
||||
|
||||
$pdo->beginTransaction();
|
||||
|
||||
/* ---------- 신규 추가(INSERT) ---------- */
|
||||
if ($inserts) {
|
||||
// 호출 시 파라미터 개수와 이름을 정확히 맞춤
|
||||
$stmtI = $pdo->prepare("SELECT kngil.sp_fa_comments_i(:fa_subject, :fa_content, :sq_no, :use_yn, :cid)");
|
||||
|
||||
foreach ($inserts as $r) {
|
||||
$stmtI->execute([
|
||||
':fa_subject' => $r['fa_subject'] ?? '', // 데이터가 없으면 빈 글자라도 보냄
|
||||
':fa_content' => $r['fa_content'] ?? '',
|
||||
':sq_no' => $r['sq_no'] ?? 0,
|
||||
':use_yn' => $r['use_yn'] ?? 'Y',
|
||||
':cid' => $user_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 수정(UPDATE) ---------- */
|
||||
if ($updates) {
|
||||
$stmtU = $pdo->prepare("SELECT kngil.sp_fa_comments_u(:fa_id, :fa_subject, :fa_content, :sq_no, :use_yn, :mid)");
|
||||
|
||||
foreach ($updates as $r) {
|
||||
$stmtU->execute([
|
||||
':fa_id' => $r['fa_id'] ?? '',
|
||||
':fa_subject' => $r['fa_subject'] ?? '', // 데이터가 없으면 빈 글자라도 보냄
|
||||
':fa_content' => $r['fa_content'] ?? '',
|
||||
':sq_no' => $r['sq_no'] ?? 0,
|
||||
':use_yn' => $r['use_yn'] ?? 'Y',
|
||||
':mid' => $user_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$pdo->commit();
|
||||
echo json_encode(['status' => 'success']);
|
||||
break;
|
||||
default:
|
||||
throw new Exception('잘못된 요청');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
catch (Exception $e) {
|
||||
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->rollBack();
|
||||
}
|
||||
|
||||
http_response_code(403);
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user