PageRenderTime 57ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/class/pagination_class_front_ajax.php

https://bitbucket.org/itoxable/chiron-gaming
PHP | 269 lines | 173 code | 63 blank | 33 comment | 30 complexity | 03ae655c68e86f03ce8a15922ec1cd80 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?
  2. /*
  3. * Sportsbetting Version 1
  4. * PaginationClassFrontAjaxSports Class
  5. * @desc class to pagination in ajax operation
  6. */
  7. class PaginationClassFrontAjax
  8. {
  9. var $item_per_page; # Variable Integer item_per_page.
  10. var $shift_page_no; # Variable Integer shift_page_no.
  11. var $display_page_no; # Variable Integer display_page_no.
  12. var $next_text; # Variable String next_text.
  13. var $previous_text; # Variable String previous_text.
  14. var $ERROR = ""; # Variable String ERROR.
  15. /*
  16. Clear error message.
  17. */
  18. function clear_error()
  19. {
  20. $this->ERROR = "";
  21. }
  22. /*
  23. * Construct the PaginationClassFrontAjaxSports object.
  24. *
  25. *
  26. * @access public
  27. * @param Integer item_per_page
  28. * @param Integer display_page_no
  29. * @param Integer shift_page_no
  30. * @param String next_text
  31. * @param String previous_text
  32. * @return mixed Error object or string
  33. */
  34. function PaginationClassFrontAjax($item_per_page,$display_page_no,$shift_page_no,$next_text="",$previous_text="")
  35. {
  36. $this->item_per_page=$item_per_page;
  37. $this->shift_page_no=$shift_page_no;
  38. $this->display_page_no=$display_page_no;
  39. $this->next_text=$next_text;
  40. $this->previous_text=$previous_text;
  41. }
  42. /*
  43. * Function the PaginationFrontAjax.
  44. *
  45. *
  46. * @access public
  47. * @param String function_name
  48. * @param String sql
  49. * @param String page_name
  50. * @param Integer CategoryID
  51. * @param String CategoryName
  52. * @return array
  53. */
  54. function PaginationFrontAjax($function_name,$sql,$page_name,$CategoryID="",$CategoryName="")
  55. {
  56. global $from;
  57. global $from_page;
  58. if(empty($from))
  59. {
  60. $from=0;
  61. }
  62. if(empty($from_page))
  63. {
  64. $from_page=1;
  65. }
  66. if(!empty($CategoryID))
  67. $category_link="&$CategoryName=".$CategoryID;
  68. $totrec=mysql_num_rows(mysql_query($sql));
  69. if($totrec>0)
  70. {
  71. if($totrec>$this->item_per_page)
  72. {
  73. $prev=$from-$this->item_per_page;
  74. $next=$from+$this->item_per_page;
  75. if($totrec-($this->item_per_page*$this->display_page_no) && $from_page>1)
  76. {
  77. $navigation.= "<li class='previous'><a href='#' onClick=\"$function_name('$page_name&from=".$from."&from_page=".($from_page-$this->shift_page_no).$category_link."');return false;\" >".$this->previous_text."</a></li>";
  78. }
  79. else
  80. {
  81. $navigation.= "";
  82. }
  83. for($i=1; $i<=ceil($totrec/$this->item_per_page);$i++)
  84. {
  85. if($i>=$from_page && $i<=($from_page+$this->display_page_no-1))
  86. {
  87. $num_len=strlen($i);
  88. if((($from/$this->item_per_page)+1)==$i)
  89. {
  90. $navigation.= "<li><a href='#' onClick=\"$function_name('$page_name&from=".$startval."&from_page=".$from_page.$category_link."'); return false;\" class='select'>".$i."</a></li>";
  91. }
  92. else
  93. {
  94. $startval=($i-1)*$this->item_per_page;
  95. $navigation.= "<li><a href='#' onClick=\"$function_name('$page_name&from=".$startval."&from_page=".$from_page.$category_link."');return false;\" >".$i."</a></li>";
  96. }
  97. }
  98. }
  99. if($totrec-($this->item_per_page*$this->display_page_no) && ($totrec>(($from_page+$this->display_page_no-1)*$this->item_per_page)))
  100. {
  101. $navigation.= "<li class='next'><a href='#' onClick=\"$function_name('$page_name&from=".$from."&from_page=".($from_page+$this->shift_page_no).$category_link."');return false;\" >".$this->next_text."</a></li>";
  102. }
  103. else
  104. {
  105. $navigation.= "&nbsp;";
  106. }
  107. }
  108. }
  109. $limit_sql=" LIMIT $from , ".$this->item_per_page;
  110. $sql=$sql.$limit_sql;
  111. $num=mysql_num_rows(mysql_query($sql));
  112. $totalrecord="<span style='font:normal 10px/13px Verdana, Arial, Helvetica, sans-serif;'>Showing ".($from+1)." To ".($from+$num)."</span>";
  113. $return_arr=array($sql,$navigation,$totalrecord,$totrec);
  114. return $return_arr;
  115. }
  116. function PaginationFrontAjaxALL($function_name,$sql,$page_name,$CategoryID="",$CategoryName="",$link="",$totalText='')
  117. {
  118. global $from;
  119. global $from_page;
  120. $navigation1 = array();
  121. if(empty($from))
  122. {
  123. $from=0;
  124. }
  125. if(empty($from_page))
  126. {
  127. $from_page=1;
  128. }
  129. if(!empty($CategoryID))
  130. $category_link="&$CategoryName=".$CategoryID;
  131. if(!empty($link))
  132. $link = ",'$link'";
  133. $totrec=mysql_num_rows(mysql_query($sql));
  134. if($this->display_page_no%2==0)
  135. {
  136. $diff=ceil(ceil($this->display_page_no/2)/2);
  137. }
  138. else
  139. {
  140. $diff=ceil(ceil($this->display_page_no/2)/2);
  141. }
  142. if($totrec>0)
  143. {
  144. if($totrec>$this->item_per_page)
  145. {
  146. $prev=$from-$this->item_per_page;
  147. $next=$from+$this->item_per_page;
  148. if($totrec-($this->item_per_page*$this->display_page_no) && $from_page>1)
  149. {
  150. $navigation.= "<li><a href='#' onclick=\"$function_name('$page_name&action=list_paginate&from=".$from."&amp;from_page=".($from_page-$this->shift_page_no).$category_link."')\" >Prev</a></li>";
  151. }
  152. else
  153. {
  154. $navigation.= "";
  155. }
  156. for($i=1; $i<=ceil($totrec/$this->item_per_page);$i++)
  157. {
  158. if($i>=$from_page && $i<=($from_page+$this->display_page_no-1))
  159. {
  160. $num_len=strlen($i);
  161. if((($from/$this->item_per_page)+1)==$i)
  162. {
  163. $navigation.= "<li><a href='#' class='pageselect'>".$i."</a></li> ";
  164. }
  165. else
  166. {
  167. $startval=($i-1)*$this->item_per_page;
  168. $navigation.= "<li><a href='#' onclick=\"$function_name('$page_name&action=list_paginate&amp;from=".$startval."&amp;from_page=".$from_page.$category_link."'); return false;\" >".$i."</a></li> ";
  169. }
  170. }
  171. }
  172. if($totrec-($this->item_per_page*$this->display_page_no) && ($totrec>(($from_page+$this->display_page_no-1)*$this->item_per_page)))
  173. {
  174. $navigation.= "<li><a href='#' onClick=\"$function_name('$page_name&action=list_paginate&from=".$from."&amp;from_page=".($from_page+$this->shift_page_no).$category_link."')\" >Next</a></li>";
  175. }
  176. else
  177. {
  178. $navigation.= " ";
  179. }
  180. }
  181. }
  182. $limit_sql=" LIMIT $from , ".$this->item_per_page;
  183. $sql=$sql.$limit_sql;
  184. $num=mysql_num_rows(mysql_query($sql));
  185. //$totalrecord="<b>Total Records:</b> ".$totrec." <b><br>(Showing</b> ".($from+1)." <b>To</b> ".($from+$num)."<b>)</b> ";
  186. $totalrecord = "Displaying <b>".($from+1)."</b> - <b>".($from+$num)."</b> of <b>".$totrec."</b> Results";
  187. $return_arr=array($sql,$navigation,$totalrecord,$totrec);
  188. return $return_arr;
  189. }
  190. function PaginationFormFrontAjax($select_box_id)
  191. {
  192. $ItemPerPageArr=array(2,5,10,15,20,25,50);
  193. $PaginationFormStr="<select name='$select_box_id' id='$select_box_id'>";
  194. for($i=0;$i<count($ItemPerPageArr);$i++)
  195. {
  196. if($_SESSION['item_per_page_session']==$ItemPerPageArr[$i])
  197. $OptionSelected="Selected";
  198. else
  199. $OptionSelected="";
  200. $PaginationFormStr .="<option value='".$ItemPerPageArr[$i]."' $OptionSelected >".$ItemPerPageArr[$i]."</option>";
  201. }
  202. $PaginationFormStr .="</select>";
  203. return $PaginationFormStr;
  204. }
  205. }
  206. ?>