From 8e55330bcbf7aff63cb7ce9824777ea40c1684bf Mon Sep 17 00:00:00 2001 From: Focuslinkstech <45756999+Focuslinkstech@users.noreply.github.com> Date: Wed, 31 Jul 2024 00:57:53 +0100 Subject: [PATCH] Add send welcome message send welcome message to new registered customers. Goto settings -> User Notification -> Welcome Message to setup message --- system/controllers/customers.php | 41 ++++++++++++++++++++ system/uploads/notifications.default.json | 4 +- ui/ui/app-notifications.tpl | 16 ++++++++ ui/ui/customers-add.tpl | 47 +++++++++++++++++++++++ 4 files changed, 107 insertions(+), 1 deletion(-) diff --git a/system/controllers/customers.php b/system/controllers/customers.php index ca95cce5..8328c7b9 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -432,6 +432,47 @@ switch ($action) { } } } + + // Send welcome message + if (isset($_POST['send_welcome_message']) && $_POST['send_welcome_message'] == true) { + $welcomeMessage = Lang::getNotifText('welcome_message'); + $welcomeMessage = str_replace('[[company_name]]', $config['CompanyName'], $welcomeMessage); + $welcomeMessage = str_replace('[[name]]', $d['fullname'], $welcomeMessage); + $welcomeMessage = str_replace('[[username]]', $d['username'], $welcomeMessage); + $welcomeMessage = str_replace('[[password]]', $d['password'], $welcomeMessage); + $welcomeMessage = str_replace('[[url]]', APP_URL . '/index.php?_route=login', $welcomeMessage); + + $emailSubject = "Welcome to " . $config['CompanyName']; + + $channels = [ + 'sms' => [ + 'enabled' => isset($_POST['sms']), + 'method' => 'sendSMS', + 'args' => [$d['phonenumber'], $welcomeMessage] + ], + 'whatsapp' => [ + 'enabled' => isset($_POST['wa']) && $_POST['wa'] == 'wa', + 'method' => 'sendWhatsapp', + 'args' => [$d['phonenumber'], $welcomeMessage] + ], + 'email' => [ + 'enabled' => isset($_POST['email']), + 'method' => 'Message::sendEmail', + 'args' => [$d['email'], $emailSubject, $welcomeMessage, $d['email']] + ] + ]; + + foreach ($channels as $channel => $message) { + if ($message['enabled']) { + try { + call_user_func_array($message['method'], $message['args']); + } catch (Exception $e) { + // Log the error and handle the failure + _log("Failed to send welcome message via $channel: " . $e->getMessage()); + } + } + } + } r2(U . 'customers/list', 's', Lang::T('Account Created Successfully')); } else { r2(U . 'customers/add', 'e', $msg); diff --git a/system/uploads/notifications.default.json b/system/uploads/notifications.default.json index a1485439..e6843cca 100644 --- a/system/uploads/notifications.default.json +++ b/system/uploads/notifications.default.json @@ -6,5 +6,7 @@ "reminder_3_day": "Hello *[[name]]*, \r\nyour internet package *[[package]]* will be expired in 3 days.", "reminder_1_day": "Hello *[[name]]*,\r\n your internet package *[[package]]* will be expired tomorrow.", "invoice_paid": "*[[company_name]]*\r\n[[address]]\r\n[[phone]]\r\n\r\n\r\nINVOICE: *[[invoice]]*\r\nDate : [[date]]\r\n[[payment_gateway]] [[payment_channel]]\r\n\r\n\r\nType : *[[type]]*\r\nPackage : *[[plan_name]]*\r\nPrice : *[[plan_price]]*\r\n\r\nUsername : *[[user_name]]*\r\nPassword : ***********\r\n\r\nExpired : *[[expired_date]]*\r\n\r\n====================\r\n[[footer]]", - "invoice_balance": "*[[company_name]]*\r\n[[address]]\r\n[[phone]]\r\n\r\n\r\nINVOICE: *[[invoice]]*\r\nDate : [[date]]\r\n[[payment_gateway]] [[payment_channel]]\r\n\r\n\r\nType : *[[type]]*\r\nPackage : *[[plan_name]]*\r\nPrice : *[[plan_price]]*\r\n\r\n====================\r\n[[footer]]" + "invoice_balance": "*[[company_name]]*\r\n[[address]]\r\n[[phone]]\r\n\r\n\r\nINVOICE: *[[invoice]]*\r\nDate : [[date]]\r\n[[payment_gateway]] [[payment_channel]]\r\n\r\n\r\nType : *[[type]]*\r\nPackage : *[[plan_name]]*\r\nPrice : *[[plan_price]]*\r\n\r\n====================\r\n[[footer]]", + "welcome_message": "Welcome aboard, [[name]]! \r\nWe're excited to have you as a new [[company]] customer. \r\nYour account is all set up and ready to go.\r\n\r\nHere's a quick overview:\r\n\r\nYour login is [[Username]]\r\nYour temporary password is [[Password]] (please change this on your first login)\r\n\r\nNeed help? Reach out to our support team at anytime.\r\n\r\nWe're here to ensure you have an amazing experience with our services. Let us know how we can best support you.\r\n\r\nWelcome to the [[company]] family!" + } diff --git a/ui/ui/app-notifications.tpl b/ui/ui/app-notifications.tpl index cb133a39..94e9e299 100644 --- a/ui/ui/app-notifications.tpl +++ b/ui/ui/app-notifications.tpl @@ -136,6 +136,22 @@
+
+ [[name]] - {Lang::T('will be replaced with Customer Name')}.
+ [[username]] - {Lang::T('will be replaced with Customer username')}.
+ [[password]] - {Lang::T('will be replaced with Customer password')}.
+ [[url]] - {Lang::T('will be replaced with Customer Portal URL')}.
+ [[company]] - {Lang::T('will be replaced with Company Name')}.
+