commit
This commit is contained in:
165
kngil/bbs/adm.php
Normal file
165
kngil/bbs/adm.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/db_conn.php';
|
||||
|
||||
/* =================================================
|
||||
0. 로그인 / 권한 체크
|
||||
================================================= */
|
||||
if (!isset($_SESSION['login'])) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => '로그인이 필요합니다.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$auth = $_SESSION['login']['auth_bc'] ?? '';
|
||||
|
||||
if (!in_array($auth, ['BS100100', 'BS100200'])) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => '접근 권한이 없습니다.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* =================================================
|
||||
공통 입력
|
||||
================================================= */
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?? [];
|
||||
$action = $_GET['action'] ?? $input['action'] ?? 'list';
|
||||
|
||||
try {
|
||||
|
||||
switch ($action) {
|
||||
|
||||
case 'user_list':
|
||||
|
||||
// 🔥 상단에서 선택한 회사
|
||||
$target_member_id = $_GET['member_id'] ?? '';
|
||||
|
||||
if (!$target_member_id) {
|
||||
throw new Exception('member_id 누락');
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT *
|
||||
FROM kngil.sp_users_r(
|
||||
:member_id,
|
||||
'',
|
||||
'',
|
||||
''
|
||||
)
|
||||
");
|
||||
|
||||
$stmt->execute([
|
||||
':member_id' => $target_member_id
|
||||
]);
|
||||
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($rows as $i => &$r) {
|
||||
$r['recid'] = $i + 1;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'records' => $rows
|
||||
]);
|
||||
break;
|
||||
|
||||
/* =================================================
|
||||
1. 통합 회원 목록 조회
|
||||
- 모든 회사(member) 조회
|
||||
================================================= */
|
||||
case 'list':
|
||||
|
||||
$sql = "SELECT * FROM kngil.sp_member_sys_r('', '', '');";
|
||||
$rows = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$i = 1;
|
||||
foreach ($rows as &$r) {
|
||||
$r['recid'] = $i++;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'records' => $rows
|
||||
]);
|
||||
break;
|
||||
|
||||
/* =================================================
|
||||
2. 회원 정보 수정 (회사 단위)
|
||||
- tel / email / 사업자번호 / 회사명
|
||||
================================================= */
|
||||
case 'save':
|
||||
|
||||
$updates = $input['updates'] ?? [];
|
||||
if (!$updates) {
|
||||
throw new Exception('저장할 데이터가 없습니다.');
|
||||
}
|
||||
|
||||
$pdo->beginTransaction();
|
||||
|
||||
$stmtU = $pdo->prepare("
|
||||
SELECT kngil.sp_member_sys_u(
|
||||
:member_id::varchar,
|
||||
:tel_no::varchar,
|
||||
:email::varchar,
|
||||
:bs_no::varchar,
|
||||
:co_nm::varchar,
|
||||
:mid::varchar
|
||||
) AS result
|
||||
");
|
||||
|
||||
foreach ($updates as $r) {
|
||||
|
||||
if (empty($r['member_id'])) {
|
||||
throw new Exception('member_id 누락');
|
||||
}
|
||||
|
||||
$stmtU->execute([
|
||||
':member_id' => $r['member_id'],
|
||||
':tel_no' => $r['tel_no'] ?? null,
|
||||
':email' => $r['email'] ?? null,
|
||||
':bs_no' => $r['bs_no'] ?? null,
|
||||
':co_nm' => $r['co_nm'] ?? null,
|
||||
':mid' => $_SESSION['login']['user_id']
|
||||
]);
|
||||
|
||||
$result = $stmtU->fetchColumn();
|
||||
|
||||
if (strpos($result, 'ERROR') === 0) {
|
||||
throw new Exception($result);
|
||||
}
|
||||
}
|
||||
|
||||
$pdo->commit();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success'
|
||||
]);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception('Invalid action');
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->rollBack();
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user