2017-03-11 02:51:06 +07:00
|
|
|
<?php
|
2022-09-01 15:35:54 +07:00
|
|
|
|
2017-03-11 02:51:06 +07:00
|
|
|
/**
|
2022-10-16 14:50:24 +07:00
|
|
|
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
2017-03-24 13:26:14 +07:00
|
|
|
|
2022-09-01 15:35:54 +07:00
|
|
|
**/
|
2017-03-11 02:51:06 +07:00
|
|
|
_admin();
|
2022-10-13 14:00:54 +07:00
|
|
|
$ui->assign('_title', $_L['Customers']);
|
2017-03-11 02:51:06 +07:00
|
|
|
$ui->assign('_system_menu', 'customers');
|
|
|
|
|
|
|
|
$action = $routes['1'];
|
|
|
|
$admin = Admin::_info();
|
|
|
|
$ui->assign('_admin', $admin);
|
|
|
|
|
|
|
|
use PEAR2\Net\RouterOS;
|
2022-09-01 15:35:54 +07:00
|
|
|
|
2017-03-11 02:51:06 +07:00
|
|
|
require_once 'system/autoload/PEAR2/Autoload.php';
|
|
|
|
|
2022-09-01 15:35:54 +07:00
|
|
|
if ($admin['user_type'] != 'Admin' and $admin['user_type'] != 'Sales') {
|
|
|
|
r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
|
2017-03-11 02:51:06 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
switch ($action) {
|
|
|
|
case 'list':
|
|
|
|
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/customers.js"></script>');
|
2023-06-15 16:46:36 +07:00
|
|
|
$search = _post('search');
|
|
|
|
$what = _post('what');
|
2023-08-21 17:09:44 +07:00
|
|
|
if (!in_array($what, ['username', 'fullname', 'phonenumber', 'email'])) {
|
2023-06-15 16:46:36 +07:00
|
|
|
$what = 'username';
|
|
|
|
}
|
2022-09-18 00:00:40 +07:00
|
|
|
run_hook('list_customers'); #HOOK
|
2023-06-15 16:46:36 +07:00
|
|
|
if ($search != '') {
|
|
|
|
$paginator = Paginator::bootstrap('tbl_customers', 'username', '%' . $search . '%');
|
|
|
|
$d = ORM::for_table('tbl_customers')
|
2023-08-21 17:09:44 +07:00
|
|
|
->where_like($what, '%' . $search . '%')
|
|
|
|
->offset($paginator['startpoint'])
|
|
|
|
->limit($paginator['limit'])
|
|
|
|
->order_by_desc('id')->find_many();
|
2022-09-01 15:35:54 +07:00
|
|
|
} else {
|
|
|
|
$paginator = Paginator::bootstrap('tbl_customers');
|
|
|
|
$d = ORM::for_table('tbl_customers')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
|
|
|
|
}
|
|
|
|
|
2023-06-15 16:46:36 +07:00
|
|
|
$ui->assign('search', htmlspecialchars($search));
|
|
|
|
$ui->assign('what', $what);
|
2022-09-01 15:35:54 +07:00
|
|
|
$ui->assign('d', $d);
|
|
|
|
$ui->assign('paginator', $paginator);
|
2017-03-11 02:51:06 +07:00
|
|
|
$ui->display('customers.tpl');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'add':
|
2022-09-18 00:00:40 +07:00
|
|
|
run_hook('view_add_customer'); #HOOK
|
2017-03-11 02:51:06 +07:00
|
|
|
$ui->display('customers-add.tpl');
|
|
|
|
break;
|
|
|
|
|
2023-08-21 17:09:44 +07:00
|
|
|
case 'view':
|
|
|
|
$id = $routes['2'];
|
|
|
|
run_hook('view_customer'); #HOOK
|
|
|
|
$customer = ORM::for_table('tbl_customers')->find_one($id);
|
|
|
|
if ($customer) {
|
|
|
|
$v = $routes['3'];
|
|
|
|
if (empty($v) || $v == 'order') {
|
|
|
|
$v = 'order';
|
|
|
|
// $paginator = Paginator::bootstrap('tbl_payment_gateway', 'username', $customer['username']);
|
|
|
|
// print_r($paginator);
|
|
|
|
$order = ORM::for_table('tbl_payment_gateway')
|
|
|
|
->where('username', $customer['username'])
|
|
|
|
->offset(0)
|
|
|
|
->limit(30)
|
|
|
|
->order_by_desc('id')
|
|
|
|
->find_many();
|
|
|
|
// $ui->assign('paginator', $paginator);
|
|
|
|
$ui->assign('order', $order);
|
|
|
|
}else if($v=='activation'){
|
|
|
|
// $paginator = Paginator::bootstrap('tbl_transactions', 'username', $customer['username']);
|
|
|
|
$activation = ORM::for_table('tbl_transactions')
|
|
|
|
->where('username', $customer['username'])
|
|
|
|
->offset(0)
|
|
|
|
->limit(30)
|
|
|
|
->order_by_desc('id')
|
|
|
|
->find_many();
|
|
|
|
// $ui->assign('paginator', $paginator);
|
|
|
|
$ui->assign('activation', $activation);
|
|
|
|
}
|
|
|
|
$ui->assign('v', $v);
|
|
|
|
$ui->assign('d', $customer);
|
|
|
|
$ui->display('customers-view.tpl');
|
|
|
|
} else {
|
|
|
|
r2(U . 'customers/list', 'e', $_L['Account_Not_Found']);
|
|
|
|
}
|
|
|
|
break;
|
2017-03-11 02:51:06 +07:00
|
|
|
case 'edit':
|
|
|
|
$id = $routes['2'];
|
2022-09-18 00:00:40 +07:00
|
|
|
run_hook('edit_customer'); #HOOK
|
2017-03-11 02:51:06 +07:00
|
|
|
$d = ORM::for_table('tbl_customers')->find_one($id);
|
2022-09-01 15:35:54 +07:00
|
|
|
if ($d) {
|
|
|
|
$ui->assign('d', $d);
|
2017-03-11 02:51:06 +07:00
|
|
|
$ui->display('customers-edit.tpl');
|
2022-09-01 15:35:54 +07:00
|
|
|
} else {
|
2017-03-11 02:51:06 +07:00
|
|
|
r2(U . 'customers/list', 'e', $_L['Account_Not_Found']);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
|
|
|
$id = $routes['2'];
|
2022-09-18 00:00:40 +07:00
|
|
|
run_hook('delete_customer'); #HOOK
|
2017-03-11 02:51:06 +07:00
|
|
|
$d = ORM::for_table('tbl_customers')->find_one($id);
|
2022-09-01 15:35:54 +07:00
|
|
|
if ($d) {
|
|
|
|
$c = ORM::for_table('tbl_user_recharges')->where('username', $d['username'])->find_one();
|
|
|
|
if ($c) {
|
2022-09-18 00:52:39 +07:00
|
|
|
$mikrotik = Mikrotik::info($c['routers']);
|
2022-09-01 15:35:54 +07:00
|
|
|
if ($c['type'] == 'Hotspot') {
|
2023-08-21 17:09:44 +07:00
|
|
|
if (!$config['radius_mode']) {
|
2022-09-18 00:52:39 +07:00
|
|
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
2023-08-21 17:09:44 +07:00
|
|
|
Mikrotik::removeHotspotUser($client, $c['username']);
|
|
|
|
Mikrotik::removeHotspotActiveUser($client, $c['username']);
|
2022-09-01 15:35:54 +07:00
|
|
|
}
|
|
|
|
} else {
|
2023-08-21 17:09:44 +07:00
|
|
|
if (!$config['radius_mode']) {
|
2022-09-18 00:52:39 +07:00
|
|
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
2023-08-21 17:09:44 +07:00
|
|
|
Mikrotik::removePpoeUser($client, $c['username']);
|
|
|
|
Mikrotik::removePpoeActive($client, $c['username']);
|
2022-09-01 15:35:54 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$d->delete();
|
|
|
|
} catch (Exception $e) {
|
2023-08-21 17:09:44 +07:00
|
|
|
} catch (Throwable $e) {
|
2022-09-01 15:35:54 +07:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
$c->delete();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
$d->delete();
|
|
|
|
} catch (Exception $e) {
|
2023-08-21 17:09:44 +07:00
|
|
|
} catch (Throwable $e) {
|
2022-09-01 15:35:54 +07:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
$c->delete();
|
|
|
|
} catch (Exception $e) {
|
2023-08-21 17:09:44 +07:00
|
|
|
} catch (Throwable $e) {
|
2022-09-01 15:35:54 +07:00
|
|
|
}
|
|
|
|
}
|
2022-08-23 16:33:21 +07:00
|
|
|
|
2017-03-11 02:51:06 +07:00
|
|
|
r2(U . 'customers/list', 's', $_L['User_Delete_Ok']);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'add-post':
|
|
|
|
$username = _post('username');
|
|
|
|
$fullname = _post('fullname');
|
|
|
|
$password = _post('password');
|
2023-08-14 13:21:41 +07:00
|
|
|
$pppoe_password = _post('pppoe_password');
|
2023-08-09 14:54:38 +07:00
|
|
|
$email = _post('email');
|
2017-03-11 02:51:06 +07:00
|
|
|
$address = _post('address');
|
2022-09-01 15:35:54 +07:00
|
|
|
$phonenumber = _post('phonenumber');
|
2022-09-18 00:00:40 +07:00
|
|
|
run_hook('add_customer'); #HOOK
|
2017-03-11 02:51:06 +07:00
|
|
|
$msg = '';
|
2022-09-01 15:35:54 +07:00
|
|
|
if (Validator::Length($username, 35, 2) == false) {
|
|
|
|
$msg .= 'Username should be between 3 to 55 characters' . '<br>';
|
2017-03-11 02:51:06 +07:00
|
|
|
}
|
2022-09-01 15:35:54 +07:00
|
|
|
if (Validator::Length($fullname, 36, 2) == false) {
|
|
|
|
$msg .= 'Full Name should be between 3 to 25 characters' . '<br>';
|
2017-03-11 02:51:06 +07:00
|
|
|
}
|
2022-09-01 15:35:54 +07:00
|
|
|
if (!Validator::Length($password, 35, 2)) {
|
|
|
|
$msg .= 'Password should be between 3 to 35 characters' . '<br>';
|
2017-03-11 02:51:06 +07:00
|
|
|
}
|
|
|
|
|
2022-09-01 15:35:54 +07:00
|
|
|
$d = ORM::for_table('tbl_customers')->where('username', $username)->find_one();
|
|
|
|
if ($d) {
|
|
|
|
$msg .= $_L['account_already_exist'] . '<br>';
|
2017-03-11 02:51:06 +07:00
|
|
|
}
|
|
|
|
|
2022-09-01 15:35:54 +07:00
|
|
|
if ($msg == '') {
|
2017-03-11 02:51:06 +07:00
|
|
|
$d = ORM::for_table('tbl_customers')->create();
|
2023-08-09 14:54:38 +07:00
|
|
|
$d->username = Lang::phoneFormat($username);
|
2017-03-11 02:51:06 +07:00
|
|
|
$d->password = $password;
|
2023-08-14 13:21:41 +07:00
|
|
|
$d->pppoe_password = $pppoe_password;
|
2023-08-09 14:54:38 +07:00
|
|
|
$d->email = $email;
|
2017-03-11 02:51:06 +07:00
|
|
|
$d->fullname = $fullname;
|
|
|
|
$d->address = $address;
|
2023-08-09 14:54:38 +07:00
|
|
|
$d->phonenumber = Lang::phoneFormat($phonenumber);
|
2017-03-11 02:51:06 +07:00
|
|
|
$d->save();
|
|
|
|
r2(U . 'customers/list', 's', $_L['account_created_successfully']);
|
2022-09-01 15:35:54 +07:00
|
|
|
} else {
|
2017-03-11 02:51:06 +07:00
|
|
|
r2(U . 'customers/add', 'e', $msg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'edit-post':
|
2023-08-09 14:54:38 +07:00
|
|
|
$username = Lang::phoneFormat(_post('username'));
|
2017-03-11 02:51:06 +07:00
|
|
|
$fullname = _post('fullname');
|
|
|
|
$password = _post('password');
|
2023-08-14 13:21:41 +07:00
|
|
|
$pppoe_password = _post('pppoe_password');
|
2023-08-09 14:54:38 +07:00
|
|
|
$email = _post('email');
|
2017-03-11 02:51:06 +07:00
|
|
|
$address = _post('address');
|
2023-08-09 14:54:38 +07:00
|
|
|
$phonenumber = Lang::phoneFormat(_post('phonenumber'));
|
2022-09-18 00:00:40 +07:00
|
|
|
run_hook('edit_customer'); #HOOK
|
2017-03-11 02:51:06 +07:00
|
|
|
$msg = '';
|
2022-09-01 15:35:54 +07:00
|
|
|
if (Validator::Length($username, 16, 2) == false) {
|
|
|
|
$msg .= 'Username should be between 3 to 15 characters' . '<br>';
|
2017-03-11 02:51:06 +07:00
|
|
|
}
|
2023-08-09 14:54:38 +07:00
|
|
|
if (Validator::Length($fullname, 26, 1) == false) {
|
|
|
|
$msg .= 'Full Name should be between 2 to 25 characters' . '<br>';
|
2017-03-11 02:51:06 +07:00
|
|
|
}
|
2022-09-01 15:35:54 +07:00
|
|
|
if ($password != '') {
|
|
|
|
if (!Validator::Length($password, 15, 2)) {
|
|
|
|
$msg .= 'Password should be between 3 to 15 characters' . '<br>';
|
2017-03-11 02:51:06 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = _post('id');
|
|
|
|
$d = ORM::for_table('tbl_customers')->find_one($id);
|
2022-09-01 15:35:54 +07:00
|
|
|
if (!$d) {
|
|
|
|
$msg .= $_L['Data_Not_Found'] . '<br>';
|
2017-03-11 02:51:06 +07:00
|
|
|
}
|
|
|
|
|
2022-09-01 15:35:54 +07:00
|
|
|
if ($d['username'] != $username) {
|
|
|
|
$c = ORM::for_table('tbl_customers')->where('username', $username)->find_one();
|
|
|
|
if ($c) {
|
|
|
|
$msg .= $_L['account_already_exist'] . '<br>';
|
2017-03-11 02:51:06 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 15:35:54 +07:00
|
|
|
if ($msg == '') {
|
|
|
|
$c = ORM::for_table('tbl_user_recharges')->where('username', $username)->find_one();
|
|
|
|
if ($c) {
|
2022-09-18 00:52:39 +07:00
|
|
|
$mikrotik = Mikrotik::info($c['routers']);
|
2022-09-01 15:35:54 +07:00
|
|
|
if ($c['type'] == 'Hotspot') {
|
2023-08-21 17:09:44 +07:00
|
|
|
if (!$config['radius_mode']) {
|
2022-09-18 00:52:39 +07:00
|
|
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
2023-08-21 17:09:44 +07:00
|
|
|
Mikrotik::setHotspotUser($client, $c['username'], $password);
|
|
|
|
Mikrotik::removeHotspotActiveUser($client, $user['username']);
|
2022-09-01 15:35:54 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
$d->password = $password;
|
|
|
|
$d->save();
|
|
|
|
} else {
|
2023-08-21 17:09:44 +07:00
|
|
|
if (!$config['radius_mode']) {
|
2022-09-18 00:52:39 +07:00
|
|
|
$client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
|
2023-08-21 17:09:44 +07:00
|
|
|
if (!empty($d['pppoe_password'])) {
|
2023-08-14 13:21:41 +07:00
|
|
|
Mikrotik::setPpoeUser($client, $c['username'], $d['pppoe_password']);
|
2023-08-21 17:09:44 +07:00
|
|
|
} else {
|
2023-08-14 13:21:41 +07:00
|
|
|
Mikrotik::setPpoeUser($client, $c['username'], $password);
|
|
|
|
}
|
2023-08-21 17:09:44 +07:00
|
|
|
Mikrotik::removePpoeActive($client, $user['username']);
|
2022-09-01 15:35:54 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
$d->password = $password;
|
|
|
|
$d->save();
|
|
|
|
}
|
|
|
|
$d->username = $username;
|
|
|
|
if ($password != '') {
|
|
|
|
$d->password = $password;
|
|
|
|
}
|
2023-08-14 13:21:41 +07:00
|
|
|
$d->pppoe_password = $pppoe_password;
|
2022-09-01 15:35:54 +07:00
|
|
|
$d->fullname = $fullname;
|
2023-08-09 14:54:38 +07:00
|
|
|
$d->email = $email;
|
2022-09-01 15:35:54 +07:00
|
|
|
$d->address = $address;
|
|
|
|
$d->phonenumber = $phonenumber;
|
|
|
|
$d->save();
|
|
|
|
} else {
|
|
|
|
$d->username = $username;
|
|
|
|
if ($password != '') {
|
|
|
|
$d->password = $password;
|
|
|
|
}
|
|
|
|
$d->fullname = $fullname;
|
2023-08-14 13:21:41 +07:00
|
|
|
$d->pppoe_password = $pppoe_password;
|
2023-08-09 14:54:38 +07:00
|
|
|
$d->email = $email;
|
2022-09-01 15:35:54 +07:00
|
|
|
$d->address = $address;
|
|
|
|
$d->phonenumber = $phonenumber;
|
|
|
|
$d->save();
|
|
|
|
}
|
2017-03-11 02:51:06 +07:00
|
|
|
r2(U . 'customers/list', 's', 'User Updated Successfully');
|
2022-09-01 15:35:54 +07:00
|
|
|
} else {
|
|
|
|
r2(U . 'customers/edit/' . $id, 'e', $msg);
|
2017-03-11 02:51:06 +07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-08-21 17:09:44 +07:00
|
|
|
r2(U . 'customers/list', 'e', 'action not defined');
|
2022-09-01 15:35:54 +07:00
|
|
|
}
|