diff --git a/app/Config/Routes.php b/app/Config/Routes.php index e409ade..e06d0f5 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -63,6 +63,7 @@ $routes->group('bag', ['filter' => 'loginAuth'], static function ($routes): void $routes->get('manual/search', 'Bag::manualSearch'); // (:segment) 보다 먼저 $routes->get('manual/(:segment)', 'Bag::manualPage/$1'); $routes->post('activity/print-log', 'Bag::printLog'); // 인쇄 활동 기록(beacon) + $routes->post('pref/font-scale', 'Bag::saveFontScale'); // 계정별·메뉴별 글자크기 저장 }); $routes->get('bag/number-lookup', 'Bag::numberLookup'); diff --git a/app/Controllers/Bag.php b/app/Controllers/Bag.php index 14fb119..440ff7e 100644 --- a/app/Controllers/Bag.php +++ b/app/Controllers/Bag.php @@ -224,6 +224,56 @@ class Bag extends BaseController ]); } + /** + * 계정별·메뉴별 글자크기(zoom %) 저장. AJAX 전용. + * menu_key(화면 경로) + scale(70~150)을 로그인 계정 기준으로 upsert. + */ + public function saveFontScale(): ResponseInterface + { + $mbIdx = (int) (session()->get('mb_idx') ?? 0); + if ($mbIdx <= 0) { + return $this->response->setJSON(['ok' => false, 'csrf' => csrf_hash()]); + } + $menuKey = trim((string) ($this->request->getPost('menu_key') ?? '')); + $scale = (int) ($this->request->getPost('scale') ?? 0); + if ($menuKey === '' || $scale < 70 || $scale > 150) { + return $this->response->setJSON(['ok' => false, 'csrf' => csrf_hash()]); + } + $menuKey = mb_substr($menuKey, 0, 191); + + $db = \Config\Database::connect(); + if (! $db->tableExists('member_menu_font_scale')) { + $db->query(<<<'SQL' +CREATE TABLE IF NOT EXISTS `member_menu_font_scale` ( + `mmf_idx` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `mmf_mb_idx` INT UNSIGNED NOT NULL, + `mmf_menu_key` VARCHAR(191) NOT NULL, + `mmf_scale` SMALLINT UNSIGNED NOT NULL DEFAULT 100, + `mmf_updated` DATETIME NOT NULL, + PRIMARY KEY (`mmf_idx`), + UNIQUE KEY `uk_mb_menu` (`mmf_mb_idx`,`mmf_menu_key`), + KEY `idx_mb` (`mmf_mb_idx`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci +SQL); + } + + $now = date('Y-m-d H:i:s'); + $exists = $db->table('member_menu_font_scale') + ->where('mmf_mb_idx', $mbIdx)->where('mmf_menu_key', $menuKey)->countAllResults(); + if ($exists > 0) { + $db->table('member_menu_font_scale') + ->where('mmf_mb_idx', $mbIdx)->where('mmf_menu_key', $menuKey) + ->update(['mmf_scale' => $scale, 'mmf_updated' => $now]); + } else { + $db->table('member_menu_font_scale')->insert([ + 'mmf_mb_idx' => $mbIdx, 'mmf_menu_key' => $menuKey, + 'mmf_scale' => $scale, 'mmf_updated' => $now, + ]); + } + + return $this->response->setJSON(['ok' => true, 'csrf' => csrf_hash()]); + } + // ────────────────────────────────────────────── // 기본정보관리 (단가·포장 단위 진입 허브) // ────────────────────────────────────────────── diff --git a/app/Helpers/admin_helper.php b/app/Helpers/admin_helper.php index c01f69a..e576d9e 100644 --- a/app/Helpers/admin_helper.php +++ b/app/Helpers/admin_helper.php @@ -229,6 +229,37 @@ if (! function_exists('current_nav_request_path')) { } } +if (! function_exists('member_font_scale_for')) { + /** + * 로그인 계정의 특정 메뉴(화면 경로)에 저장된 글자크기(zoom %)를 반환. + * 저장값이 없거나 범위(70~150) 밖이면 100. + */ + function member_font_scale_for(string $menuKey): int + { + $mbIdx = (int) (session()->get('mb_idx') ?? 0); + $menuKey = trim($menuKey); + if ($mbIdx <= 0 || $menuKey === '') { + return 100; + } + try { + $db = \Config\Database::connect(); + if (! $db->tableExists('member_menu_font_scale')) { + return 100; + } + $row = $db->table('member_menu_font_scale') + ->select('mmf_scale') + ->where('mmf_mb_idx', $mbIdx) + ->where('mmf_menu_key', $menuKey) + ->get()->getRow(); + } catch (\Throwable $e) { + return 100; + } + $s = $row ? (int) $row->mmf_scale : 100; + + return ($s >= 70 && $s <= 150) ? $s : 100; + } +} + if (! function_exists('normalize_menu_link_for_url')) { /** * menu.mm_link 를 base_url() 인자로 쓸 수 있는 상대 경로로 정규화합니다. diff --git a/app/Views/admin/layout.php b/app/Views/admin/layout.php index 54fc564..39498e3 100644 --- a/app/Views/admin/layout.php +++ b/app/Views/admin/layout.php @@ -62,6 +62,9 @@ $navPartial = [