106 lines
3.8 KiB
PHP
106 lines
3.8 KiB
PHP
<?php
|
|
// 총계, 페이지당, 페이지당 및에 나오는 링크갯수, 오프셋, 옵션넘길거.
|
|
function pageNavigation($total,$scale,$pagescale,$offset,$opt_var){
|
|
$page= floor($offset/($scale*$pagescale));
|
|
|
|
if($total >= 1){
|
|
// 오프셋이 없거나 잘못되어 있을경우 초기화
|
|
if (empty($offset) || ($offset < 0) || ($offset > $total)) {
|
|
$offset=0;
|
|
}
|
|
|
|
// 처음 페이지
|
|
if($offset=="0"){
|
|
$link_array[][] = "<a class='direction first disabled' href='#'><span>처음페이지</span></a>";
|
|
}else{
|
|
$link_array[][] = "<a class='direction first' href=\"$_SERVER[DOCUMENT_URI]?$opt_var&offset=0\"><span>처음페이지</span></a>";
|
|
}
|
|
|
|
// 이전 scale 갯수의 페이지 설정
|
|
if($offset+1 > $scale*$pagescale){
|
|
$pre_page= $offset - $scale*$pagescale ;
|
|
//$link_array[][] = "<a class='direction prev' href=\"$_SERVER[DOCUMENT_URI]?$opt_var&offset=$pre_page\"><span>이전페이지</span></a>";
|
|
}
|
|
|
|
// 이전 1페이지 링크 설정
|
|
$prevoffset = 0;
|
|
if (($offset > 0) && ($offset <= $total)) {
|
|
$prevoffset = $offset - $scale;
|
|
$link_array[][] = "<a class='direction prev' href=\"$_SERVER[DOCUMENT_URI]?$opt_var&offset=$prevoffset\"><span>이전페이지</span></a>";
|
|
}else{
|
|
$link_array[][] = "<a class='direction prev disabled' href=\"$_SERVER[DOCUMENT_URI]?$opt_var&offset=$prevoffset\"><span>이전페이지</span></a>";
|
|
//$link_array[][] = "<img src='/common/images/button_page_prev.gif' border='0' align='absmiddle'>";
|
|
}
|
|
|
|
//$link_array[][] = " ";
|
|
|
|
// 목록 하단 페이지 링크 설정
|
|
$pages=intval($total/$scale);
|
|
if ($total % $scale) {
|
|
$pages++;
|
|
}
|
|
|
|
for($i=0; $i < $pagescale ; $i++){
|
|
$ln = ($page * $pagescale + $i)*$scale ;
|
|
$vk= $page * $pagescale + $i+1 ;
|
|
if($ln<$total){
|
|
if($ln!=$offset){
|
|
$link_array[][] = " <a href=\"$_SERVER[DOCUMENT_URI]?$opt_var&offset=$ln\">$vk</a> ";
|
|
}else{
|
|
$link_array[][] = " <strong>$vk</strong> ";
|
|
}
|
|
|
|
if($i != $pagescale-1 && $pages !=1){
|
|
//$link_array[][] = " ";
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//$link_array[][] = " ";
|
|
|
|
// 다음 1페이지 설정
|
|
// if (!(($offset/$scale)==$pages) && $pages!=1) {
|
|
if (!(($offset/$scale)==$pages)) {
|
|
$newoffset=$offset+$scale;
|
|
|
|
if((($total - $offset) > $scale) && ($pages !=1) && ($offset < $total)){
|
|
$link_array[][] = "<a class='direction next' href=\"$_SERVER[DOCUMENT_URI]?$opt_var&offset=$newoffset\"><span>다음페이지</span></a>";
|
|
}else{
|
|
$link_array[][] = "<a href='#' class='direction next disabled'><span>다음페이지</span></a>";
|
|
}
|
|
}
|
|
|
|
// 다음 scale 갯수의 페이지 설정
|
|
if($total > (($page+1)*$scale*$pagescale)){
|
|
$next_page= ($page+1)*$scale*$pagescale ;
|
|
//$link_array[][] = "<a class='direction next' href=\"$_SERVER[DOCUMENT_URI]?$opt_var&offset=$next_page\"><span>다음페이지</span></a>";
|
|
}
|
|
|
|
// 끝 페이지
|
|
$lastoffset = $total-($total%$scale);
|
|
if($lastoffset==$total){
|
|
$lastoffset=$lastoffset-$scale;
|
|
}
|
|
if($total > (($page+1)*$scale*$pagescale)){
|
|
$link_array[][] = "<a class='direction last' href=\"$_SERVER[DOCUMENT_URI]?$opt_var&offset=$lastoffset\"><span>마지막페이지</span></a>";
|
|
}else{
|
|
$link_array[][] = "<a class='direction last disabled' href='#'><span>마지막페이지</span></a>";
|
|
}
|
|
}else{
|
|
// 목록이 없을경우 표시안함.
|
|
;
|
|
}
|
|
|
|
// 위에서 받은 링크를 배열값으로 반환
|
|
//return $link_array;
|
|
for($t=0;$t<sizeof($link_array);$t++){
|
|
for($u=0;$u<sizeof($link_array[$t]);$u++){
|
|
echo $link_array[$t][$u] . "";
|
|
}
|
|
}
|
|
|
|
}// pageNavigation 종료
|
|
?>
|