diff --git a/install/phpnuxbill.sql b/install/phpnuxbill.sql index 1e5ea998..3ea5e188 100644 --- a/install/phpnuxbill.sql +++ b/install/phpnuxbill.sql @@ -315,4 +315,5 @@ ALTER TABLE `tbl_customers` ADD `created_by` INT NOT NULL DEFAULT '0' AFTER `aut ALTER TABLE `tbl_plans` ADD `list_expired` VARCHAR(32) NOT NULL DEFAULT '' COMMENT 'address list' AFTER `pool_expired`; ALTER TABLE `tbl_bandwidth` ADD `burst` VARCHAR(128) NOT NULL DEFAULT '' AFTER `rate_up_unit`; ALTER TABLE `tbl_transactions` ADD `admin_id` INT NOT NULL DEFAULT '1' AFTER `type`; -ALTER TABLE `tbl_user_recharges` ADD `admin_id` INT NOT NULL DEFAULT '1' AFTER `type`; \ No newline at end of file +ALTER TABLE `tbl_user_recharges` ADD `admin_id` INT NOT NULL DEFAULT '1' AFTER `type`; +ALTER TABLE `tbl_plans` CHANGE `allow_purchase` `prepaid` ENUM('yes','no') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'yes' COMMENT 'is prepaid'; \ No newline at end of file diff --git a/system/autoload/Package.php b/system/autoload/Package.php index 3bbc7405..8c585d94 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -32,12 +32,12 @@ class Package $c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one(); $p = ORM::for_table('tbl_plans')->where('id', $plan_id)->find_one(); - if(isset($zero) && $zero==1){ + if (isset($zero) && $zero == 1) { $p['price'] = 0; } - if(!$p['enabled']){ - if(!isset($admin) || !isset($admin['id']) || empty($admin['id'])){ + if (!$p['enabled']) { + if (!isset($admin) || !isset($admin['id']) || empty($admin['id'])) { r2(U . 'home', 'e', Lang::T('Plan Not found')); } if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { @@ -114,12 +114,29 @@ class Package } /** - * 1 Customer only can have 1 PPPOE and 1 Hotspot Plan + * 1 Customer only can have 1 PPPOE and 1 Hotspot Plan, 1 prepaid and 1 postpaid */ $b = ORM::for_table('tbl_user_recharges') + ->select('tbl_user_recharges.id', 'id') + ->select('customer_id') + ->select('username') + ->select('plan_id') + ->select('namebp') + ->select('recharged_on') + ->select('recharged_time') + ->select('expiration') + ->select('time') + ->select('status') + ->select('method') + ->select('tbl_user_recharges.routers', 'routers') + ->select('tbl_user_recharges.type', 'type') + ->select('admin_id') + ->select('prepaid') ->where('customer_id', $id_customer) - ->where('routers', $router_name) - ->where('Type', $p['type']) + ->where('tbl_user_recharges.routers', $router_name) + ->where('tbl_user_recharges.Type', $p['type']) + ->where('prepaid', $p['prepaid']) + ->join('tbl_plans', array('tbl_plans.id', '=', 'tbl_user_recharges.plan_id')) ->find_one(); run_hook("recharge_user"); @@ -608,7 +625,7 @@ class Package public static function _raid() { - return ORM::for_table('tbl_transactions')->max('id')+1; + return ORM::for_table('tbl_transactions')->max('id') + 1; } /** diff --git a/system/autoload/User.php b/system/autoload/User.php index 645190c7..af0a05f6 100644 --- a/system/autoload/User.php +++ b/system/autoload/User.php @@ -8,15 +8,16 @@ class User { - public static function getID(){ + public static function getID() + { global $db_password; - if(isset($_SESSION['uid']) && !empty($_SESSION['uid'])){ + if (isset($_SESSION['uid']) && !empty($_SESSION['uid'])) { return $_SESSION['uid']; - }else if(isset($_COOKIE['uid'])){ + } else if (isset($_COOKIE['uid'])) { // id.time.sha1 - $tmp = explode('.',$_COOKIE['uid']); - if(sha1($tmp[0].'.'.$tmp[1].'.'.$db_password)==$tmp[2]){ - if(time()-$tmp[1] < 86400*30){ + $tmp = explode('.', $_COOKIE['uid']); + if (sha1($tmp[0] . '.' . $tmp[1] . '.' . $db_password) == $tmp[2]) { + if (time() - $tmp[1] < 86400 * 30) { $_SESSION['uid'] = $tmp[0]; return $tmp[0]; } @@ -25,37 +26,93 @@ class User return 0; } - public static function setCookie($uid){ + public static function getAttribute($name, $id = 0) + { + if (!$id) { + $id = User::getID(); + } + if (!$id) { + return ''; + } + $f = ORM::for_table('tbl_customers_fields')->where('field_name', $name)->where('customer_id', $id)->find_one(); + if ($f) { + return $f['field_value']; + } + return ''; + } + + public static function getAttributes($endWith, $id = 0) + { + if (!$id) { + $id = User::getID(); + } + if (!$id) { + return []; + } + $attrs = []; + $f = ORM::for_table('tbl_customers_fields')->where_like('field_name', $endWith)->where('customer_id', $id)->find_one(); + if ($f) { + foreach ($f as $k) { + $attrs[$k['field_name']] = $k['field_value']; + } + return $attrs; + } + return []; + } + + public static function setCookie($uid) + { global $db_password; - if(isset($uid)){ + if (isset($uid)) { $time = time(); - setcookie('uid', $uid.'.'.$time.'.'.sha1($uid.'.'.$time.'.'.$db_password), time()+86400*30); + setcookie('uid', $uid . '.' . $time . '.' . sha1($uid . '.' . $time . '.' . $db_password), time() + 86400 * 30); } } - public static function removeCookie(){ - if(isset($_COOKIE['uid'])){ - setcookie('uid', '', time()-86400); + public static function removeCookie() + { + if (isset($_COOKIE['uid'])) { + setcookie('uid', '', time() - 86400); } } public static function _info($id = 0) { - if(!$id){ + if (!$id) { $id = User::getID(); } $d = ORM::for_table('tbl_customers')->find_one($id); - if(empty($d['username'])){ + if (empty($d['username'])) { r2(U . 'logout', 'd', ''); } return $d; } - public static function _billing() + public static function _billing($id = 0) { - $id = User::getID(); - $d = ORM::for_table('tbl_user_recharges')->where('customer_id', $id)->find_many(); + if (!$id) { + $id = User::getID(); + } + $d = ORM::for_table('tbl_user_recharges') + ->select('tbl_user_recharges.id', 'id') + ->select('customer_id') + ->select('username') + ->select('plan_id') + ->select('namebp') + ->select('recharged_on') + ->select('recharged_time') + ->select('expiration') + ->select('time') + ->select('status') + ->select('method') + ->select('tbl_user_recharges.routers', 'routers') + ->select('tbl_user_recharges.type', 'type') + ->select('admin_id') + ->select('prepaid') + ->where('customer_id', $id) + ->join('tbl_plans', array('tbl_plans.id', '=', 'tbl_user_recharges.plan_id')) + ->find_many(); return $d; } } diff --git a/system/controllers/order.php b/system/controllers/order.php index 03bdfd97..08ae8067 100644 --- a/system/controllers/order.php +++ b/system/controllers/order.php @@ -37,7 +37,7 @@ switch ($action) { } $ui->assign('_title', 'Top Up'); $ui->assign('_system_menu', 'balance'); - $plans_balance = ORM::for_table('tbl_plans')->where('enabled', '1')->where('type', 'Balance')->where('allow_purchase', 'yes')->find_many(); + $plans_balance = ORM::for_table('tbl_plans')->where('enabled', '1')->where('type', 'Balance')->where('prepaid', 'yes')->find_many(); $ui->assign('plans_balance', $plans_balance); $ui->display('user-orderBalance.tpl'); break; @@ -49,24 +49,24 @@ switch ($action) { $ui->assign('_system_menu', 'package'); if (!empty($_SESSION['nux-router'])) { if ($_SESSION['nux-router'] == 'radius') { - $radius_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'PPPOE')->where('allow_purchase', 'yes')->find_many(); - $radius_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'Hotspot')->where('allow_purchase', 'yes')->find_many(); + $radius_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'PPPOE')->where('prepaid', 'yes')->find_many(); + $radius_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'Hotspot')->where('prepaid', 'yes')->find_many(); } else { $routers = ORM::for_table('tbl_routers')->where('id', $_SESSION['nux-router'])->find_many(); $rs = []; foreach ($routers as $r) { $rs[] = $r['name']; } - $plans_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where_in('routers', $rs)->where('is_radius', 0)->where('type', 'PPPOE')->where('allow_purchase', 'yes')->find_many(); - $plans_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where_in('routers', $rs)->where('is_radius', 0)->where('type', 'Hotspot')->where('allow_purchase', 'yes')->find_many(); + $plans_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where_in('routers', $rs)->where('is_radius', 0)->where('type', 'PPPOE')->where('prepaid', 'yes')->find_many(); + $plans_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where_in('routers', $rs)->where('is_radius', 0)->where('type', 'Hotspot')->where('prepaid', 'yes')->find_many(); } } else { - $radius_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'PPPOE')->where('allow_purchase', 'yes')->find_many(); - $radius_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'Hotspot')->where('allow_purchase', 'yes')->find_many(); + $radius_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'PPPOE')->where('prepaid', 'yes')->find_many(); + $radius_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'Hotspot')->where('prepaid', 'yes')->find_many(); $routers = ORM::for_table('tbl_routers')->find_many(); - $plans_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 0)->where('type', 'PPPOE')->where('allow_purchase', 'yes')->find_many(); - $plans_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 0)->where('type', 'Hotspot')->where('allow_purchase', 'yes')->find_many(); + $plans_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 0)->where('type', 'PPPOE')->where('prepaid', 'yes')->find_many(); + $plans_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 0)->where('type', 'Hotspot')->where('prepaid', 'yes')->find_many(); } $ui->assign('routers', $routers); $ui->assign('radius_pppoe', $radius_pppoe); diff --git a/system/controllers/prepaid.php b/system/controllers/prepaid.php index f31aadd5..af66d95a 100644 --- a/system/controllers/prepaid.php +++ b/system/controllers/prepaid.php @@ -692,7 +692,11 @@ switch ($action) { } $ui->assign('_title', Lang::T('Refill Balance')); $ui->assign('xfooter', $select2_customer); - $ui->assign('p', ORM::for_table('tbl_plans')->where('enabled', '1')->where('type', 'Balance')->find_many()); + if (in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { + $ui->assign('p', ORM::for_table('tbl_plans')->where('type', 'Balance')->find_many()); + }else{ + $ui->assign('p', ORM::for_table('tbl_plans')->where('enabled', '1')->where('type', 'Balance')->find_many()); + } run_hook('view_deposit'); #HOOK $ui->display('deposit.tpl'); break; diff --git a/system/controllers/services.php b/system/controllers/services.php index 29991dc7..d0fb3b41 100644 --- a/system/controllers/services.php +++ b/system/controllers/services.php @@ -201,7 +201,7 @@ switch ($action) { $pool_expired = _post('pool_expired'); $list_expired = _post('list_expired'); $enabled = _post('enabled'); - $allow_purchase = _post('allow_purchase'); + $prepaid = _post('prepaid'); $msg = ''; if (Validator::UnsignedNumber($validity) == false) { @@ -269,7 +269,7 @@ switch ($action) { $d->pool_expired = $pool_expired; $d->list_expired = $list_expired; $d->enabled = $enabled; - $d->allow_purchase = $allow_purchase; + $d->prepaid = $prepaid; $d->save(); $plan_id = $d->id(); @@ -309,7 +309,7 @@ switch ($action) { $pool_expired = _post('pool_expired'); $list_expired = _post('list_expired'); $enabled = _post('enabled'); - $allow_purchase = _post('allow_purchase'); + $prepaid = _post('prepaid'); $routers = _post('routers'); $msg = ''; if (Validator::UnsignedNumber($validity) == false) { @@ -374,7 +374,7 @@ switch ($action) { $d->pool_expired = $pool_expired; $d->list_expired = $list_expired; $d->enabled = $enabled; - $d->allow_purchase = $allow_purchase; + $d->prepaid = $prepaid; $d->save(); r2(U . 'services/hotspot', 's', Lang::T('Data Updated Successfully')); @@ -471,7 +471,7 @@ switch ($action) { $pool_expired = _post('pool_expired'); $list_expired = _post('list_expired'); $enabled = _post('enabled'); - $allow_purchase = _post('allow_purchase'); + $prepaid = _post('prepaid'); $msg = ''; @@ -533,7 +533,7 @@ switch ($action) { $d->pool_expired = $pool_expired; $d->list_expired = $list_expired; $d->enabled = $enabled; - $d->allow_purchase = $allow_purchase; + $d->prepaid = $prepaid; $d->save(); $plan_id = $d->id(); @@ -566,7 +566,7 @@ switch ($action) { $pool_expired = _post('pool_expired'); $list_expired = _post('list_expired'); $enabled = _post('enabled'); - $allow_purchase = _post('allow_purchase'); + $prepaid = _post('prepaid'); $msg = ''; if (Validator::UnsignedNumber($validity) == false) { @@ -626,7 +626,7 @@ switch ($action) { $d->pool_expired = $pool_expired; $d->list_expired = $list_expired; $d->enabled = $enabled; - $d->allow_purchase = $allow_purchase; + $d->prepaid = $prepaid; $d->save(); r2(U . 'services/pppoe', 's', Lang::T('Data Updated Successfully')); @@ -678,7 +678,7 @@ switch ($action) { $name = _post('name'); $price = _post('price'); $enabled = _post('enabled'); - $allow_purchase = _post('allow_purchase'); + $prepaid = _post('prepaid'); $msg = ''; if (Validator::UnsignedNumber($price) == false) { @@ -698,7 +698,7 @@ switch ($action) { $d->name_plan = $name; $d->price = $price; $d->enabled = $enabled; - $d->allow_purchase = $allow_purchase; + $d->prepaid = 'yes'; $d->save(); r2(U . 'services/balance', 's', Lang::T('Data Updated Successfully')); @@ -710,7 +710,6 @@ switch ($action) { $name = _post('name'); $price = _post('price'); $enabled = _post('enabled'); - $allow_purchase = _post('allow_purchase'); $msg = ''; if (Validator::UnsignedNumber($price) == false) { @@ -736,7 +735,7 @@ switch ($action) { $d->routers = ''; $d->pool = ''; $d->enabled = $enabled; - $d->allow_purchase = $allow_purchase; + $d->prepaid = 'yes'; $d->save(); r2(U . 'services/balance', 's', Lang::T('Data Created Successfully')); diff --git a/system/lan/english.json b/system/lan/english.json index 4e8d8977..08349a9f 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -468,7 +468,7 @@ "Payment_Gateway_Deleted": "Payment Gateway Deleted", "Payment_Gateway_not_set__please_set_it_in_Settings": "Payment Gateway not set, please set it in Settings", "Failed_to_create_Transaction__": "Failed to create Transaction..", - "Show_To_Customer": "Show To Customer", + "Show_To_Customer": "Type", "Using": "Using", "Default": "Default", "Customer_Balance": "Customer Balance" diff --git a/system/updates.json b/system/updates.json index aa67225a..60cd6177 100644 --- a/system/updates.json +++ b/system/updates.json @@ -72,5 +72,8 @@ ], "2024.3.3" : [ "ALTER TABLE `tbl_plans` CHANGE `validity_unit` `validity_unit` ENUM('Mins','Hrs','Days','Months','Period') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;" + ], + "2024.3.12" : [ + "ALTER TABLE `tbl_plans` CHANGE `allow_purchase` `prepaid` ENUM('yes','no') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT 'yes' COMMENT 'is prepaid';" ] } \ No newline at end of file diff --git a/ui/ui/autoload.tpl b/ui/ui/autoload.tpl index 30ff8b96..e5dffbcf 100644 --- a/ui/ui/autoload.tpl +++ b/ui/ui/autoload.tpl @@ -1,4 +1,4 @@ {foreach $d as $ds} - + {/foreach} \ No newline at end of file diff --git a/ui/ui/balance-add.tpl b/ui/ui/balance-add.tpl index 748ffcba..d2116352 100644 --- a/ui/ui/balance-add.tpl +++ b/ui/ui/balance-add.tpl @@ -17,17 +17,6 @@ -
{Lang::T('1 Period = 1 Month, Expires the 20th of each month')}
{Lang::T('1 Period = 1 Month, Expires the 20th of each month')}
{Lang::T('1 Period = 1 Month, Expires the 20th of each month')}
{Lang::T('1 Period = 1 Month, Expires the 20th of each month')}
Postpaid Recharge for the first time use {$_c['currency_code']} 0
{$_user['fullname']}
{$_user['phonenumber']}
- {$_user['email']}
+ {$_user['email']}