PageRenderTime 47ms CodeModel.GetById 11ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 1ms

/nnpclass.php

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