* Release 0.1 - 17 de Abril de 2005
* em buenos Aires, Argentina
*/
/*
* Paginação - Paginaçãããão
* Realize um include do arquivo paginacao.php, e chame a função passando, ao menos, o número de resultados que quer paginar.
* Seria ideal utilizar CSS para este menu, mas, como está 100% abstraído, utilizei definições estáticas FONT
*/
function paginacao (
$numrows,
$link = '' ,
$limit = 20 ,
$pagelimit = 10 ,
$fontface = 'verdana' ,
$fontcolor = '#000000' ,
$fontsize = '2' ,
$fontfacelimit = 'verdana' ,
$fontcolorlimit = '#000000' ,
$fontsizelimit = '2' ,
$fontfacepagelimit = 'verdana' ,
$fontcolorpagelimit = '#000000' ,
$fontsizepagelimit = '2' ) {
if (!(is_numeric($numrows))) { return ''; } // Numrows passado não é numérico!
if ($numrows == 0) { return ''; } // 0 Resultados. Sem necessidade de paginar.
$pos1 = strpos($link,'?');
$link_separator = ($pos1 !== false) ? '&' : '?';
$offsets = (($numrows-1)/$limit);
$xpl = explode('.',$offsets);
$offsets = $xpl[0];
if ($offsets == 0) { return ''; } // Offsets = 0. Sem necessidade de paginar.
$offsets_chk = (isset($xpl[1])) ? true : false;
if ($offsets_chk === false) { $offsets++; }
$pageoffsets = (($offsets-1)/$pagelimit);
$xpl = explode('.',$pageoffsets);
$pageoffsets = $xpl[0];
$pageoffsets_chk = (isset($xpl[1])) ? true : false;
if ($pageoffsets >= 1) {
$havesubpaging = true;
if ($pageoffsets_chk === false) { $pageoffsets++; }
} elseif (!(isset($pageoffsets))) {
$pageoffsets = 0;
} else {
$pageoffsets = 0;
}
$offset = (is_numeric($_REQUEST['offset'])) ? $_REQUEST['offset'] : 0 ;
if (($offset > $offsets) || ($offset < 0)) { return ''; } // $_REQUEST['offset'] -> Injection? ;D
$pageoffset = $offset / $pagelimit;
$xpl = explode('.',$pageoffset);
$pageoffset = $xpl[0];
$offset_ini = $pageoffset * $pagelimit;
$offset = (is_numeric($_REQUEST['offset'])) ? $_REQUEST['offset'] : $offset_ini ;
for ( $w = $offset_ini; $w < $offset_ini + $pagelimit; $w++) {
if ($w > $offsets) { break; }
if ($w == $offset) {
$out .= '' . ($w + 1) . ' ';
} else {
$out .= '' . ($w + 1) . ' ';
}
}
if ($offset != 0) {
$out = '-' . ($limit) . ' ' . $out;
}
if ($offset != $offsets) {
$out = $out . '+' . ($limit) . ' ';
}
if ($havesubpaging) {
if ($pageoffset != 0) {
$out = '-' . ($pagelimit * $limit) . ' ' . $out;
}
if ($pageoffset != $pageoffsets) {
$out = $out . '+' . ($pagelimit * $limit) . ' ';
}
}
return $out;
}
/*
Exemplo:
if (!(isset($_REQUEST['numrows']))) { $_REQUEST['numrows'] = 123546; }
echo paginacao($_REQUEST['numrows'],'?numrows=' . $_REQUEST['numrows']);
*/
?>