diff --git a/system/autoload/Lang.php b/system/autoload/Lang.php
index 752d76bd..c3f870ab 100644
--- a/system/autoload/Lang.php
+++ b/system/autoload/Lang.php
@@ -127,11 +127,19 @@ class Lang
if(time()>strtotime($datetime)){
$when = Lang::T('ago');
}else{
- $when = Lang::T('later');
+ $when = '';
}
if (!$full)
$string = array_slice($string, 0, 1);
- return $string ? implode(', ', $string) .' '. $when : Lang::T('just now');
+ if($string){
+ if(empty($when)){
+ return ''. implode(', ', $string) .'';
+ }else{
+ return implode(', ', $string) .' '. $when;
+ }
+ }else{
+ return Lang::T('just now');
+ }
}
public static function nl2br($text)
diff --git a/system/controllers/plan.php b/system/controllers/plan.php
index c5d083a4..c71f2bae 100644
--- a/system/controllers/plan.php
+++ b/system/controllers/plan.php
@@ -37,20 +37,28 @@ switch ($action) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
}
set_time_limit(-1);
- $plans = ORM::for_table('tbl_user_recharges')->where('status', 'on')->find_many();
+ $turs = ORM::for_table('tbl_user_recharges')->where('status', 'on')->find_many();
$log = '';
$router = '';
- foreach ($plans as $plan) {
- $p = ORM::for_table('tbl_plans')->findOne($plan['plan_id']);
- $c = ORM::for_table('tbl_customers')->findOne($plan['customer_id']);
- $dvc = Package::getDevice($plan);
- if (file_exists($dvc) && $_app_stage != 'demo') {
- require_once $dvc;
- (new $p['device'])->add_customer($c, $p);
- } else {
- new Exception(Lang::T("Devices Not Found"));
+ foreach ($turs as $tur) {
+ $p = ORM::for_table('tbl_plans')->findOne($tur['plan_id']);
+ if($p){
+ $c = ORM::for_table('tbl_customers')->findOne($tur['customer_id']);
+ if($c){
+ $dvc = Package::getDevice($p);
+ if (file_exists($dvc) && $_app_stage != 'demo') {
+ require_once $dvc;
+ (new $p['device'])->add_customer($c, $p);
+ } else {
+ new Exception(Lang::T("Devices Not Found"));
+ }
+ $log .= "DONE : $tur[username], $ptur[namebp], $tur[type], $tur[routers]
";
+ }else{
+ $log .= "Customer NOT FOUND : $tur[username], $tur[namebp], $tur[type], $tur[routers]
";
+ }
+ }else{
+ $log .= "PLAN NOT FOUND : $tur[username], $tur[namebp], $tur[type], $tur[routers]
";
}
- $log .= "DONE : $plan[username], $plan[namebp], $plan[type], $plan[routers]
";
}
r2(U . 'plan/list', 's', $log);
case 'recharge':
@@ -235,12 +243,13 @@ switch ($action) {
$d = ORM::for_table('tbl_user_recharges')->find_one($id);
if ($d) {
$ui->assign('d', $d);
+ $p = ORM::for_table('tbl_plans')->find_one($d['plan_id']);
if (in_array($admin['user_type'], array('SuperAdmin', 'Admin'))) {
- $p = ORM::for_table('tbl_plans')->where_not_equal('type', 'Balance')->find_many();
+ $ps = ORM::for_table('tbl_plans')->where('type', $p['type'])->where('is_radius', $p['is_radius'])->find_many();
} else {
- $p = ORM::for_table('tbl_plans')->where('enabled', '1')->where_not_equal('type', 'Balance')->find_many();
+ $ps = ORM::for_table('tbl_plans')->where("enabled", 1)->where('is_radius', $p['is_radius'])->where('type', $p['type'])->find_many();
}
- $ui->assign('p', $p);
+ $ui->assign('p', $ps);
run_hook('view_edit_customer_plan'); #HOOK
$ui->assign('_title', 'Edit Plan');
$ui->display('plan-edit.tpl');
@@ -274,7 +283,6 @@ switch ($action) {
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
}
- $username = _post('username');
$id_plan = _post('id_plan');
$recharged_on = _post('recharged_on');
$expiration = _post('expiration');
@@ -286,17 +294,14 @@ switch ($action) {
} else {
$msg .= Lang::T('Data Not Found') . '
';
}
- $p = ORM::for_table('tbl_plans')->where('id', $id_plan)->where('enabled', '1')->find_one();
- if ($d) {
+ $oldPlanID = $d['plan_id'];
+ $newPlan = ORM::for_table('tbl_plans')->where('id', $id_plan)->find_one();
+ if ($newPlan) {
} else {
$msg .= ' Plan Not Found
';
}
if ($msg == '') {
run_hook('edit_customer_plan'); #HOOK
- $d->username = $username;
- $d->plan_id = $id_plan;
- $d->namebp = $p['name_plan'];
- //$d->recharged_on = $recharged_on;
$d->expiration = $expiration;
$d->time = $time;
if ($d['status'] == 'off') {
@@ -304,15 +309,29 @@ switch ($action) {
$d->status = 'on';
}
}
- if ($p['is_radius']) {
- $d->routers = 'radius';
- } else {
- $d->routers = $p['routers'];
+ if ($d['status'] == 'on' && $oldPlanID != $id_plan) {
+ $d->plan_id = $newPlan['id'];
+ $d->namebp = $newPlan['name_plan'];
+ $customer = User::_info($d['customer_id']);
+ //remove from old plan
+ $p = ORM::for_table('tbl_plans')->find_one($oldPlanID);
+ $dvc = Package::getDevice($p);
+ if (file_exists($dvc) && $_app_stage != 'demo') {
+ require_once $dvc;
+ (new $p['device'])->remove_customer($customer, $p);
+ } else {
+ new Exception(Lang::T("Devices Not Found"));
+ }
+ //add new plan
+ $dvc = Package::getDevice($newPlan);
+ if (file_exists($dvc) && $_app_stage != 'demo') {
+ require_once $dvc;
+ (new $newPlan['device'])->add_customer($customer, $newPlan);
+ } else {
+ new Exception(Lang::T("Devices Not Found"));
+ }
}
$d->save();
- if ($d['status'] == 'on') {
- Package::changeTo($username, $id_plan, $id);
- }
_log('[' . $admin['username'] . ']: ' . 'Edit Plan for Customer ' . $d['username'] . ' to [' . $d['namebp'] . '][' . Lang::moneyFormat($p['price']) . ']', $admin['user_type'], $admin['id']);
r2(U . 'plan/list', 's', Lang::T('Data Updated Successfully'));
} else {
diff --git a/system/devices/MikrotikHotspot.php b/system/devices/MikrotikHotspot.php
index 8aab6d32..ed08786a 100644
--- a/system/devices/MikrotikHotspot.php
+++ b/system/devices/MikrotikHotspot.php
@@ -35,15 +35,6 @@ class MikrotikHotspot
$this->removeHotspotActiveUser($client, $customer['username']);
}
- function change_customer($customer, $plan)
- {
- $mikrotik = $this->info($plan['routers']);
- $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
- $this->removeHotspotUser($client, $customer['username']);
- $this->removeHotspotActiveUser($client, $customer['username']);
- $this->addHotspotUser($client, $plan, $customer);
- }
-
function add_plan($plan)
{
$mikrotik = $this->info($plan['routers']);
diff --git a/system/devices/MikrotikPppoe.php b/system/devices/MikrotikPppoe.php
index bc333288..84c1a2df 100644
--- a/system/devices/MikrotikPppoe.php
+++ b/system/devices/MikrotikPppoe.php
@@ -35,16 +35,6 @@ class MikrotikPppoe
$this->removePpoeActive($client, $customer['username']);
}
- function change_customer($customer, $plan)
- {
- $mikrotik = $this->info($plan['routers']);
- $client = $this->getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']);
- $this->removePpoeUser($client, $customer['username']);
- $this->removePpoeActive($client, $customer['username']);
- $this->addPpoeUser($client, $plan, $customer);
- }
-
-
function add_plan($plan)
{
$mikrotik = $this->info($plan['routers']);
diff --git a/system/devices/Radius.php b/system/devices/Radius.php
index b60c6f52..b8e62a7a 100644
--- a/system/devices/Radius.php
+++ b/system/devices/Radius.php
@@ -20,19 +20,13 @@ class Radius {
{
if (empty($plan['plan_expired'])) {
$p = ORM::for_table("tbl_plans")->find_one($plan['plan_expired']);
- $this->customerDeactivate($customer['username']);
- $this->customerAddPlan($customer, $p);
+ $this->customerAddPlan($customer, $plan);
} else {
$this->upsertCustomerAttr($customer['username'], 'Framed-Pool', $plan['pool_expired'], ':=');
$this->disconnectCustomer($customer['username']);
}
}
- function change_customer($customer, $plan)
- {
- $this->customerUpsert($customer, $plan);
- }
-
function add_plan($plan)
{
$bw = ORM::for_table("tbl_bandwidth")->find_one($plan['id_bw']);
@@ -92,6 +86,7 @@ class Radius {
function disconnect_customer($customer, $router_name)
{
+ $this->disconnectCustomer($customer['username']);
}
public function getTableNas()
diff --git a/system/devices/readme.md b/system/devices/readme.md
index 12e626ee..8188cef7 100644
--- a/system/devices/readme.md
+++ b/system/devices/readme.md
@@ -7,38 +7,42 @@ just follow the template
class FileName {
+ // Add Customer to Mikrotik/Device
function add_customer($customer, $plan)
{
}
+ // Remove Customer to Mikrotik/Device
function remove_customer($customer, $plan)
{
}
- function change_customer($customer, $plan)
- {
- }
-
+ // Add Plan to Mikrotik/Device
function add_plan($plan)
{
}
+ // Update Plan to Mikrotik/Device
function update_plan($old_name, $plan)
{
}
+ // Remove Plan from Mikrotik/Device
function remove_plan($plan)
{
}
+ // check if customer is online
function online_customer($customer, $router_name)
{
}
+ // make customer online
function connect_customer($customer, $ip, $mac_address, $router_name)
{
}
+ // make customer disconnect
function disconnect_customer($customer, $router_name)
{
}
diff --git a/ui/ui/plan-edit.tpl b/ui/ui/plan-edit.tpl
index 2e6f04dd..cb85d3c1 100644
--- a/ui/ui/plan-edit.tpl
+++ b/ui/ui/plan-edit.tpl
@@ -20,11 +20,15 @@