00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 define('PN_PAGE', 'pn_page');
00023
00032 class PageNavigator
00033 {
00037 var $pageLength;
00038
00042 var $pageNumber;
00043
00047 var $pageLinks;
00048
00052 var $action;
00053
00057 var $queryRange;
00058
00062 var $rowCount;
00063
00067 var $pnCount;
00068
00072 var $showPageNo = false;
00073
00077 var $pageNo;
00078
00082 var $linktype;
00083
00087 var $aButtons;
00088
00092 var $aControls;
00093
00103 function PageNavigator($length = 20,
00104 $action = '?'
00105 )
00106 {
00107 $this->pageNumber = $_GET[PN_PAGE] ? $_GET[PN_PAGE] : $_POST[PN_PAGE];
00108 $this->pageLength = $length;
00109 $this->pnCount = $length;
00110
00111 $this->action = $action;
00112
00113 $this->queryRange = new QueryRange($this->pageNumber, $this->pageLength);
00114 $this->rowCount = $this->queryRange->total;
00115 $this->linktype = 'hyperlink';
00116 $aButtons = null;
00117 }
00118
00128 function SetAction($url)
00129 {
00130 $this->action = $url;
00131 }
00132
00142 function SetButtons($aButtons)
00143 {
00144 if (!is_array($aButtons))
00145 $aButtons = array($aButtons);
00146
00147 $this->aButtons = $aButtons;
00148 }
00149
00159 function SetControls($aControls)
00160 {
00161 if (!is_array($aControls))
00162 $aControls = array($aControls);
00163
00164 $this->aControls = $aControls;
00165 }
00166
00174 function SetShowPageNo()
00175 {
00176 $this->showPageNo = true;
00177 }
00178
00188 function SetLinkType($linktype)
00189 {
00190 $this->linktype = $linktype;
00191 }
00192
00200 function GetPageNo()
00201 {
00202 $this->pageNo = '[' . _M('Page') . ' ' . ($this->GetCurrentPage() + 1) . ' ' . _M('of') . ' '
00203 . $this->GetTotalPages() . "]";
00204 return ($this->pageNo);
00205 }
00206
00207 function &GetQueryRange()
00208 {
00209 return $this->queryRange;
00210 }
00211
00219 function GetTotalRows()
00220 {
00221
00222 return $this->rowCount;
00223 }
00224
00232 function GetCurrentPage()
00233 {
00234 return (int)$this->pageNumber;
00235 }
00236
00246 function SetCurrentPage($num)
00247 {
00248 $this->pageNumber = (int)$num;
00249
00250 $this->queryRange = new QueryRange($this->pageNumber, $this->pageLength);
00251 }
00252
00260 function GetTotalPages()
00261 {
00262 return (int)(($this->rowCount + $this->pageLength - 1) / $this->pageLength);
00263 }
00264
00272 function Generate()
00273 {
00274
00275 $rowCount = $this->rowCount;
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 $btn_first0 = '<img src="/images/but_pg_primeira.gif" border="0">';
00288 $btn_first1 = '<img src="/images/but_pg_primeira_x.gif" border="0">';
00289 $btn_prev0 = '<img src="/images/but_pg_anterior.gif" border="0">';
00290 $btn_prev1 = '<img src="/images/but_pg_anterior_x.gif" border="0">';
00291 $btn_next0 = '<img src="/images/but_pg_proxima.gif" border="0">';
00292 $btn_next1 = '<img src="/images/but_pg_proxima_x.gif" border="0">';
00293 $btn_last0 = '<img src="/images/but_pg_ultima.gif" border="0">';
00294 $btn_last1 = '<img src="/images/but_pg_ultima_x.gif" border="0">';
00295
00296 echo "<!-- PageNavigator -->\n";
00297 echo "<table class=\"pageNavigator\" align=\"center\">\n";
00298 echo " <tr>\n";
00299
00300 if ($this->pageNumber > 0)
00301 {
00302 if ($this->linktype == 'hyperlink')
00303 {
00304 echo " <td><a href=\"$this->action&" . PN_PAGE . "=0\">$btn_first1</a></td>\n";
00305 echo " <td><a href=\"$this->action&" . PN_PAGE . "=" . ($this->pageNumber
00306 - 1) . "\">$btn_prev1</a></td>\n";
00307 }
00308 else
00309 {
00310 $action = "$this->action&" . PN_PAGE . "=0";
00311 echo " <td><a href=\"javascript:_MIOLO_LinkButton(document.forms[0].name, '{$action}','')\">$btn_first1</a></td>\n";
00312 $action = "$this->action&" . PN_PAGE . "=" . ($this->pageNumber - 1);
00313 echo " <td><a href=\"javascript:_MIOLO_LinkButton(document.forms[0].name, '{$action}','')\">$btn_prev1</a></td>\n";
00314 }
00315 }
00316 else
00317 {
00318 echo " <td>$btn_first0</td>\n";
00319 echo " <td>$btn_prev0</td>\n";
00320 }
00321
00322
00323 $pageCount = (int)(($rowCount + $this->pageLength - 1) / $this->pageLength);
00324
00325 echo " <td width=\"100%\" align=\"center\">";
00326
00327 if ($pageCount >= 2)
00328 {
00329 if ($this->pageNumber < 10)
00330 {
00331 $o = 0;
00332 }
00333 else
00334 {
00335 $o = $this->pageNumber - 10;
00336
00337 if ($o > 0)
00338 {
00339 $this->pageLinks
00340 .= " <a class=\"pageNavigatorLink\" href=\"$this->action&" . PN_PAGE . "=" . ($o
00341 - 1)
00342 . "\">...</a> ";
00343 }
00344 }
00345
00346 for ($i = 0; $i < 11 && $o < $pageCount; $i++, $o++)
00347 {
00348 if ($i > 0)
00349 {
00350 $this->pageLinks .= " ";
00351 }
00352
00353 $p = $o + 1;
00354
00355 if ($o != $this->pageNumber)
00356 {
00357 if ($this->linktype == 'hyperlink')
00358 {
00359 $this->pageLinks
00360 .= "<a href=\"$this->action&" . PN_PAGE
00361 . "=$o\" class=\"pageNavigatorLink\" onMouseOver=\"top.status='". _M('Page') ." $p'\">$p</a>";
00362 }
00363 else
00364 {
00365 $action = "$this->action&" . PN_PAGE . "=$o";
00366 $this->pageLinks
00367 .= "<a href=\"javascript:_MIOLO_LinkButton(document.forms[0].name,'{$action}','')\" class=\"pageNavigatorLink\" onMouseOver=\"top.status='" . _M('Page') . " $p'\">$p</a>";
00368 }
00369 }
00370 else
00371 {
00372 $this->pageLinks .= "<span class=\"pageNavigatorSelected\">$p</span>";
00373 }
00374 }
00375
00376 if ($o < $pageCount)
00377 {
00378 $this->pageLinks
00379 .= " <a class=\"pageNavigatorLink\" href=\"$this->action&" . PN_PAGE . "=$p\">...</a>";
00380 }
00381
00382 if ($this->ShowPageNo)
00383 {
00384 echo $this->pageLinks;
00385 }
00386 }
00387 else
00388 {
00389 echo " ";
00390 }
00391
00392 if ($this->aButtons)
00393 {
00394 for ($i = 0; $i < count($this->aButtons); $i++)
00395 {
00396 echo $this->aButtons[$i]->Generate();
00397 echo " ";
00398 }
00399 }
00400
00401 if ($this->aControls)
00402 {
00403 for ($i = 0; $i < count($this->aControls); $i++)
00404 {
00405 echo $this->aControls[$i]->Generate();
00406 echo " ";
00407 }
00408 }
00409
00410 echo "</td>\n";
00411
00412 $maxRow = $this->pageNumber * $this->pageLength + $this->pageLength - 1;
00413
00414 if ($maxRow + 1 < $rowCount)
00415 {
00416 if ($this->linktype == 'hyperlink')
00417 {
00418 echo " <td><a href=\"$this->action&" . PN_PAGE . "=" . ($this->pageNumber
00419 + 1) . "\">$btn_next1</a></td>\n";
00420 echo " <td><a href=\"$this->action&" . PN_PAGE . "=" . ($pageCount - 1) . "\">$btn_last1</a></td>\n";
00421 }
00422 else
00423 {
00424 $action = "$this->action&" . PN_PAGE . "=" . ($this->pageNumber + 1);
00425 echo " <td><a href=\"javascript:_MIOLO_LinkButton(document.forms[0].name, '{$action}','')\">$btn_next1</a></td>\n";
00426 $action = "$this->action&" . PN_PAGE . "=" . ($pageCount - 1);
00427 echo " <td><a href=\"javascript:_MIOLO_LinkButton(document.forms[0].name, '{$action}','')\">$btn_last1</a></td>\n";
00428 }
00429 }
00430 else
00431 {
00432 echo " <td>$btn_next0</td>\n";
00433 echo " <td>$btn_last0</td>\n";
00434 }
00435
00436 echo " </tr>\n";
00437 echo " <tr>\n";
00438 echo " <td align=\"center\" colspan=\"5\" class=\"pageNavigatorText\">\n";
00439
00440 if ($this->showPageNo)
00441 {
00442 echo " " . $this->pageNo . "\n";
00443 }
00444
00445 echo " </td>\n";
00446 echo " </tr>\n";
00447 echo "</table>\n";
00448 }
00449 }
00450 ?>