From 91fe5a4b468ff3c64961000cd3eb2aa09cd27ab6 Mon Sep 17 00:00:00 2001 From: Free Isp Radius <167556847+freeispradius@users.noreply.github.com> Date: Mon, 22 Apr 2024 23:31:36 +0300 Subject: [PATCH 1/2] Update to case csv. added columns separated case csv now we will have one for all customers and another one for prepaid users. for all customers csv will be downloaded from list and prepaid csv will be from prepaid users. Also added columns instead of the previous one --- system/controllers/customers.php | 121 ++++++++++++++++++++++++++----- 1 file changed, 104 insertions(+), 17 deletions(-) diff --git a/system/controllers/customers.php b/system/controllers/customers.php index b8e9f38b..ebcad67b 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -25,19 +25,19 @@ switch ($action) { if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); } + $cs = ORM::for_table('tbl_customers') ->select('tbl_customers.id', 'id') ->select('tbl_customers.username', 'username') ->select('fullname') + ->select('address') ->select('phonenumber') ->select('email') ->select('balance') - ->select('namebp') - ->select('routers') - ->select('status') - ->select('method', 'Payment') - ->join('tbl_user_recharges', array('tbl_customers.id', '=', 'tbl_user_recharges.customer_id')) - ->order_by_asc('tbl_customers.id')->find_array(); + ->select('service_type') + ->order_by_asc('tbl_customers.id') + ->find_array(); + $h = false; set_time_limit(-1); header('Pragma: public'); @@ -46,20 +46,107 @@ switch ($action) { header("Content-type: text/csv"); header('Content-Disposition: attachment;filename="phpnuxbill_customers_' . date('Y-m-d_H_i') . '.csv"'); header('Content-Transfer-Encoding: binary'); + + $headers = [ + 'id', + 'username', + 'fullname', + 'address', + 'phonenumber', + 'email', + 'balance', + 'service_type', + ]; + + if (!$h) { + echo '"' . implode('","', $headers) . "\"\n"; + $h = true; + } + foreach ($cs as $c) { - $ks = []; - $vs = []; - foreach ($c as $k => $v) { - $ks[] = $k; - $vs[] = $v; - } - if (!$h) { - echo '"' . implode('";"', $ks) . "\"\n"; - $h = true; - } - echo '"' . implode('";"', $vs) . "\"\n"; + $row = [ + $c['id'], + $c['username'], + $c['fullname'], + $c['address'], + $c['phonenumber'], + $c['email'], + $c['balance'], + $c['service_type'], + ]; + echo '"' . implode('","', $row) . "\"\n"; } break; + //case csv-prepaid can be moved later to (plan.php) php file dealing with prepaid users + case 'csv-prepaid': + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { + _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); + } + + $cs = ORM::for_table('tbl_customers') + ->select('tbl_customers.id', 'id') + ->select('tbl_customers.username', 'username') + ->select('fullname') + ->select('address') + ->select('phonenumber') + ->select('email') + ->select('balance') + ->select('service_type') + ->select('namebp') + ->select('routers') + ->select('status') + ->select('method', 'Payment') + ->join('tbl_user_recharges', array('tbl_customers.id', '=', 'tbl_user_recharges.customer_id')) + ->order_by_asc('tbl_customers.id') + ->find_array(); + + $h = false; + set_time_limit(-1); + header('Pragma: public'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header("Content-type: text/csv"); + header('Content-Disposition: attachment;filename="phpnuxbill_prepaid_users' . date('Y-m-d_H_i') . '.csv"'); + header('Content-Transfer-Encoding: binary'); + + $headers = [ + 'id', + 'username', + 'fullname', + 'address', + 'phonenumber', + 'email', + 'balance', + 'service_type', + 'namebp', + 'routers', + 'status', + 'Payment' + ]; + + if (!$h) { + echo '"' . implode('","', $headers) . "\"\n"; + $h = true; + } + + foreach ($cs as $c) { + $row = [ + $c['id'], + $c['username'], + $c['fullname'], + $c['address'], + $c['phonenumber'], + $c['email'], + $c['balance'], + $c['service_type'], + $c['namebp'], + $c['routers'], + $c['status'], + $c['Payment'] + ]; + echo '"' . implode('","', $row) . "\"\n"; + } + break; case 'add': if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent', 'Sales'])) { _alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard"); From 45a6085205fad2c441227ec95d112139497c7304 Mon Sep 17 00:00:00 2001 From: Free Isp Radius <167556847+freeispradius@users.noreply.github.com> Date: Mon, 22 Apr 2024 23:33:54 +0300 Subject: [PATCH 2/2] Update case csv-prepaid changed the url --- ui/ui/plan.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/ui/plan.tpl b/ui/ui/plan.tpl index b28a39f6..67704fa0 100644 --- a/ui/ui/plan.tpl +++ b/ui/ui/plan.tpl @@ -11,7 +11,7 @@ class="glyphicon glyphicon-refresh" aria-hidden="true"> sync
- CSV
@@ -100,4 +100,4 @@ function extend(idP){ } -{include file="sections/footer.tpl"} \ No newline at end of file +{include file="sections/footer.tpl"}