Skip to content

Commit

Permalink
Merge pull request #66 from hotspotbilling/Development
Browse files Browse the repository at this point in the history
2023.8.24
  • Loading branch information
ibnux authored Aug 24, 2023
2 parents 127576b + 6166dd6 commit 93bc9ba
Show file tree
Hide file tree
Showing 46 changed files with 3,295 additions and 2,856 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

# CHANGELOG

## 2023.8.24

- Balance transfer between Customer
- Optimize Cronjob
- View Customer Info
- Ajax for select customer

## 2023.8.18

- Fix Auto Renewall Cronjob
Expand Down
2 changes: 1 addition & 1 deletion install/phpnuxbill.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ CREATE TABLE
`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',
`pppoe_password` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '',
`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',
Expand Down
12 changes: 4 additions & 8 deletions system/autoload/Balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ public static function plus($id_customer, $amount)
public static function transfer($id_customer, $phoneTarget, $amount)
{
global $config;
if ($config['allow_balance_transfer'] == 'yes') {
if (Balance::min($id_customer, $amount)) {
if (Balance::plusByPhone($phoneTarget, $amount)) {
return true;
} else {
Balance::plus($id_customer, $amount);
return false;
}
if (Balance::min($id_customer, $amount)) {
if (Balance::plusByPhone($phoneTarget, $amount)) {
return true;
} else {
Balance::plus($id_customer, $amount);
return false;
}
} else {
Expand Down
27 changes: 27 additions & 0 deletions system/autoload/Lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,31 @@ public static function phoneFormat($phone)
return $phone;
}
}

public static function dateFormat($date){
global $config;
return date($config['date_format'], strtotime($date));
}

public static function dateTimeFormat($date){
global $config;
return date($config['date_format']. ' H:i', strtotime($date));
}

public static function nl2br($text){
return nl2br($text);
}

public static function arrayCount($arr){
return count($arr);
}

public static function getNotifText($key){
global $_notifmsg, $_notifmsg_default;
if(isset($_notifmsg[$key])){
return $_notifmsg[$key];
}else{
return $_notifmsg_default[$key];
}
}
}
16 changes: 16 additions & 0 deletions system/autoload/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,20 @@ public static function sendPackageNotification($phone, $name, $package, $message
return "$via: $msg";
}

public static function sendBalanceNotification($phone, $name, $balance, $message, $via)
{
$msg = str_replace('[[name]]', "*$name*", $message);
$msg = str_replace('[[balance]]', "*" . Lang::moneyFormat($balance) . "*", $msg);
if (
!empty($phone) && strlen($phone) > 5
&& !empty($message) && in_array($via, ['sms', 'wa'])
) {
if ($via == 'sms') {
Message::sendSMS($phone, $msg);
} else if ($via == 'wa') {
Message::sendWhatsapp($phone, $msg);
}
}
return "$via: $msg";
}
}
12 changes: 8 additions & 4 deletions system/autoload/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static function rechargeUser($id_customer, $router_name, $plan_id, $gatew

Balance::plus($id_customer, $p['price']);

$textInvoice = $_notifmsg['invoice_balance'];
$textInvoice = Lang::getNotifText('invoice_balance');
$textInvoice = str_replace('[[company_name]]', $_c['CompanyName'], $textInvoice);
$textInvoice = str_replace('[[address]]', $_c['address'], $textInvoice);
$textInvoice = str_replace('[[phone]]', $_c['phone'], $textInvoice);
Expand Down Expand Up @@ -96,6 +96,7 @@ public static function rechargeUser($id_customer, $router_name, $plan_id, $gatew
if (!$_c['radius_mode']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::removePpoeUser($client, $c['username']);
Mikrotik::addHotspotUser($client, $p, $c);
}

Expand Down Expand Up @@ -128,6 +129,7 @@ public static function rechargeUser($id_customer, $router_name, $plan_id, $gatew
} else {
if (!$_c['radius_mode']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removePpoeUser($client, $c['username']);
Mikrotik::addHotspotUser($client, $p, $c);
}

Expand Down Expand Up @@ -163,12 +165,13 @@ public static function rechargeUser($id_customer, $router_name, $plan_id, $gatew
"\nRouter: " . $router_name .
"\nGateway: " . $gateway .
"\nChannel: " . $channel .
"\nPrice: " . $p['price']);
"\nPrice: " . Lang::moneyFormat($p['price']));
} else {

if ($b) {
if (!$_c['radius_mode']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::removePpoeUser($client, $c['username']);
Mikrotik::addPpoeUser($client, $p, $c);
}
Expand Down Expand Up @@ -202,6 +205,7 @@ public static function rechargeUser($id_customer, $router_name, $plan_id, $gatew
} else {
if (!$_c['radius_mode']) {
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
Mikrotik::removeHotspotUser($client, $c['username']);
Mikrotik::addPpoeUser($client, $p, $c);
}

Expand Down Expand Up @@ -237,12 +241,12 @@ public static function rechargeUser($id_customer, $router_name, $plan_id, $gatew
"\nRouter: " . $router_name .
"\nGateway: " . $gateway .
"\nChannel: " . $channel .
"\nPrice: " . $p['price']);
"\nPrice: " . Lang::moneyFormat($p['price']));
}

$in = ORM::for_table('tbl_transactions')->where('username', $c['username'])->order_by_desc('id')->find_one();

$textInvoice = $_notifmsg['invoice_paid'];
$textInvoice = Lang::getNotifText('invoice_paid');
$textInvoice = str_replace('[[company_name]]', $_c['CompanyName'], $textInvoice);
$textInvoice = str_replace('[[address]]', $_c['address'], $textInvoice);
$textInvoice = str_replace('[[phone]]', $_c['phone'], $textInvoice);
Expand Down
130 changes: 109 additions & 21 deletions system/autoload/Paginator.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
<?php

/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
**/
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
**/

Class Paginator
class Paginator
{
public static function bootstrap($table, $w1='',$c1='', $w2='', $c2= '', $w3='',$c3='', $w4='', $c4= '', $per_page = '10')
public static function bootstrap($table, $w1 = '', $c1 = '', $w2 = '', $c2 = '', $w3 = '', $c3 = '', $w4 = '', $c4 = '', $per_page = '10')
{
global $routes;
global $routes;
global $_L;
$url = U.$routes['0'].'/'.$routes['1'].'/';
$url = U . $routes['0'] . '/' . $routes['1'] . '/';
$adjacents = "2";
$page = (int)(!isset($routes['2']) ? 1 : $routes['2']);
$pagination = "";

if($w1 != ''){
$totalReq = ORM::for_table($table)->where($w1,$c1)->count();
}elseif($w2 != ''){
$totalReq = ORM::for_table($table)->where($w1,$c1)->where($w2,$c2)->count();
}elseif($w3 != ''){
$totalReq = ORM::for_table($table)->where($w1,$c1)->where($w2,$c2)->where($w3,$c3)->count();
}elseif($w4 != ''){
$totalReq = ORM::for_table($table)->where($w1,$c1)->where($w2,$c2)->where($w3,$c3)->where($w4,$c4)->count();
}else{
if ($w1 != '') {
$totalReq = ORM::for_table($table)->where($w1, $c1)->count();
} elseif ($w2 != '') {
$totalReq = ORM::for_table($table)->where($w1, $c1)->where($w2, $c2)->count();
} elseif ($w3 != '') {
$totalReq = ORM::for_table($table)->where($w1, $c1)->where($w2, $c2)->where($w3, $c3)->count();
} elseif ($w4 != '') {
$totalReq = ORM::for_table($table)->where($w1, $c1)->where($w2, $c2)->where($w3, $c3)->where($w4, $c4)->count();
} else {
$totalReq = ORM::for_table($table)->count();
}

Expand Down Expand Up @@ -85,16 +86,103 @@ public static function bootstrap($table, $w1='',$c1='', $w2='', $c2= '', $w3='',
}

if ($page < $counter - 1) {
$pagination .= "<li><a href='{$url}$next'>".$_L['Next']."</a></li>";
$pagination .= "<li><a href='{$url}$lastpage'>".$_L['Last']."</a></li>";
$pagination .= "<li><a href='{$url}$next'>" . $_L['Next'] . "</a></li>";
$pagination .= "<li><a href='{$url}$lastpage'>" . $_L['Last'] . "</a></li>";
} else {
$pagination .= "<li class='disabled'><a class='disabled'>".$_L['Next']."</a></li>";
$pagination .= "<li class='disabled'><a class='disabled'>".$_L['Last']."</a></li>";
$pagination .= "<li class='disabled'><a class='disabled'>" . $_L['Next'] . "</a></li>";
$pagination .= "<li class='disabled'><a class='disabled'>" . $_L['Last'] . "</a></li>";
}
$pagination .= "</ul>";


$gen = array("startpoint" => $startpoint, "limit" => $limit, "found" => $totalReq, "page" => $page, "lastpage" => $lastpage, "contents" => $pagination);
return $gen;
}
}

public static function bootstrapRaw($table, $w1 = '', $c1 = [], $per_page = '10')
{
global $routes;
global $_L;
$url = U . $routes['0'] . '/' . $routes['1'] . '/';
$adjacents = "2";
$page = (int)(!isset($routes['2']) ? 1 : $routes['2']);
$pagination = "";

if ($w1 != '') {
$totalReq = ORM::for_table($table)->where_raw($w1, $c1)->count();
} else {
$totalReq = ORM::for_table($table)->count();
}

$i = 0;
$page = ($page == 0 ? 1 : $page);
$start = ($page - 1) * $per_page;

$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($totalReq / $per_page);

$lpm1 = $lastpage - 1;
$limit = $per_page;
$startpoint = ($page * $limit) - $limit;

if ($lastpage >= 1) {
$pagination .= '<ul class="pagination pagination-sm">';
if ($lastpage < 7 + ($adjacents * 2)) {
for ($counter = 1; $counter <= $lastpage; $counter++) {
if ($counter == $page)
$pagination .= "<li class='active'><a href='javascript:void(0);'>$counter</a></li>";
else
$pagination .= "<li><a href='{$url}$counter'>$counter</a></li>";
}
} elseif ($lastpage > 5 + ($adjacents * 2)) {
if ($page < 1 + ($adjacents * 2)) {
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) {
if ($counter == $page)
$pagination .= "<li class='active'><a href='javascript:void(0);'>$counter</a></li>";
else
$pagination .= "<li><a href='{$url}$counter'>$counter</a></li>";
}
$pagination .= "<li class='disabled'><a href='#'>...</a></li>";
$pagination .= "<li><a href='{$url}$lpm1'>$lpm1</a></li>";
$pagination .= "<li><a href='{$url}$lastpage'>$lastpage</a></li>";
} elseif ($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) {
$pagination .= "<li><a href='{$url}1'>1</a></li>";
$pagination .= "<li><a href='{$url}2'>2</a></li>";
$pagination .= "<li class='disabled'><a href='#'>...</a></li>";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) {
if ($counter == $page)
$pagination .= "<li class='active'><a href='javascript:void(0);'>$counter</a></li>";
else
$pagination .= "<li><a href='{$url}$counter'>$counter</a></li>";
}
$pagination .= "<li class='disabled'><a href='#'>...</a></li>";
$pagination .= "<li><a href='{$url}$lpm1'>$lpm1</a></li>";
$pagination .= "<li><a href='{$url}$lastpage'>$lastpage</a></li>";
} else {
$pagination .= "<li><a href='{$url}1'>1</a></li>";
$pagination .= "<li><a href='{$url}2'>2</a></li>";
$pagination .= "<li><a href='#'>...</a></li>";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) {
if ($counter == $page)
$pagination .= "<li class='active'><a class='disabled'>$counter</a></li>";
else
$pagination .= "<li><a href='{$url}$counter'>$counter</a></li>";
}
}
}

if ($page < $counter - 1) {
$pagination .= "<li><a href='{$url}$next'>" . $_L['Next'] . "</a></li>";
$pagination .= "<li><a href='{$url}$lastpage'>" . $_L['Last'] . "</a></li>";
} else {
$pagination .= "<li class='disabled'><a class='disabled'>" . $_L['Next'] . "</a></li>";
$pagination .= "<li class='disabled'><a class='disabled'>" . $_L['Last'] . "</a></li>";
}
$pagination .= "</ul>";

$gen = array("startpoint" => $startpoint, "limit" => $limit, "found" => $totalReq, "page" => $page, "lastpage" => $lastpage, "contents" => $pagination);
return $gen;
}
}
}
}
3 changes: 1 addition & 2 deletions system/boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ function _msglog($type, $msg)
// notification message
if(file_exists("system/uploads/notifications.json")){
$_notifmsg =json_decode(file_get_contents('system/uploads/notifications.json'), true);
}else{
$_notifmsg = json_decode(file_get_contents('system/uploads/notifications.default.json'), true);
}
$_notifmsg_default = json_decode(file_get_contents('system/uploads/notifications.default.json'), true);

//register all plugin
foreach (glob("system/plugin/*.php") as $filename) {
Expand Down
46 changes: 32 additions & 14 deletions system/controllers/autoload.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* used for ajax
**/
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* used for ajax
**/

_admin();
$ui->assign('_title', $_L['Network']);
Expand All @@ -14,28 +15,45 @@

switch ($action) {
case 'pool':
$routers = _get('routers');
$d = ORM::for_table('tbl_pool')->where('routers', $routers)->find_many();
$ui->assign('d',$d);
$routers = _get('routers');
$d = ORM::for_table('tbl_pool')->where('routers', $routers)->find_many();
$ui->assign('d', $d);
$ui->display('autoload-pool.tpl');
break;

case 'server':
$d = ORM::for_table('tbl_routers')->where('enabled', '1')->find_many();
$ui->assign('d',$d);
$d = ORM::for_table('tbl_routers')->where('enabled', '1')->find_many();
$ui->assign('d', $d);

$ui->display('autoload-server.tpl');
break;

case 'plan':
$server = _post('server');
$jenis = _post('jenis');
$d = ORM::for_table('tbl_plans')->where('routers', $server)->where('type', $jenis)->where('enabled', '1')->find_many();
$ui->assign('d',$d);
$server = _post('server');
$jenis = _post('jenis');
$d = ORM::for_table('tbl_plans')->where('routers', $server)->where('type', $jenis)->where('enabled', '1')->find_many();
$ui->assign('d', $d);

$ui->display('autoload.tpl');
break;

case 'customer_select2':

$s = addslashes(_get('s'));
if (empty($s)) {
$c = ORM::for_table('tbl_customers')->limit(30)->find_many();
} else {
$c = ORM::for_table('tbl_customers')->where_raw("(`username` LIKE '%$s%' OR `fullname` LIKE '%$s%' OR `phonenumber` LIKE '%$s%' OR `email` LIKE '%$s%')", [$s, $s, $s, $s])->limit(30)->find_many();
}
header('Content-Type: application/json');
foreach ($c as $cust) {
$json[] = [
'id' => $cust['id'],
'text' => $cust['username'] . ' - ' . $cust['fullname'] . ' - ' . $cust['email']
];
}
echo json_encode(['results' => $json]);
die();
break;
default:
echo 'action not defined';
}
}
Loading

0 comments on commit 93bc9ba

Please sign in to comment.