PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/plugins/function.pager.php

http://pos-tracker-temar.googlecode.com/
PHP | 66 lines | 47 code | 13 blank | 6 comment | 20 complexity | 3156839f99d2f2f6c2f132e7f3a91b30 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
  1. <?php
  2. function smarty_function_pager($params, &$smarty)
  3. {
  4. $startnum = $params['startnum'];
  5. $numitems = $params['numitems'];
  6. // Going to be common so let's use it
  7. $searchphrase = $params['searchphrase'];
  8. if (!$numitems) {
  9. return null;
  10. }
  11. $max = $params['numitems'];
  12. $split = $params['limit'];
  13. $html = "<p><strong>[</strong> ";
  14. $endpage = ceil($max / $split);
  15. $page = Eve::VarCleanFromInput('page');
  16. $qstring = Eve::ServerGetVar('QUERY_STRING');
  17. $script = Eve::ServerGetVar('SCRIPT_NAME');
  18. //$script = substr($script, -1, strlen($script));
  19. if ($page) {
  20. $url = preg_replace("/&page=([0-9]?[0-9]?[0-9])/", "", $qstring);//return $url;
  21. if ($url == $qstring) { $url = preg_replace("/page=([0-9]?[0-9]?[0-9])/", "", $qstring); }
  22. } else {
  23. $url = $qstring;//urlencode($qstring);
  24. $page = 1;
  25. }
  26. //if (eregi('.html', $url)) {
  27. //$url = 'a='.Eve::SessionGetVar('kburl');
  28. //}
  29. // Fixing damn &amp; for validation
  30. $url = preg_replace("/&/", "&amp;", $url);
  31. for ($i = 1; $i <= $endpage; $i++) {
  32. if ($i != $page) {
  33. if ($i == 1 || $i == $endpage || (($i >= $page - 1 && $i <= $page + 1))) {
  34. if ($i != 1) {
  35. $html .= "<a href=\"".$script."?".$url.((empty($url)) ? "" : "&amp;")."page=".$i.((!empty($searchphrase)) ? "&amp;searchphrase=".urlencode($searchphrase) : "")."\" title=\"Page ".$i."\">".$i."</a>&nbsp;";
  36. } else {
  37. $html .= "<a href=\"".$script."?".$url."\" title=\"Page ".$i."\">".$i."</a>&nbsp;";
  38. }
  39. } elseif ($i < $page && !$dotted) {
  40. $dotted = true;
  41. $html .= "<strong>..&nbsp;</strong>";
  42. } elseif ($i > $page && !$ldotted) {
  43. $ldotted = true;
  44. $html .= "<strong>..&nbsp;</strong>";
  45. }
  46. } else {
  47. $html .= "<strong>".$i."</strong>&nbsp;";
  48. }
  49. }
  50. $html .= "<strong>]</strong></p>";
  51. return $html;
  52. }
  53. ?>