From c76aefb7e0cb23b712e772cad4abe7fa6858b029 Mon Sep 17 00:00:00 2001
From: Ibnu Maksum <ibnumaksum@gmail.com>
Date: Fri, 6 Oct 2023 16:57:18 +0700
Subject: [PATCH] check if radius tabel exists

---
 system/controllers/settings.php | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/system/controllers/settings.php b/system/controllers/settings.php
index 49f69611..50ae71e2 100644
--- a/system/controllers/settings.php
+++ b/system/controllers/settings.php
@@ -34,7 +34,7 @@ switch ($action) {
         $folders = [];
         $files = scandir('system/lan/');
         foreach ($files as $file) {
-            if(is_dir('system/lan/'.$file) && !in_array($file,['.','..'])){
+            if (is_dir('system/lan/' . $file) && !in_array($file, ['.', '..'])) {
                 $folders[] = $file;
             }
         }
@@ -424,6 +424,19 @@ switch ($action) {
                 $d->save();
             }
 
+            if ($radius_enable) {
+                try {
+                    ORM::for_table('nasi', 'radius')->where('setting', 'tawkto')->find_one();
+                } catch (Exception $e) {
+                    $ui->assign("error_title", "RADIUS Error");
+                    $ui->assign("error_message", "Radius table not found.<br><br>" .
+                        $e->getMessage() .
+                        "<br><br>Download <a href=\"https://raw.githubusercontent.com/hotspotbilling/phpnuxbill/Development/install/radius.sql\">here</a> or <a href=\"https://raw.githubusercontent.com/hotspotbilling/phpnuxbill/master/install/radius.sql\">here</a> and import it to database.<br><br>Check config.php for radius connection details");
+                    $ui->display('router-error.tpl');
+                    die();
+                }
+            }
+
             $d = ORM::for_table('tbl_appconfig')->where('setting', 'radius_enable')->find_one();
             if ($d) {
                 $d->value = $radius_enable;