fix admin pager for links list

master
Jean-Christian Paul Denis 2021-08-28 23:17:13 +02:00
parent f13814ff5e
commit ab9b5e9b6b
2 changed files with 101 additions and 98 deletions

View File

@ -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()) {
if ($filter) {
echo '<p><strong>' . __('No short link matches the filter') . '</strong></p>';
} else {
echo '<p><strong>' . __('No short link') . '</strong></p>';
}
} else {
$pager = new pager($page, $this->rs_count, $nb_per_page, 10);
$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;
}
}
$pager->base_url = $url;
$html_block =
'<table class="clear">' .
'<thead>' .
$blocks = explode('%s', sprintf($enclose_block,
'<div class="table-outer"><table>' .
($filter ?
'<caption>' . sprintf(__('List of %s links matching the filter.'), $this->rs_count) . '</caption>' :
'<caption>' . sprintf(__('List of links (%s)'), $this->rs_count) . '</caption>'
) .
'<tr>' .
'<th class="nowrap" colspan="2">' . __('Hash') . '</th>' .
'<th class="maximal">' . __('Link') . '</th>' .
'<th class="nowrap">' . __('Date') . '</th>' .
'<th class="nowrap">' . __('Service') . '</th>' .
'</tr>' .
'</thead>' .
'<tbody>%s</tbody>' .
'</table>';
'<th colspan="2" class="first">' . __('Hash') . '</th>' .
'<th scope="col">' . __('Link') . '</th>' .
'<th scope="col">' . __('Date') . '</th>' .
'<th scope="col">' . __('Service') . '</th>' .
'</tr>%s</table>%s</div>'
));
echo '<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>';
$blocks = explode('%s', $html_block);
echo $blocks[0];
echo $pager->getLinks().$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++;
}
echo $blocks[1];
echo '<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>';
}
}
private function line($url, $loop)
{
while ($this->rs->fetch()) {
$type = $this->rs->kut_type;
$hash = $this->rs->kut_hash;
if (null !== ($o = kutrl::quickService($this->rs->kut_type))) {
if (null !== ($o = kutrl::quickService($type))) {
$type = '<a href="' . $o->home . '" title="' . $o->name . '">' . $o->name . '</a>';
$hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
}
return
'<tr class="line">' . "\n" .
echo
'<tr class="line">' .
'<td class="nowrap">' .
form::checkbox(['entries[' . $loop . ']'], $this->rs->kut_id, 0) .
form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) .
'</td>' .
'<td class="nowrap">' .
$hash .
"</td>\n" .
'<td class="maximal">' .
'</td>' .
'<td class="maximal" scope="row">' .
'<a href="' . $this->rs->kut_url . '">' . $this->rs->kut_url . '</a>' .
"</td>\n" .
'<td class="nowrap">' .
'</td>' .
'<td class="nowrap count">' .
dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) .
"</td>\n" .
'</td>' .
'<td class="nowrap">' .
$type .
"</td>\n" .
'</tr>' . "\n";
'</td>' .
'</tr>';
}
echo $blocks[1].$blocks[2].$pager->getLinks();
}
}
}

View File

@ -237,14 +237,6 @@ if ($part == 'links') {
$show_filters = true;
}
$pager_base_url =
$p_url .
'&amp;urlsrv=' . $urlsrv .
'&amp;sortby=' . $sortby .
'&amp;order=' . $order .
'&amp;nb=' . $nb_per_page .
'&amp;page=%s';
try {
$list_all = $log->getLogs($params);
$list_counter = $log->getLogs($params, true)->f(0);
@ -532,13 +524,15 @@ if ($part == 'links') {
<p><input type="submit" value="' . __('Apply filters and display options') . '" />
<br class="clear" /></p>
</form>
</form>';
<form action="' . $p_url . '&amp;part=links" method="post" id="form-actions">';
$list_current->display(
$page,
$nb_per_page,
'<form action="' . $p_url . '&amp;part=links" method="post" id="form-actions">
$list_current->display($page, $nb_per_page, $pager_base_url);
%s
echo '
<div class="two-cols">
<p class="col checkboxes-helpers"></p>
<p class="col right">
@ -553,9 +547,11 @@ if ($part == 'links') {
$core->formNonce() . '
</p>
</div>
</form>';
</form>',
$show_filters
);
}
# display footer
dcPage::helpBlock('kUtRL');