User Notification Option to Email

This commit is contained in:
Ibnu Maksum 2024-07-22 15:19:29 +07:00
parent 79585d54a1
commit 922f24b630
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5
4 changed files with 240 additions and 40 deletions

159
pages_template/Email.html Normal file
View File

@ -0,0 +1,159 @@
<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>[[Subject]]</title>
<style media="all" type="text/css">
@media all {
.btn-primary table td:hover {
background-color: #ec0867 !important;
}
.btn-primary a:hover {
background-color: #ec0867 !important;
border-color: #ec0867 !important;
}
}
@media only screen and (max-width: 640px) {
.main p,
.main td,
.main span {
font-size: 16px !important;
}
.wrapper {
padding: 8px !important;
}
.content {
padding: 0 !important;
}
.container {
padding: 0 !important;
padding-top: 8px !important;
width: 100% !important;
}
.main {
border-left-width: 0 !important;
border-radius: 0 !important;
border-right-width: 0 !important;
}
.btn table {
max-width: 100% !important;
width: 100% !important;
}
.btn a {
font-size: 16px !important;
max-width: 100% !important;
width: 100% !important;
}
}
@media all {
.ExternalClass {
width: 100%;
}
.ExternalClass,
.ExternalClass p,
.ExternalClass span,
.ExternalClass font,
.ExternalClass td,
.ExternalClass div {
line-height: 100%;
}
.apple-link a {
color: inherit !important;
font-family: inherit !important;
font-size: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
text-decoration: none !important;
}
#MessageViewBody a {
color: inherit;
text-decoration: none;
font-size: inherit;
font-family: inherit;
font-weight: inherit;
line-height: inherit;
}
}
</style>
</head>
<body
style="font-family: Helvetica, sans-serif; -webkit-font-smoothing: antialiased; font-size: 16px; line-height: 1.3; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; background-color: #f4f5f6; margin: 0; padding: 0;">
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="body"
style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #f4f5f6; width: 100%;"
width="100%" bgcolor="#f4f5f6">
<tr>
<td style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top;" valign="top">&nbsp;
</td>
<td class="container"
style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top; max-width: 600px; padding: 0; padding-top: 24px; width: 600px; margin: 0 auto;"
width="600" valign="top">
<div class="content"
style="box-sizing: border-box; display: block; margin: 0 auto; max-width: 600px; padding: 0;">
<!-- START CENTERED WHITE CONTAINER -->
<span class="preheader"
style="color: transparent; display: none; height: 0; max-height: 0; max-width: 0; opacity: 0; overflow: hidden; mso-hide: all; visibility: hidden; width: 0;">This
is preheader text. Some clients will show this text as a preview.</span>
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="main"
style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background: #ffffff; border: 1px solid #eaebed; border-radius: 16px; width: 100%;"
width="100%">
<!-- START MAIN CONTENT AREA -->
<tr>
<td align="center"><h3>[[Company_Name]]</h3></td>
</tr>
<tr>
<td class="wrapper"
style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top; box-sizing: border-box; padding: 24px;"
valign="top">
<p
style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;">
[[Body]]</p>
</td>
</tr>
<!-- END MAIN CONTENT AREA -->
</table>
<!-- START FOOTER -->
<div class="footer" style="clear: both; padding-top: 24px; text-align: center; width: 100%;">
<table role="presentation" border="0" cellpadding="0" cellspacing="0"
style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;"
width="100%">
<tr>
<td class="content-block"
style="font-family: Helvetica, sans-serif; vertical-align: top; color: #9a9ea6; font-size: 16px; text-align: center;"
valign="top" align="center">
<span class="apple-link"
style="color: #9a9ea6; font-size: 16px; text-align: center;">[[Company_Address]]</span>
</td>
</tr>
</table>
</div>
<!-- END FOOTER -->
<!-- END CENTERED WHITE CONTAINER -->
</div>
</td>
<td style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top;" valign="top">&nbsp;
</td>
</tr>
</table>
</body>
</html>

View File

@ -30,7 +30,7 @@ class Message
public static function sendSMS($phone, $txt) public static function sendSMS($phone, $txt)
{ {
global $config; global $config;
if(empty($txt)){ if (empty($txt)) {
return ""; return "";
} }
run_hook('send_sms', [$phone, $txt]); #HOOK run_hook('send_sms', [$phone, $txt]); #HOOK
@ -68,7 +68,7 @@ class Message
if ($_app_stage == 'demo') { if ($_app_stage == 'demo') {
return null; return null;
} }
if(!isset($client_m)){ if (!isset($client_m)) {
$mikrotik = ORM::for_table('tbl_routers')->where('name', $router_name)->find_one(); $mikrotik = ORM::for_table('tbl_routers')->where('name', $router_name)->find_one();
$iport = explode(":", $mikrotik['ip_address']); $iport = explode(":", $mikrotik['ip_address']);
$client_m = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null); $client_m = new RouterOS\Client($iport[0], $mikrotik['username'], $mikrotik['password'], ($iport[1]) ? $iport[1] : null);
@ -83,7 +83,7 @@ class Message
public static function sendWhatsapp($phone, $txt) public static function sendWhatsapp($phone, $txt)
{ {
global $config; global $config;
if(empty($txt)){ if (empty($txt)) {
return "kosong"; return "kosong";
} }
run_hook('send_whatsapp', [$phone, $txt]); #HOOK run_hook('send_whatsapp', [$phone, $txt]); #HOOK
@ -96,8 +96,11 @@ class Message
public static function sendEmail($to, $subject, $body) public static function sendEmail($to, $subject, $body)
{ {
global $config; global $config, $PAGES_PATH, $_app_stage;
if(empty($body)){ if (empty($body)) {
return "";
}
if (empty($to)) {
return ""; return "";
} }
run_hook('send_email', [$to, $subject, $body]); #HOOK run_hook('send_email', [$to, $subject, $body]); #HOOK
@ -113,7 +116,9 @@ class Message
} else { } else {
$mail = new PHPMailer(); $mail = new PHPMailer();
$mail->isSMTP(); $mail->isSMTP();
$mail->SMTPDebug = SMTP::DEBUG_SERVER; if ($_app_stage == 'Dev') {
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
}
$mail->Host = $config['smtp_host']; $mail->Host = $config['smtp_host'];
$mail->SMTPAuth = true; $mail->SMTPAuth = true;
$mail->Username = $config['smtp_user']; $mail->Username = $config['smtp_user'];
@ -126,18 +131,38 @@ class Message
if (!empty($config['mail_reply_to'])) { if (!empty($config['mail_reply_to'])) {
$mail->addReplyTo($config['mail_reply_to']); $mail->addReplyTo($config['mail_reply_to']);
} }
$mail->isHTML(false);
$mail->addAddress($to); $mail->addAddress($to);
$mail->Subject = $subject; $mail->Subject = $subject;
$mail->Body = $body;
if (!file_exists($PAGES_PATH . DIRECTORY_SEPARATOR . 'Email.html')) {
if (!copy($PAGES_PATH . '_template' . DIRECTORY_SEPARATOR . 'Email.html', $PAGES_PATH . DIRECTORY_SEPARATOR . 'Email.html')) {
file_put_contents($PAGES_PATH . DIRECTORY_SEPARATOR . 'Email.html', Http::getData('https://raw.githubusercontent.com/hotspotbilling/phpnuxbill/master/pages_template/Email.html'));
}
}
if (file_exists($PAGES_PATH . DIRECTORY_SEPARATOR . 'Email.html')) {
$html = file_get_contents($PAGES_PATH . DIRECTORY_SEPARATOR . 'Email.html');
$html = str_replace('[[Subject]]', $subject, $html);
$html = str_replace('[[Company_Address]]', nl2br($config['address']), $html);
$html = str_replace('[[Company_Name]]', nl2br($config['CompanyName']), $html);
$html = str_replace('[[Body]]', nl2br($body), $html);
$mail->isHTML(true);
$mail->Body = $html;
} else {
$mail->isHTML(false);
$mail->Body = $body;
}
$mail->send(); $mail->send();
//<p style="font-family: Helvetica, sans-serif; font-size: 16px; font-weight: normal; margin: 0; margin-bottom: 16px;">
} }
} }
public static function sendPackageNotification($customer, $package, $price, $message, $via) public static function sendPackageNotification($customer, $package, $price, $message, $via)
{ {
global $ds; global $ds, $config;
if(empty($message)){ if (empty($message)) {
return ""; return "";
} }
$msg = str_replace('[[name]]', $customer['fullname'], $message); $msg = str_replace('[[name]]', $customer['fullname'], $message);
@ -146,19 +171,19 @@ class Message
$msg = str_replace('[[package]]', $package, $msg); $msg = str_replace('[[package]]', $package, $msg);
$msg = str_replace('[[price]]', Lang::moneyFormat($price), $msg); $msg = str_replace('[[price]]', Lang::moneyFormat($price), $msg);
list($bills, $add_cost) = User::getBills($customer['id']); list($bills, $add_cost) = User::getBills($customer['id']);
if($add_cost>0){ if ($add_cost > 0) {
$note = ""; $note = "";
foreach ($bills as $k => $v) { foreach ($bills as $k => $v) {
$note .= $k . " : " . Lang::moneyFormat($v) . "\n"; $note .= $k . " : " . Lang::moneyFormat($v) . "\n";
} }
$note .= "Total : " . Lang::moneyFormat($add_cost+$price) . "\n"; $note .= "Total : " . Lang::moneyFormat($add_cost + $price) . "\n";
$msg = str_replace('[[bills]]', $note, $msg); $msg = str_replace('[[bills]]', $note, $msg);
}else{ } else {
$msg = str_replace('[[bills]]', '', $msg); $msg = str_replace('[[bills]]', '', $msg);
} }
if ($ds) { if ($ds) {
$msg = str_replace('[[expired_date]]', Lang::dateAndTimeFormat($ds['expiration'], $ds['time']), $msg); $msg = str_replace('[[expired_date]]', Lang::dateAndTimeFormat($ds['expiration'], $ds['time']), $msg);
}else{ } else {
$msg = str_replace('[[expired_date]]', "", $msg); $msg = str_replace('[[expired_date]]', "", $msg);
} }
if ( if (
@ -167,6 +192,8 @@ class Message
) { ) {
if ($via == 'sms') { if ($via == 'sms') {
echo Message::sendSMS($customer['phonenumber'], $msg); echo Message::sendSMS($customer['phonenumber'], $msg);
} else if ($via == 'email') {
self::sendEmail($customer['email'], '[' . $config['CompanyName'] . '] ' . Lang::T("Internet Plan Reminder"), $msg);
} else if ($via == 'wa') { } else if ($via == 'wa') {
echo Message::sendWhatsapp($customer['phonenumber'], $msg); echo Message::sendWhatsapp($customer['phonenumber'], $msg);
} }
@ -174,17 +201,21 @@ class Message
return "$via: $msg"; return "$via: $msg";
} }
public static function sendBalanceNotification($phone, $name, $balance, $balance_now, $message, $via) public static function sendBalanceNotification($cust, $balance, $balance_now, $message, $via)
{ {
$msg = str_replace('[[name]]', $name, $message); global $config;
$msg = str_replace('[[name]]', $cust['fullname'] . ' (' . $cust['username'] . ')', $message);
$msg = str_replace('[[current_balance]]', Lang::moneyFormat($balance_now), $msg); $msg = str_replace('[[current_balance]]', Lang::moneyFormat($balance_now), $msg);
$msg = str_replace('[[balance]]', Lang::moneyFormat($balance), $msg); $msg = str_replace('[[balance]]', Lang::moneyFormat($balance), $msg);
$phone = $cust['phonenumber'];
if ( if (
!empty($phone) && strlen($phone) > 5 !empty($phone) && strlen($phone) > 5
&& !empty($message) && in_array($via, ['sms', 'wa']) && !empty($message) && in_array($via, ['sms', 'wa', 'email'])
) { ) {
if ($via == 'sms') { if ($via == 'sms') {
Message::sendSMS($phone, $msg); Message::sendSMS($phone, $msg);
} else if ($config['user_notification_payment'] == 'email') {
self::sendEmail($cust['email'], '[' . $config['CompanyName'] . '] ' . Lang::T("Balance Notification"), $msg);
} else if ($via == 'wa') { } else if ($via == 'wa') {
Message::sendWhatsapp($phone, $msg); Message::sendWhatsapp($phone, $msg);
} }
@ -221,6 +252,8 @@ class Message
if ($config['user_notification_payment'] == 'sms') { if ($config['user_notification_payment'] == 'sms') {
Message::sendSMS($cust['phonenumber'], $textInvoice); Message::sendSMS($cust['phonenumber'], $textInvoice);
} else if ($config['user_notification_payment'] == 'email') {
self::sendEmail($cust['email'], '[' . $config['CompanyName'] . '] ' . Lang::T("Invoice") . ' #' . $trx['invoice'], $textInvoice);
} else if ($config['user_notification_payment'] == 'wa') { } else if ($config['user_notification_payment'] == 'wa') {
Message::sendWhatsapp($cust['phonenumber'], $textInvoice); Message::sendWhatsapp($cust['phonenumber'], $textInvoice);
} }

View File

@ -71,8 +71,8 @@ if (_post('send') == 'balance') {
$d->pg_url_payment = 'balance'; $d->pg_url_payment = 'balance';
$d->status = 2; $d->status = 2;
$d->save(); $d->save();
Message::sendBalanceNotification($user['phonenumber'], $target['fullname'] . ' (' . $target['username'] . ')', $balance, ($user['balance'] - $balance), Lang::getNotifText('balance_send'), $config['user_notification_payment']); Message::sendBalanceNotification($user, $balance, ($user['balance'] - $balance), Lang::getNotifText('balance_send'), $config['user_notification_payment']);
Message::sendBalanceNotification($target['phonenumber'], $user['fullname'] . ' (' . $user['username'] . ')', $balance, ($target['balance'] + $balance), Lang::getNotifText('balance_received'), $config['user_notification_payment']); Message::sendBalanceNotification($target, $balance, ($target['balance'] + $balance), Lang::getNotifText('balance_received'), $config['user_notification_payment']);
Message::sendTelegram("#u$user[username] send balance to #u$target[username] \n" . Lang::moneyFormat($balance)); Message::sendTelegram("#u$user[username] send balance to #u$target[username] \n" . Lang::moneyFormat($balance));
r2(U . 'home', 's', Lang::T('Sending balance success')); r2(U . 'home', 's', Lang::T('Sending balance success'));
} }
@ -245,16 +245,16 @@ if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'] && !empty($_SESSI
$ui->assign('logged', $_GET['logged']); $ui->assign('logged', $_GET['logged']);
if ($_app_stage != 'demo') { if ($_app_stage != 'demo') {
if ($_GET['mikrotik'] == 'login') { if ($_GET['mikrotik'] == 'login') {
r2(U . 'home&hchap=true', 's', Lang::T('Login Request successfully')); r2(U . 'home&hchap=true', 's', Lang::T('Login Request successfully'));
} }
$getmsg = $_GET['msg']; $getmsg = $_GET['msg'];
///get auth notification from mikrotik ///get auth notification from mikrotik
if($getmsg == 'Connected') { if($getmsg == 'Connected') {
$msg .= Lang::T($getmsg); $msg .= Lang::T($getmsg);
r2(U . 'home&logged=1', 's', $msg); r2(U . 'home&logged=1', 's', $msg);
} else if($getmsg){ } else if($getmsg){
$msg .= Lang::T($getmsg); $msg .= Lang::T($getmsg);
r2(U . 'home', 's', $msg); r2(U . 'home', 's', $msg);
} }
} }
} }
@ -272,16 +272,16 @@ if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'] && !empty($_SESSI
$ui->assign('logged', $_GET['logged']); $ui->assign('logged', $_GET['logged']);
if ($_app_stage != 'demo') { if ($_app_stage != 'demo') {
if ($_GET['mikrotik'] == 'login') { if ($_GET['mikrotik'] == 'login') {
r2(U . 'home&hchap=true', 's', Lang::T('Login Request successfully')); r2(U . 'home&hchap=true', 's', Lang::T('Login Request successfully'));
} }
$getmsg = $_GET['msg']; $getmsg = $_GET['msg'];
///get auth notification from mikrotik ///get auth notification from mikrotik
if($getmsg == 'Connected') { if($getmsg == 'Connected') {
$msg .= Lang::T($getmsg); $msg .= Lang::T($getmsg);
r2(U . 'home&logged=1', 's', $msg); r2(U . 'home&logged=1', 's', $msg);
} else if($getmsg){ } else if($getmsg){
$msg .= Lang::T($getmsg); $msg .= Lang::T($getmsg);
r2(U . 'home', 's', $msg); r2(U . 'home', 's', $msg);
} }
} }
} }

View File

@ -476,6 +476,8 @@
{/if}>Whatsapp</option> {/if}>Whatsapp</option>
<option value="sms" {if $_c['user_notification_expired']=='sms' }selected="selected" <option value="sms" {if $_c['user_notification_expired']=='sms' }selected="selected"
{/if}>SMS</option> {/if}>SMS</option>
<option value="email" {if $_c['user_notification_expired']=='email' }selected="selected"
{/if}>Email</option>
</select> </select>
</div> </div>
<p class="help-block col-md-4">{Lang::T('User will get notification when package expired')}</p> <p class="help-block col-md-4">{Lang::T('User will get notification when package expired')}</p>
@ -490,6 +492,8 @@
{/if}>Whatsapp</option> {/if}>Whatsapp</option>
<option value="sms" {if $_c['user_notification_payment']=='sms' }selected="selected" <option value="sms" {if $_c['user_notification_payment']=='sms' }selected="selected"
{/if}>SMS</option> {/if}>SMS</option>
<option value="email" {if $_c['user_notification_payment']=='email' }selected="selected"
{/if}>Email</option>
</select> </select>
</div> </div>
<p class="help-block col-md-4"> <p class="help-block col-md-4">
@ -505,6 +509,8 @@
{/if}>Whatsapp</option> {/if}>Whatsapp</option>
<option value="sms" {if $_c['user_notification_reminder']=='sms' }selected="selected" <option value="sms" {if $_c['user_notification_reminder']=='sms' }selected="selected"
{/if}>SMS</option> {/if}>SMS</option>
<option value="sms" {if $_c['user_notification_reminder']=='email' }selected="selected"
{/if}>Email</option>
</select> </select>
</div> </div>
</div> </div>
@ -622,21 +628,23 @@
{Lang::T('If user buy same internet plan, expiry date will extend')}</p> {Lang::T('If user buy same internet plan, expiry date will extend')}</p>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-md-2 control-label">{Lang::T('Hotspot Auth Method')}</label> <label class="col-md-2 control-label">{Lang::T('Hotspot Auth Method')}</label>
<div class="col-md-6"> <div class="col-md-6">
<select name="hs_auth_method" id="auth_method" class="form-control"> <select name="hs_auth_method" id="auth_method" class="form-control">
<option value="api" {if $_c['hs_auth_method']=='api' }selected="selected" {/if}> <option value="api" {if $_c['hs_auth_method']=='api' }selected="selected" {/if}>
{Lang::T('Api')} {Lang::T('Api')}
</option> </option>
<option value="hchap" {if $_c['hs_auth_method']=='hchap' }selected="selected" {/if}> <option value="hchap" {if $_c['hs_auth_method']=='hchap' }selected="selected" {/if}>
{Lang::T('Http-Chap')} {Lang::T('Http-Chap')}
</option> </option>
</select> </select>
</div>
<p class="help-block col-md-4">
{Lang::T('Hotspot Authentication Method. Make sure you have changed your hotspot login page.')}<br><a href="https://github.com/agstrxyz/phpnuxbill-login-hotspot" target="_blank">Download phpnuxbill-login-hotspot</a>
</p>
</div> </div>
<p class="help-block col-md-4">
{Lang::T('Hotspot Authentication Method. Make sure you have changed your hotspot login page.')}<br><a
href="https://github.com/agstrxyz/phpnuxbill-login-hotspot" target="_blank">Download
phpnuxbill-login-hotspot</a>
</p>
</div>
</div> </div>
<div class="panel-heading"> <div class="panel-heading">