paginator dynamic

This commit is contained in:
Ibnu Maksum
2023-10-20 10:34:24 +07:00
parent 8cbe32e313
commit 7ebf95f4be
14 changed files with 352 additions and 216 deletions

View File

@ -8,6 +8,88 @@
class Paginator
{
public static function build($table, $colVal = [], $query='', $per_page = '10')
{
global $routes;
global $_L;
$url = U . implode('/', $routes);
$query = urlencode($query);
$adjacents = "2";
$page = (int)(empty(_get('p')) ? 1 : _get('p'));
$pagination = "";
foreach($colVal as $k=>$v) {
if(!empty($query)){
$table = $table->where_like($k, $v);
}else{
$table = $table->where($k, $v);
}
}
$totalReq = $table->count();
$page = ($page == 0 ? 1 : $page);
$next = $page + 1;
$lastpage = ceil($totalReq / $per_page);
$lpm1 = $lastpage - 1;
$limit = $per_page;
$startpoint = ($page * $limit) - $limit;
if ($lastpage >= 1) {
$pagination .= '<ul class="pagination pagination-sm">';
if ($lastpage < 7 + ($adjacents * 2)) {
for ($counter = 1; $counter <= $lastpage; $counter++) {
if ($counter == $page)
$pagination .= "<li class='active'><a href='javascript:void(0);'>$counter</a></li>";
else
$pagination .= "<li><a href='{$url}&p=$counter&q=$query'>$counter</a></li>";
}
} elseif ($lastpage > 5 + ($adjacents * 2)) {
if ($page < 1 + ($adjacents * 2)) {
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) {
if ($counter == $page)
$pagination .= "<li class='active'><a href='javascript:void(0);'>$counter</a></li>";
else
$pagination .= "<li><a href='{$url}&p=$counter&q=$query'>$counter</a></li>";
}
$pagination .= "<li class='disabled'><a href='#'>...</a></li>";
$pagination .= "<li><a href='{$url}&p=$lpm1&q=$query'>$lpm1</a></li>";
$pagination .= "<li><a href='{$url}&p=$lastpage&q=$query'>$lastpage</a></li>";
} elseif ($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) {
$pagination .= "<li><a href='{$url}&p=1&q=$query'>1</a></li>";
$pagination .= "<li><a href='{$url}&p=2&q=$query'>2</a></li>";
$pagination .= "<li class='disabled'><a href='#'>...</a></li>";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) {
if ($counter == $page)
$pagination .= "<li class='active'><a href='javascript:void(0);'>$counter</a></li>";
else
$pagination .= "<li><a href='{$url}&p=$counter&q=$query'>$counter</a></li>";
}
$pagination .= "<li class='disabled'><a href='#'>...</a></li>";
$pagination .= "<li><a href='{$url}&p=$lpm1&q=$query'>$lpm1</a></li>";
$pagination .= "<li><a href='{$url}&p=$lastpage&q=$query'>$lastpage</a></li>";
} else {
$pagination .= "<li><a href='{$url}&p=1&q=$query'>1</a></li>";
$pagination .= "<li><a href='{$url}&p=2&q=$query'>2</a></li>";
$pagination .= "<li><a href='#'>...</a></li>";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) {
if ($counter == $page)
$pagination .= "<li class='active'><a class='disabled'>$counter</a></li>";
else
$pagination .= "<li><a href='{$url}&p=$counter&q=$query'>$counter</a></li>";
}
}
}
if ($page < $counter - 1) {
$pagination .= "<li><a href='{$url}&p=$next&q=$query'>" . $_L['Next'] . "</a></li>";
$pagination .= "<li><a href='{$url}&p=$lastpage&q=$query'>" . $_L['Last'] . "</a></li>";
} else {
$pagination .= "<li class='disabled'><a class='disabled'>" . $_L['Next'] . "</a></li>";
$pagination .= "<li class='disabled'><a class='disabled'>" . $_L['Last'] . "</a></li>";
}
$pagination .= "</ul>";
return array("startpoint" => $startpoint, "limit" => $limit, "found" => $totalReq, "page" => $page, "lastpage" => $lastpage, "contents" => $pagination);
}
}
public static function bootstrap($table, $w1 = '', $c1 = '', $w2 = '', $c2 = '', $w3 = '', $c3 = '', $w4 = '', $c4 = '', $per_page = '10')
{
global $routes;
@ -17,16 +99,30 @@ class Paginator
$page = (int)(!isset($routes['2']) ? 1 : $routes['2']);
$pagination = "";
if ($w1 != '') {
$totalReq = ORM::for_table($table)->where($w1, $c1)->count();
} elseif ($w2 != '') {
$totalReq = ORM::for_table($table)->where($w1, $c1)->where($w2, $c2)->count();
} elseif ($w3 != '') {
$totalReq = ORM::for_table($table)->where($w1, $c1)->where($w2, $c2)->where($w3, $c3)->count();
} elseif ($w4 != '') {
$totalReq = ORM::for_table($table)->where($w1, $c1)->where($w2, $c2)->where($w3, $c3)->where($w4, $c4)->count();
} else {
$totalReq = ORM::for_table($table)->count();
if(is_object($table)){
if ($w1 != '') {
$totalReq = $table->where($w1, $c1)->count();
} elseif ($w2 != '') {
$totalReq = $table->where($w1, $c1)->where($w2, $c2)->count();
} elseif ($w3 != '') {
$totalReq = $table->where($w1, $c1)->where($w2, $c2)->where($w3, $c3)->count();
} elseif ($w4 != '') {
$totalReq = $table->where($w1, $c1)->where($w2, $c2)->where($w3, $c3)->where($w4, $c4)->count();
} else {
$totalReq = $table->count();
}
}else{
if ($w1 != '') {
$totalReq = ORM::for_table($table)->where($w1, $c1)->count();
} elseif ($w2 != '') {
$totalReq = ORM::for_table($table)->where($w1, $c1)->where($w2, $c2)->count();
} elseif ($w3 != '') {
$totalReq = ORM::for_table($table)->where($w1, $c1)->where($w2, $c2)->where($w3, $c3)->count();
} elseif ($w4 != '') {
$totalReq = ORM::for_table($table)->where($w1, $c1)->where($w2, $c2)->where($w3, $c3)->where($w4, $c4)->count();
} else {
$totalReq = ORM::for_table($table)->count();
}
}
$i = 0;
@ -109,11 +205,18 @@ class Paginator
$adjacents = "2";
$page = (int)(!isset($routes['2']) ? 1 : $routes['2']);
$pagination = "";
if ($w1 != '') {
$totalReq = ORM::for_table($table)->where_raw($w1, $c1)->count();
} else {
$totalReq = ORM::for_table($table)->count();
if(is_object($table)){
if ($w1 != '') {
$totalReq = $table->where_raw($w1, $c1)->count();
} else {
$totalReq = $table->count();
}
}else{
if ($w1 != '') {
$totalReq = ORM::for_table($table)->where_raw($w1, $c1)->count();
} else {
$totalReq = ORM::for_table($table)->count();
}
}
$i = 0;

View File

@ -20,43 +20,42 @@ if ($admin['user_type'] != 'Admin') {
switch ($action) {
case 'list':
$name = _post('name');
$q = (_post('q') ? _post('q') : _get('q'));
$keep = _post('keep');
if (!empty($keep)) {
ORM::raw_execute("DELETE FROM tbl_logs WHERE date < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL $keep DAY))");
r2(U . "logs/list/", 's', "Delete logs older than $keep days");
}
if ($name != '') {
$paginator = Paginator::bootstrap('tbl_logs', 'description', '%' . $name . '%');
$d = ORM::for_table('tbl_logs')->where_like('description', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
if ($q != '') {
$paginator = Paginator::build(ORM::for_table('tbl_logs'), ['description' => '%' . $q . '%'], $q);
$d = ORM::for_table('tbl_logs')->where_like('description', '%' . $q . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
} else {
$paginator = Paginator::bootstrap('tbl_logs');
$paginator = Paginator::build(ORM::for_table('tbl_logs'));
$d = ORM::for_table('tbl_logs')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
}
$ui->assign('name', $name);
$ui->assign('d', $d);
$ui->assign('q', $q);
$ui->assign('paginator', $paginator);
$ui->display('logs.tpl');
break;
case 'radius':
$name = _post('name');
$q = (_post('q') ? _post('q') : _get('q'));
$keep = _post('keep');
$page = (isset($routes['2']) ? intval($routes['2']) : 0);
$pageNow = $page * 20;
if (!empty($keep)) {
ORM::raw_execute("DELETE FROM radpostauth WHERE UNIX_TIMESTAMP(authdate) < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL $keep DAY))", [], 'radius');
r2(U . "logs/radius/", 's', "Delete logs older than $keep days");
}
if ($name != '') {
$d = ORM::for_table('radpostauth', 'radius')->where_like('username', '%' . $name . '%')->offset($pageNow)->limit(10)->order_by_desc('id')->find_many();
if ($q != '') {
$paginator = Paginator::build(ORM::for_table('radpostauth', 'radius'), ['username' => '%' . $q . '%'], $q);
$d = ORM::for_table('radpostauth', 'radius')->where_like('username', '%' . $q . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
} else {
$d = ORM::for_table('radpostauth', 'radius')->offset($pageNow)->limit(10)->order_by_desc('id')->find_many();
$paginator = Paginator::build(ORM::for_table('radpostauth', 'radius'));
$d = ORM::for_table('radpostauth', 'radius')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
}
$ui->assign('page', $page);
$ui->assign('name', $name);
$ui->assign('d', $d);
$ui->assign('q', $q);
$ui->assign('paginator', $paginator);
$ui->display('logs-radius.tpl');
break;

View File

@ -31,43 +31,51 @@ switch ($action) {
run_hook('customer_view_order_history'); #HOOK
$ui->display('user-orderHistory.tpl');
break;
case 'package':
if (strpos($user['email'], '@') === false) {
r2(U . 'accounts/profile', 'e', Lang::T("Please enter your email address"));
}
$ui->assign('_title', 'Order Plan');
$ui->assign('_system_menu', 'package');
if (!empty($_SESSION['nux-router'])) {
if ($_SESSION['nux-router'] == 'radius') {
case 'balance':
if (strpos($user['email'], '@') === false) {
r2(U . 'accounts/profile', 'e', Lang::T("Please enter your email address"));
}
$ui->assign('_title', 'Top Up');
$ui->assign('_system_menu', 'balance');
$plans_balance = ORM::for_table('tbl_plans')->where('enabled', '1')->where('type', 'Balance')->find_many();
$ui->assign('plans_balance', $plans_balance);
$ui->display('user-orderBalance.tpl');
break;
case 'package':
if (strpos($user['email'], '@') === false) {
r2(U . 'accounts/profile', 'e', Lang::T("Please enter your email address"));
}
$ui->assign('_title', 'Order Plan');
$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')->find_many();
$radius_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'Hotspot')->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')->find_many();
$plans_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where_in('routers', $rs)->where('is_radius', 0)->where('type', 'Hotspot')->find_many();
}
} else {
$radius_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'PPPOE')->find_many();
$radius_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'Hotspot')->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')->find_many();
$plans_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where_in('routers', $rs)->where('is_radius', 0)->where('type', 'Hotspot')->find_many();
}
} else {
$radius_pppoe = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'PPPOE')->find_many();
$radius_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 1)->where('type', 'Hotspot')->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')->find_many();
$plans_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 0)->where('type', 'Hotspot')->find_many();
}
$plans_balance = ORM::for_table('tbl_plans')->where('enabled', '1')->where('type', 'Balance')->find_many();
$ui->assign('routers', $routers);
$ui->assign('radius_pppoe', $radius_pppoe);
$ui->assign('radius_hotspot', $radius_hotspot);
$ui->assign('plans_pppoe', $plans_pppoe);
$ui->assign('plans_hotspot', $plans_hotspot);
$ui->assign('plans_balance', $plans_balance);
run_hook('customer_view_order_plan'); #HOOK
$ui->display('user-orderPlan.tpl');
break;
$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')->find_many();
$plans_hotspot = ORM::for_table('tbl_plans')->where('enabled', '1')->where('is_radius', 0)->where('type', 'Hotspot')->find_many();
}
$ui->assign('routers', $routers);
$ui->assign('radius_pppoe', $radius_pppoe);
$ui->assign('radius_hotspot', $radius_hotspot);
$ui->assign('plans_pppoe', $plans_pppoe);
$ui->assign('plans_hotspot', $plans_hotspot);
run_hook('customer_view_order_plan'); #HOOK
$ui->display('user-orderPlan.tpl');
break;
case 'unpaid':
$d = ORM::for_table('tbl_payment_gateway')
->where('username', $user['username'])

View File

@ -12,7 +12,19 @@ $action = $routes['1'];
$admin = Admin::_info();
$ui->assign('_admin', $admin);
if(strpos($action,"-post")===false){
if(strpos($action,"-reset")!==false){
$action = str_replace("-reset","",$action);
$path = "pages/".str_replace(".","",$action).".html";
$temp = "pages_template/".str_replace(".","",$action).".html";
if(file_exists($temp)){
if(!copy($temp, $path)){
file_put_contents($path, Http::getData('https://raw.githubusercontent.com/hotspotbilling/phpnuxbill/master/pages_template/'.$action.'.html'));
}
}else{
file_put_contents($path, Http::getData('https://raw.githubusercontent.com/hotspotbilling/phpnuxbill/master/pages_template/'.$action.'.html'));
}
r2(U . 'pages/'.$action);
}else if(strpos($action,"-post")===false){
$path = "pages/".str_replace(".","",$action).".html";
//echo $path;
run_hook('view_edit_pages'); #HOOK

View File

@ -355,7 +355,7 @@ $_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';
$_L['Buy_Balance'] = 'Buy Balance?';
$_L['Buy_Balance'] = 'Buy Balance';
$_L['Price'] = 'Price';
$_L['Validity'] = 'Validity';
$_L['Disable_auto_renewal'] = 'Disable auto renewal?';
@ -403,8 +403,8 @@ $_L['Deactivate'] = 'Deactivate';
$_L['Sync'] = 'Sync';
$_L['Failed_to_create_PaymeTrust_transaction'] = 'Failed to create PaymeTrust transaction.';
$_L['Location'] = 'Location';
$_L['Radius_Plans'] = 'Radius Plans';
$_L['Change_title_in_user_Plan_order'] = 'Change title in user Plan order';
$_L['Logs'] = 'Logs';
$_L['Voucher_Format'] = 'Voucher Format';
$_L['Resend_To_Customer'] = 'Resend To Customer';
$_L['Radius_Plans'] = 'Radius Plans';
$_L['Change_title_in_user_Plan_order'] = 'Change title in user Plan order';
$_L['Logs'] = 'Logs';
$_L['Voucher_Format'] = 'Voucher Format';
$_L['Resend_To_Customer'] = 'Resend To Customer';

View File

@ -355,7 +355,7 @@ $_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['Buy_Balance'] = 'Buy Balance?';
$_L['Buy_Balance'] = 'Buy Balance';
$_L['Price'] = 'Price';
$_L['Validity'] = 'Validity';
$_L['Disable_auto_renewal'] = 'Disable auto renewal?';

View File

@ -354,7 +354,7 @@ $_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['Buy_Balance'] = 'Buy Balance?';
$_L['Buy_Balance'] = 'Buy Balance';
$_L['Price'] = 'Price';
$_L['Validity'] = 'Validity';
$_L['Disable_auto_renewal'] = 'Disable auto renewal?';

View File

@ -330,7 +330,7 @@ $_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';
$_L['Buy_Balance'] = 'Buy Balance?';
$_L['Buy_Balance'] = 'Buy Balance';
$_L['Price'] = 'Price';
$_L['Validity'] = 'Validity';
$_L['Disable_auto_renewal'] = 'Disable auto renewal?';