5) { header("Content-Type: application/json"); echo json_encode(['success' => false, 'message' => '권한이 없습니다.']); exit; } header("Content-Type: application/json"); $action = $_POST['action'] ?? ''; $excludedNotesFile = $_SERVER['DOCUMENT_ROOT'] . "/account/excluded_notes.json"; // JSON 파일이 없으면 생성 if (!file_exists($excludedNotesFile)) { file_put_contents($excludedNotesFile, '[]'); } // 기존 제외된 어음 목록 로드 $excludedNotes = json_decode(file_get_contents($excludedNotesFile), true) ?: []; try { switch ($action) { case 'exclude': $noteNum = intval($_POST['note_num']); $contentDetail = $_POST['content_detail'] ?? ''; if (!$noteNum) { throw new Exception('어음 번호가 필요합니다.'); } // 이미 제외된 어음인지 확인 $alreadyExcluded = false; foreach ($excludedNotes as $note) { if ($note['note_num'] == $noteNum) { $alreadyExcluded = true; break; } } if ($alreadyExcluded) { throw new Exception('이미 제외된 어음입니다.'); } // 제외된 어음 정보 추가 $excludedNote = [ 'note_num' => $noteNum, 'content_detail' => $contentDetail, 'excluded_date' => date('Y-m-d H:i:s'), 'excluded_by' => $user_name ?? 'Unknown' ]; $excludedNotes[] = $excludedNote; // JSON 파일에 저장 if (file_put_contents($excludedNotesFile, json_encode($excludedNotes, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)) === false) { throw new Exception('제외 정보 저장에 실패했습니다.'); } echo json_encode(['success' => true, 'message' => '어음이 제외되었습니다.']); break; case 'restore': $noteNum = intval($_POST['note_num']); if (!$noteNum) { throw new Exception('어음 번호가 필요합니다.'); } // 제외된 어음 목록에서 해당 어음 제거 $found = false; $newExcludedNotes = []; foreach ($excludedNotes as $note) { if ($note['note_num'] != $noteNum) { $newExcludedNotes[] = $note; } else { $found = true; } } if (!$found) { throw new Exception('제외된 어음 목록에서 해당 어음을 찾을 수 없습니다.'); } // JSON 파일에 저장 if (file_put_contents($excludedNotesFile, json_encode($newExcludedNotes, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)) === false) { throw new Exception('복원 정보 저장에 실패했습니다.'); } echo json_encode(['success' => true, 'message' => '어음이 복원되었습니다.']); break; case 'get_excluded': echo json_encode(['success' => true, 'data' => $excludedNotes]); break; default: throw new Exception('잘못된 요청입니다.'); } } catch (Exception $e) { echo json_encode(['success' => false, 'message' => $e->getMessage()]); } ?>