diff --git a/system/controllers/services.php b/system/controllers/services.php index 7621a535..d36277d7 100644 --- a/system/controllers/services.php +++ b/system/controllers/services.php @@ -70,10 +70,10 @@ switch ($action) { $d = ORM::for_table('tbl_plans')->find_one($id); if ($d) { run_hook('delete_plan'); #HOOK - if(!$config['radius_mode']){ + if (!$config['radius_mode']) { $mikrotik = Mikrotik::info($d['routers']); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); - Mikrotik::removeHotspotPlan($client,$d['name_plan']); + Mikrotik::removeHotspotPlan($client, $d['name_plan']); } $d->delete(); @@ -96,7 +96,7 @@ switch ($action) { $validity = _post('validity'); $validity_unit = _post('validity_unit'); $routers = _post('routers'); - $enabled = _post('enabled')*1; + $enabled = _post('enabled'); $msg = ''; if (Validator::UnsignedNumber($validity) == false) { @@ -130,7 +130,7 @@ switch ($action) { } $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; - if(!$config['radius_mode']){ + if (!$config['radius_mode']) { $mikrotik = Mikrotik::info($routers); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::addHotspotPlan($client, $name, $sharedusers, $rate); @@ -176,7 +176,7 @@ switch ($action) { $validity = _post('validity'); $validity_unit = _post('validity_unit'); $routers = _post('routers'); - $enabled = _post('enabled')*1; + $enabled = _post('enabled'); $msg = ''; if (Validator::UnsignedNumber($validity) == false) { @@ -209,7 +209,7 @@ switch ($action) { } $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; - if(!$config['radius_mode']){ + if (!$config['radius_mode']) { $mikrotik = Mikrotik::info($routers); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::setHotspotPlan($client, $name, $sharedusers, $rate); @@ -293,7 +293,7 @@ switch ($action) { $d = ORM::for_table('tbl_plans')->find_one($id); if ($d) { run_hook('delete_ppoe'); #HOOK - if(!$config['radius_mode']){ + if (!$config['radius_mode']) { $mikrotik = Mikrotik::info($d['routers']); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::removePpoePlan($client, $d['name_plan']); @@ -312,7 +312,7 @@ switch ($action) { $validity_unit = _post('validity_unit'); $routers = _post('routers'); $pool = _post('pool_name'); - $enabled = _post('enabled')*1; + $enabled = _post('enabled'); $msg = ''; if (Validator::UnsignedNumber($validity) == false) { @@ -344,7 +344,7 @@ switch ($action) { } $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; - if(!$config['radius_mode']){ + if (!$config['radius_mode']) { $mikrotik = Mikrotik::info($routers); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::addPpoePlan($client, $name, $pool, $rate); @@ -377,7 +377,7 @@ switch ($action) { $validity_unit = _post('validity_unit'); $routers = _post('routers'); $pool = _post('pool_name'); - $enabled = _post('enabled')*1; + $enabled = _post('enabled'); $msg = ''; if (Validator::UnsignedNumber($validity) == false) { @@ -410,7 +410,7 @@ switch ($action) { } $rate = $b['rate_up'] . $unitup . "/" . $b['rate_down'] . $unitdown; - if(!$config['radius_mode']){ + if (!$config['radius_mode']) { $mikrotik = Mikrotik::info($routers); $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); Mikrotik::setPpoePlan($client, $name, $pool, $rate); @@ -431,7 +431,112 @@ switch ($action) { r2(U . 'services/pppoe-edit/' . $id, 'e', $msg); } break; + case 'balance': + $ui->assign('_title', Lang::T('Balance Plans')); + $name = _post('name'); + if ($name != '') { + $paginator = Paginator::bootstrap('tbl_plans', 'name_plan', '%' . $name . '%', 'type', 'Balance'); + $d = ORM::for_table('tbl_plans')->where('tbl_plans.type', 'Balance')->where_like('tbl_plans.name_plan', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); + } else { + $paginator = Paginator::bootstrap('tbl_plans', 'type', 'Hotspot'); + $d = ORM::for_table('tbl_plans')->where('tbl_plans.type', 'Balance')->offset($paginator['startpoint'])->limit($paginator['limit'])->find_many(); + } + $ui->assign('d', $d); + $ui->assign('paginator', $paginator); + run_hook('view_list_balance'); #HOOK + $ui->display('balance.tpl'); + break; + case 'balance-add': + $ui->assign('_title', Lang::T('Balance Plans')); + run_hook('view_add_balance'); #HOOK + $ui->display('balance-add.tpl'); + break; + case 'balance-edit': + $ui->assign('_title', Lang::T('Balance Plans')); + $id = $routes['2']; + $d = ORM::for_table('tbl_plans')->find_one($id); + $ui->assign('d', $d); + run_hook('view_edit_balance'); #HOOK + $ui->display('balance-edit.tpl'); + break; + case 'balance-delete': + $id = $routes['2']; + + $d = ORM::for_table('tbl_plans')->find_one($id); + if ($d) { + run_hook('delete_balance'); #HOOK + $d->delete(); + r2(U . 'services/balance', 's', $_L['Delete_Successfully']); + } + break; + case 'balance-edit-post': + $id = _post('id'); + $name = _post('name'); + $price = _post('price'); + $enabled = _post('enabled'); + + $msg = ''; + if (Validator::UnsignedNumber($price) == false) { + $msg .= 'The price must be a number' . '
'; + } + if ($name == '') { + $msg .= $_L['All_field_is_required'] . '
'; + } + + $d = ORM::for_table('tbl_plans')->where('id', $id)->find_one(); + if ($d) { + } else { + $msg .= $_L['Data_Not_Found'] . '
'; + } + run_hook('edit_ppoe'); #HOOK + if ($msg == '') { + $d->name_plan = $name; + $d->price = $price; + $d->enabled = $enabled; + $d->save(); + + r2(U . 'services/balance', 's', $_L['Updated_Successfully']); + } else { + r2(U . 'services/balance-edit/' . $id, 'e', $msg); + } + break; + case 'balance-add-post': + $name = _post('name'); + $price = _post('price'); + $enabled = _post('enabled'); + + $msg = ''; + if (Validator::UnsignedNumber($price) == false) { + $msg .= 'The price must be a number' . '
'; + } + if ($name == '') { + $msg .= $_L['All_field_is_required'] . '
'; + } + + $d = ORM::for_table('tbl_plans')->where('name_plan', $name)->find_one(); + if ($d) { + $msg .= $_L['Plan_already_exist'] . '
'; + } + run_hook('add_ppoe'); #HOOK + if ($msg == '') { + $d = ORM::for_table('tbl_plans')->create(); + $d->type = 'Balance'; + $d->name_plan = $name; + $d->id_bw = 0; + $d->price = $price; + $d->validity = 0; + $d->validity_unit = 'Months'; + $d->routers = ''; + $d->pool = ''; + $d->enabled = $enabled; + $d->save(); + + r2(U . 'services/balance', 's', $_L['Created_Successfully']); + } else { + r2(U . 'services/balance-add', 'e', $msg); + } + break; default: echo 'action not defined'; } diff --git a/system/lan/english/common.lan.php b/system/lan/english/common.lan.php index 2efded68..5fdd9f37 100644 --- a/system/lan/english/common.lan.php +++ b/system/lan/english/common.lan.php @@ -355,3 +355,4 @@ $_L['User_Cannot_change_this_only_admin_if_it_Empty_it_will_use_user_password'] $_L['Invoice_Balance_Message'] = 'Invoice Balance Message'; $_L['Invoice_Notification_Payment'] = 'Invoice Notification Payment'; $_L['Balance_Notification_Payment'] = 'Balance Notification Payment'; +$_L['Balance_Plans'] = 'Balance Plans'; diff --git a/system/updates.json b/system/updates.json index c825cc63..5413b575 100644 --- a/system/updates.json +++ b/system/updates.json @@ -6,6 +6,8 @@ "ALTER TABLE `tbl_customers_meta` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;" ], "2023.8.14": [ - "ALTER TABLE `tbl_customers` ADD `pppoe_password` varchar(45) NOT NULL DEFAULT '1' COMMENT 'For PPPOE Login' AFTER `password`;" + "ALTER TABLE `tbl_customers` ADD `pppoe_password` varchar(45) NOT NULL DEFAULT '1' COMMENT 'For PPPOE Login' AFTER `password`;", + "ALTER TABLE `tbl_plans` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;", + "ALTER TABLE `tbl_transactions` CHANGE `type` `type` ENUM('Hotspot','PPPOE','Balance') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;" ] } \ No newline at end of file diff --git a/ui/ui/balance-add.tpl b/ui/ui/balance-add.tpl new file mode 100644 index 00000000..8fa3c734 --- /dev/null +++ b/ui/ui/balance-add.tpl @@ -0,0 +1,48 @@ +{include file="sections/header.tpl"} + +
+
+
+
{$_L['Add_Plan']}
+
+
+
+ +
+ + +
+
+
+ +
+ +
+
+
+ +
+
+ {$_c['currency_code']} + +
+
+
+ +
+
+ + Or {$_L['Cancel']} +
+
+
+
+
+
+
+ +{include file="sections/footer.tpl"} diff --git a/ui/ui/balance-edit.tpl b/ui/ui/balance-edit.tpl new file mode 100644 index 00000000..16922bfb --- /dev/null +++ b/ui/ui/balance-edit.tpl @@ -0,0 +1,49 @@ +{include file="sections/header.tpl"} + +
+
+
+
{$_L['Edit_Plan']}
+
+
+ +
+ +
+ + +
+
+
+ +
+ +
+
+
+ +
+
+ {$_c['currency_code']} + +
+
+
+ +
+
+ + Or {$_L['Cancel']} +
+
+
+
+
+
+
+ +{include file="sections/footer.tpl"} diff --git a/ui/ui/balance.tpl b/ui/ui/balance.tpl new file mode 100644 index 00000000..17ace703 --- /dev/null +++ b/ui/ui/balance.tpl @@ -0,0 +1,56 @@ +{include file="sections/header.tpl"} + +
+
+
+
{Lang::T('Balance Plans')}
+
+
+
+ +
+   +
+
+ + + + + + + + + + {foreach $d as $ds} + + + + + + {/foreach} + +
{$_L['Plan_Name']}{$_L['Plan_Price']}{$_L['Manage']}
{$ds['name_plan']}{Lang::moneyFormat($ds['price'])} + {$_L['Edit']} + {$_L['Delete']} +
+
+ {$paginator['contents']} + +
+
+
+
+ +{include file="sections/footer.tpl"} diff --git a/ui/ui/hotspot-add.tpl b/ui/ui/hotspot-add.tpl index 4477bcfc..67a4a972 100644 --- a/ui/ui/hotspot-add.tpl +++ b/ui/ui/hotspot-add.tpl @@ -21,7 +21,6 @@
-

{Lang::T('Cannot be change after saved')}

@@ -83,7 +82,10 @@
- +
+ {$_c['currency_code']} + +
diff --git a/ui/ui/hotspot-edit.tpl b/ui/ui/hotspot-edit.tpl index b6387279..3f3edc3d 100644 --- a/ui/ui/hotspot-edit.tpl +++ b/ui/ui/hotspot-edit.tpl @@ -21,7 +21,7 @@
- +
@@ -82,7 +82,10 @@
- +
+ {$_c['currency_code']} + +
diff --git a/ui/ui/hotspot.tpl b/ui/ui/hotspot.tpl index 371f0dcb..be5809d8 100644 --- a/ui/ui/hotspot.tpl +++ b/ui/ui/hotspot.tpl @@ -51,7 +51,7 @@ {$ds['routers']} {$_L['Edit']} - {$_L['Delete']} + {$_L['Delete']} {/foreach} diff --git a/ui/ui/pool.tpl b/ui/ui/pool.tpl index 6bf39add..d49a78f1 100644 --- a/ui/ui/pool.tpl +++ b/ui/ui/pool.tpl @@ -47,7 +47,7 @@ {$_L['Edit']} - {$_L['Delete']} diff --git a/ui/ui/pppoe-add.tpl b/ui/ui/pppoe-add.tpl index fbe86a6c..119f38f0 100644 --- a/ui/ui/pppoe-add.tpl +++ b/ui/ui/pppoe-add.tpl @@ -21,7 +21,6 @@
-

{Lang::T('Cannot be change after saved')}

@@ -38,7 +37,10 @@
- +
+ {$_c['currency_code']} + +
diff --git a/ui/ui/pppoe-edit.tpl b/ui/ui/pppoe-edit.tpl index b710db45..d079f58a 100644 --- a/ui/ui/pppoe-edit.tpl +++ b/ui/ui/pppoe-edit.tpl @@ -21,7 +21,7 @@
- +
@@ -37,7 +37,10 @@
- +
+ {$_c['currency_code']} + +
diff --git a/ui/ui/pppoe.tpl b/ui/ui/pppoe.tpl index 090c9a76..36aa1fe4 100644 --- a/ui/ui/pppoe.tpl +++ b/ui/ui/pppoe.tpl @@ -47,7 +47,7 @@ {$ds['routers']} {$_L['Edit']} - {$_L['Delete']} + {$_L['Delete']} {/foreach} diff --git a/ui/ui/routers.tpl b/ui/ui/routers.tpl index 5d9fa3d5..e4857e62 100644 --- a/ui/ui/routers.tpl +++ b/ui/ui/routers.tpl @@ -50,7 +50,7 @@ {$_L['Edit']} - {$_L['Delete']} + {$_L['Delete']} {/foreach} diff --git a/ui/ui/sections/header.tpl b/ui/ui/sections/header.tpl index b9d17279..be43feb2 100644 --- a/ui/ui/sections/header.tpl +++ b/ui/ui/sections/header.tpl @@ -157,6 +157,8 @@ href="{$_url}services/pppoe">{$_L['PPPOE_Plans']}
  • {$_L['Bandwidth_Plans']}
  • +
  • {Lang::T('Balance Plans')}
  • {$_MENU_SERVICES}