70 lines
2.7 KiB
PHP
70 lines
2.7 KiB
PHP
<?php
|
|
include_once('./_common.php');
|
|
|
|
// 관리자 권한 확인
|
|
if (!$is_admin) {
|
|
die(json_encode(['success' => false, 'message' => '관리자 권한이 필요합니다.']));
|
|
}
|
|
|
|
// lib/notification_helper.php 포함
|
|
if (file_exists(G5_LIB_PATH . '/notification_helper.php')) {
|
|
include_once(G5_LIB_PATH . '/notification_helper.php');
|
|
}
|
|
|
|
$action = isset($_REQUEST['action']) ? clean_xss_tags($_REQUEST['action']) : '';
|
|
$id = isset($_REQUEST['id']) ? (int)$_REQUEST['id'] : 0;
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
try {
|
|
switch ($action) {
|
|
case 'get_details':
|
|
if (!$id) throw new Exception('예약 ID가 없습니다.');
|
|
|
|
$reservation = sql_fetch("SELECT * FROM expert_visit_reservations WHERE id = '{$id}'");
|
|
if (!$reservation) throw new Exception('예약 정보를 찾을 수 없습니다.');
|
|
|
|
echo json_encode(['success' => true, 'data' => $reservation]);
|
|
break;
|
|
|
|
case 'update_reservation':
|
|
if (!$id) throw new Exception('예약 ID가 없습니다.');
|
|
|
|
$status = isset($_POST['status']) ? clean_xss_tags($_POST['status']) : '';
|
|
$expert_id = isset($_POST['expert_id']) ? clean_xss_tags($_POST['expert_id']) : '';
|
|
$admin_memo = isset($_POST['admin_memo']) ? clean_xss_tags($_POST['admin_memo']) : '';
|
|
|
|
// 기존 정보 조회 (상태 변경 시 알림을 위함)
|
|
$old_reservation = sql_fetch("SELECT status FROM expert_visit_reservations WHERE id = '{$id}'");
|
|
|
|
$sql = "UPDATE expert_visit_reservations SET " .
|
|
" status = '" . sql_real_escape_string($status) . "', " .
|
|
" expert_id = '" . sql_real_escape_string($expert_id) . "', " .
|
|
" admin_memo = '" . sql_real_escape_string($admin_memo) . "', " .
|
|
" updated_at = NOW(), " .
|
|
" updated_by = '{$member['mb_id']}' " .
|
|
" WHERE id = '{$id}' ";
|
|
sql_query($sql);
|
|
|
|
// 상태 변경 시 알림 발송
|
|
if (function_exists('notify_for_expert_visit')) {
|
|
// 입금 확인 -> 예약 확정
|
|
if ($old_reservation['status'] !== 'reserved' && $status === 'reserved') {
|
|
notify_for_expert_visit($id, '예약확정');
|
|
}
|
|
}
|
|
|
|
echo json_encode(['success' => true, 'message' => '방문 예약 정보가 성공적으로 업데이트되었습니다.']);
|
|
break;
|
|
|
|
default:
|
|
throw new Exception('유효하지 않은 요청입니다.');
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
echo json_encode([
|
|
'success' => false,
|
|
'message' => $e->getMessage()
|
|
]);
|
|
}
|
|
exit; |