<?php

$param = $option['param'];

if ($param) {
    $pass = '&';

    foreach ($param as $key => $value) {
        $pass .= "$key=$value&";
    }
}

$title     = $option['paginate_title'];
$counter   = (int) $option['counter'];
$limit     = (int) $option['limit'];
$totalrow  = (int) $option['totalrow'];
$type      = (int) $option['type'];
$splitpage = ceil($totalrow / $limit);

$html = '';

if ($counter != 0) {
    $prv = $counter - 1;
    $url = $option['url'] . '/' . $prv . '/' . $pass;
    $html .= "<a href='" . $url . "' onclick='return paginate(" . $prv . ",this)' title='" . $title . "' class=$css1>Prev</a>
		<span class=paginate_np>|&nbsp;</span>";
} else {
    $html .= '<span class=paginate_np>Prev&nbsp;|&nbsp;</span>';
}



$iof       = floor($counter / $limit) * $limit;
$next      = $counter + 1;
$totalrow2 = ceil($totalrow / $limit) - 1;
$limitone  = $iof + $limit;
$splitpage = ceil($totalrow / $limit);

if ($splitpage > $limit) {
    if ($limitone > $splitpage) {
        $limitof = $splitpage;
    } else {
        $limitof = $limitone;
    }
} else {
    $limitof = $splitpage;
}

if ($counter) {
    $limitof++;
    $iof--;
}

$lastpage = $totalrow2 + 1;



for ($i = $iof,$i1 = 0;$i < $limitof; $i++,$i1++) {
    $pages = $i + 1;

    if ($pages && $i < $lastpage) {
        $label = '&nbsp;|&nbsp;';
        $url   = $option['url'] . '/' . $i . '/' . $pass;

        if ($i != $counter) {
            $html .= "<a href='" . $url . "' onclick='return paginate(" . $i . ",this)' title='" . $title . "' class=$css1>" . $pages . '</a>
				<span class=paginate_np>' . $label . '</span>';
        } else {
            $html .= "<span class=$css>" . $pages . '</span><span class=paginate_np>' . $label . '</span>';
        }
    }
}//end of for




if ($splitpage > ($limit + 1)) {
    if ($counter == $totalrow2) {
        $html .= '.......<span class=text_jobsector>' . $splitpage . '</span><span class=text_jobsector>' . $label . '</span>';
    } else {
        $url = $option['url'] . '/' . $totalrow2 . '/' . $pass;
        $html .= "......<a href='" . $url . "' title='" . $title . "' onclick='return paginate(" . $totalrow2 . ",this)'   class=$css1>" . $splitpage . '</a><span class=text_jobsector>' . $label . '</span>';
    }
}

//----------------next
if ($counter < $totalrow2) {
    $url = $option['url'] . '/' . $next . '/' . $pass;
    $html .= "<a href='" . $url . "'  title='" . $title . "' onclick='return paginate(" . $next . ",this)' class=$css1>Next</a>";
} else {
    $html .= '<span class=paginate_np>Next</span>';
}
echo $html;
