From 44cded581ad4ecc3a88701cdfa81f60db0bc3630 Mon Sep 17 00:00:00 2001 From: Focuslinkstech <45756999+Focuslinkstech@users.noreply.github.com> Date: Thu, 21 Mar 2024 16:52:52 +0100 Subject: [PATCH 01/19] Enhancement in bulk SMS/WA message Enhancement in SMS/WA message sending --- system/controllers/message.php | 230 ++++++++++++++++++--------------- ui/ui/message-bulk.tpl | 85 +++++++++++- 2 files changed, 207 insertions(+), 108 deletions(-) diff --git a/system/controllers/message.php b/system/controllers/message.php index 9da65ba6..a4a1a197 100644 --- a/system/controllers/message.php +++ b/system/controllers/message.php @@ -95,124 +95,144 @@ 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"); } - $ui->display('message-bulk.tpl'); - break; - case 'send_bulk-post': - // Check user permissions - 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']; // Initialize counters - $successCount = 0; - $failCount = 0; - $successMessages = []; - $failMessages = []; + $totalSMSSent = 0; + $totalSMSFailed = 0; + $totalWhatsappSent = 0; + $totalWhatsappFailed = 0; + $batchStatus = []; - // Check if fields are empty - if ($group == '' or $message == '' or $via == '') { - r2(U . '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(); - } 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(); - } 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(); - } 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(); - } - - // Loop through customers and send messages - foreach ($customers as $customer) { - // Create a copy of the original message for each customer and save it as currentMessage - $currentMessage = $message; - - // Replace placeholders in the message with actual values for each customer - $currentMessage = str_replace('[[name]]', $customer['fullname'], $currentMessage); - $currentMessage = str_replace('[[user_name]]', $customer['username'], $currentMessage); - $currentMessage = str_replace('[[phone]]', $customer['phonenumber'], $currentMessage); - $currentMessage = str_replace('[[company_name]]', $config['CompanyName'], $currentMessage); - - // Send the message based on the selected method - if ($via == 'sms' || $via == 'both') { - $smsSent = Message::sendSMS($customer['phonenumber'], $currentMessage); - if ($smsSent) { - $successCount++; - $successMessages[] = "SMS sent to {$customer['fullname']}: {$customer['phonenumber']}"; - } else { - $failCount++; - $failMessages[] = "Failed to send SMS to {$customer['fullname']}: {$customer['phonenumber']}"; - } - // Introduce a delay of 5 seconds between each SMS - sleep(5); - } - - if ($via == 'wa' || $via == 'both') { - $waSent = Message::sendWhatsapp($customer['phonenumber'], $currentMessage); - if ($waSent) { - $successCount++; - $successMessages[] = "WhatsApp message sent to {$customer['fullname']}: {$customer['phonenumber']}"; - } else { - $failCount++; - $failMessages[] = "Failed to send WhatsApp message to {$customer['fullname']}: {$customer['phonenumber']}"; - } - // Introduce a delay of 5 seconds between each WhatsApp message - sleep(5); - } - } - - $responseMessage = ''; - - if ($successCount > 0) { - $responseMessage .= "Messages Sent Successfully: {$successCount}
"; - $responseMessage .= ""; - } - - if ($failCount > 0) { - $responseMessage .= "Failed to send messages: {$failCount}
"; - $responseMessage .= ""; - } - - if ($responseMessage != '') { - r2(U . 'message/send_bulk', 's', $responseMessage); + if (_req('send') == 'now') { + // Check if fields are empty + if ($group == '' || $message == '' || $via == '') { + r2(U . 'message/send_bulk', 'e', Lang::T('All fields are required')); } else { - r2(U . 'message/send_bulk', 'e', Lang::T('No messages sent')); + // Get customer details from the database based on the selected group + if ($group == 'all') { + $customers = ORM::for_table('tbl_customers')->find_many()->as_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(); + } 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(); + } 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(); + } + + // Set the batch size + $batchSize = $batch; + + // Calculate the number of batches + $totalCustomers = count($customers); + $totalBatches = ceil($totalCustomers / $batchSize); + + // Loop through batches + for ($batchIndex = 0; $batchIndex < $totalBatches; $batchIndex++) { + // Get the starting and ending index for the current batch + $start = $batchIndex * $batchSize; + $end = min(($batchIndex + 1) * $batchSize, $totalCustomers); + $batchCustomers = array_slice($customers, $start, $end - $start); + + // Loop through customers in the current batch and send messages + foreach ($batchCustomers as $customer) { + // Create a copy of the original message for each customer and save it as currentMessage + $currentMessage = $message; + $currentMessage = str_replace('[[name]]', $customer['fullname'], $currentMessage); + $currentMessage = str_replace('[[user_name]]', $customer['username'], $currentMessage); + $currentMessage = str_replace('[[phone]]', $customer['phonenumber'], $currentMessage); + $currentMessage = str_replace('[[company_name]]', $config['CompanyName'], $currentMessage); + + // Send the message based on the selected method + if ($test === 'yes') { + // Only for testing, do not send messages to customers + $batchStatus[] = [ + 'name' => $customer['fullname'], + 'phone' => $customer['phonenumber'], + 'message' => $currentMessage, + 'status' => 'Test Mode - Message not sent' + ]; + } else { + // Send the actual messages + if ($via == 'sms' || $via == 'both') { + $smsSent = Message::sendSMS($customer['phonenumber'], $currentMessage); + if ($smsSent) { + $totalSMSSent++; + $batchStatus[] = [ + 'name' => $customer['fullname'], + 'phone' => $customer['phonenumber'], + 'message' => $currentMessage, + 'status' => 'SMS Message Sent' + ]; + } else { + $totalSMSFailed++; + $batchStatus[] = [ + 'name' => $customer['fullname'], + 'phone' => $customer['phonenumber'], + 'message' => $currentMessage, + 'status' => 'SMS Message Failed' + ]; + } + } + + if ($via == 'wa' || $via == 'both') { + $waSent = Message::sendWhatsapp($customer['phonenumber'], $currentMessage); + if ($waSent) { + $totalWhatsappSent++; + $batchStatus[] = [ + 'name' => $customer['fullname'], + 'phone' => $customer['phonenumber'], + 'message' => $currentMessage, + 'status' => 'WhatsApp Message Sent' + ]; + } else { + $totalWhatsappFailed++; + $batchStatus[] = [ + 'name' => $customer['fullname'], + 'phone' => $customer['phonenumber'], + 'message' => $currentMessage, + 'status' => 'WhatsApp Message Failed' + ]; + } + } + } + } + + // Introduce a delay between each batch + if ($batchIndex < $totalBatches - 1) { + sleep($delay); + } + } } } - + $ui->assign('batchStatus', $batchStatus); + $ui->assign('totalSMSSent', $totalSMSSent); + $ui->assign('totalSMSFailed', $totalSMSFailed); + $ui->assign('totalWhatsappSent', $totalWhatsappSent); + $ui->assign('totalWhatsappFailed', $totalWhatsappFailed); + $ui->display('message-bulk.tpl'); break; - - - default: r2(U . 'message/send_sms', 'e', 'action not defined'); } diff --git a/ui/ui/message-bulk.tpl b/ui/ui/message-bulk.tpl index 7d1248ac..e28230ce 100644 --- a/ui/ui/message-bulk.tpl +++ b/ui/ui/message-bulk.tpl @@ -1,11 +1,13 @@ {include file="sections/header.tpl"} + +
{Lang::T('Send Bulk Message')}
-
+
@@ -27,11 +29,39 @@
+
+ +
+ {Lang::T('Use 20 and above if you are sending to all customers to avoid server time out')} +
+
+
+ +
+ {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('Use placeholders:')} @@ -45,10 +75,10 @@ [[company_name]] - {Lang::T('Your Company Name')}

-
- + {Lang::T('Cancel')}
@@ -59,5 +89,54 @@
+{if $batchStatus} +

Total SMS Sent: {$totalSMSSent} Total SMS + Failed: {$totalSMSFailed} Total WhatsApp Sent: + {$totalWhatsappSent} Total WhatsApp Failed: + {$totalWhatsappFailed}

+{/if} +
+
+

Message Results

+
+ +
+ + + + + + + + + + + {foreach $batchStatus as $customer} + + + + + + + {/foreach} + +
NamePhoneMessageStatus
{$customer.name}{$customer.phone}{$customer.message}{$customer.status}
+
+ +
+ + + + + + + + {include file="sections/footer.tpl"} \ No newline at end of file From 75955de6c59dd982eb130664f357cbfab6dd2f8a Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Fri, 22 Mar 2024 10:40:51 +0700 Subject: [PATCH 02/19] Fix Broadcast Message by @Focuslinkstech --- CHANGELOG.md | 4 ++++ system/lan/english.json | 21 ++++++++++++++++++++- version.json | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0a3bf45..a67f63c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ # CHANGELOG +## 2024.3.22 + +- Fix Broadcast Message by @Focuslinkstech + ## 2024.3.20 - Fixing some bugs diff --git a/system/lan/english.json b/system/lan/english.json index 9865a3b2..07f97d1c 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -515,5 +515,24 @@ "List": "List", "Lists": "Lists", "Single_Customer": "Single Customer", - "Bulk_Customers": "Bulk Customers" + "Bulk_Customers": "Bulk Customers", + "Message_per_time": "Message per time", + "5_Messages": "5 Messages", + "10_Messages": "10 Messages", + "15_Messages": "15 Messages", + "20_Messages": "20 Messages", + "30_Messages": "30 Messages", + "40_Messages": "40 Messages", + "50_Messages": "50 Messages", + "60_Messages": "60 Messages", + "Use_20_and_above_if_you_are_sending_to_all_customers_to_avoid_server_time_out": "Use 20 and above if you are sending to all customers to avoid server time out", + "Delay": "Delay", + "No_Delay": "No Delay", + "5_Seconds": "5 Seconds", + "10_Seconds": "10 Seconds", + "15_Seconds": "15 Seconds", + "20_Seconds": "20 Seconds", + "Use_at_least_5_secs_if_you_are_sending_to_all_customers_to_avoid_being_banned_by_your_message_provider": "Use at least 5 secs if you are sending to all customers to avoid being banned by your message provider", + "Testing__if_checked_no_real_message_is_sent_": "Testing [if checked no real message is sent]", + "All_fields_are_required": "All fields are required" } \ No newline at end of file diff --git a/version.json b/version.json index 4ec1dcc2..664e6988 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "2024.3.20" + "version": "2024.3.22" } \ No newline at end of file From ffe913cb8f42d750d1ea2c03de4c89700de5ced4 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Fri, 22 Mar 2024 20:29:05 +0700 Subject: [PATCH 03/19] .htaccess allow update.php --- .htaccess_firewall | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.htaccess_firewall b/.htaccess_firewall index a58990b7..5d37c58f 100644 --- a/.htaccess_firewall +++ b/.htaccess_firewall @@ -6,4 +6,9 @@ Order Allow,Deny Allow from all + + + + Order Allow,Deny + Allow from all \ No newline at end of file From 177cdef1cdf29ec5740d2d5e048df5d7c7504737 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Fri, 22 Mar 2024 21:21:23 +0700 Subject: [PATCH 04/19] Add Location Picker --- CHANGELOG.md | 1 + system/controllers/customers.php | 7 +- system/lan/english.json | 3 +- ui/ui/customers-add.tpl | 105 +++++++++++++++-------- ui/ui/customers-edit.tpl | 141 ++++++++++++++++++++----------- ui/ui/customers-view.tpl | 2 +- ui/ui/map-customer.tpl | 80 +++++++++++------- version.json | 2 +- 8 files changed, 218 insertions(+), 123 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a67f63c9..f89ef8ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## 2024.3.22 - Fix Broadcast Message by @Focuslinkstech +- Add Location Picker ## 2024.3.20 diff --git a/system/controllers/customers.php b/system/controllers/customers.php index 7baecae0..4a62781d 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -16,6 +16,10 @@ if (empty ($action)) { $action = 'list'; } +$leafletpickerHeader = << +EOT; + switch ($action) { case 'list': $search = _post('search'); @@ -89,6 +93,7 @@ switch ($action) { if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) { _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } + $ui->assign('xheader', $leafletpickerHeader); run_hook('view_add_customer'); #HOOK $ui->display('customers-add.tpl'); break; @@ -210,7 +215,6 @@ switch ($action) { $customFields = ORM::for_table('tbl_customers_fields') ->where('customer_id', $customer['id']) ->find_many(); - $v = $routes['3']; if (empty ($v)) { $v = 'activation'; @@ -260,6 +264,7 @@ switch ($action) { if ($d) { $ui->assign('d', $d); $ui->assign('customFields', $customFields); + $ui->assign('xheader', $leafletpickerHeader); $ui->display('customers-edit.tpl'); } else { r2(U . 'customers/list', 'e', $_L['Account_Not_Found']); diff --git a/system/lan/english.json b/system/lan/english.json index 07f97d1c..68a7fd86 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -534,5 +534,6 @@ "20_Seconds": "20 Seconds", "Use_at_least_5_secs_if_you_are_sending_to_all_customers_to_avoid_being_banned_by_your_message_provider": "Use at least 5 secs if you are sending to all customers to avoid being banned by your message provider", "Testing__if_checked_no_real_message_is_sent_": "Testing [if checked no real message is sent]", - "All_fields_are_required": "All fields are required" + "All_fields_are_required": "All fields are required", + "Personal": "Personal" } \ No newline at end of file diff --git a/ui/ui/customers-add.tpl b/ui/ui/customers-add.tpl index 7f9f03c8..806cbda4 100644 --- a/ui/ui/customers-add.tpl +++ b/ui/ui/customers-add.tpl @@ -11,10 +11,10 @@
{if $_c['country_code_phone']!= ''} - + + + {else} - + {/if} @@ -38,10 +38,10 @@
{if $_c['country_code_phone']!= ''} - + + + {else} - + {/if} @@ -73,17 +73,6 @@
-
- -
- - - {Lang::T('Latitude and Longitude coordinates for map must be separate with comma - ","')} - -
-
@@ -102,7 +91,15 @@ - + +
+
+
+ +
+ +
@@ -132,16 +129,16 @@ {literal} - + + + {/literal} diff --git a/ui/ui/customers-edit.tpl b/ui/ui/customers-edit.tpl index 9269e033..9e3e5d23 100644 --- a/ui/ui/customers-edit.tpl +++ b/ui/ui/customers-edit.tpl @@ -12,10 +12,10 @@
{if $_c['country_code_phone']!= ''} - + + + {else} - + {/if}
{if $_c['country_code_phone']!= ''} - + + + {else} - + {/if} @@ -77,16 +77,6 @@
-
- -
- - - {Lang::T('Latitude and Longitude coordinates for map must be separate with comma - ","')} - -
-
@@ -98,15 +88,23 @@
-
+ + +
+
+
+ +
+ +
@@ -118,20 +116,20 @@
{if $customFields} - {foreach $customFields as $customField} -
- -
- -
- -
- {/foreach} + {foreach $customFields as $customField} +
+ +
+ +
+ +
+ {/foreach} {/if} @@ -155,16 +153,16 @@ {literal} - + + + + {/literal} {include file="sections/footer.tpl"} \ No newline at end of file diff --git a/ui/ui/customers-view.tpl b/ui/ui/customers-view.tpl index 2f969a73..3cd5d421 100644 --- a/ui/ui/customers-view.tpl +++ b/ui/ui/customers-view.tpl @@ -38,7 +38,7 @@ {/if}
  • - {Lang::T('Coordinates')} {Lang::T($d['coordinates'])} + {Lang::T('Coordinates')} {$d['coordinates']}
  • {if $customFields} diff --git a/ui/ui/map-customer.tpl b/ui/ui/map-customer.tpl index b19aebd5..7ecff00c 100644 --- a/ui/ui/map-customer.tpl +++ b/ui/ui/map-customer.tpl @@ -4,42 +4,58 @@
    {literal} - + customers.forEach(function(customer) { + var name = customer.id; + var name = customer.name; + var info = customer.info; + var coordinates = customer.coordinates; + var balance = customer.balance; + var address = customer.address; + + // Create a popup for the marker + var popupContent = "Customer Name: " + name + "
    " + + "Customer Info: " + info + "
    " + + "Customer Balance: " + balance + "
    " + + "Address: " + address + "
    " + + "Coordinates: " + coordinates + "
    " + + "More Info
    "; + + // Add marker to map + var marker = L.marker(JSON.parse(coordinates)).addTo(group); + marker.bindTooltip(name).bindPopup(popupContent); + }); + + map.fitBounds(group.getBounds()); + } + window.onload = function() { + getLocation(); + } + {/literal} {include file="sections/footer.tpl"} \ No newline at end of file diff --git a/version.json b/version.json index 664e6988..d3f813d5 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "2024.3.22" + "version": "2024.3.22.1" } \ No newline at end of file From 273d98f3adcf5bcc3e7fb481845ce817c6e358e4 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Sat, 23 Mar 2024 12:16:42 +0700 Subject: [PATCH 05/19] map-customer.tpl to customer-map.tpl --- system/controllers/map.php | 2 +- ui/ui/{map-customer.tpl => customer-map.tpl} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename ui/ui/{map-customer.tpl => customer-map.tpl} (100%) diff --git a/system/controllers/map.php b/system/controllers/map.php index 21c95cad..20a9d9b9 100644 --- a/system/controllers/map.php +++ b/system/controllers/map.php @@ -38,7 +38,7 @@ switch ($action) { $ui->assign('xheader', ''); $ui->assign('_title', Lang::T('Customer Geo Location Information')); $ui->assign('xfooter', ''); - $ui->display('map-customer.tpl'); + $ui->display('customer-map.tpl'); break; default: diff --git a/ui/ui/map-customer.tpl b/ui/ui/customer-map.tpl similarity index 100% rename from ui/ui/map-customer.tpl rename to ui/ui/customer-map.tpl From 04a21d3eb219276f02cc52783b14e73d399038bc Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Sat, 23 Mar 2024 12:38:23 +0700 Subject: [PATCH 06/19] Maps always show Tooltip --- system/controllers/map.php | 1 + ui/ui/customer-map.tpl | 49 +++++----- ui/ui/customers-view.tpl | 180 +++++++++++++++++++------------------ 3 files changed, 118 insertions(+), 112 deletions(-) diff --git a/system/controllers/map.php b/system/controllers/map.php index 20a9d9b9..0ef05bd4 100644 --- a/system/controllers/map.php +++ b/system/controllers/map.php @@ -28,6 +28,7 @@ switch ($action) { 'name' => $customer->fullname, 'balance' => $customer->balance, 'address' => $customer->address, + 'direction' => $customer->coordinates, 'info' => Lang::T("Username") . ": " . $customer->username . " - " . Lang::T("Full Name") . ": " . $customer->fullname . " - " . Lang::T("Email") . ": " . $customer->email . " - " . Lang::T("Phone") . ": " . $customer->phonenumber . " - " . Lang::T("Service Type") . ": " . $customer->service_type, 'coordinates' => '[' . $customer->coordinates . ']', ]; diff --git a/ui/ui/customer-map.tpl b/ui/ui/customer-map.tpl index 7ecff00c..44404ec4 100644 --- a/ui/ui/customer-map.tpl +++ b/ui/ui/customer-map.tpl @@ -24,34 +24,35 @@ var customers = {/literal}{$customers|json_encode}{literal}; L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/light_all/{z}/{x}/{y}.png', { - attribution: - '© OpenStreetMap contributors © CARTO', - subdomains: 'abcd', - maxZoom: 20 - }).addTo(map); + attribution: + '© OpenStreetMap contributors © CARTO', + subdomains: 'abcd', + maxZoom: 20 + }).addTo(map); - customers.forEach(function(customer) { - var name = customer.id; - var name = customer.name; - var info = customer.info; - var coordinates = customer.coordinates; - var balance = customer.balance; - var address = customer.address; + customers.forEach(function(customer) { + var name = customer.id; + var name = customer.name; + var info = customer.info; + var direction = customer.direction; + var coordinates = customer.coordinates; + var balance = customer.balance; + var address = customer.address; - // Create a popup for the marker - var popupContent = "Customer Name: " + name + "
    " + - "Customer Info: " + info + "
    " + - "Customer Balance: " + balance + "
    " + - "Address: " + address + "
    " + - "Coordinates: " + coordinates + "
    " + - "More Info
    "; + // Create a popup for the marker + var popupContent = "Name: " + name + "
    " + + "Info: " + info + "
    " + + "Balance: " + balance + "
    " + + "Address: " + address + "
    " + + "More Info • " + + "Get Direction
    "; - // Add marker to map - var marker = L.marker(JSON.parse(coordinates)).addTo(group); - marker.bindTooltip(name).bindPopup(popupContent); - }); + // Add marker to map + var marker = L.marker(JSON.parse(coordinates)).addTo(group); + marker.bindTooltip(name, { permanent: true }).bindPopup(popupContent); + }); - map.fitBounds(group.getBounds()); + map.fitBounds(group.getBounds()); } window.onload = function() { getLocation(); diff --git a/ui/ui/customers-view.tpl b/ui/ui/customers-view.tpl index 3cd5d421..755130e0 100644 --- a/ui/ui/customers-view.tpl +++ b/ui/ui/customers-view.tpl @@ -30,29 +30,34 @@ onclick="this.select()"> {if $d['pppoe_password'] != ''} -
  • - PPPOE {Lang::T('Password')} -
  • +
  • + PPPOE {Lang::T('Password')} +
  • + {/if} + {if $d['coordinates']} +
  • + {Lang::T('Coordinates')} + Get + Directions + +
  • {/if} -
  • - {Lang::T('Coordinates')} {$d['coordinates']} -
  • {if $customFields} - {foreach $customFields as $customField} -
  • - {$customField.field_name} - {if strpos($customField.field_value, ':0') === false} - {$customField.field_value} - {else} - {Lang::T('Paid')} - {/if} - -
  • - {/foreach} + {foreach $customFields as $customField} +
  • + {$customField.field_name} + {if strpos($customField.field_value, ':0') === false} + {$customField.field_value} + {else} + {Lang::T('Paid')} + {/if} + +
  • + {/foreach} {/if}
  • @@ -92,12 +97,12 @@
  • {foreach $packages as $package} -
    -
    -

    {$package['type']} - {$package['namebp']}

    -
      -
    • - {Lang::T('Active')} {if +
      +
      +

      {$package['type']} - {$package['namebp']}

      +
        +
      • + {Lang::T('Active')} {if $package['status']=='on'}yes{else}no {/if}
      • @@ -110,8 +115,7 @@ class="pull-right">{Lang::dateAndTimeFormat($package['recharged_on'],$package['recharged_time'])}
      • - {Lang::T('Expires On')} {Lang::dateAndTimeFormat($package['expiration'], + {Lang::T('Expires On')} {Lang::dateAndTimeFormat($package['expiration'], $package['time'])}
      • @@ -157,68 +161,68 @@
        {if Lang::arrayCount($activation)} - - - - - - - - - - - - - - {foreach $activation as $ds} - - - - - - - - - - - {/foreach} - + + + + + + + + + + + + + + {foreach $activation as $ds} + + + + + + + + + + + {/foreach} + {/if} {if Lang::arrayCount($order)} - - - - - - - - - - - - - - - {foreach $order as $ds} - - - - - - - - - - - - {/foreach} - + + + + + + + + + + + + + + + {foreach $order as $ds} + + + + + + + + + + + + {/foreach} + {/if}
        {Lang::T('Invoice')}{Lang::T('Username')}{Lang::T('Plan Name')}{Lang::T('Plan Price')}{Lang::T('Type')}{Lang::T('Created On')}{Lang::T('Expires On')}{Lang::T('Method')}
        {$ds['invoice']}{$ds['username']}{$ds['plan_name']}{Lang::moneyFormat($ds['price'])}{$ds['type']}{Lang::dateAndTimeFormat($ds['recharged_on'],$ds['recharged_time'])} - {Lang::dateAndTimeFormat($ds['expiration'],$ds['time'])}{$ds['method']}
        {Lang::T('Invoice')}{Lang::T('Username')}{Lang::T('Plan Name')}{Lang::T('Plan Price')}{Lang::T('Type')}{Lang::T('Created On')}{Lang::T('Expires On')}{Lang::T('Method')}
        {$ds['invoice']}{$ds['username']}{$ds['plan_name']}{Lang::moneyFormat($ds['price'])}{$ds['type']}{Lang::dateAndTimeFormat($ds['recharged_on'],$ds['recharged_time'])} + {Lang::dateAndTimeFormat($ds['expiration'],$ds['time'])}{$ds['method']}
        {Lang::T('Plan Name')}{Lang::T('Gateway')}{Lang::T('Routers')}{Lang::T('Type')}{Lang::T('Plan Price')}{Lang::T('Created On')}{Lang::T('Expires On')}{Lang::T('Date Done')}{Lang::T('Method')}
        {$ds['plan_name']}{$ds['gateway']}{$ds['routers']}{$ds['payment_channel']}{Lang::moneyFormat($ds['price'])}{Lang::dateTimeFormat($ds['created_date'])}{Lang::dateTimeFormat($ds['expired_date'])}{if $ds['status']!=1}{Lang::dateTimeFormat($ds['paid_date'])}{/if}{if $ds['status']==1}{Lang::T('UNPAID')} - {elseif $ds['status']==2}{Lang::T('PAID')} - {elseif $ds['status']==3}{$_L['FAILED']} - {elseif $ds['status']==4}{Lang::T('CANCELED')} - {elseif $ds['status']==5}{Lang::T('UNKNOWN')} - {/if}
        {Lang::T('Plan Name')}{Lang::T('Gateway')}{Lang::T('Routers')}{Lang::T('Type')}{Lang::T('Plan Price')}{Lang::T('Created On')}{Lang::T('Expires On')}{Lang::T('Date Done')}{Lang::T('Method')}
        {$ds['plan_name']}{$ds['gateway']}{$ds['routers']}{$ds['payment_channel']}{Lang::moneyFormat($ds['price'])}{Lang::dateTimeFormat($ds['created_date'])}{Lang::dateTimeFormat($ds['expired_date'])}{if $ds['status']!=1}{Lang::dateTimeFormat($ds['paid_date'])}{/if}{if $ds['status']==1}{Lang::T('UNPAID')} + {elseif $ds['status']==2}{Lang::T('PAID')} + {elseif $ds['status']==3}{$_L['FAILED']} + {elseif $ds['status']==4}{Lang::T('CANCELED')} + {elseif $ds['status']==5}{Lang::T('UNKNOWN')} + {/if}
        From 58c4037d8c71b32f98ffc261494ecf3efe4f5e8d Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Sat, 23 Mar 2024 12:44:17 +0700 Subject: [PATCH 07/19] full height maps --- ui/ui/customer-map.tpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/ui/customer-map.tpl b/ui/ui/customer-map.tpl index 44404ec4..36f19d9d 100644 --- a/ui/ui/customer-map.tpl +++ b/ui/ui/customer-map.tpl @@ -1,7 +1,8 @@ {include file="sections/header.tpl"} -
        + +
        {literal} + +{/literal} +{/if} {include file="sections/footer.tpl"} \ No newline at end of file diff --git a/ui/ui/customers.tpl b/ui/ui/customers.tpl index 6ae2aec4..a89a4748 100644 --- a/ui/ui/customers.tpl +++ b/ui/ui/customers.tpl @@ -18,8 +18,8 @@
        @@ -53,7 +53,7 @@ {$ds['username']} - {$ds['account_type']} + {$ds['account_type']} {$ds['fullname']} {Lang::moneyFormat($ds['balance'])} @@ -83,23 +83,23 @@ {include file="sections/footer.tpl"} \ No newline at end of file diff --git a/version.json b/version.json index d3f813d5..cbc7f71f 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "2024.3.22.1" + "version": "2024.3.23" } \ No newline at end of file From 90f72852ca630e884bf90b5f262303b4dcc1bdcc Mon Sep 17 00:00:00 2001 From: "S.Siavash Mirtaheri" <90767717+siavashmirtaheri@users.noreply.github.com> Date: Sat, 23 Mar 2024 11:45:58 +0330 Subject: [PATCH 09/19] Update country.json IR translate start --- system/lan/country.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/lan/country.json b/system/lan/country.json index 384469e9..f9f798bd 100644 --- a/system/lan/country.json +++ b/system/lan/country.json @@ -26,6 +26,7 @@ "hebrew": "iw", "hindi": "hi", "hungarian": "hu", + "iran": "ir", "icelandic": "is", "italian": "it", "japanese": "ja", @@ -55,4 +56,4 @@ "ukrainian": "uk", "vietnamese": "vi", "welsh": "cy" -} \ No newline at end of file +} From 338861a63088ef5a9d2c40dea6a58a930391ab3e Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Sat, 23 Mar 2024 15:34:44 +0700 Subject: [PATCH 10/19] Change to icon --- ui/ui/customers.tpl | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/ui/ui/customers.tpl b/ui/ui/customers.tpl index a89a4748..f7e0d72d 100644 --- a/ui/ui/customers.tpl +++ b/ui/ui/customers.tpl @@ -40,8 +40,7 @@ {Lang::T('Account Type')} {Lang::T('Full Name')} {Lang::T('Balance')} - {Lang::T('Phone Number')} - {Lang::T('Email')} + {Lang::T('Package')} {Lang::T('Service Type')} {Lang::T('Created On')} @@ -57,16 +56,32 @@ {$ds['fullname']} {Lang::moneyFormat($ds['balance'])} - {$ds['phonenumber']} - {$ds['email']} + + {if $ds['phonenumber']} + + {/if} + {if $ds['email']} + + {/if} + {if $ds['coordinates']} + + {/if} + {$ds['service_type']} {Lang::dateTimeFormat($ds['created_at'])} -   {Lang::T('View')}   +   {Lang::T('Edit')}   {Lang::T('Recharge')} From 3c2ca66b48c3872ac9ee6bc55c5b910917d7f94d Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Sat, 23 Mar 2024 17:46:08 +0700 Subject: [PATCH 11/19] fix sql --- install/phpnuxbill.sql | 2 +- system/updates.json | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/install/phpnuxbill.sql b/install/phpnuxbill.sql index 1bfed1c9..0d41fd30 100644 --- a/install/phpnuxbill.sql +++ b/install/phpnuxbill.sql @@ -21,7 +21,7 @@ CREATE TABLE `tbl_customers` ( `id` int(10) NOT NULL, `username` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `password` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, - `pppoe_password` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '1' COMMENT 'For PPPOE Login', + `pppoe_password` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'For PPPOE Login', `fullname` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `address` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, `phonenumber` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0', diff --git a/system/updates.json b/system/updates.json index 295e71fa..cb0de143 100644 --- a/system/updates.json +++ b/system/updates.json @@ -6,13 +6,13 @@ "ALTER TABLE `tbl_customers_meta` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;" ], "2023.8.14": [ - "ALTER TABLE `tbl_customers` ADD `pppoe_password` varchar(45) NOT NULL DEFAULT '1' COMMENT 'For PPPOE Login' AFTER `password`;", + "ALTER TABLE `tbl_customers` ADD `pppoe_password` varchar(45) NOT NULL DEFAULT '' COMMENT 'For PPPOE Login' AFTER `password`;", "ALTER TABLE `tbl_plans` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;", "ALTER TABLE `tbl_transactions` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;", "ALTER TABLE `tbl_customers` ADD `auto_renewal` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Auto renewall using balance' AFTER `balance`;" ], "2023.8.23": [ - "ALTER TABLE `tbl_customers` CHANGE `pppoe_password` `pppoe_password` VARCHAR(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT 'For PPPOE Login';" + "ALTER TABLE `tbl_customers` CHANGE `pppoe_password` `pppoe_password` VARCHAR(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'For PPPOE Login';" ], "2023.8.28": [ "ALTER TABLE `tbl_user_recharges` ADD `recharged_time` time NOT NULL DEFAULT '00:00:00' AFTER `recharged_on`;", @@ -87,5 +87,8 @@ ], "2024.3.19.2" : [ "ALTER TABLE `tbl_plans` ADD `plan_type` ENUM('Business', 'Personal') DEFAULT 'Personal' COMMENT 'For selecting account type' ;" + ], + "2023.3.20": [ + "ALTER TABLE `tbl_customers` CHANGE `pppoe_password` `pppoe_password` VARCHAR(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'For PPPOE Login';" ] } \ No newline at end of file From 18967b59e2db45bb827ee1d13b6e4feccdc9b949 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Sun, 24 Mar 2024 13:35:31 +0700 Subject: [PATCH 12/19] Handle Http for maps --- system/controllers/map.php | 2 +- ui/ui/{customer-map.tpl => customers-map.tpl} | 2 +- ui/ui/plan.tpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename ui/ui/{customer-map.tpl => customers-map.tpl} (96%) diff --git a/system/controllers/map.php b/system/controllers/map.php index 0ef05bd4..526ed8ca 100644 --- a/system/controllers/map.php +++ b/system/controllers/map.php @@ -39,7 +39,7 @@ switch ($action) { $ui->assign('xheader', ''); $ui->assign('_title', Lang::T('Customer Geo Location Information')); $ui->assign('xfooter', ''); - $ui->display('customer-map.tpl'); + $ui->display('customers-map.tpl'); break; default: diff --git a/ui/ui/customer-map.tpl b/ui/ui/customers-map.tpl similarity index 96% rename from ui/ui/customer-map.tpl rename to ui/ui/customers-map.tpl index 36f19d9d..a4291f2d 100644 --- a/ui/ui/customer-map.tpl +++ b/ui/ui/customers-map.tpl @@ -7,7 +7,7 @@ {literal} '); + $ui->assign('xfooter', ''); run_hook('view_list_bandwidth'); #HOOK - $name = _post('name'); - if ($name != ''){ - $paginator = Paginator::build(ORM::for_table('tbl_bandwidth'), ['name_bw' => '%' . $name . '%'], $name); - $d = ORM::for_table('tbl_bandwidth')->where_like('name_bw','%'.$name.'%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); - }else{ - $paginator = Paginator::build(ORM::for_table('tbl_bandwidth')); - $d = ORM::for_table('tbl_bandwidth')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); - } + $name = _post('name'); + if ($name != '') { + $query = ORM::for_table('tbl_bandwidth')->where_like('name_bw', '%' . $name . '%'); + $paginator = Paginator::generate($query, ['name' => $name]); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + } else { + $query = ORM::for_table('tbl_bandwidth'); + $paginator = Paginator::generate($query); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + } - $ui->assign('d',$d); - $ui->assign('paginator',$paginator); + $ui->assign('d', $d); + $ui->assign('paginator', $paginator); $ui->display('bandwidth.tpl'); break; case 'add': if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { - _alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard"); + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } run_hook('view_add_bandwidth'); #HOOK $ui->display('bandwidth-add.tpl'); @@ -43,28 +46,28 @@ switch ($action) { case 'edit': if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { - _alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard"); + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } $id = $routes['2']; run_hook('view_edit_bandwith'); #HOOK $d = ORM::for_table('tbl_bandwidth')->find_one($id); - if($d){ - $ui->assign('burst',explode(" ", $d['burst'])); - $ui->assign('d',$d); + if ($d) { + $ui->assign('burst', explode(" ", $d['burst'])); + $ui->assign('d', $d); $ui->display('bandwidth-edit.tpl'); - }else{ + } else { r2(U . 'bandwidth/list', 'e', $_L['Account_Not_Found']); } break; case 'delete': if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { - _alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard"); + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } $id = $routes['2']; run_hook('delete_bandwidth'); #HOOK $d = ORM::for_table('tbl_bandwidth')->find_one($id); - if($d){ + if ($d) { $d->delete(); r2(U . 'bandwidth/list', 's', Lang::T('Data Deleted Successfully')); } @@ -72,40 +75,48 @@ switch ($action) { case 'add-post': if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { - _alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard"); + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } $name = _post('name'); $rate_down = _post('rate_down'); $rate_down_unit = _post('rate_down_unit'); - $rate_up = _post('rate_up'); - $rate_up_unit = _post('rate_up_unit'); + $rate_up = _post('rate_up'); + $rate_up_unit = _post('rate_up_unit'); run_hook('add_bandwidth'); #HOOK $isBurst = true; $burst = ""; - if(isset($_POST['burst'])){ - foreach($_POST['burst'] as $b){ - if(empty($b)){ + if (isset($_POST['burst'])) { + foreach ($_POST['burst'] as $b) { + if (empty($b)) { $isBurst = false; } } - if($isBurst){ + if ($isBurst) { $burst = implode(' ', $_POST['burst']); }; } $msg = ''; - if(Validator::Length($name,16,4) == false){ - $msg .= 'Name should be between 5 to 15 characters'. '
        '; + if (Validator::Length($name, 16, 4) == false) { + $msg .= 'Name should be between 5 to 15 characters' . '
        '; } - if($rate_down_unit == 'Kbps'){ $unit_rate_down = $rate_down * 1024; }else{ $unit_rate_down = $rate_down * 1048576; } - if($rate_up_unit == 'Kbps'){ $unit_rate_up = $min_up * 1024; }else{ $unit_rate_up = $min_up * 1048576; } - - $d = ORM::for_table('tbl_bandwidth')->where('name_bw',$name)->find_one(); - if($d){ - $msg .= Lang::T('Name Bandwidth Already Exist'). '
        '; + if ($rate_down_unit == 'Kbps') { + $unit_rate_down = $rate_down * 1024; + } else { + $unit_rate_down = $rate_down * 1048576; + } + if ($rate_up_unit == 'Kbps') { + $unit_rate_up = $min_up * 1024; + } else { + $unit_rate_up = $min_up * 1048576; } - if($msg == ''){ + $d = ORM::for_table('tbl_bandwidth')->where('name_bw', $name)->find_one(); + if ($d) { + $msg .= Lang::T('Name Bandwidth Already Exist') . '
        '; + } + + if ($msg == '') { $d = ORM::for_table('tbl_bandwidth')->create(); $d->name_bw = $name; $d->rate_down = $rate_down; @@ -116,53 +127,53 @@ switch ($action) { $d->save(); r2(U . 'bandwidth/list', 's', Lang::T('Data Created Successfully')); - }else{ + } else { r2(U . 'bandwidth/add', 'e', $msg); } break; case 'edit-post': if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { - _alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard"); + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } $name = _post('name'); $rate_down = _post('rate_down'); $rate_down_unit = _post('rate_down_unit'); - $rate_up = _post('rate_up'); - $rate_up_unit = _post('rate_up_unit'); - run_hook('edit_bandwidth'); #HOOK + $rate_up = _post('rate_up'); + $rate_up_unit = _post('rate_up_unit'); + run_hook('edit_bandwidth'); #HOOK $isBurst = true; $burst = ""; - if(isset($_POST['burst'])){ - foreach($_POST['burst'] as $b){ - if(empty($b)){ + if (isset($_POST['burst'])) { + foreach ($_POST['burst'] as $b) { + if (empty($b)) { $isBurst = false; } } - if($isBurst){ + if ($isBurst) { $burst = implode(' ', $_POST['burst']); }; } $msg = ''; - if(Validator::Length($name,16,4) == false){ - $msg .= 'Name should be between 5 to 15 characters'. '
        '; + if (Validator::Length($name, 16, 4) == false) { + $msg .= 'Name should be between 5 to 15 characters' . '
        '; } $id = _post('id'); $d = ORM::for_table('tbl_bandwidth')->find_one($id); - if($d){ - }else{ - $msg .= Lang::T('Data Not Found'). '
        '; + if ($d) { + } else { + $msg .= Lang::T('Data Not Found') . '
        '; } - if($d['name_bw'] != $name){ - $c = ORM::for_table('tbl_bandwidth')->where('name_bw',$name)->find_one(); - if($c){ - $msg .= Lang::T('Name Bandwidth Already Exist'). '
        '; + if ($d['name_bw'] != $name) { + $c = ORM::for_table('tbl_bandwidth')->where('name_bw', $name)->find_one(); + if ($c) { + $msg .= Lang::T('Name Bandwidth Already Exist') . '
        '; } } - if($msg == ''){ + if ($msg == '') { $d->name_bw = $name; $d->rate_down = $rate_down; $d->rate_down_unit = $rate_down_unit; @@ -172,11 +183,11 @@ switch ($action) { $d->save(); r2(U . 'bandwidth/list', 's', Lang::T('Data Updated Successfully')); - }else{ - r2(U . 'bandwidth/edit/'.$id, 'e', $msg); + } else { + r2(U . 'bandwidth/edit/' . $id, 'e', $msg); } break; default: $ui->display('a404.tpl'); -} \ No newline at end of file +} diff --git a/system/controllers/customers.php b/system/controllers/customers.php index b956613c..a5b5a604 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -12,7 +12,7 @@ $ui->assign('_system_menu', 'customers'); $action = $routes['1']; $ui->assign('_admin', $admin); -if (empty ($action)) { +if (empty($action)) { $action = 'list'; } @@ -21,35 +21,6 @@ $leafletpickerHeader = << '%' . $search . '%', - 'fullname' => '%' . $search . '%', - 'phonenumber' => '%' . $search . '%', - 'email' => '%' . $search . '%', - 'service_type' => '%' . $search . '%' - ], $search); - $d = ORM::for_table('tbl_customers') - ->where_raw("(`username` LIKE '%$search%' OR `fullname` LIKE '%$search%' OR `phonenumber` LIKE '%$search%' OR `email` LIKE '%$search%')") - ->offset($paginator['startpoint']) - ->limit($paginator['limit']) - ->order_by_asc('username') - ->find_many(); - } else { - $paginator = Paginator::build(ORM::for_table('tbl_customers')); - $d = ORM::for_table('tbl_customers') - ->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); - } - - $ui->assign('search', htmlspecialchars($search)); - $ui->assign('d', $d); - $ui->assign('paginator', $paginator); - $ui->display('customers.tpl'); - break; - case 'csv': if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); @@ -216,14 +187,14 @@ switch ($action) { ->where('customer_id', $customer['id']) ->find_many(); $v = $routes['3']; - if (empty ($v)) { + if (empty($v)) { $v = 'activation'; } if ($v == 'order') { $v = 'order'; - $paginator = Paginator::build(ORM::for_table('tbl_payment_gateway'), ['username' => $customer['username']]); - $order = ORM::for_table('tbl_payment_gateway') - ->where('username', $customer['username']) + $query = ORM::for_table('tbl_transactions')->where('username', $customer['username']); + $paginator = Paginator::generate($query); + $order = $query ->offset($paginator['startpoint']) ->limit($paginator['limit']) ->order_by_desc('id') @@ -231,10 +202,9 @@ switch ($action) { $ui->assign('paginator', $paginator); $ui->assign('order', $order); } else if ($v == 'activation') { - $paginator = Paginator::build(ORM::for_table('tbl_transactions'), ['username' => $customer['username']]); - $activation = ORM::for_table('tbl_transactions') - ->where('username', $customer['username']) - ->offset($paginator['startpoint']) + $query = ORM::for_table('tbl_transactions')->where('username', $customer['username']); + $paginator = Paginator::generate($query); + $activation = $query->offset($paginator['startpoint']) ->limit($paginator['limit']) ->order_by_desc('id') ->find_many(); @@ -376,13 +346,13 @@ switch ($action) { // Retrieve the customer ID of the newly created customer $customerId = $d->id(); // Save Customers Attributes details - if (!empty ($custom_field_names) && !empty ($custom_field_values)) { + if (!empty($custom_field_names) && !empty($custom_field_values)) { $totalFields = min(count($custom_field_names), count($custom_field_values)); for ($i = 0; $i < $totalFields; $i++) { $name = $custom_field_names[$i]; $value = $custom_field_values[$i]; - if (!empty ($name)) { + if (!empty($name)) { $customField = ORM::for_table('tbl_customers_fields')->create(); $customField->customer_id = $customerId; $customField->field_name = $name; @@ -475,7 +445,7 @@ switch ($action) { // Update Customers Attributes values in tbl_customers_fields table foreach ($customFields as $customField) { $fieldName = $customField['field_name']; - if (isset ($_POST['custom_fields'][$fieldName])) { + if (isset($_POST['custom_fields'][$fieldName])) { $customFieldValue = $_POST['custom_fields'][$fieldName]; $customField->set('field_value', $customFieldValue); $customField->save(); @@ -483,7 +453,7 @@ switch ($action) { } // Add new Customers Attributess - if (isset ($_POST['custom_field_name']) && isset ($_POST['custom_field_value'])) { + if (isset($_POST['custom_field_name']) && isset($_POST['custom_field_value'])) { $newCustomFieldNames = $_POST['custom_field_name']; $newCustomFieldValues = $_POST['custom_field_value']; @@ -506,7 +476,7 @@ switch ($action) { } // Delete Customers Attributess - if (isset ($_POST['delete_custom_fields'])) { + if (isset($_POST['delete_custom_fields'])) { $fieldsToDelete = $_POST['delete_custom_fields']; foreach ($fieldsToDelete as $fieldName) { // Delete the Customers Attributes with the given field name @@ -536,7 +506,7 @@ switch ($action) { Mikrotik::removeHotspotActiveUser($client, $d['username']); } else { $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - if (!empty ($d['pppoe_password'])) { + if (!empty($d['pppoe_password'])) { Mikrotik::setPpoeUser($client, $c['username'], $d['pppoe_password']); } else { Mikrotik::setPpoeUser($client, $c['username'], $password); @@ -553,5 +523,25 @@ switch ($action) { break; default: - r2(U . 'customers/list', 'e', 'action not defined'); + $search = _post('search'); + run_hook('list_customers'); #HOOK + if ($search != '') { + $query = ORM::for_table('tbl_customers')->where_raw("(`username` LIKE '%$search%' OR `fullname` LIKE '%$search%' OR `phonenumber` LIKE '%$search%' OR `email` LIKE '%$search%')"); + $paginator = Paginator::generate($query, ['search' => $search]); + $d = $query->offset($paginator['startpoint']) + ->limit($paginator['limit']) + ->order_by_asc('username') + ->find_many(); + } else { + $query = ORM::for_table('tbl_customers'); + $paginator = Paginator::generate($query); + $d = ORM::for_table('tbl_customers') + ->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + } + + $ui->assign('search', htmlspecialchars($search)); + $ui->assign('d', $d); + $ui->assign('paginator', $paginator); + $ui->display('customers.tpl'); + break; } diff --git a/system/controllers/dashboard.php b/system/controllers/dashboard.php index caeeda52..a51bbe07 100644 --- a/system/controllers/dashboard.php +++ b/system/controllers/dashboard.php @@ -19,7 +19,7 @@ $month_n = date('n'); $iday = ORM::for_table('tbl_transactions') ->where('recharged_on', $mdate) ->where_not_equal('method', 'Customer - Balance') - ->where_not_equal('method', 'Recharge Balance - Administrator') + ->where_not_equal('method', 'Recharge Balance - Administrator') ->sum('price'); if ($iday == '') { @@ -54,9 +54,10 @@ $ui->assign('c_all', $c_all); if ($config['hide_uet'] != 'yes') { //user expire - $paginator = Paginator::build(ORM::for_table('tbl_user_recharges')); - $expire = ORM::for_table('tbl_user_recharges') - ->where_lte('expiration', $mdate) + $query = ORM::for_table('tbl_user_recharges') + ->where_lte('expiration', $mdate); + $paginator = Paginator::generate($query); + $expire = $query ->offset($paginator['startpoint']) ->limit($paginator['limit']) ->order_by_desc('expiration') @@ -150,7 +151,7 @@ if (file_exists($cacheMSfile) && time() - filemtime($cacheMSfile) < 43200) { ->select_expr('SUM(price)', 'total') ->where_raw("YEAR(recharged_on) = YEAR(CURRENT_DATE())") // Filter by the current year ->where_not_equal('method', 'Customer - Balance') - ->where_not_equal('method', 'Recharge Balance - Administrator') + ->where_not_equal('method', 'Recharge Balance - Administrator') ->group_by_expr('MONTH(recharged_on)') ->find_many(); diff --git a/system/controllers/logs.php b/system/controllers/logs.php index 1427194d..0677f21c 100644 --- a/system/controllers/logs.php +++ b/system/controllers/logs.php @@ -26,11 +26,13 @@ switch ($action) { r2(U . "logs/list/", 's', "Delete logs older than $keep days"); } if ($q != '') { - $paginator = Paginator::build(ORM::for_table('tbl_logs'), ['description' => '%' . $q . '%'], $q); - $d = ORM::for_table('tbl_logs')->where_like('description', '%' . $q . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + $query = ORM::for_table('tbl_logs')->where_like('description', '%' . $q . '%'); + $paginator = Paginator::generate($query, ['q' => $q]); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); } else { - $paginator = Paginator::build(ORM::for_table('tbl_logs')); - $d = ORM::for_table('tbl_logs')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + $query = ORM::for_table('tbl_logs'); + $paginator = Paginator::generate($query); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); } $ui->assign('d', $d); @@ -46,11 +48,13 @@ switch ($action) { r2(U . "logs/radius/", 's', "Delete logs older than $keep days"); } if ($q != '') { - $paginator = Paginator::build(ORM::for_table('radpostauth', 'radius'), ['username' => '%' . $q . '%'], $q); - $d = ORM::for_table('radpostauth', 'radius')->where_like('username', '%' . $q . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + $query = ORM::for_table('radpostauth', 'radius')->where_like('username', '%' . $q . '%'); + $paginator = Paginator::generate($query, ['q' => $q]); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); } else { - $paginator = Paginator::build(ORM::for_table('radpostauth', 'radius')); - $d = ORM::for_table('radpostauth', 'radius')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + $query = ORM::for_table('radpostauth', 'radius'); + $paginator = Paginator::generate($query); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); } $ui->assign('d', $d); diff --git a/system/controllers/order.php b/system/controllers/order.php index 410144ec..7495a7bf 100644 --- a/system/controllers/order.php +++ b/system/controllers/order.php @@ -19,9 +19,9 @@ switch ($action) { break; case 'history': $ui->assign('_system_menu', 'history'); - $paginator = Paginator::build(ORM::for_table('tbl_payment_gateway'), ['username' => $user['username']]); - $d = ORM::for_table('tbl_payment_gateway') - ->where('username', $user['username']) + $query = ORM::for_table('tbl_payment_gateway')->where('username', $user['username']); + $paginator = Paginator::generate($query); + $d = $query ->order_by_desc('id') ->offset($paginator['startpoint'])->limit($paginator['limit']) ->find_many(); diff --git a/system/controllers/plan.php b/system/controllers/plan.php index 5dc28a7d..21e76bf7 100644 --- a/system/controllers/plan.php +++ b/system/controllers/plan.php @@ -68,11 +68,13 @@ switch ($action) { $ui->assign('_title', Lang::T('Customer')); $search = _post('search'); if ($search != '') { - $paginator = Paginator::build(ORM::for_table('tbl_user_recharges'), ['username' => '%' . $search . '%'], $search); - $d = ORM::for_table('tbl_user_recharges')->where_like('username', '%' . $search . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + $query = ORM::for_table('tbl_user_recharges')->where_like('username', '%' . $search . '%'); + $paginator = Paginator::generate($query, ['search' => $search]); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); } else { - $paginator = Paginator::build(ORM::for_table('tbl_user_recharges')); - $d = ORM::for_table('tbl_user_recharges')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_array(); + $query = ORM::for_table('tbl_user_recharges'); + $paginator = Paginator::generate($query); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_array(); } run_hook('view_list_billing'); #HOOK if ($isApi) { diff --git a/system/controllers/pool.php b/system/controllers/pool.php index 5d0f928b..4ec35f6e 100644 --- a/system/controllers/pool.php +++ b/system/controllers/pool.php @@ -23,11 +23,13 @@ switch ($action) { $name = _post('name'); if ($name != '') { - $paginator = Paginator::build(ORM::for_table('tbl_pool'), ['pool_name' => '%' . $name . '%'], $name); - $d = ORM::for_table('tbl_pool')->where_like('pool_name', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + $query = ORM::for_table('tbl_pool')->where_like('pool_name', '%' . $name . '%'); + $paginator = Paginator::generate($query, ['name' => $name]); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); } else { - $paginator = Paginator::build(ORM::for_table('tbl_pool')); - $d = ORM::for_table('tbl_pool')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + $query = ORM::for_table('tbl_pool'); + $paginator = Paginator::generate($query); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); } $ui->assign('d', $d); diff --git a/system/controllers/radius.php b/system/controllers/radius.php index d76461f9..f9c55957 100644 --- a/system/controllers/radius.php +++ b/system/controllers/radius.php @@ -1,4 +1,5 @@ assign('_admin', $admin); if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { - _alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard"); + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } switch ($action) { @@ -134,20 +135,18 @@ switch ($action) { $ui->assign('_title', "Network Access Server"); $name = _post('name'); if (empty($name)) { - $paginator = Paginator::build(ORM::for_table('nas', 'radius')); - $nas = ORM::for_table('nas', 'radius')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); + $query = ORM::for_table('nas', 'radius'); + $paginator = Paginator::generate($query); + $nas = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); } else { - $paginator = Paginator::build(ORM::for_table('nas', 'radius'), [ - 'nasname' => '%'.$search.'%', - 'shortname' => '%'.$search.'%', - 'description' => '%'.$search.'%' - ]); - $nas = ORM::for_table('nas', 'radius') - ->where_like('nasname', $search) - ->where_like('shortname', $search) - ->where_like('description', $search) - ->offset($paginator['startpoint'])->limit($paginator['limit']) - ->find_many(); + $query = ORM::for_table('nas', 'radius') + ->where_like('nasname', $search) + ->where_like('shortname', $search) + ->where_like('description', $search); + $paginator = Paginator::generate($query, ['name' => $name]); + $nas = $query + ->offset($paginator['startpoint'])->limit($paginator['limit']) + ->find_many(); } $ui->assign('paginator', $paginator); $ui->assign('name', $name); diff --git a/system/controllers/reports.php b/system/controllers/reports.php index ca79b027..cd159fc4 100644 --- a/system/controllers/reports.php +++ b/system/controllers/reports.php @@ -30,11 +30,13 @@ switch ($action) { r2(U . "logs/list/", 's', "Delete logs older than $keep days"); } if ($q != '') { - $paginator = Paginator::build(ORM::for_table('tbl_transactions'), ['invoice' => '%' . $q . '%'], $q); - $d = ORM::for_table('tbl_transactions')->where_like('invoice', '%' . $q . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + $query = ORM::for_table('tbl_transactions')->where_like('invoice', '%' . $q . '%'); + $paginator = Paginator::generate($query, ['q' => $q]); + $d = $where->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); } else { - $paginator = Paginator::build(ORM::for_table('tbl_transactions')); - $d = ORM::for_table('tbl_transactions')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + $query = ORM::for_table('tbl_transactions'); + $paginator = Paginator::generate($query); + $d = $where->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); } $ui->assign('activation', $d); @@ -43,9 +45,10 @@ switch ($action) { $ui->display('reports-activation.tpl'); break; case 'daily-report': - $paginator = Paginator::build(ORM::for_table('tbl_transactions'), ['recharged_on' => $mdate]); - $d = ORM::for_table('tbl_transactions')->where('recharged_on', $mdate)->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); - $dr = ORM::for_table('tbl_transactions')->where('recharged_on', $mdate)->sum('price'); + $query = ORM::for_table('tbl_transactions')->where('recharged_on', $mdate); + $paginator = Paginator::generate($query); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + $dr = $query->sum('price'); $ui->assign('d', $d); $ui->assign('dr', $dr); diff --git a/system/controllers/routers.php b/system/controllers/routers.php index 49f68ef7..92357c32 100644 --- a/system/controllers/routers.php +++ b/system/controllers/routers.php @@ -17,7 +17,7 @@ use PEAR2\Net\RouterOS; require_once 'system/autoload/PEAR2/Autoload.php'; if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { - _alert(Lang::T('You do not have permission to access this page'),'danger', "dashboard"); + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } switch ($action) { @@ -26,11 +26,13 @@ switch ($action) { $name = _post('name'); if ($name != '') { - $paginator = Paginator::build(ORM::for_table('tbl_routers'), ['name' => '%' . $name . '%'], $name); - $d = ORM::for_table('tbl_routers')->where_like('name', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + $query = ORM::for_table('tbl_routers')->where_like('name', '%' . $name . '%'); + $paginator = Paginator::generate($query, ['name' => $name]); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); } else { - $paginator = Paginator::build(ORM::for_table('tbl_routers')); - $d = ORM::for_table('tbl_routers')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + $query = ORM::for_table('tbl_routers'); + $paginator = Paginator::generate($query); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); } $ui->assign('d', $d); diff --git a/system/controllers/services.php b/system/controllers/services.php index ab025528..90059d9f 100644 --- a/system/controllers/services.php +++ b/system/controllers/services.php @@ -119,11 +119,13 @@ switch ($action) { $name = _post('name'); if ($name != '') { - $paginator = Paginator::build(ORM::for_table('tbl_plans'), ['name_plan' => '%' . $name . '%', 'type' => 'Hotspot'], $name); - $d = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'Hotspot')->where_like('tbl_plans.name_plan', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); + $query = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'Hotspot')->where_like('tbl_plans.name_plan', '%' . $name . '%'); + $paginator = Paginator::generate($query, ['name'=> $name]); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); } else { - $paginator = Paginator::build(ORM::for_table('tbl_plans'), ['type' => 'Hotspot']); - $d = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'Hotspot')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); + $query = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'Hotspot'); + $paginator = Paginator::generate($query); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); } $ui->assign('d', $d); @@ -393,11 +395,13 @@ switch ($action) { $name = _post('name'); if ($name != '') { - $paginator = Paginator::build(ORM::for_table('tbl_plans'), ['name_plan' => '%' . $name . '%', 'type' => 'PPPOE'], $name); - $d = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'PPPOE')->where_like('tbl_plans.name_plan', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); + $query = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'PPPOE')->where_like('tbl_plans.name_plan', '%' . $name . '%'); + $paginator = Paginator::generate($query, ['name' => $name]); + $d =$query->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); } else { - $paginator = Paginator::build(ORM::for_table('tbl_plans'), ['type' => 'PPPOE'], $name); - $d = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'PPPOE')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); + $query = ORM::for_table('tbl_bandwidth')->join('tbl_plans', array('tbl_bandwidth.id', '=', 'tbl_plans.id_bw'))->where('tbl_plans.type', 'PPPOE'); + $paginator = Paginator::generate($query); + $d =$query->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); } $ui->assign('d', $d); @@ -646,11 +650,13 @@ switch ($action) { $ui->assign('_title', Lang::T('Balance Plans')); $name = _post('name'); if ($name != '') { - $paginator = Paginator::build(ORM::for_table('tbl_plans'), ['name_plan' => '%' . $name . '%', 'type' => 'Balance'], $name); - $d = ORM::for_table('tbl_plans')->where('tbl_plans.type', 'Balance')->where_like('tbl_plans.name_plan', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); + $query = ORM::for_table('tbl_plans')->where('tbl_plans.type', 'Balance')->where_like('tbl_plans.name_plan', '%' . $name . '%'); + $paginator = Paginator::generate($query, ['name' => $name]); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); } else { - $paginator = Paginator::build(ORM::for_table('tbl_plans'), ['type' => 'Balance'], $name); - $d = ORM::for_table('tbl_plans')->where('tbl_plans.type', 'Balance')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); + $query = ORM::for_table('tbl_plans')->where('tbl_plans.type', 'Balance'); + $paginator = Paginator::generate($query); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); } $ui->assign('d', $d); diff --git a/system/controllers/settings.php b/system/controllers/settings.php index 7d20d163..fa50eb8a 100644 --- a/system/controllers/settings.php +++ b/system/controllers/settings.php @@ -30,7 +30,7 @@ switch ($action) { r2(U . "settings/app", 's', 'Test Telegram has been send
        Result: ' . $result); } - $UPLOAD_URL_PATH = str_replace($root_path,'', $UPLOAD_PATH); + $UPLOAD_URL_PATH = str_replace($root_path, '', $UPLOAD_PATH); if (file_exists($UPLOAD_PATH . DIRECTORY_SEPARATOR . 'logo.png')) { $logo = $UPLOAD_URL_PATH . DIRECTORY_SEPARATOR . 'logo.png?' . time(); } else { @@ -276,59 +276,58 @@ switch ($action) { $search = _req('search'); if ($search != '') { if ($admin['user_type'] == 'SuperAdmin') { - $paginator = Paginator::build(ORM::for_table('tbl_users'), ['username' => '%' . $search . '%'], $search); - $d = ORM::for_table('tbl_users') - ->where_like('username', '%' . $search . '%') + $query = ORM::for_table('tbl_users') + ->where_like('username', '%' . $search . '%'); + $paginator = Paginator::generate($query, ['search' => $search]); + $d = $query ->offset($paginator['startpoint']) ->limit($paginator['limit'])->order_by_asc('id')->findArray(); } else if ($admin['user_type'] == 'Admin') { - $paginator = Paginator::build(ORM::for_table('tbl_users'), [ - 'username' => '%' . $search . '%', - ['user_type' => 'Report'], - ['user_type' => 'Agent'], - ['user_type' => 'Sales'], - ['id' => $admin['id']] - ], $search); - $d = ORM::for_table('tbl_users') - ->where_like('username', '%' . $search . '%') - ->where_any_is([ + $query = ORM::for_table('tbl_users') + ->where_like('username', '%' . $search . '%')->where_any_is([ ['user_type' => 'Report'], ['user_type' => 'Agent'], ['user_type' => 'Sales'], ['id' => $admin['id']] - ]) + ]); + $paginator = Paginator::generate($query, ['search' => $search]); + $d = $query ->offset($paginator['startpoint']) ->limit($paginator['limit'])->order_by_asc('id')->findArray(); } else { - $paginator = Paginator::build(ORM::for_table('tbl_users'), ['username' => '%' . $search . '%'], $search); - $d = ORM::for_table('tbl_users') + $query = ORM::for_table('tbl_users') ->where_like('username', '%' . $search . '%') ->where_any_is([ ['id' => $admin['id']], ['root' => $admin['id']] - ]) + ]); + $paginator = Paginator::generate($query, ['search' => $search]); + $d = $query ->offset($paginator['startpoint']) ->limit($paginator['limit'])->order_by_asc('id')->findArray(); } } else { if ($admin['user_type'] == 'SuperAdmin') { - $paginator = Paginator::build(ORM::for_table('tbl_users')); - $d = ORM::for_table('tbl_users')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->findArray(); + $query = ORM::for_table('tbl_users'); + $paginator = Paginator::generate($query); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->findArray(); } else if ($admin['user_type'] == 'Admin') { - $paginator = Paginator::build(ORM::for_table('tbl_users')); - $d = ORM::for_table('tbl_users')->where_any_is([ + $query = ORM::for_table('tbl_users')->where_any_is([ ['user_type' => 'Report'], ['user_type' => 'Agent'], ['user_type' => 'Sales'], ['id' => $admin['id']] - ])->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->findArray(); + ]); + $paginator = Paginator::generate($query); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->findArray(); } else { - $paginator = Paginator::build(ORM::for_table('tbl_users')); - $d = ORM::for_table('tbl_users') + $query = ORM::for_table('tbl_users') ->where_any_is([ ['id' => $admin['id']], ['root' => $admin['id']] - ]) + ]); + $paginator = Paginator::generate($query); + $d = $query ->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->findArray(); } } diff --git a/system/controllers/voucher.php b/system/controllers/voucher.php index e9d65bad..5fe9a4f3 100644 --- a/system/controllers/voucher.php +++ b/system/controllers/voucher.php @@ -40,8 +40,9 @@ switch ($action) { case 'list-activated': $ui->assign('_system_menu', 'list-activated'); - $paginator = Paginator::build(ORM::for_table('tbl_transactions'), ['username' => $user['username']]); - $d = ORM::for_table('tbl_transactions')->where('username', $user['username'])->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); + $query = ORM::for_table('tbl_transactions')->where('username', $user['username']); + $paginator = Paginator::generate($query); + $d = $query->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many(); $ui->assign('d', $d); $ui->assign('paginator', $paginator); diff --git a/ui/ui/balance.tpl b/ui/ui/balance.tpl index 057c608a..54570792 100644 --- a/ui/ui/balance.tpl +++ b/ui/ui/balance.tpl @@ -46,7 +46,7 @@
        - {$paginator['contents']} + {include file="pagination.tpl"}
      diff --git a/ui/ui/bandwidth.tpl b/ui/ui/bandwidth.tpl index 0c4df8ce..8ec665dd 100644 --- a/ui/ui/bandwidth.tpl +++ b/ui/ui/bandwidth.tpl @@ -48,7 +48,7 @@
      - {$paginator['contents']} + {include file="pagination.tpl"}
    diff --git a/ui/ui/customers-view.tpl b/ui/ui/customers-view.tpl index 8cb1ae3d..fbc25a9b 100644 --- a/ui/ui/customers-view.tpl +++ b/ui/ui/customers-view.tpl @@ -228,7 +228,7 @@ {/if}
    - {$paginator['contents']} + {include file="pagination.tpl"} diff --git a/ui/ui/customers.tpl b/ui/ui/customers.tpl index 1949f277..d87ad173 100644 --- a/ui/ui/customers.tpl +++ b/ui/ui/customers.tpl @@ -16,7 +16,7 @@
    -
    diff --git a/ui/ui/dashboard.tpl b/ui/ui/dashboard.tpl index be8de2ab..07993ba5 100644 --- a/ui/ui/dashboard.tpl +++ b/ui/ui/dashboard.tpl @@ -163,7 +163,7 @@ {/foreach} -   {$paginator['contents']} +   {include file="pagination.tpl"} {/if} diff --git a/ui/ui/hotspot.tpl b/ui/ui/hotspot.tpl index d79204f3..fa2440a3 100644 --- a/ui/ui/hotspot.tpl +++ b/ui/ui/hotspot.tpl @@ -85,7 +85,7 @@ - {$paginator['contents']} + {include file="pagination.tpl"} diff --git a/ui/ui/logs-radius.tpl b/ui/ui/logs-radius.tpl index 4178e2f1..904c8d0e 100644 --- a/ui/ui/logs-radius.tpl +++ b/ui/ui/logs-radius.tpl @@ -53,7 +53,7 @@ - {$paginator['contents']} + {include file="pagination.tpl"} diff --git a/ui/ui/logs.tpl b/ui/ui/logs.tpl index dd60cdfa..00df9ebf 100644 --- a/ui/ui/logs.tpl +++ b/ui/ui/logs.tpl @@ -50,7 +50,7 @@ - {$paginator['contents']} + {include file="pagination.tpl"} diff --git a/ui/ui/pagination.tpl b/ui/ui/pagination.tpl new file mode 100644 index 00000000..9b4ef089 --- /dev/null +++ b/ui/ui/pagination.tpl @@ -0,0 +1,19 @@ +{if $paginator} + +{/if} \ No newline at end of file diff --git a/ui/ui/plan.tpl b/ui/ui/plan.tpl index fb9e886d..35a34d9c 100644 --- a/ui/ui/plan.tpl +++ b/ui/ui/plan.tpl @@ -79,7 +79,7 @@ - {$paginator['contents']} + {include file="pagination.tpl"} diff --git a/ui/ui/pool.tpl b/ui/ui/pool.tpl index 6c0efd66..4c8dc915 100644 --- a/ui/ui/pool.tpl +++ b/ui/ui/pool.tpl @@ -61,7 +61,7 @@ - {$paginator['contents']} + {include file="pagination.tpl"} diff --git a/ui/ui/pppoe.tpl b/ui/ui/pppoe.tpl index 41c242c7..7db044a7 100644 --- a/ui/ui/pppoe.tpl +++ b/ui/ui/pppoe.tpl @@ -82,7 +82,7 @@ - {$paginator['contents']} + {include file="pagination.tpl"} diff --git a/ui/ui/radius-nas.tpl b/ui/ui/radius-nas.tpl index 8e749fa3..7b6fee56 100644 --- a/ui/ui/radius-nas.tpl +++ b/ui/ui/radius-nas.tpl @@ -64,7 +64,7 @@ - {$paginator['contents']} + {include file="pagination.tpl"} diff --git a/ui/ui/reports-activation.tpl b/ui/ui/reports-activation.tpl index 020c4982..0f57b49a 100644 --- a/ui/ui/reports-activation.tpl +++ b/ui/ui/reports-activation.tpl @@ -61,7 +61,7 @@ - {$paginator['contents']} + {include file="pagination.tpl"} diff --git a/ui/ui/reports-daily.tpl b/ui/ui/reports-daily.tpl index f076fb9f..998b3e83 100644 --- a/ui/ui/reports-daily.tpl +++ b/ui/ui/reports-daily.tpl @@ -51,7 +51,7 @@ - {$paginator['contents']} + {include file="pagination.tpl"}

    {Lang::T('Total Income')}:

    diff --git a/ui/ui/routers.tpl b/ui/ui/routers.tpl index 2c0dae73..9aad56a3 100644 --- a/ui/ui/routers.tpl +++ b/ui/ui/routers.tpl @@ -61,7 +61,7 @@
    - {$paginator['contents']} + {include file="pagination.tpl"} diff --git a/ui/ui/user-activation-list.tpl b/ui/ui/user-activation-list.tpl index 8b89e1df..11513f14 100644 --- a/ui/ui/user-activation-list.tpl +++ b/ui/ui/user-activation-list.tpl @@ -34,7 +34,7 @@ - {$paginator['contents']} + {include file="pagination.tpl"} diff --git a/ui/ui/user-orderHistory.tpl b/ui/ui/user-orderHistory.tpl index 78c87593..03aa2379 100644 --- a/ui/ui/user-orderHistory.tpl +++ b/ui/ui/user-orderHistory.tpl @@ -46,7 +46,7 @@ - {$paginator['contents']} + {include file="pagination.tpl"} diff --git a/ui/ui/users.tpl b/ui/ui/users.tpl index c809938a..1ce6ca9a 100644 --- a/ui/ui/users.tpl +++ b/ui/ui/users.tpl @@ -71,7 +71,7 @@ - {$paginator['contents']} + {include file="pagination.tpl"} diff --git a/version.json b/version.json index cbc7f71f..ad181ed8 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "2024.3.23" + "version": "2024.3.26" } \ No newline at end of file From e11ab5ba012af786be8b18f99ca036ac6d6d90bb Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Tue, 26 Mar 2024 15:46:45 +0700 Subject: [PATCH 16/19] remove print_r --- system/autoload/Paginator.php | 1 - ui/ui/hotspot.tpl | 1 - 2 files changed, 2 deletions(-) diff --git a/system/autoload/Paginator.php b/system/autoload/Paginator.php index a4d5c651..bc8769fe 100644 --- a/system/autoload/Paginator.php +++ b/system/autoload/Paginator.php @@ -69,7 +69,6 @@ class Paginator 'prev' => ($page>0) ? ($page-1): "0", 'next' => ($page>= $lastpage) ? $lastpage : $page+1 ]; - print_r($result); return $result; } } diff --git a/ui/ui/hotspot.tpl b/ui/ui/hotspot.tpl index fa2440a3..f309af43 100644 --- a/ui/ui/hotspot.tpl +++ b/ui/ui/hotspot.tpl @@ -86,7 +86,6 @@ {include file="pagination.tpl"} - From 37a7da614e088e43c6a7c61a83778bb1addeab77 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Wed, 27 Mar 2024 09:44:48 +0700 Subject: [PATCH 17/19] Fixing Pagination, more Simple --- system/autoload/Package.php | 5 +- system/autoload/Paginator.php | 171 ++++++++++++++++--------------- system/controllers/bandwidth.php | 11 +- system/controllers/customers.php | 36 ++----- system/controllers/dashboard.php | 11 +- system/controllers/logs.php | 22 ++-- system/controllers/order.php | 9 +- system/controllers/plan.php | 11 +- system/controllers/pool.php | 11 +- system/controllers/radius.php | 9 +- system/controllers/reports.php | 17 ++- system/controllers/routers.php | 11 +- system/controllers/services.php | 21 ++-- system/controllers/settings.php | 39 +++---- system/controllers/voucher.php | 6 +- ui/ui/pagination.tpl | 9 +- 16 files changed, 166 insertions(+), 233 deletions(-) diff --git a/system/autoload/Package.php b/system/autoload/Package.php index de5ea9a4..3ab9645d 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -44,6 +44,7 @@ class Package foreach ($bills as $k => $v) { $note .= $k . " : " . Lang::moneyFormat($v) . "\n"; } + $note .= $p['name_plan'] . " : " . Lang::moneyFormat($p['price']) . "\n"; } } @@ -520,7 +521,9 @@ class Package $t->plan_name = $p['name_plan']; if ($p['validity_unit'] == 'Period') { // Postpaid price always zero for first time - $t->price = 0 + $add_cost; + $note = ''; + $bills = []; + $t->price = 0; } else { $t->price = $p['price'] + $add_cost; } diff --git a/system/autoload/Paginator.php b/system/autoload/Paginator.php index bc8769fe..24766ae6 100644 --- a/system/autoload/Paginator.php +++ b/system/autoload/Paginator.php @@ -1,16 +1,16 @@ $url, 'page' => $page, 'pages' => $pages, - 'prev' => ($page>0) ? ($page-1): "0", - 'next' => ($page>= $lastpage) ? $lastpage : $page+1 + 'prev' => ($page > 0) ? ($page - 1) : "0", + 'next' => ($page >= $lastpage) ? $lastpage : $page + 1 ]; - return $result; + if ($ui) { + $ui->assign('paginator', $result); + } + return $query->offset($startpoint)->limit($per_page)->find_many(); } } + public static function build($table, $colVal = [], $query = '', $per_page = '10') { global $routes; + global $_L; $url = U . implode('/', $routes); $query = urlencode($query); $adjacents = "2"; @@ -99,60 +104,60 @@ class Paginator $limit = $per_page; $startpoint = ($page * $limit) - $limit; if ($lastpage >= 1) { - $pagination .= '