phpnuxbill/system/controllers/voucher.php

68 lines
2.4 KiB
PHP
Raw Normal View History

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