69 lines
2.4 KiB
PHP
Raw Normal View History

2017-03-11 02:51:06 +07:00
<?php
2024-08-11 19:54:33 +07:00
2017-03-11 02:51:06 +07:00
/**
2023-10-12 15:55:42 +07:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
2022-08-23 16:33:21 +07:00
**/
2017-03-11 02:51:06 +07:00
_auth();
2024-02-13 13:54:01 +07:00
$ui->assign('_title', Lang::T('Voucher'));
2017-03-11 02:51:06 +07:00
$ui->assign('_system_menu', 'voucher');
$action = $routes['1'];
$user = User::_info();
$ui->assign('_user', $user);
switch ($action) {
2022-08-23 16:33:21 +07:00
2017-03-11 02:51:06 +07:00
case 'activation':
2022-09-18 00:00:40 +07:00
run_hook('view_activate_voucher'); #HOOK
2024-08-11 19:54:33 +07:00
$ui->assign('code', alphanumeric(_get('code'), "-_.,"));
$ui->display('customer/activation.tpl');
2017-03-11 02:51:06 +07:00
break;
case 'activation-post':
2024-08-11 19:54:33 +07:00
$code = alphanumeric(_post('code'), "-_.,");
2024-10-15 16:10:08 +07:00
$v1 = ORM::for_table('tbl_voucher')->whereRaw("BINARY code = '$code'")->where('status', 0)->find_one();
2022-09-18 00:00:40 +07:00
run_hook('customer_activate_voucher'); #HOOK
2022-08-23 16:33:21 +07:00
if ($v1) {
if (Package::rechargeUser($user['id'], $v1['routers'], $v1['id_plan'], "Voucher", $code)) {
2022-08-23 16:33:21 +07:00
$v1->status = "1";
2024-07-24 08:56:40 +07:00
$v1->used_date = date('Y-m-d H:i:s');
$v1->user = $user['username'];
2022-08-23 16:33:21 +07:00
$v1->save();
2024-02-13 13:54:01 +07:00
r2(U . "voucher/list-activated", 's', Lang::T('Activation Vouchers Successfully'));
2022-08-23 16:33:21 +07:00
} else {
2023-08-28 09:44:57 +07:00
r2(U . 'voucher/activation', 'e', "Failed to refill account");
2022-08-23 16:33:21 +07:00
}
} else {
2024-02-13 13:54:01 +07:00
r2(U . 'voucher/activation', 'e', Lang::T('Voucher Not Valid'));
2022-08-23 16:33:21 +07:00
}
2017-03-11 02:51:06 +07:00
break;
case 'list-activated':
2022-10-13 15:19:51 +07:00
$ui->assign('_system_menu', 'list-activated');
2024-04-19 14:43:06 +07:00
$query = ORM::for_table('tbl_transactions')->where('username', $user['username'])->order_by_desc('id');
2024-03-27 09:44:48 +07:00
$d = Paginator::findMany($query);
2022-08-23 16:33:21 +07:00
$ui->assign('d', $d);
2022-09-18 00:00:40 +07:00
run_hook('customer_view_activation_list'); #HOOK
$ui->display('customer/activation-list.tpl');
2017-03-11 02:51:06 +07:00
break;
2024-03-14 13:40:44 +07:00
case 'invoice':
$id = $routes[2];
2024-08-11 19:54:33 +07:00
if (empty($id)) {
2024-03-14 14:42:20 +07:00
$in = ORM::for_table('tbl_transactions')->where('username', $user['username'])->order_by_desc('id')->find_one();
2024-08-11 19:54:33 +07:00
} else {
2024-03-14 14:42:20 +07:00
$in = ORM::for_table('tbl_transactions')->where('username', $user['username'])->where('id', $id)->find_one();
}
2024-08-11 19:54:33 +07:00
if ($in) {
2024-03-14 14:42:20 +07:00
Package::createInvoice($in);
$ui->display('customer/invoice-customer.tpl');
2024-08-11 19:54:33 +07:00
} else {
2024-03-14 14:42:20 +07:00
r2(U . 'voucher/list-activated', 'e', Lang::T('Not Found'));
}
2024-03-19 09:34:28 +07:00
break;
2017-03-11 02:51:06 +07:00
default:
2023-09-27 15:01:48 +07:00
$ui->display('a404.tpl');
2022-08-23 16:33:21 +07:00
}