123 lines
4.6 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
**/
2025-03-17 14:48:01 +07:00
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'];
2025-03-17 14:48:01 +07:00
if(!_auth(false)){
if($action== 'invoice'){
$id = $routes[2];
$sign = $routes[3];
if($sign != md5($id. $db_pass)) {
die("beda");
}
if (empty($id)) {
$in = ORM::for_table('tbl_transactions')->order_by_desc('id')->find_one();
} else {
$in = ORM::for_table('tbl_transactions')->where('id', $id)->find_one();
}
if ($in) {
Package::createInvoice($in);
$UPLOAD_URL_PATH = str_replace($root_path, '', $UPLOAD_PATH);
$logo = '';
if (file_exists($UPLOAD_PATH . DIRECTORY_SEPARATOR . 'logo.png')) {
$logo = $UPLOAD_URL_PATH . DIRECTORY_SEPARATOR . 'logo.png';
$imgsize = getimagesize($logo);
$width = $imgsize[0];
$height = $imgsize[1];
$ui->assign('wlogo', $width);
$ui->assign('hlogo', $height);
}
$ui->assign('public_url', getUrl("voucher/invoice/$id/".md5($id. $db_pass)));
$ui->assign('logo', $logo);
$ui->display('customer/invoice-customer.tpl');
die();
} else {
r2(getUrl('voucher/list-activated'), 'e', Lang::T('Not Found'));
}
}else{
r2(getUrl('login'));
}
}
2017-03-11 02:51:06 +07:00
$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();
2025-01-31 16:22:58 +07:00
r2(getUrl('voucher/list-activated'), 's', Lang::T('Activation Vouchers Successfully'));
2022-08-23 16:33:21 +07:00
} else {
2025-01-31 16:22:58 +07:00
r2(getUrl('voucher/activation'), 'e', "Failed to refill account");
2022-08-23 16:33:21 +07:00
}
} else {
2025-01-31 16:22:58 +07:00
r2(getUrl('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');
$query = ORM::for_table('tbl_transactions')->where('user_id', $user['id'])->order_by_desc('id');
2024-03-27 09:44:48 +07:00
$d = Paginator::findMany($query);
2022-08-23 16:33:21 +07:00
if (empty($d) || $d < 5) {
$query = ORM::for_table('tbl_transactions')->where('username', $user['username'])->order_by_desc('id');
$d = Paginator::findMany($query);
}
2022-08-23 16:33:21 +07:00
$ui->assign('d', $d);
$ui->assign('_title', Lang::T('Activation History'));
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);
2025-03-13 14:57:23 +07:00
$UPLOAD_URL_PATH = str_replace($root_path, '', $UPLOAD_PATH);
$logo = '';
if (file_exists($UPLOAD_PATH . DIRECTORY_SEPARATOR . 'logo.png')) {
$logo = $UPLOAD_URL_PATH . DIRECTORY_SEPARATOR . 'logo.png';
$imgsize = getimagesize($logo);
$width = $imgsize[0];
$height = $imgsize[1];
$ui->assign('wlogo', $width);
$ui->assign('hlogo', $height);
}
2025-03-17 14:48:01 +07:00
$ui->assign('public_url', getUrl("voucher/invoice/$id/".md5($id. $db_pass)));
2025-03-13 14:57:23 +07:00
$ui->assign('logo', $logo);
$ui->display('customer/invoice-customer.tpl');
2024-08-11 19:54:33 +07:00
} else {
2025-01-31 16:22:58 +07:00
r2(getUrl('voucher/list-activated'), 'e', Lang::T('Not Found'));
2024-03-14 14:42:20 +07:00
}
2024-03-19 09:34:28 +07:00
break;
2017-03-11 02:51:06 +07:00
default:
2025-02-04 09:23:55 +07:00
$ui->display('admin/404.tpl');
2022-08-23 16:33:21 +07:00
}