pkg_search_results: rewrite of pagination

* Most of the PHP-code was moved to pkgfuncs.php to keep the template simple.

Signed-off-by: PyroPeter <abi1789@googlemail.com>
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
PyroPeter 2011-02-16 18:48:09 +01:00 committed by Lukas Fleischer
parent 0de4ce61be
commit 1fdecbd5a4
3 changed files with 46 additions and 69 deletions

View file

@ -328,19 +328,19 @@ blockquote.code {
text-decoration: none;
}
#pages { margin: 5px; }
#pages .page_num {
.page_nav {
margin: 5px 0;
}
.page_nav .page_num {
border: 1px solid #ddd;
padding: 2px;
color: #0771a6;
}
#pages .page_num:hover {
.page_nav .page_num:hover {
border: 1px solid #8faecd;
color: #333;
}
#pages #page_sel {
.page_nav .page_sel {
border: 1px solid #8faecd;
padding: 2px;
color: #333;

View file

@ -559,6 +559,32 @@ function pkg_search_page($SID="") {
if ($total > 1 || $total == 0) {
# calculation of pagination links
$per_page = ($_GET['PP'] > 0) ? $_GET['PP'] : 25;
$current = ceil($first / $per_page);
$pages = ceil($total / $per_page);
$templ_pages = array();
if ($current > 1) {
$templ_pages[__('First')] = 0;
$templ_pages[__('Previous')] = ($current - 2) * $per_page;
}
if ($current - 5 > 1)
$templ_pages["..."] = false;
for ($i = max($current - 5, 1); $i <= min($pages, $current + 5); $i++) {
$templ_pages[$i] = ($i - 1) * $per_page;
}
if ($current + 5 < $pages)
$templ_pages["... "] = false;
if ($current < $pages) {
$templ_pages[__('Next')] = $current * $per_page;
$templ_pages[__('Last')] = ($pages - 1) * $per_page;
}
include('pkg_search_form.php');
include('pkg_search_results.php');
}

View file

@ -113,73 +113,24 @@ for ($i = 0; $row = mysql_fetch_assoc($result); $i++) {
</td>
<td align='right'>
<span class='f4'><span class='blue'>
<div class="f4 blue">
<?php print __("Showing results %s - %s of %s", $first, $last, $total) ?>
</span></span>
<br />
<div id="pages">
<?php
if ($_GET['O'] > 0):
$O = $_GET['O'] - $_GET['PP'];
if ($_GET['O'] < $_GET['PP']) {
$O = 0;
}
?>
<a class="page_num" href="packages.php?<?php print mkurl("O=0") ?>"><?php echo __('First') ?></a>
<a class="page_num" href="packages.php?<?php print mkurl("O=$O") ?>"><?php echo __('Previous') ?></a>
<?php endif; ?>
<?php
if ($_GET['PP'] > 0) {
$pages = ceil($total / $_GET['PP']);
}
if ($pages > 1) {
if ($_GET['O'] > 0) {
$currentpage = ceil(($_GET['O'] + 1) / $_GET['PP']);
}
else {
$currentpage = 1;
}
$morepages = $currentpage + 5;
print (($currentpage-5) > 1) ? '...' : '';
# Display links for more search results.
for ($i = ($currentpage - 5); $i <= $morepages && $i <= $pages; $i++) {
if ($i < 1) {
$i = 1;
}
$pagestart = ($i - 1) * $_GET['PP'];
if ($i <> $currentpage) :
?>
<a class="page_num" href="packages.php?<?php print mkurl('O=' . ($pagestart)) ?>"><?php echo $i ?></a>
<?php else : echo "<span id=\"page_sel\">$i</span>";
endif;
}
print ($pages > $morepages) ? '...' : '';
?>
<?php if ($total - $_GET['PP'] - $_GET['O'] > 0): ?>
<a class="page_num" href='packages.php?<?php print mkurl('O=' . ($_GET['O'] + $_GET['PP'])) ?>'><?php echo __('Next') ?></a>
<a class="page_num" href='packages.php?<?php print mkurl('O=' . ($total - $_GET['PP'])) ?>'><?php echo __('Last') ?></a>
<?php endif; ?>
</div>
<div class="page_nav">
<?php foreach($templ_pages as $pagenr => $pagestart) { ?>
<?php if ($pagestart === false) { ?>
<?php echo $pagenr ?>
<?php } else if ($pagestart + 1 == $first) { ?>
<span class="page_sel"><?php echo $pagenr ?></span>
<?php } else { ?>
<a class="page_num" href="packages.php?<?php print mkurl('O=' . ( $pagestart)) ?>"><?php echo $pagenr ?></a>
<?php } ?>
<?php } ?>
</div>
</td>
</tr>
<?php
}
}
?>
<?php } ?>
</table>
</div>
</form>