From 7e7b70ba757e586f46682b77d8105b7ae97e5344 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Wed, 24 Jan 2024 14:02:58 +0700 Subject: [PATCH] Add test SMS, WA and Telegram --- system/autoload/Message.php | 20 +++++++-------- system/controllers/settings.php | 16 +++++++++++- ui/ui/app-settings.tpl | 44 ++++++++++++++++++++++++++------- ui/ui/community.tpl | 7 +++++- 4 files changed, 66 insertions(+), 21 deletions(-) diff --git a/system/autoload/Message.php b/system/autoload/Message.php index df17aec1..3496f79a 100644 --- a/system/autoload/Message.php +++ b/system/autoload/Message.php @@ -14,7 +14,7 @@ class Message global $config; run_hook('send_telegram'); #HOOK if (!empty($config['telegram_bot']) && !empty($config['telegram_target_id'])) { - Http::getData('https://api.telegram.org/bot' . $config['telegram_bot'] . '/sendMessage?chat_id=' . $config['telegram_target_id'] . '&text=' . urlencode($txt)); + return Http::getData('https://api.telegram.org/bot' . $config['telegram_bot'] . '/sendMessage?chat_id=' . $config['telegram_target_id'] . '&text=' . urlencode($txt)); } } @@ -27,17 +27,17 @@ class Message if (strlen($config['sms_url']) > 4 && substr($config['sms_url'], 0, 4) != "http") { if (strlen($txt) > 160) { $txts = str_split($txt, 160); - foreach ($txts as $txt) { - try { - $mikrotik = Mikrotik::info($config['sms_url']); - $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + try { + $mikrotik = Mikrotik::info($config['sms_url']); + $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); + foreach ($txts as $txt) { Mikrotik::sendSMS($client, $phone, $txt); - } catch (Exception $e) { - // ignore, add to logs - _log("Failed to send SMS using Mikrotik.\n" . $e->getMessage(), 'SMS', 0); } + } catch (Exception $e) { + // ignore, add to logs + _log("Failed to send SMS using Mikrotik.\n" . $e->getMessage(), 'SMS', 0); } - }else{ + } else { try { $mikrotik = Mikrotik::info($config['sms_url']); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); @@ -50,7 +50,7 @@ class Message } else { $smsurl = str_replace('[number]', urlencode($phone), $config['sms_url']); $smsurl = str_replace('[text]', urlencode($txt), $smsurl); - Http::getData($smsurl); + return Http::getData($smsurl); } } } diff --git a/system/controllers/settings.php b/system/controllers/settings.php index 346d695d..97d66404 100644 --- a/system/controllers/settings.php +++ b/system/controllers/settings.php @@ -17,6 +17,20 @@ switch ($action) { if ($admin['user_type'] != 'Admin') { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } + + if (!empty(_get('testWa'))) { + $result = Message::sendWhatsapp(_get('testWa'), 'PHPNuxBill Test Whatsapp'); + r2(U . "settings/app", 's', 'Test Whatsapp has been send
Result: ' . $result); + } + if (!empty(_get('testSms'))) { + $result = Message::sendSMS(_get('testSms'), 'PHPNuxBill Test SMS'); + r2(U . "settings/app", 's', 'Test SMS has been send
Result: ' . $result); + } + if (!empty(_get('testTg'))) { + $result = Message::sendTelegram('PHPNuxBill Test Telegram'); + r2(U . "settings/app", 's', 'Test Telegram has been send
Result: ' . $result); + } + if (file_exists('system/uploads/logo.png')) { $logo = 'system/uploads/logo.png?' . time(); } else { @@ -272,7 +286,7 @@ switch ($action) { } } // save all settings - foreach($_POST as $key => $value) { + foreach ($_POST as $key => $value) { $d = ORM::for_table('tbl_appconfig')->where('setting', $key)->find_one(); if ($d) { $d->value = $value; diff --git a/ui/ui/app-settings.tpl b/ui/ui/app-settings.tpl index 78d7667e..fc91a6f6 100644 --- a/ui/ui/app-settings.tpl +++ b/ui/ui/app-settings.tpl @@ -54,10 +54,11 @@
- +
- +
For invoice print using Thermal Printer
@@ -218,6 +219,7 @@
@@ -244,6 +246,7 @@
@@ -281,6 +284,7 @@
@@ -427,14 +431,17 @@
- Create Token + Create Token
-
@@ -465,4 +472,23 @@ add dst-host=*.{$_domain} + {include file="sections/footer.tpl"} \ No newline at end of file diff --git a/ui/ui/community.tpl b/ui/ui/community.tpl index 582c654f..25586a6f 100644 --- a/ui/ui/community.tpl +++ b/ui/ui/community.tpl @@ -104,7 +104,12 @@