From cf4f708f83d1ea2461a8d23f498003926a227cbc Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Fri, 16 Aug 2024 09:35:25 +0700 Subject: [PATCH] set customer language to cookie --- init.php | 2 ++ ui/ui/sections/user-footer.tpl | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/init.php b/init.php index 1d03d95e..d3da03d8 100644 --- a/init.php +++ b/init.php @@ -134,6 +134,8 @@ if ((!empty($radius_user) && $config['radius_enable']) || _post('radius_enable') // Check if the user has selected a language if (!empty($_SESSION['user_language'])) { $config['language'] = $_SESSION['user_language']; +}else if (!empty($_COOKIE['user_language'])) { + $config['language'] = $_COOKIE['user_language']; } if (empty($_SESSION['Lang'])) { diff --git a/ui/ui/sections/user-footer.tpl b/ui/ui/sections/user-footer.tpl index b6017e68..bda37fc4 100644 --- a/ui/ui/sections/user-footer.tpl +++ b/ui/ui/sections/user-footer.tpl @@ -108,6 +108,28 @@ }) }); }); + + function setCookie(name, value, days) { + var expires = ""; + if (days) { + var date = new Date(); + date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); + expires = "; expires=" + date.toUTCString(); + } + document.cookie = name + "=" + (value || "") + expires + "; path=/"; + } + + function getCookie(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for (var i = 0; i < ca.length; i++) { + var c = ca[i]; + while (c.charAt(0) == ' ') c = c.substring(1, c.length); + if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); + } + return null; + } + setCookie('user_language', '{/literal}{$user_language}{literal}', 365); {/literal}