2017-03-11 03:51:06 +08:00
|
|
|
<?php
|
2022-09-11 12:02:30 +08:00
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
/**
|
2022-10-16 15:50:24 +08:00
|
|
|
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
2022-09-11 12:02:30 +08:00
|
|
|
**/
|
2017-03-11 03:51:06 +08:00
|
|
|
_auth();
|
2022-10-13 15:00:54 +08:00
|
|
|
$ui->assign('_title', $_L['Dashboard']);
|
2017-03-11 03:51:06 +08:00
|
|
|
|
|
|
|
$user = User::_info();
|
|
|
|
$ui->assign('_user', $user);
|
|
|
|
|
2023-08-23 17:46:05 +08:00
|
|
|
if (isset($_GET['renewal'])) {
|
2023-08-15 11:27:46 +08:00
|
|
|
$user->auto_renewal = $_GET['renewal'];
|
|
|
|
$user->save();
|
|
|
|
}
|
|
|
|
|
2023-08-23 17:46:05 +08:00
|
|
|
if (_post('send') == 'balance') {
|
2023-08-28 10:47:04 +08:00
|
|
|
if ($config['enable_balance'] == 'yes' && $config['allow_balance_transfer'] == 'yes') {
|
2023-08-23 17:46:05 +08:00
|
|
|
$target = ORM::for_table('tbl_customers')->where('username', _post('username'))->find_one();
|
|
|
|
if (!$target) {
|
|
|
|
r2(U . 'home', 'd', Lang::T('Username not found'));
|
|
|
|
}
|
|
|
|
$username = _post('username');
|
|
|
|
$balance = _post('balance');
|
|
|
|
if ($user['balance'] < $balance) {
|
|
|
|
r2(U . 'home', 'd', Lang::T('insufficient balance'));
|
|
|
|
}
|
2023-09-13 17:23:51 +08:00
|
|
|
if (!empty($config['minimum_transfer']) && intval($balance) < intval($config['minimum_transfer'])) {
|
2023-08-24 12:52:43 +08:00
|
|
|
r2(U . 'home', 'd', Lang::T('Minimum Transfer') . ' ' . Lang::moneyFormat($config['minimum_transfer']));
|
|
|
|
}
|
2023-08-23 17:46:05 +08:00
|
|
|
if ($user['username'] == $target['username']) {
|
|
|
|
r2(U . 'home', 'd', Lang::T('Cannot send to yourself'));
|
|
|
|
}
|
2023-08-24 12:35:23 +08:00
|
|
|
if (Balance::transfer($user['id'], $username, $balance)) {
|
2023-08-23 17:46:05 +08:00
|
|
|
//sender
|
|
|
|
$d = ORM::for_table('tbl_payment_gateway')->create();
|
|
|
|
$d->username = $user['username'];
|
|
|
|
$d->gateway = $target['username'];
|
|
|
|
$d->plan_id = 0;
|
|
|
|
$d->plan_name = 'Send Balance';
|
|
|
|
$d->routers_id = 0;
|
|
|
|
$d->routers = 'balance';
|
|
|
|
$d->price = $balance;
|
|
|
|
$d->payment_method = "Customer";
|
|
|
|
$d->payment_channel = "Balance";
|
|
|
|
$d->created_date = date('Y-m-d H:i:s');
|
|
|
|
$d->paid_date = date('Y-m-d H:i:s');
|
|
|
|
$d->expired_date = date('Y-m-d H:i:s');
|
|
|
|
$d->pg_url_payment = 'balance';
|
|
|
|
$d->status = 2;
|
|
|
|
$d->save();
|
|
|
|
//receiver
|
|
|
|
$d = ORM::for_table('tbl_payment_gateway')->create();
|
|
|
|
$d->username = $target['username'];
|
|
|
|
$d->gateway = $user['username'];
|
|
|
|
$d->plan_id = 0;
|
|
|
|
$d->plan_name = 'Receive Balance';
|
|
|
|
$d->routers_id = 0;
|
|
|
|
$d->routers = 'balance';
|
|
|
|
$d->payment_method = "Customer";
|
|
|
|
$d->payment_channel = "Balance";
|
|
|
|
$d->price = $balance;
|
|
|
|
$d->created_date = date('Y-m-d H:i:s');
|
|
|
|
$d->paid_date = date('Y-m-d H:i:s');
|
|
|
|
$d->expired_date = date('Y-m-d H:i:s');
|
|
|
|
$d->pg_url_payment = 'balance';
|
|
|
|
$d->status = 2;
|
|
|
|
$d->save();
|
2023-09-13 17:23:51 +08:00
|
|
|
Message::sendBalanceNotification($user['phonenumber'], $target['fullname'] . ' (' . $target['username'] . ')', $balance, ($user['balance'] - $balance), Lang::getNotifText('balance_send'), $config['user_notification_payment']);
|
|
|
|
Message::sendBalanceNotification($target['phonenumber'], $user['fullname'] . ' (' . $user['username'] . ')', $balance, ($target['balance'] + $balance), Lang::getNotifText('balance_received'), $config['user_notification_payment']);
|
2023-08-24 12:35:23 +08:00
|
|
|
Message::sendTelegram("#u$user[username] send balance to #u$target[username] \n" . Lang::moneyFormat($balance));
|
2023-08-23 17:46:05 +08:00
|
|
|
r2(U . 'home', 's', Lang::T('Sending balance success'));
|
|
|
|
}
|
2023-08-24 12:35:23 +08:00
|
|
|
} else {
|
2023-09-13 16:38:56 +08:00
|
|
|
r2(U . 'home', 'd', Lang::T('Failed, balance is not available'));
|
|
|
|
}
|
2023-09-13 17:23:51 +08:00
|
|
|
} else if (_post('send') == 'plan') {
|
2023-09-13 16:38:56 +08:00
|
|
|
$active = ORM::for_table('tbl_user_recharges')
|
|
|
|
->where('username', _post('username'))
|
|
|
|
->find_one();
|
2023-09-13 17:23:51 +08:00
|
|
|
$router = ORM::for_table('tbl_routers')->where('name', $active['routers'])->find_one();
|
|
|
|
if ($router) {
|
|
|
|
r2(U . "order/send/$router[id]/$active[plan_id]&u=" . trim(_post('username')), 's', Lang::T('Review package before recharge'));
|
|
|
|
} else {
|
2023-09-13 16:38:56 +08:00
|
|
|
r2(U . 'package/order', 'w', Lang::T('Your friend do not have active package'));
|
2023-08-23 17:46:05 +08:00
|
|
|
}
|
|
|
|
}
|
2023-06-15 18:06:22 +08:00
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
//Client Page
|
|
|
|
$bill = User::_billing();
|
|
|
|
$ui->assign('_bill', $bill);
|
|
|
|
|
2023-06-15 16:26:38 +08:00
|
|
|
if (!empty($_SESSION['nux-mac']) && !empty($_SESSION['nux-ip'])) {
|
|
|
|
$ui->assign('nux_mac', $_SESSION['nux-mac']);
|
|
|
|
$ui->assign('nux_ip', $_SESSION['nux-ip']);
|
|
|
|
if ($_GET['mikrotik'] == 'login') {
|
|
|
|
$m = Mikrotik::info($bill['routers']);
|
|
|
|
$c = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
|
|
|
|
Mikrotik::logMeIn($c, $user['username'], $user['password'], $_SESSION['nux-ip'], $_SESSION['nux-mac']);
|
|
|
|
r2(U . 'home', 's', Lang::T('Login Request successfully'));
|
2023-08-23 17:46:05 +08:00
|
|
|
} else if ($_GET['mikrotik'] == 'logout') {
|
2023-06-15 16:26:38 +08:00
|
|
|
$m = Mikrotik::info($bill['routers']);
|
|
|
|
$c = Mikrotik::getClient($m['ip_address'], $m['username'], $m['password']);
|
|
|
|
Mikrotik::logMeOut($c, $user['username']);
|
|
|
|
r2(U . 'home', 's', Lang::T('Logout Request successfully'));
|
|
|
|
}
|
|
|
|
}
|
2022-09-11 12:02:30 +08:00
|
|
|
|
|
|
|
$ui->assign('unpaid', ORM::for_table('tbl_payment_gateway')
|
|
|
|
->where('username', $user['username'])
|
|
|
|
->where('status', 1)
|
|
|
|
->find_one());
|
2022-09-18 01:00:40 +08:00
|
|
|
run_hook('view_customer_dashboard'); #HOOK
|
2022-09-11 12:02:30 +08:00
|
|
|
$ui->display('user-dashboard.tpl');
|