diff --git a/system/controllers/message.php b/system/controllers/message.php index 046ff092..78fa3790 100644 --- a/system/controllers/message.php +++ b/system/controllers/message.php @@ -95,49 +95,65 @@ EOT; if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) { _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } - - // Get form data - $group = $_POST['group']; - $message = $_POST['message']; - $via = $_POST['via']; - $test = isset($_POST['test']) && $_POST['test'] === 'on' ? 'yes' : 'no'; - $batch = $_POST['batch']; - $delay = $_POST['delay']; - + set_time_limit(0); // Initialize counters $totalSMSSent = 0; $totalSMSFailed = 0; $totalWhatsappSent = 0; $totalWhatsappFailed = 0; - $batchStatus = []; + $totalCustomers = 0; + $batchStatus = $_SESSION['batchStatus']; + $page = _req('page', -1); if (_req('send') == 'now') { + // Get form data + $group = $_REQUEST['group']; + $message = $_REQUEST['message']; + $via = $_REQUEST['via']; + $test = isset($_REQUEST['test']) && $_REQUEST['test'] === 'on' ? 'yes' : 'no'; + $batch = $_REQUEST['batch']; + $delay = $_REQUEST['delay']; + + $ui->assign('group', $group); + $ui->assign('message', $message); + $ui->assign('via', $via); + $ui->assign('test', $test); + $ui->assign('batch', $batch); + $ui->assign('delay', $delay); + if($page<0){ + $batchStatus = []; + $page = 0; + } + $startpoint = $page * $batch; + $page++; // Check if fields are empty if ($group == '' || $message == '' || $via == '') { r2(getUrl('message/send_bulk'), 'e', Lang::T('All fields are required')); } else { // Get customer details from the database based on the selected group if ($group == 'all') { - $customers = ORM::for_table('tbl_customers')->find_many()->as_array(); + $customers = ORM::for_table('tbl_customers') + ->offset($startpoint) + ->limit($batch)->find_array(); } elseif ($group == 'new') { // Get customers created just a month ago - $customers = ORM::for_table('tbl_customers')->where_raw("DATE(created_at) >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)")->find_many()->as_array(); + $customers = ORM::for_table('tbl_customers')->where_raw("DATE(created_at) >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)") + ->offset($startpoint)->limit($batch) + ->find_array(); } elseif ($group == 'expired') { // Get expired user recharges where status is 'off' - $expired = ORM::for_table('tbl_user_recharges')->where('status', 'off')->find_many(); - $customer_ids = []; - foreach ($expired as $recharge) { - $customer_ids[] = $recharge->customer_id; - } - $customers = ORM::for_table('tbl_customers')->where_in('id', $customer_ids)->find_many()->as_array(); + $expired = ORM::for_table('tbl_user_recharges')->select('customer_id')->where('status', 'off') + ->offset($startpoint)->limit($batch) + ->find_array(); + $customer_ids = array_column($expired, 'customer_id'); + $customers = ORM::for_table('tbl_customers')->where_in('id', $customer_ids)->find_array(); } elseif ($group == 'active') { // Get active user recharges where status is 'on' - $active = ORM::for_table('tbl_user_recharges')->where('status', 'on')->find_many(); - $customer_ids = []; - foreach ($active as $recharge) { - $customer_ids[] = $recharge->customer_id; - } - $customers = ORM::for_table('tbl_customers')->where_in('id', $customer_ids)->find_many()->as_array(); + $active = ORM::for_table('tbl_user_recharges')->select('customer_id')->where('status', 'on') + ->offset($startpoint)->limit($batch) + ->find_array(); + $customer_ids = array_column($active, 'customer_id'); + $customers = ORM::for_table('tbl_customers')->where_in('id', $customer_ids)->find_array(); } // Set the batch size @@ -225,6 +241,9 @@ EOT; } } } + $ui->assign('page', $page); + $ui->assign('totalCustomers', $totalCustomers); + $_SESSION['batchStatus'] = $batchStatus; $ui->assign('batchStatus', $batchStatus); $ui->assign('totalSMSSent', $totalSMSSent); $ui->assign('totalSMSFailed', $totalSMSFailed); diff --git a/system/lan/english.json b/system/lan/english.json index b85e3525..ec4b1a37 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -967,5 +967,15 @@ "Create_Bandwidth_Package_for_expired_Internet_Package": "Create Bandwidth Package for expired Internet Package", "Maps": "Maps", "Enable": "Enable", - "Continue_the_process_of_changing_Routers_": "Continue the process of changing Routers?" + "Continue_the_process_of_changing_Routers_": "Continue the process of changing Routers?", + "Customer_cannot_buy_disabled_Package__but_admin_can_recharge_it__use_it_if_you_want_only_admin_recharge_it": "Customer cannot buy disabled Package, but admin can recharge it, use it if you want only admin recharge it", + "Postpaid_will_have_fix_expired_date": "Postpaid will have fix expired date", + "Personal_Package_will_only_show_to_personal_Customer__Business_package_will_only_show_to_Business_Customer": "Personal Package will only show to personal Customer, Business package will only show to Business Customer", + "If_you_enable_Radius__choose_device_to_radius__except_if_you_have_custom_device_": "If you enable Radius, choose device to radius, except if you have custom device.", + "This_Device_are_the_logic_how_PHPNuxBill_Communicate_with_Mikrotik_or_other_Devices": "This Device are the logic how PHPNuxBill Communicate with Mikrotik or other Devices", + "Expired_will_be_this_date_every_month": "Expired will be this date every month", + "Continue_the_process_of_adding_the_PPPoE_Package_": "Continue the process of adding the PPPoE Package?", + "Personal_Package_will_only_show_to_personal_Customer__Business_Package_will_only_show_to_Business_Customer": "Personal Package will only show to personal Customer, Business Package will only show to Business Customer", + "Continue_the_PPPoE_Package_change_process_": "Continue the PPPoE Package change process?", + "Sending_message_in_progress__Don_t_close_this_page_": "Sending message in progress. Don't close this page." } \ No newline at end of file diff --git a/ui/ui/admin/footer.tpl b/ui/ui/admin/footer.tpl index 8eb193f4..c755d6fb 100644 --- a/ui/ui/admin/footer.tpl +++ b/ui/ui/admin/footer.tpl @@ -113,15 +113,16 @@ }); function ask(field, text){ + var txt = field.innerHTML; if (confirm(text)) { setTimeout(() => { - field.innerHTML = field.innerHTML.replace(``, ''); + field.innerHTML = field.innerHTML.replace(``, txt); field.removeAttribute("disabled"); }, 5000); return true; } else { setTimeout(() => { - field.innerHTML = field.innerHTML.replace(``, ''); + field.innerHTML = field.innerHTML.replace(``, txt); field.removeAttribute("disabled"); }, 500); return false; diff --git a/ui/ui/admin/message/bulk.tpl b/ui/ui/admin/message/bulk.tpl index 209e04ca..8a1cb44e 100644 --- a/ui/ui/admin/message/bulk.tpl +++ b/ui/ui/admin/message/bulk.tpl @@ -4,18 +4,26 @@
-
+ {if $page>0 && $totalCustomers>0} + + {/if} +
{Lang::T('Send Bulk Message')}
-
+ +
@@ -23,9 +31,10 @@
@@ -33,14 +42,14 @@
{Lang::T('Use 20 and above if you are sending to all customers to avoid server time out')}
@@ -48,20 +57,21 @@
{Lang::T('Use at least 5 secs if you are sending to all customers to avoid being banned by your message provider')}
- - {Lang::T('Testing [if checked no real message is sent]')} + + + {Lang::T('Testing [if checked no real message is sent]')}

{Lang::T('Use placeholders:')} @@ -77,8 +87,15 @@

- + {if $page >= 0} + + {else} + + {/if} {Lang::T('Cancel')}
@@ -90,10 +107,11 @@
{if $batchStatus} -

{Lang::T('Total SMS Sent')}: {$totalSMSSent} {Lang::T('Total SMS +

{Lang::T('Total SMS Sent')}: {$totalSMSSent} {Lang::T('Total SMS Failed')}: {$totalSMSFailed} {Lang::T('Total WhatsApp Sent')}: - {$totalWhatsappSent} {Lang::T('Total WhatsApp Failed')}: - {$totalWhatsappFailed}

+ {$totalWhatsappSent} {Lang::T('Total WhatsApp Failed')}: + {$totalWhatsappFailed}

{/if}
@@ -112,12 +130,12 @@ {foreach $batchStatus as $customer} - - {$customer.name} - {$customer.phone} - {$customer.message} - {$customer.status} - + + {$customer.name} + {$customer.phone} + {$customer.message} + {$customer.status} + {/foreach} @@ -131,12 +149,32 @@ -{include file="sections/footer.tpl"} +{include file="sections/footer.tpl"} \ No newline at end of file diff --git a/ui/ui/customer/footer.tpl b/ui/ui/customer/footer.tpl index 019f130c..0b3740b5 100644 --- a/ui/ui/customer/footer.tpl +++ b/ui/ui/customer/footer.tpl @@ -160,15 +160,16 @@ }); function ask(field, text){ + var txt = field.innerHTML; if (confirm(text)) { setTimeout(() => { - field.innerHTML = field.innerHTML.replace(``, ''); + field.innerHTML = field.innerHTML.replace(``, txt); field.removeAttribute("disabled"); }, 5000); return true; } else { setTimeout(() => { - field.innerHTML = field.innerHTML.replace(``, ''); + field.innerHTML = field.innerHTML.replace(``, txt); field.removeAttribute("disabled"); }, 500); return false;