From ab9b5e9b6b1de9b757bd90e5cd1f3aee812d8f29 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 28 Aug 2021 23:17:13 +0200 Subject: [PATCH] fix admin pager for links list --- inc/lib.kutrl.lst.php | 145 ++++++++++++++++++++++-------------------- index.php | 54 ++++++++-------- 2 files changed, 101 insertions(+), 98 deletions(-) diff --git a/inc/lib.kutrl.lst.php b/inc/lib.kutrl.lst.php index 03a008a..0f9a97c 100644 --- a/inc/lib.kutrl.lst.php +++ b/inc/lib.kutrl.lst.php @@ -11,79 +11,86 @@ # # -- END LICENSE BLOCK ------------------------------------ -class kutrlLinkslist extends adminGenericList +class kutrlLinkslist { - public function display($page, $nb_per_page, $url) + protected $core; + protected $rs; + protected $rs_count; + protected $html_prev; + protected $html_next; + + public function __construct(dcCore $core, $rs, $rs_count) + { + $this->core = &$core; + $this->rs = &$rs; + $this->rs_count = $rs_count; + $this->html_prev = __('« prev.'); + $this->html_next = __('next »'); + } + + public function display($page, $nb_per_page, $enclose_block, $filter = false) { if ($this->rs->isEmpty()) { - echo '

' . __('No short link') . '

'; - } else { - $pager = new pager($page, $this->rs_count, $nb_per_page, 10); - - $pager->base_url = $url; - - $html_block = - '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . - '' . - '%s' . - '
' . __('Hash') . '' . __('Link') . '' . __('Date') . '' . __('Service') . '
'; - - echo '

' . __('Page(s)') . ' : ' . $pager->getLinks() . '

'; - $blocks = explode('%s', $html_block); - echo $blocks[0]; - - $this->rs->index(((integer)$page - 1) * $nb_per_page); - $iter = 0; - while ($iter < $nb_per_page) { - - echo $this->line($url,$iter); - - if ($this->rs->isEnd()) { - break; - } else { - $this->rs->moveNext(); - } - $iter++; + if ($filter) { + echo '

' . __('No short link matches the filter') . '

'; + } else { + echo '

' . __('No short link') . '

'; } - echo $blocks[1]; - echo '

' . __('Page(s)') . ' : ' . $pager->getLinks() . '

'; + } else { + $pager = new dcPager($page, $this->rs_count, $nb_per_page, 10); + $entries = []; + if (isset($_REQUEST['entries'])) { + foreach ($_REQUEST['entries'] as $v) { + $entries[(integer) $v] = true; + } + } + + $blocks = explode('%s', sprintf($enclose_block, + '
' . + ($filter ? + '' : + '' + ) . + '' . + '' . + '' . + '' . + '' . + '%s
' . sprintf(__('List of %s links matching the filter.'), $this->rs_count) . '' . sprintf(__('List of links (%s)'), $this->rs_count) . '
' . __('Hash') . '' . __('Link') . '' . __('Date') . '' . __('Service') . '
%s
' + )); + + echo $pager->getLinks().$blocks[0]; + + while ($this->rs->fetch()) { + $type = $this->rs->kut_type; + $hash = $this->rs->kut_hash; + + if (null !== ($o = kutrl::quickService($type))) { + $type = '' . $o->name . ''; + $hash = '' . $hash . ''; + } + + echo + '' . + '' . + form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) . + '' . + '' . + $hash . + '' . + '' . + '' . $this->rs->kut_url . '' . + '' . + '' . + dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) . + '' . + '' . + $type . + '' . + ''; + } + + echo $blocks[1].$blocks[2].$pager->getLinks(); } } - - private function line($url, $loop) - { - $type = $this->rs->kut_type; - $hash = $this->rs->kut_hash; - - if (null !== ($o = kutrl::quickService($this->rs->kut_type))) { - $type = '' . $o->name . ''; - $hash = '' . $hash . ''; - } - - return - '' . "\n" . - '' . - form::checkbox(['entries[' . $loop . ']'], $this->rs->kut_id, 0) . - '' . - '' . - $hash . - "\n" . - '' . - '' . $this->rs->kut_url . '' . - "\n" . - '' . - dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) . - "\n" . - '' . - $type . - "\n" . - '' . "\n"; - } } \ No newline at end of file diff --git a/index.php b/index.php index 7c7c683..2c8d4c4 100644 --- a/index.php +++ b/index.php @@ -237,14 +237,6 @@ if ($part == 'links') { $show_filters = true; } - $pager_base_url = - $p_url . - '&urlsrv=' . $urlsrv . - '&sortby=' . $sortby . - '&order=' . $order . - '&nb=' . $nb_per_page . - '&page=%s'; - try { $list_all = $log->getLogs($params); $list_counter = $log->getLogs($params, true)->f(0); @@ -532,30 +524,34 @@ if ($part == 'links') {


- - -
'; - - $list_current->display($page, $nb_per_page, $pager_base_url); - - echo ' -
-

-

- ' . - form::hidden(['deletelinks'], 1) . - form::hidden(['urlsrv'], $urlsrv) . - form::hidden(['sortby'], $sortby) . - form::hidden(['order'], $order) . - form::hidden(['page'], $page) . - form::hidden(['nb'], $nb_per_page) . - form::hidden(['part'], 'links') . - $core->formNonce() . ' -

-
'; + $list_current->display( + $page, + $nb_per_page, + '
+ + %s + +
+

+

+ ' . + form::hidden(['deletelinks'], 1) . + form::hidden(['urlsrv'], $urlsrv) . + form::hidden(['sortby'], $sortby) . + form::hidden(['order'], $order) . + form::hidden(['page'], $page) . + form::hidden(['nb'], $nb_per_page) . + form::hidden(['part'], 'links') . + $core->formNonce() . ' +

+
+
', + $show_filters + ); } + # display footer dcPage::helpBlock('kUtRL');