PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/nnpclass.php

https://github.com/joodtelecom/opencallshop
PHP | 273 lines | 249 code | 22 blank | 2 comment | 50 complexity | 9e7160e6529e25bbc9b7b0c279b576c1 MD5 | raw file
  1. <?
  2. class npp {
  3. var $page;
  4. var $limit;
  5. var $startof;
  6. var $totalrecords;
  7. var $row;
  8. var $last;
  9. var $start;
  10. var $sql;
  11. var $lang=array();
  12. function show($op,$nopages,$url="") {
  13. //Set vars
  14. $this->lang = $this->lang();
  15. $this->NumberOfPagesToShow = $nopages;
  16. $this->start = $this->start();
  17. $this->last = $this->last();
  18. // Do The Work!
  19. if ($this->totalrecords > $this->limit) {
  20. $search = array(
  21. "#\{H\}#is",
  22. "#\{A\}#is",
  23. "#\{P\}#is",
  24. "#\{F\}#is",
  25. "#\{L\}#is",
  26. "#\{R\}#is",
  27. "#\{N\}#is",
  28. "#\{E\}#is",
  29. "#\{S\}#is",
  30. );
  31. $replace = array(
  32. $this->printheader(),
  33. $this->NumberOfPages(),
  34. $this->pages(),
  35. $this->firstpage(),
  36. $this->lastpage(),
  37. $this->prevpage(),
  38. $this->nextpage(),
  39. $this->BuildExtra(),
  40. $this->select(),
  41. );
  42. $op=preg_replace($search, $replace, $op);
  43. $checked = $this->CheckUrl($url);
  44. $op = str_replace("{url}",$checked['url'],$op);
  45. $op = str_replace("{chr}",$checked['chr'],$op);
  46. return $op;
  47. }// * End : if ($this->totalrecords > $this->limit)
  48. }//## End : function show($op,$url,$chr,$nopages)
  49. function BuildExtra(){
  50. $pages = ceil($this->totalrecords/$this->limit);
  51. for ($i=1;$i<=$pages;$i++) {
  52. $newoffset = $this->limit * ($i-1);
  53. $to = $newoffset + $this->limit ;
  54. if ($to > $this->totalrecords ) {
  55. $to = $this->totalrecords;
  56. } // End of :if ($to > $this->totalrecords )
  57. $from = $newoffset;
  58. if ($from==0) {
  59. $from=1;
  60. } // End of :if ($from==0)
  61. if (!$i == 1) {
  62. $from=$from+1;
  63. } // End of : if (!$i == 1) {
  64. if($this->page != $i ) {
  65. $after=($this->page+($this->NumberOfPagesToShow+1));
  66. $befor=($this->page-($this->NumberOfPagesToShow+1));
  67. if(($i<$after) && ($i>$befor)) {
  68. if ((empty($this->page)) && ($i==1)) {
  69. $result .="<b><font color=\"blue\" size=\"4\"> (".$from."- ".$to.") &nbsp;</b></font>";
  70. } else {
  71. $url = $this->CheckPageOne($i);
  72. $result .="<a href=\"".$url."\">(".$from."-".$to." )</a> &nbsp;"; }
  73. } // End : if ((empty($this->page)) && ($i==1))
  74. } //End of : if(($i<$after) && ($i>$befor))
  75. else {
  76. $result .="<b><font color=\"blue\" size=\"4\"> (".$from."-".$to." ) &nbsp;</b></font>";
  77. } // End : if($this->page != $i )
  78. } // End : for ($i = 1; $i <= $pages; $i++)
  79. return $result;
  80. }//## End : function BuildExtra(
  81. function set($page,$limit,$totalrecords) {
  82. $this->page = $page;
  83. $this->limit = $limit;
  84. $this->totalrecords = $totalrecords;
  85. $this->CheckPage();
  86. $this->sqllimit();
  87. }//## End : function set
  88. function sql() {
  89. return $this->sql;
  90. }//## End : function sql()
  91. function row() {
  92. return $this->row;
  93. }//## End : function row()
  94. function CheckPage() {
  95. if ((empty($this->page)) || ((!is_numeric($this->page)))) {
  96. $this->page=0;
  97. } else {
  98. $this->page=intval($this->page);
  99. if($this->page > $this->allpages()) {
  100. $this->page=$this->allpages();
  101. } else {
  102. $this->page=$this->page;
  103. }
  104. }
  105. return $this->page;
  106. }//## End of : function CheckPage
  107. function sqllimit() {
  108. if ($this->page <= 1){
  109. $sql_limit="0,".$this->limit." ";
  110. $row=0;
  111. } else {
  112. $this->startof = $this->limit*($this->page-1);
  113. $sql_limit = " ".$this->startof." , ".$this->limit." ";
  114. $row=$this->startof;
  115. }
  116. $this->sql = $sql_limit;
  117. $this->row = $row;
  118. } //## End of : function sqllimit()
  119. function start () {
  120. return $this->start = $this->row+1;
  121. }//## End : function start
  122. function last () {
  123. $this->last = $this->startof + $this->limit;
  124. if ($this->last > $this->totalrecords) {
  125. $this->last = $this->totalrecords ;
  126. }// End of : if ($last > $totalRecords) {
  127. return $this->last;
  128. }//##End : function last ()
  129. function NumberOfPages() {
  130. return $this->lang[PAGES]." (".$this->allpages().") : ";
  131. }
  132. function printheader() {
  133. return $this->lang[SHOW_RESULTS]." (".$this->start.") ".$this->lang[TO]." (".$this->last.") ".$this->lang[TOTAL]." (".$this->totalrecords.")<br>" ;
  134. }//##End : function printheader
  135. function firstpage() {
  136. $isfirst =ceil($this->totalrecords/$this->limit);
  137. if (($isfirst>5) && (!empty($this->page))) {
  138. return "<a href=\"{url}\"><font color=blue><b>".$this->lang[FIRST_PAGE]."</a>&nbsp;&nbsp;</font></b>";
  139. }
  140. }//## End : function firstpage ()
  141. function lastpage() {
  142. $url ="{url}";
  143. $islast = ceil($this->totalrecords/$this->limit);
  144. if ($islast > 5 ) {
  145. $this->last=($this->limit*$islast)-$this->limit;
  146. if ($this->page < $this->allpages()) {
  147. $url .= "{chr}page=".$islast."";
  148. $result = "<a href=\"".$url."\">".$this->lang[LAST]."</a>&nbsp;&nbsp;";
  149. } // End of : if ($this->page < $this->allpages())
  150. } // End of : if ($islast > 5 )
  151. return $result;
  152. }//## End : function lastpage()
  153. function allpages() {
  154. return ceil($this->totalrecords/$this->limit);
  155. }//##End: function allpages()
  156. function prevpage() {
  157. $url ="{url}";
  158. if ($this->page != 0) {
  159. $prevpage = ($this->startof/$this->limit);
  160. if(($this->page-1) >=2) {
  161. $url .="{chr}page=$prevpage";
  162. }
  163. $result = "<a href=\"".$url."\">".$this->lang[PREV]." </a> &nbsp;";
  164. }
  165. return $result;
  166. }//## End:function prevpage(
  167. function nextpage() {
  168. $url ="{url}";
  169. if ($this->page < $this->allpages()) {
  170. $nextpage = ($this->startof/$this->limit)+2;
  171. $url .="{chr}page=$nextpage";
  172. $result ="<a href=\"".$url."\">".$this->lang[NEXT]."</a> &nbsp;";
  173. } // End of :if ($this->page < $this->allpages())
  174. return $result;
  175. }//## End :function nextpage
  176. function select(){
  177. $url ="{url}";
  178. $result .= "<form method=\"get\">
  179. <select name=\"page\" onchange='window.location.href=this.options[this.selectedIndex].value'>
  180. <option selected>".$this->lang[CHOOSE]."
  181. ";
  182. $pages = ceil($this->totalrecords/$this->limit);
  183. for ($i=1;$i<=$pages;$i++) {
  184. if(($this->page == $i) || ( ($i==1) && (empty($this->page))) ) {
  185. $result .= "<option style=\"color: #FF0000\" value=\"".$url."\">-(".$i." >".$this->allpages().")-</option></style>";
  186. } else {
  187. $url =$this->CheckPageOne($i);
  188. $result .= "<option value=\"".$url."\">".$i." >".$this->allpages()."</option>";
  189. }
  190. }
  191. $result .="</select></form>";
  192. return $result;
  193. }//## End : function select()
  194. function CheckPageOne($i){
  195. if ($i!==1) {
  196. return "{url}{chr}page=$i";
  197. } else {
  198. return "{url}";
  199. }
  200. }//## End : function CheckPageOne
  201. function pages(){
  202. $pages = floor($this->totalrecords/$this->limit);
  203. for ($i=1;$i<=$pages+1;$i++) {
  204. if($this->page != $i ) {
  205. $after=($this->page+($this->NumberOfPagesToShow));
  206. $befor=($this->page-($this->NumberOfPagesToShow));
  207. if($i<$after && $i>$befor) {
  208. if((empty($this->page)) && ($i==1)) {
  209. $pagelist .="<b><font color=\"blue\" size=\"4\">&nbsp;".$i."&nbsp;</b></font>|";
  210. } else {
  211. $url =$this->CheckPageOne($i);
  212. $pagelist .="&nbsp;<a href=\"".$url."\" style='text-decoration: none; font-family:\"Microsoft Sans Serif\"; font-size:12px; color:#646464;'>".$i."</a>&nbsp;|";
  213. }// End :if(empty($page) && $i==1) {
  214. } // End of : if ($i < $b && $i > $a)
  215. } // End of : if ($page != $i)
  216. else
  217. {
  218. $pagelist .="<b><font color=\"blue\" size=\"4\">&nbsp;".$i."&nbsp;</b></font>|";
  219. } // End of : else
  220. } // End of : for ($i = 2; $i <= $pages; $i++)
  221. return $pagelist;
  222. }//## End : function pages()
  223. function lang(){
  224. return array(
  225. 'SHOW_RESULTS'=> 'Showing results from' ,
  226. 'TO'=> 'to',
  227. 'TOTAL'=>'of total',
  228. 'FIRST_PAGE'=> '<img src="images/resultset_first.png" border=0 alt="First page" />',
  229. 'PREV'=> '<img src="images/resultset_previous.png" border=0 alt="Previous page" />',
  230. 'NEXT'=>'<img src="images/resultset_next.png" border=0 alt="Next page" />',
  231. 'PAGES'=> '<br /><img src="images/page_white_copy.png" /> Pages',
  232. 'LAST'=>'<img src="images/resultset_last.png" border=0 alt="Last page" />',
  233. 'CHOOSE'=>'Choose page',
  234. );
  235. } //## End : function lang()
  236. function CheckUrl($url){
  237. if(empty($url)) {
  238. $url = $_SERVER['PHP_SELF'];
  239. $chr="?";
  240. } else {
  241. if(strpos($url,"?")===false) {
  242. $url = "?".$url;
  243. } else {
  244. $url = $url;
  245. }
  246. $chr="&";
  247. }
  248. return array("url"=>$url,"chr"=>$chr);
  249. }//## End : function CheckUrl($url)
  250. }//@@ End of class
  251. ?>