Router Maps

This commit is contained in:
Ibnu Maksum
2024-08-05 15:20:18 +07:00
parent 46a4c5f24d
commit 7d2f69f96f
12 changed files with 306 additions and 93 deletions

View File

@ -8,7 +8,7 @@
class Paginator
{
public static function findMany($query, $search = [], $per_page = '10', $append_url = "")
public static function findMany($query, $search = [], $per_page = '10', $append_url = "", $toArray = false)
{
global $routes, $ui;
$adjacents = "2";
@ -71,7 +71,11 @@ class Paginator
if ($ui) {
$ui->assign('paginator', $result);
}
return $query->offset($startpoint)->limit($per_page)->find_many();
if($toArray){
return $query->offset($startpoint)->limit($per_page)->find_array();
}else{
return $query->offset($startpoint)->limit($per_page)->find_many();
}
}
}

View File

@ -713,7 +713,6 @@ switch ($action) {
die();
}
$d = Paginator::findMany($query, ['search' => $search], 30, $append_url);
$ui->assign('xheader', '<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css">');
$ui->assign('d', $d);
$ui->assign('statuses', ORM::for_table('tbl_customers')->getEnum("status"));
$ui->assign('filter', $filter);

View File

@ -18,24 +18,26 @@ if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
}
$leafletpickerHeader = <<<EOT
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css">
EOT;
switch ($action) {
case 'list':
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/routers.js"></script>');
case 'maps':
$name = _post('name');
$query = ORM::for_table('tbl_routers')->where_not_equal('coordinates', '')->order_by_desc('id');
$query->selects(['id', 'name', 'coordinates', 'description', 'coverage', 'enabled']);
if ($name != '') {
$query = ORM::for_table('tbl_routers')->where_like('name', '%' . $name . '%')->order_by_desc('id');
$d = Paginator::findMany($query, ['name' => $name]);
} else {
$query = ORM::for_table('tbl_routers')->order_by_desc('id');
$d = Paginator::findMany($query);
$query->where_like('name', '%' . $name . '%');
}
$d = Paginator::findMany($query, ['name' => $name], '20', '', true);
$ui->assign('name', $name);
$ui->assign('d', $d);
run_hook('view_list_routers'); #HOOK
$ui->display('routers.tpl');
$ui->assign('_title', Lang::T('Routers Geo Location Information'));
$ui->assign('xheader', $leafletpickerHeader);
$ui->assign('xfooter', '<script src="https://unpkg.com/leaflet@1.9.3/dist/leaflet.js"></script>');
$ui->display('routers-maps.tpl');
break;
case 'add':
run_hook('view_add_routers'); #HOOK
$ui->display('routers-add.tpl');
@ -47,6 +49,7 @@ switch ($action) {
if (!$d) {
$d = ORM::for_table('tbl_routers')->where_equal('name', _get('name'))->find_one();
}
$ui->assign('xheader', $leafletpickerHeader);
if ($d) {
$ui->assign('d', $d);
run_hook('view_router_edit'); #HOOK
@ -75,16 +78,18 @@ switch ($action) {
$enabled = _post('enabled');
$msg = '';
if (Validator::Length($name, 30, 4) == false) {
$msg .= 'Name should be between 5 to 30 characters' . '<br>';
}
if ($ip_address == '' or $username == '') {
$msg .= Lang::T('All field is required') . '<br>';
if (Validator::Length($name, 30, 1) == false) {
$msg .= 'Name should be between 1 to 30 characters' . '<br>';
}
if($enabled || _post("testIt")){
if ($ip_address == '' or $username == '') {
$msg .= Lang::T('All field is required') . '<br>';
}
$d = ORM::for_table('tbl_routers')->where('ip_address', $ip_address)->find_one();
if ($d) {
$msg .= Lang::T('IP Router Already Exist') . '<br>';
$d = ORM::for_table('tbl_routers')->where('ip_address', $ip_address)->find_one();
if ($d) {
$msg .= Lang::T('IP Router Already Exist') . '<br>';
}
}
if (strtolower($name) == 'radius') {
$msg .= '<b>Radius</b> name is reserved<br>';
@ -92,7 +97,7 @@ switch ($action) {
if ($msg == '') {
run_hook('add_router'); #HOOK
if(_post("testIt")){
if (_post("testIt")) {
(new MikrotikHotspot())->getClient($ip_address, $username, $password);
}
$d = ORM::for_table('tbl_routers')->create();
@ -104,7 +109,7 @@ switch ($action) {
$d->enabled = $enabled;
$d->save();
r2(U . 'routers/list', 's', Lang::T('Data Created Successfully'));
r2(U . 'routers/edit/' . $d->id(), 's', Lang::T('Data Created Successfully'));
} else {
r2(U . 'routers/add', 'e', $msg);
}
@ -117,13 +122,17 @@ switch ($action) {
$username = _post('username');
$password = _post('password');
$description = _post('description');
$coordinates = _post('coordinates');
$coverage = _post('coverage');
$enabled = $_POST['enabled'];
$msg = '';
if (Validator::Length($name, 30, 4) == false) {
$msg .= 'Name should be between 5 to 30 characters' . '<br>';
}
if ($ip_address == '' or $username == '') {
$msg .= Lang::T('All field is required') . '<br>';
if($enabled || _post("testIt")){
if ($ip_address == '' or $username == '') {
$msg .= Lang::T('All field is required') . '<br>';
}
}
$id = _post('id');
@ -141,10 +150,12 @@ switch ($action) {
}
$oldname = $d['name'];
if ($d['ip_address'] != $ip_address) {
$c = ORM::for_table('tbl_routers')->where('ip_address', $ip_address)->where_not_equal('id', $id)->find_one();
if ($c) {
$msg .= 'IP Already Exists<br>';
if($enabled || _post("testIt")){
if ($d['ip_address'] != $ip_address) {
$c = ORM::for_table('tbl_routers')->where('ip_address', $ip_address)->where_not_equal('id', $id)->find_one();
if ($c) {
$msg .= 'IP Already Exists<br>';
}
}
}
@ -154,7 +165,7 @@ switch ($action) {
if ($msg == '') {
run_hook('router_edit'); #HOOK
if(_post("testIt")){
if (_post("testIt")) {
(new MikrotikHotspot())->getClient($ip_address, $username, $password);
}
$d->name = $name;
@ -162,6 +173,8 @@ switch ($action) {
$d->username = $username;
$d->password = $password;
$d->description = $description;
$d->coordinates = $coordinates;
$d->coverage = $coverage;
$d->enabled = $enabled;
$d->save();
if ($name != $oldname) {
@ -191,5 +204,17 @@ switch ($action) {
break;
default:
r2(U . 'routers/list/', 's', '');
$ui->assign('xfooter', '<script type="text/javascript" src="ui/lib/c/routers.js"></script>');
$name = _post('name');
$name = _post('name');
$query = ORM::for_table('tbl_routers')->order_by_desc('id');
if ($name != '') {
$query->where_like('name', '%' . $name . '%');
}
$d = Paginator::findMany($query, ['name' => $name]);
$ui->assign('d', $d);
run_hook('view_list_routers'); #HOOK
$ui->display('routers.tpl');
break;
}

View File

@ -690,5 +690,9 @@
"Mail_Deleted_Successfully": "Mail Deleted Successfully",
"Message_Not_Found": "Message Not Found",
"Send_Welcome_Message": "Send Welcome Message",
"WA": "WA"
"WA": "WA",
"_": "-",
"Routers_Maps": "Routers Maps",
"Routers_Geo_Location_Information": "Routers Geo Location Information",
"Coverage": "Coverage"
}

View File

@ -140,5 +140,9 @@
"2024.8.5" : [
"ALTER TABLE `tbl_customers` ADD `pppoe_username` VARCHAR(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'For PPPOE Login' AFTER `password`;",
"ALTER TABLE `tbl_customers` ADD `pppoe_ip` VARCHAR(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'For PPPOE Login' AFTER `pppoe_password`;"
],
"2024.8.5.1" : [
"ALTER TABLE `tbl_routers` ADD `coordinates` VARCHAR(50) NOT NULL DEFAULT '' AFTER `description`;",
"ALTER TABLE `tbl_routers` ADD `coverage` VARCHAR(8) NOT NULL DEFAULT '0' AFTER `coordinates`;"
]
}