blob: 86b3a50cceb1b0276e757a45189b2fa8ab55a7b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
<?php
/* -----------------------------------------------------------------------------
class name: pages_navigation
class version: 1.0
date: 2007-11-17
------------------------------------------------------------------------------
author: grum at grum.dnsalias.com
<< May the Little SpaceFrog be with you >>
------------------------------------------------------------------------------
this classes provides base functions to manage pages navigation
- constructor pages_navigation($url)
- (public) function set_nb_items($nbitems)
- (public) function get_nb_items()
- (public) function set_nb_items_per_page($nbitems)
- (public) function get_nb_items_per_page()
- (public) function get_nb_pages()
- (public) function set_current_page($page)
- (public) function get_current_page()
- (public) function set_base_url($url)
- (public) function get_base_url()
- (public) function make_navigation()
- (public) function make_navigation_function()
- (private) function calc_nb_pages()
---------------------------------------------------------------------- */
class pages_navigation
{
var $nbitems;
var $nbitemsperpages;
var $nbpages;
var $currentpage;
var $baseurl;
var $pagevarurl;
var $options;
function pages_navigation()
{
$this->nbitems=0;
$this->nbitemsperpages=0;
$this->nbpages=0;
$this->currentpage=0;
$this->baseurl='';
$this->pagevarurl='';
$this->options=array(
'prev_next' => true,
'first_last' => true,
'display_all' => true,
'number_displayed' => 2 //number of page displayed before and after current page
);
}
/*
define value for total number of items
*/
function set_nb_items($nbitems)
{
if($nbitems!=$this->nbitems)
{
$this->nbitems=$nbitems;
$this->calc_nb_pages();
}
return($nbitems);
}
function get_nb_items()
{
return($nbitems);
}
/*
define value for number of items displayed per pages
*/
function set_nb_items_per_page($nbitems)
{
if(($nbitems!=$this->nbitemsperpages)&&($nbitems>0))
{
$this->nbitemsperpages=$nbitems;
$this->calc_nb_pages();
}
return($this->nbitemsperpages);
}
function get_nb_items_per_page()
{
return($this->nbitemsperpages);
}
/*
return numbers of pages
*/
function get_nb_pages()
{
return($this->nbpages);
}
/*
define the current page number
*/
function set_current_page($page)
{
if(($page!=$this->currentpage)&&($page<=$this->nbpages)&&($page>0))
{
$this->currentpage=$page;
}
return($this->currentpage);
}
/*
returns the current page number
*/
function get_current_page()
{
return($this->currentpage);
}
/*
define the value for url
ex: "http://mysite.com/admin.php?var1=xxx&var2=xxx"
*/
function set_base_url($url)
{
if($url!=$this->baseurl)
{
$this->baseurl=$url;
}
return($this->baseurl);
}
function get_base_url()
{
return($this->baseurl);
}
/*
define the value for variables's name
ex: url = "http://mysite.com/admin.php?var1=xxx&var2=xxx"
pagevar = "pagenumber"
url made is "http://mysite.com/admin.php?var1=xxx&var2=xxx&pagenumber=xxx"
*/
function set_pagevar_url($var)
{
if($var!=$this->pagevarurl)
{
$this->pagevarurl=$var;
}
return($this->pagevarurl);
}
function get_pagevar_url()
{
return($this->pagevarurl);
}
/*
returns an html formatted string
*/
function make_navigation($functionname='')
{
$text='';
if(($this->options['display_all'])||($this->options['number_displayed']>=$this->nbpages))
{
for($i=1;$i<=$this->nbpages;$i++)
{
if($i!=$this->currentpage)
{
if($functionname=='')
{
$text.='<a href="'.$this->baseurl.'&'.$this->pagevarurl.'='.$i.'">'.$i.'</a> ';
}
else
{
$text.='<a style="cursor:pointer;" onclick="'.$functionname.'('.$i.');">'.$i.'</a> ';
}
}
else
{
$text.=$i.' ';
}
}
}
else
{
for($i=$this->currentpage-$this->options['number_displayed'];$i<=$this->currentpage+$this->options['number_displayed'];$i++)
{
if(($i>0)&&($i<=$this->nbpages))
{
if($i!=$this->currentpage)
{
if($functionname=='')
{
$text.='<a href="'.$this->baseurl.'&'.$this->pagevarurl.'='.$i.'">'.$i.'</a> ';
}
else
{
$text.='<a style="cursor:pointer;" onclick="'.$functionname.'('.$i.');">'.$i.'</a> ';
}
}
else
{
$text.=$i.' ';
}
}
}
if($this->currentpage-$this->options['number_displayed']>0)
{
$text=' ... '.$text;
}
if($this->currentpage+$this->options['number_displayed']<$this->nbpages)
{
$text.=' ... ';
}
}
if($this->options['prev_next'])
{
$prevp='';
$nextp='';
if($this->currentpage>1)
{
if($functionname=='')
{
$prevp='<a href="'.$this->baseurl.'&'.$this->pagevarurl.'='.($this->currentpage-1).'"> Prev </a>';
}
else
{
$prevp='<a style="cursor:pointer;" onclick="'.$functionname.'('.($this->currentpage-1).');"> Prev </a>';
}
}
if($this->currentpage<$this->nbpages)
{
if($functionname=='')
{
$nextp='<a href="'.$this->baseurl.'&'.$this->pagevarurl.'='.($this->currentpage+1).'"> Next </a>';
}
else
{
$nextp='<a style="cursor:pointer;" onclick="'.$functionname.'('.($this->currentpage+1).');"> Next </a>';
}
}
$text=$prevp.$text.$nextp;
}
if($this->options['first_last'])
{
$firstp='';
$lastp='';
if($this->currentpage>1)
{
if($functionname=='')
{
$firstp='<a href="'.$this->baseurl.'&'.$this->pagevarurl.'=1"> First </a>';
}
else
{
$firstp='<a style="cursor:pointer;" onclick="'.$functionname.'(1);"> First </a>';
}
}
if($this->currentpage<$this->nbpages)
{
if($functionname=='')
{
$lastp='<a href="'.$this->baseurl.'&'.$this->pagevarurl.'='.$this->nbpages.'"> Last </a>';
}
else
{
$lastp='<a style="cursor:pointer;" onclick="'.$functionname.'('.$this->nbpages.');"> Last </a>';
}
}
$text=$firstp.$text.$lastp;
}
return($text);
}
/*
calculate the number of pages...
*/
function calc_nb_pages()
{
if($this->nbitemsperpages>0)
{
$this->nbpages=ceil($this->nbitems/$this->nbitemsperpages);
}
}
} //class
?>
|