Subversion Repositories eFlore/Applications.coel-consultation

Rev

Rev 10 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10 Rev 264
1
<?php
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
 
3
 
4
/**
4
/**
5
 * Contains the Pager_Common class
5
 * Contains the Pager_Common class
6
 *
6
 *
7
 * PHP versions 4 and 5
7
 * PHP versions 4 and 5
8
 *
8
 *
9
 * LICENSE: Redistribution and use in source and binary forms, with or without
9
 * LICENSE: Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
10
 * modification, are permitted provided that the following conditions are met:
11
 * 1. Redistributions of source code must retain the above copyright
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
15
 *    documentation and/or other materials provided with the distribution.
16
 * 3. The name of the author may not be used to endorse or promote products
16
 * 3. The name of the author may not be used to endorse or promote products
17
 *    derived from this software without specific prior written permission.
17
 *    derived from this software without specific prior written permission.
18
 *
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
20
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
22
 * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
23
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 *
29
 *
30
 * @category   HTML
30
 * @category   HTML
31
 * @package    Pager
31
 * @package    Pager
32
 * @author     Lorenzo Alberton <l dot alberton at quipo dot it>
32
 * @author     Lorenzo Alberton <l dot alberton at quipo dot it>
33
 * @author     Richard Heyes <richard@phpguru.org>
33
 * @author     Richard Heyes <richard@phpguru.org>
34
 * @copyright  2003-2006 Lorenzo Alberton, Richard Heyes
34
 * @copyright  2003-2006 Lorenzo Alberton, Richard Heyes
35
 * @license    http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
35
 * @license    http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
36
 * @version    CVS: $Id: Common.php 10 2010-03-05 14:15:42Z jpm $
36
 * @version    CVS: $Id: Common.php 264 2016-12-19 13:27:31Z mathias $
37
 * @link       http://pear.php.net/package/Pager
37
 * @link       http://pear.php.net/package/Pager
38
 */
38
 */
39
 
39
 
40
/**
40
/**
41
 * Two constants used to guess the path- and file-name of the page
41
 * Two constants used to guess the path- and file-name of the page
42
 * when the user doesn't set any other value
42
 * when the user doesn't set any other value
43
 */
43
 */
44
if (substr($_SERVER['PHP_SELF'], -1) == '/') {
44
if (substr($_SERVER['PHP_SELF'], -1) == '/') {
45
    $http = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://';
45
    $http = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://';
46
    define('CURRENT_FILENAME', '');
46
    define('CURRENT_FILENAME', '');
47
    define('CURRENT_PATHNAME', $http.$_SERVER['HTTP_HOST'].str_replace('\\', '/', $_SERVER['PHP_SELF']));
47
    define('CURRENT_PATHNAME', $http.$_SERVER['HTTP_HOST'].str_replace('\\', '/', $_SERVER['PHP_SELF']));
48
} else {
48
} else {
49
    define('CURRENT_FILENAME', preg_replace('/(.*)\?.*/', '\\1', basename($_SERVER['PHP_SELF'])));
49
    define('CURRENT_FILENAME', preg_replace('/(.*)\?.*/', '\\1', basename($_SERVER['PHP_SELF'])));
50
    define('CURRENT_PATHNAME', str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])));
50
    define('CURRENT_PATHNAME', str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])));
51
}
51
}
52
/**
52
/**
53
 * Error codes
53
 * Error codes
54
 */
54
 */
55
define('PAGER_OK',                         0);
55
define('PAGER_OK',                         0);
56
define('ERROR_PAGER',                     -1);
56
define('ERROR_PAGER',                     -1);
57
define('ERROR_PAGER_INVALID',             -2);
57
define('ERROR_PAGER_INVALID',             -2);
58
define('ERROR_PAGER_INVALID_PLACEHOLDER', -3);
58
define('ERROR_PAGER_INVALID_PLACEHOLDER', -3);
59
define('ERROR_PAGER_INVALID_USAGE',       -4);
59
define('ERROR_PAGER_INVALID_USAGE',       -4);
60
define('ERROR_PAGER_NOT_IMPLEMENTED',     -5);
60
define('ERROR_PAGER_NOT_IMPLEMENTED',     -5);
61
 
61
 
62
/**
62
/**
63
 * Pager_Common - Common base class for [Sliding|Jumping] Window Pager
63
 * Pager_Common - Common base class for [Sliding|Jumping] Window Pager
64
 * Extend this class to write a custom paging class
64
 * Extend this class to write a custom paging class
65
 *
65
 *
66
 * @category   HTML
66
 * @category   HTML
67
 * @package    Pager
67
 * @package    Pager
68
 * @author     Lorenzo Alberton <l dot alberton at quipo dot it>
68
 * @author     Lorenzo Alberton <l dot alberton at quipo dot it>
69
 * @author     Richard Heyes <richard@phpguru.org>
69
 * @author     Richard Heyes <richard@phpguru.org>
70
 * @copyright  2003-2005 Lorenzo Alberton, Richard Heyes
70
 * @copyright  2003-2005 Lorenzo Alberton, Richard Heyes
71
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
71
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
72
 * @link       http://pear.php.net/package/Pager
72
 * @link       http://pear.php.net/package/Pager
73
 */
73
 */
74
class Pager_Common
74
class Pager_Common
75
{
75
{
76
    // {{{ class vars
76
    // {{{ class vars
77
 
77
 
78
    /**
78
    /**
79
     * @var integer number of items
79
     * @var integer number of items
80
     * @access private
80
     * @access private
81
     */
81
     */
82
    var $_totalItems;
82
    var $_totalItems;
83
 
83
 
84
    /**
84
    /**
85
     * @var integer number of items per page
85
     * @var integer number of items per page
86
     * @access private
86
     * @access private
87
     */
87
     */
88
    var $_perPage     = 10;
88
    var $_perPage     = 10;
89
 
89
 
90
    /**
90
    /**
91
     * @var integer number of page links for each window
91
     * @var integer number of page links for each window
92
     * @access private
92
     * @access private
93
     */
93
     */
94
    var $_delta       = 10;
94
    var $_delta       = 10;
95
 
95
 
96
    /**
96
    /**
97
     * @var integer current page number
97
     * @var integer current page number
98
     * @access private
98
     * @access private
99
     */
99
     */
100
    var $_currentPage = 1;
100
    var $_currentPage = 1;
101
 
101
 
102
    /**
102
    /**
103
     * @var integer total pages number
103
     * @var integer total pages number
104
     * @access private
104
     * @access private
105
     */
105
     */
106
    var $_totalPages  = 1;
106
    var $_totalPages  = 1;
107
 
107
 
108
    /**
108
    /**
109
     * @var string CSS class for links
109
     * @var string CSS class for links
110
     * @access private
110
     * @access private
111
     */
111
     */
112
    var $_linkClass   = '';
112
    var $_linkClass   = '';
113
 
113
 
114
    /**
114
    /**
115
     * @var string wrapper for CSS class name
115
     * @var string wrapper for CSS class name
116
     * @access private
116
     * @access private
117
     */
117
     */
118
    var $_classString = '';
118
    var $_classString = '';
119
 
119
 
120
    /**
120
    /**
121
     * @var string path name
121
     * @var string path name
122
     * @access private
122
     * @access private
123
     */
123
     */
124
    var $_path        = CURRENT_PATHNAME;
124
    var $_path        = CURRENT_PATHNAME;
125
 
125
 
126
    /**
126
    /**
127
     * @var string file name
127
     * @var string file name
128
     * @access private
128
     * @access private
129
     */
129
     */
130
    var $_fileName    = CURRENT_FILENAME;
130
    var $_fileName    = CURRENT_FILENAME;
131
    
131
    
132
    /**
132
    /**
133
     * @var boolean If false, don't override the fileName option. Use at your own risk.
133
     * @var boolean If false, don't override the fileName option. Use at your own risk.
134
     * @access private
134
     * @access private
135
     */
135
     */
136
    var $_fixFileName = true;
136
    var $_fixFileName = true;
137
 
137
 
138
    /**
138
    /**
139
     * @var boolean you have to use FALSE with mod_rewrite
139
     * @var boolean you have to use FALSE with mod_rewrite
140
     * @access private
140
     * @access private
141
     */
141
     */
142
    var $_append      = true;
142
    var $_append      = true;
143
 
143
 
144
    /**
144
    /**
145
     * @var string specifies which HTTP method to use
145
     * @var string specifies which HTTP method to use
146
     * @access private
146
     * @access private
147
     */
147
     */
148
    var $_httpMethod  = 'GET';
148
    var $_httpMethod  = 'GET';
149
    
149
    
150
    /**
150
    /**
151
     * @var string specifies which HTML form to use
151
     * @var string specifies which HTML form to use
152
     * @access private
152
     * @access private
153
     */
153
     */
154
    var $_formID  = '';
154
    var $_formID  = '';
155
 
155
 
156
    /**
156
    /**
157
     * @var boolean whether or not to import submitted data
157
     * @var boolean whether or not to import submitted data
158
     * @access private
158
     * @access private
159
     */
159
     */
160
    var $_importQuery = true;
160
    var $_importQuery = true;
161
 
161
 
162
    /**
162
    /**
163
     * @var string name of the querystring var for pageID
163
     * @var string name of the querystring var for pageID
164
     * @access private
164
     * @access private
165
     */
165
     */
166
    var $_urlVar      = 'pageID';
166
    var $_urlVar      = 'pageID';
167
 
167
 
168
    /**
168
    /**
169
     * @var array data to pass through the link
169
     * @var array data to pass through the link
170
     * @access private
170
     * @access private
171
     */
171
     */
172
    var $_linkData    = array();
172
    var $_linkData    = array();
173
 
173
 
174
    /**
174
    /**
175
     * @var array additional URL vars
175
     * @var array additional URL vars
176
     * @access private
176
     * @access private
177
     */
177
     */
178
    var $_extraVars   = array();
178
    var $_extraVars   = array();
179
    
179
    
180
    /**
180
    /**
181
     * @var array URL vars to ignore
181
     * @var array URL vars to ignore
182
     * @access private
182
     * @access private
183
     */
183
     */
184
    var $_excludeVars = array();
184
    var $_excludeVars = array();
185
 
185
 
186
    /**
186
    /**
187
     * @var boolean TRUE => expanded mode (for Pager_Sliding)
187
     * @var boolean TRUE => expanded mode (for Pager_Sliding)
188
     * @access private
188
     * @access private
189
     */
189
     */
190
    var $_expanded    = true;
190
    var $_expanded    = true;
191
    
191
    
192
    /**
192
    /**
193
     * @var boolean TRUE => show accesskey attribute on <a> tags
193
     * @var boolean TRUE => show accesskey attribute on <a> tags
194
     * @access private
194
     * @access private
195
     */
195
     */
196
    var $_accesskey   = false;
196
    var $_accesskey   = false;
197
 
197
 
198
    /**
198
    /**
199
     * @var string extra attributes for the <a> tag
199
     * @var string extra attributes for the <a> tag
200
     * @access private
200
     * @access private
201
     */
201
     */
202
    var $_attributes  = '';
202
    var $_attributes  = '';
203
    
203
    
204
    /**
204
    /**
205
     * @var string onclick
205
     * @var string onclick
206
     * @access private
206
     * @access private
207
     */
207
     */
208
    var $_onclick = '';
208
    var $_onclick = '';
209
 
209
 
210
    /**
210
    /**
211
     * @var string alt text for "first page" (use "%d" placeholder for page number)
211
     * @var string alt text for "first page" (use "%d" placeholder for page number)
212
     * @access private
212
     * @access private
213
     */
213
     */
214
    var $_altFirst     = 'first page';
214
    var $_altFirst     = 'first page';
215
 
215
 
216
    /**
216
    /**
217
     * @var string alt text for "previous page"
217
     * @var string alt text for "previous page"
218
     * @access private
218
     * @access private
219
     */
219
     */
220
    var $_altPrev     = 'previous page';
220
    var $_altPrev     = 'previous page';
221
 
221
 
222
    /**
222
    /**
223
     * @var string alt text for "next page"
223
     * @var string alt text for "next page"
224
     * @access private
224
     * @access private
225
     */
225
     */
226
    var $_altNext     = 'next page';
226
    var $_altNext     = 'next page';
227
 
227
 
228
    /**
228
    /**
229
     * @var string alt text for "last page" (use "%d" placeholder for page number)
229
     * @var string alt text for "last page" (use "%d" placeholder for page number)
230
     * @access private
230
     * @access private
231
     */
231
     */
232
    var $_altLast     = 'last page';
232
    var $_altLast     = 'last page';
233
 
233
 
234
    /**
234
    /**
235
     * @var string alt text for "page"
235
     * @var string alt text for "page"
236
     * @access private
236
     * @access private
237
     */
237
     */
238
    var $_altPage     = 'page';
238
    var $_altPage     = 'page';
239
 
239
 
240
    /**
240
    /**
241
     * @var string image/text to use as "prev" link
241
     * @var string image/text to use as "prev" link
242
     * @access private
242
     * @access private
243
     */
243
     */
244
    var $_prevImg     = '&lt;&lt; Back';
244
    var $_prevImg     = '&lt;&lt; Back';
245
 
245
 
246
    /**
246
    /**
247
     * @var string image/text to use as "next" link
247
     * @var string image/text to use as "next" link
248
     * @access private
248
     * @access private
249
     */
249
     */
250
    var $_nextImg     = 'Next &gt;&gt;';
250
    var $_nextImg     = 'Next &gt;&gt;';
251
 
251
 
252
    /**
252
    /**
253
     * @var string link separator
253
     * @var string link separator
254
     * @access private
254
     * @access private
255
     */
255
     */
256
    var $_separator   = '';
256
    var $_separator   = '';
257
 
257
 
258
    /**
258
    /**
259
     * @var integer number of spaces before separator
259
     * @var integer number of spaces before separator
260
     * @access private
260
     * @access private
261
     */
261
     */
262
    var $_spacesBeforeSeparator = 0;
262
    var $_spacesBeforeSeparator = 0;
263
 
263
 
264
    /**
264
    /**
265
     * @var integer number of spaces after separator
265
     * @var integer number of spaces after separator
266
     * @access private
266
     * @access private
267
     */
267
     */
268
    var $_spacesAfterSeparator  = 1;
268
    var $_spacesAfterSeparator  = 1;
269
 
269
 
270
    /**
270
    /**
271
     * @var string CSS class name for current page link
271
     * @var string CSS class name for current page link
272
     * @access private
272
     * @access private
273
     */
273
     */
274
    var $_curPageLinkClassName  = '';
274
    var $_curPageLinkClassName  = '';
275
 
275
 
276
    /**
276
    /**
277
     * @var string Text before current page link
277
     * @var string Text before current page link
278
     * @access private
278
     * @access private
279
     */
279
     */
280
    var $_curPageSpanPre        = '';
280
    var $_curPageSpanPre        = '';
281
 
281
 
282
    /**
282
    /**
283
     * @var string Text after current page link
283
     * @var string Text after current page link
284
     * @access private
284
     * @access private
285
     */
285
     */
286
    var $_curPageSpanPost       = '';
286
    var $_curPageSpanPost       = '';
287
 
287
 
288
    /**
288
    /**
289
     * @var string Text before first page link
289
     * @var string Text before first page link
290
     * @access private
290
     * @access private
291
     */
291
     */
292
    var $_firstPagePre  = '[';
292
    var $_firstPagePre  = '[';
293
 
293
 
294
    /**
294
    /**
295
     * @var string Text to be used for first page link
295
     * @var string Text to be used for first page link
296
     * @access private
296
     * @access private
297
     */
297
     */
298
    var $_firstPageText = '';
298
    var $_firstPageText = '';
299
 
299
 
300
    /**
300
    /**
301
     * @var string Text after first page link
301
     * @var string Text after first page link
302
     * @access private
302
     * @access private
303
     */
303
     */
304
    var $_firstPagePost = ']';
304
    var $_firstPagePost = ']';
305
 
305
 
306
    /**
306
    /**
307
     * @var string Text before last page link
307
     * @var string Text before last page link
308
     * @access private
308
     * @access private
309
     */
309
     */
310
    var $_lastPagePre   = '[';
310
    var $_lastPagePre   = '[';
311
 
311
 
312
    /**
312
    /**
313
     * @var string Text to be used for last page link
313
     * @var string Text to be used for last page link
314
     * @access private
314
     * @access private
315
     */
315
     */
316
    var $_lastPageText  = '';
316
    var $_lastPageText  = '';
317
 
317
 
318
    /**
318
    /**
319
     * @var string Text after last page link
319
     * @var string Text after last page link
320
     * @access private
320
     * @access private
321
     */
321
     */
322
    var $_lastPagePost  = ']';
322
    var $_lastPagePost  = ']';
323
 
323
 
324
    /**
324
    /**
325
     * @var string Will contain the HTML code for the spaces
325
     * @var string Will contain the HTML code for the spaces
326
     * @access private
326
     * @access private
327
     */
327
     */
328
    var $_spacesBefore  = '';
328
    var $_spacesBefore  = '';
329
 
329
 
330
    /**
330
    /**
331
     * @var string Will contain the HTML code for the spaces
331
     * @var string Will contain the HTML code for the spaces
332
     * @access private
332
     * @access private
333
     */
333
     */
334
    var $_spacesAfter   = '';
334
    var $_spacesAfter   = '';
335
 
335
 
336
    /**
336
    /**
337
     * @var string $_firstLinkTitle
337
     * @var string $_firstLinkTitle
338
     * @access private
338
     * @access private
339
     */
339
     */
340
    var $_firstLinkTitle = 'first page';
340
    var $_firstLinkTitle = 'first page';
341
 
341
 
342
    /**
342
    /**
343
     * @var string $_nextLinkTitle
343
     * @var string $_nextLinkTitle
344
     * @access private
344
     * @access private
345
     */
345
     */
346
    var $_nextLinkTitle = 'next page';
346
    var $_nextLinkTitle = 'next page';
347
 
347
 
348
    /**
348
    /**
349
     * @var string $_prevLinkTitle
349
     * @var string $_prevLinkTitle
350
     * @access private
350
     * @access private
351
     */
351
     */
352
    var $_prevLinkTitle = 'previous page';
352
    var $_prevLinkTitle = 'previous page';
353
 
353
 
354
    /**
354
    /**
355
     * @var string $_lastLinkTitle
355
     * @var string $_lastLinkTitle
356
     * @access private
356
     * @access private
357
     */
357
     */
358
    var $_lastLinkTitle = 'last page';
358
    var $_lastLinkTitle = 'last page';
359
 
359
 
360
    /**
360
    /**
361
     * @var string Text to be used for the 'show all' option in the select box
361
     * @var string Text to be used for the 'show all' option in the select box
362
     * @access private
362
     * @access private
363
     */
363
     */
364
    var $_showAllText   = '';
364
    var $_showAllText   = '';
365
 
365
 
366
    /**
366
    /**
367
     * @var array data to be paged
367
     * @var array data to be paged
368
     * @access private
368
     * @access private
369
     */
369
     */
370
    var $_itemData      = null;
370
    var $_itemData      = null;
371
 
371
 
372
    /**
372
    /**
373
     * @var boolean If TRUE and there's only one page, links aren't shown
373
     * @var boolean If TRUE and there's only one page, links aren't shown
374
     * @access private
374
     * @access private
375
     */
375
     */
376
    var $_clearIfVoid   = true;
376
    var $_clearIfVoid   = true;
377
 
377
 
378
    /**
378
    /**
379
     * @var boolean Use session for storing the number of items per page
379
     * @var boolean Use session for storing the number of items per page
380
     * @access private
380
     * @access private
381
     */
381
     */
382
    var $_useSessions   = false;
382
    var $_useSessions   = false;
383
 
383
 
384
    /**
384
    /**
385
     * @var boolean Close the session when finished reading/writing data
385
     * @var boolean Close the session when finished reading/writing data
386
     * @access private
386
     * @access private
387
     */
387
     */
388
    var $_closeSession  = false;
388
    var $_closeSession  = false;
389
 
389
 
390
    /**
390
    /**
391
     * @var string name of the session var for number of items per page
391
     * @var string name of the session var for number of items per page
392
     * @access private
392
     * @access private
393
     */
393
     */
394
    var $_sessionVar    = 'setPerPage';
394
    var $_sessionVar    = 'setPerPage';
395
 
395
 
396
    /**
396
    /**
397
     * Pear error mode (when raiseError is called)
397
     * Pear error mode (when raiseError is called)
398
     * (see PEAR doc)
398
     * (see PEAR doc)
399
     *
399
     *
400
     * @var int $_pearErrorMode
400
     * @var int $_pearErrorMode
401
     * @access private
401
     * @access private
402
     */
402
     */
403
    var $_pearErrorMode = null;
403
    var $_pearErrorMode = null;
404
 
404
 
405
    // }}}
405
    // }}}
406
    // {{{ public vars
406
    // {{{ public vars
407
 
407
 
408
    /**
408
    /**
409
     * @var string Complete set of links
409
     * @var string Complete set of links
410
     * @access public
410
     * @access public
411
     */
411
     */
412
    var $links = '';
412
    var $links = '';
413
 
413
 
414
    /**
414
    /**
415
     * @var string Complete set of link tags
415
     * @var string Complete set of link tags
416
     * @access public
416
     * @access public
417
     */
417
     */
418
    var $linkTags = '';
418
    var $linkTags = '';
419
 
419
 
420
    /**
420
    /**
421
     * @var array Array with a key => value pair representing
421
     * @var array Array with a key => value pair representing
422
     *            page# => bool value (true if key==currentPageNumber).
422
     *            page# => bool value (true if key==currentPageNumber).
423
     *            can be used for extreme customization.
423
     *            can be used for extreme customization.
424
     * @access public
424
     * @access public
425
     */
425
     */
426
    var $range = array();
426
    var $range = array();
427
    
427
    
428
    /**
428
    /**
429
     * @var array list of available options (safety check)
429
     * @var array list of available options (safety check)
430
     * @access private
430
     * @access private
431
     */
431
     */
432
    var $_allowed_options = array(
432
    var $_allowed_options = array(
433
        'totalItems',
433
        'totalItems',
434
        'perPage',
434
        'perPage',
435
        'delta',
435
        'delta',
436
        'linkClass',
436
        'linkClass',
437
        'path',
437
        'path',
438
        'fileName',
438
        'fileName',
439
        'fixFileName',
439
        'fixFileName',
440
        'append',
440
        'append',
441
        'httpMethod',
441
        'httpMethod',
442
        'formID',
442
        'formID',
443
        'importQuery',
443
        'importQuery',
444
        'urlVar',
444
        'urlVar',
445
        'altFirst',
445
        'altFirst',
446
        'altPrev',
446
        'altPrev',
447
        'altNext',
447
        'altNext',
448
        'altLast',
448
        'altLast',
449
        'altPage',
449
        'altPage',
450
        'prevImg',
450
        'prevImg',
451
        'nextImg',
451
        'nextImg',
452
        'expanded',
452
        'expanded',
453
        'accesskey',
453
        'accesskey',
454
        'attributes',
454
        'attributes',
455
        'onclick',
455
        'onclick',
456
        'separator',
456
        'separator',
457
        'spacesBeforeSeparator',
457
        'spacesBeforeSeparator',
458
        'spacesAfterSeparator',
458
        'spacesAfterSeparator',
459
        'curPageLinkClassName',
459
        'curPageLinkClassName',
460
        'curPageSpanPre',
460
        'curPageSpanPre',
461
        'curPageSpanPost',
461
        'curPageSpanPost',
462
        'firstPagePre',
462
        'firstPagePre',
463
        'firstPageText',
463
        'firstPageText',
464
        'firstPagePost',
464
        'firstPagePost',
465
        'lastPagePre',
465
        'lastPagePre',
466
        'lastPageText',
466
        'lastPageText',
467
        'lastPagePost',
467
        'lastPagePost',
468
        'firstLinkTitle',
468
        'firstLinkTitle',
469
        'nextLinkTitle',
469
        'nextLinkTitle',
470
        'prevLinkTitle',
470
        'prevLinkTitle',
471
        'lastLinkTitle',
471
        'lastLinkTitle',
472
        'showAllText',
472
        'showAllText',
473
        'itemData',
473
        'itemData',
474
        'clearIfVoid',
474
        'clearIfVoid',
475
        'useSessions',
475
        'useSessions',
476
        'closeSession',
476
        'closeSession',
477
        'sessionVar',
477
        'sessionVar',
478
        'pearErrorMode',
478
        'pearErrorMode',
479
        'extraVars',
479
        'extraVars',
480
        'excludeVars',
480
        'excludeVars',
481
        'currentPage',
481
        'currentPage',
482
    );
482
    );
483
 
483
 
484
    // }}}
484
    // }}}
485
    // {{{ build()
485
    // {{{ build()
486
 
486
 
487
    /**
487
    /**
488
     * Generate or refresh the links and paged data after a call to setOptions()
488
     * Generate or refresh the links and paged data after a call to setOptions()
489
     *
489
     *
490
     * @access public
490
     * @access public
491
     */
491
     */
492
    function build()
492
    function build()
493
    {
493
    {
494
        //reset
494
        //reset
495
        $this->_pageData = array();
495
        $this->_pageData = array();
496
        $this->links = '';
496
        $this->links = '';
497
 
497
 
498
        $this->_generatePageData();
498
        $this->_generatePageData();
499
        $this->_setFirstLastText();
499
        $this->_setFirstLastText();
500
 
500
 
501
        if ($this->_totalPages > (2 * $this->_delta + 1)) {
501
        if ($this->_totalPages > (2 * $this->_delta + 1)) {
502
            $this->links .= $this->_printFirstPage();
502
            $this->links .= $this->_printFirstPage();
503
        }
503
        }
504
 
504
 
505
        $this->links .= $this->_getBackLink();
505
        $this->links .= $this->_getBackLink();
506
        $this->links .= $this->_getPageLinks();
506
        $this->links .= $this->_getPageLinks();
507
        $this->links .= $this->_getNextLink();
507
        $this->links .= $this->_getNextLink();
508
 
508
 
509
        $this->linkTags .= $this->_getFirstLinkTag();
509
        $this->linkTags .= $this->_getFirstLinkTag();
510
        $this->linkTags .= $this->_getPrevLinkTag();
510
        $this->linkTags .= $this->_getPrevLinkTag();
511
        $this->linkTags .= $this->_getNextLinkTag();
511
        $this->linkTags .= $this->_getNextLinkTag();
512
        $this->linkTags .= $this->_getLastLinkTag();
512
        $this->linkTags .= $this->_getLastLinkTag();
513
 
513
 
514
        if ($this->_totalPages > (2 * $this->_delta + 1)) {
514
        if ($this->_totalPages > (2 * $this->_delta + 1)) {
515
            $this->links .= $this->_printLastPage();
515
            $this->links .= $this->_printLastPage();
516
        }
516
        }
517
    }
517
    }
518
 
518
 
519
    // }}}
519
    // }}}
520
    // {{{ getPageData()
520
    // {{{ getPageData()
521
 
521
 
522
    /**
522
    /**
523
     * Returns an array of current pages data
523
     * Returns an array of current pages data
524
     *
524
     *
525
     * @param $pageID Desired page ID (optional)
525
     * @param $pageID Desired page ID (optional)
526
     * @return array Page data
526
     * @return array Page data
527
     * @access public
527
     * @access public
528
     */
528
     */
529
    function getPageData($pageID = null)
529
    function getPageData($pageID = null)
530
    {
530
    {
531
        $pageID = empty($pageID) ? $this->_currentPage : $pageID;
531
        $pageID = empty($pageID) ? $this->_currentPage : $pageID;
532
 
532
 
533
        if (!isset($this->_pageData)) {
533
        if (!isset($this->_pageData)) {
534
            $this->_generatePageData();
534
            $this->_generatePageData();
535
        }
535
        }
536
        if (!empty($this->_pageData[$pageID])) {
536
        if (!empty($this->_pageData[$pageID])) {
537
            return $this->_pageData[$pageID];
537
            return $this->_pageData[$pageID];
538
        }
538
        }
539
        return array();
539
        return array();
540
    }
540
    }
541
 
541
 
542
    // }}}
542
    // }}}
543
    // {{{ getPageIdByOffset()
543
    // {{{ getPageIdByOffset()
544
 
544
 
545
    /**
545
    /**
546
     * Returns pageID for given offset
546
     * Returns pageID for given offset
547
     *
547
     *
548
     * @param $index Offset to get pageID for
548
     * @param $index Offset to get pageID for
549
     * @return int PageID for given offset
549
     * @return int PageID for given offset
550
     */
550
     */
551
    function getPageIdByOffset($index)
551
    function getPageIdByOffset($index)
552
    {
552
    {
553
        $msg = '<b>PEAR::Pager Error:</b>'
553
        $msg = '<b>PEAR::Pager Error:</b>'
554
              .' function "getPageIdByOffset()" not implemented.';
554
              .' function "getPageIdByOffset()" not implemented.';
555
        return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
555
        return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
556
    }
556
    }
557
 
557
 
558
    // }}}
558
    // }}}
559
    // {{{ getOffsetByPageId()
559
    // {{{ getOffsetByPageId()
560
 
560
 
561
    /**
561
    /**
562
     * Returns offsets for given pageID. Eg, if you
562
     * Returns offsets for given pageID. Eg, if you
563
     * pass it pageID one and your perPage limit is 10
563
     * pass it pageID one and your perPage limit is 10
564
     * it will return (1, 10). PageID of 2 would
564
     * it will return (1, 10). PageID of 2 would
565
     * give you (11, 20).
565
     * give you (11, 20).
566
     *
566
     *
567
     * @param integer PageID to get offsets for
567
     * @param integer PageID to get offsets for
568
     * @return array  First and last offsets
568
     * @return array  First and last offsets
569
     * @access public
569
     * @access public
570
     */
570
     */
571
    function getOffsetByPageId($pageid = null)
571
    function getOffsetByPageId($pageid = null)
572
    {
572
    {
573
        $pageid = isset($pageid) ? $pageid : $this->_currentPage;
573
        $pageid = isset($pageid) ? $pageid : $this->_currentPage;
574
        if (!isset($this->_pageData)) {
574
        if (!isset($this->_pageData)) {
575
            $this->_generatePageData();
575
            $this->_generatePageData();
576
        }
576
        }
577
 
577
 
578
        if (isset($this->_pageData[$pageid]) || is_null($this->_itemData)) {
578
        if (isset($this->_pageData[$pageid]) || is_null($this->_itemData)) {
579
            return array(
579
            return array(
580
                        max(($this->_perPage * ($pageid - 1)) + 1, 1),
580
                        max(($this->_perPage * ($pageid - 1)) + 1, 1),
581
                        min($this->_totalItems, $this->_perPage * $pageid)
581
                        min($this->_totalItems, $this->_perPage * $pageid)
582
                   );
582
                   );
583
        } else {
583
        } else {
584
            return array(0, 0);
584
            return array(0, 0);
585
        }
585
        }
586
    }
586
    }
587
 
587
 
588
    // }}}
588
    // }}}
589
    // {{{ getPageRangeByPageId()
589
    // {{{ getPageRangeByPageId()
590
 
590
 
591
    /**
591
    /**
592
     * @param integer PageID to get offsets for
592
     * @param integer PageID to get offsets for
593
     * @return array  First and last offsets
593
     * @return array  First and last offsets
594
     */
594
     */
595
    function getPageRangeByPageId($pageID)
595
    function getPageRangeByPageId($pageID)
596
    {
596
    {
597
        $msg = '<b>PEAR::Pager Error:</b>'
597
        $msg = '<b>PEAR::Pager Error:</b>'
598
              .' function "getPageRangeByPageId()" not implemented.';
598
              .' function "getPageRangeByPageId()" not implemented.';
599
        return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
599
        return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
600
    }
600
    }
601
 
601
 
602
    // }}}
602
    // }}}
603
    // {{{ getLinks()
603
    // {{{ getLinks()
604
 
604
 
605
    /**
605
    /**
606
     * Returns back/next/first/last and page links,
606
     * Returns back/next/first/last and page links,
607
     * both as ordered and associative array.
607
     * both as ordered and associative array.
608
     *
608
     *
609
     * NB: in original PEAR::Pager this method accepted two parameters,
609
     * NB: in original PEAR::Pager this method accepted two parameters,
610
     * $back_html and $next_html. Now the only parameter accepted is
610
     * $back_html and $next_html. Now the only parameter accepted is
611
     * an integer ($pageID), since the html text for prev/next links can
611
     * an integer ($pageID), since the html text for prev/next links can
612
     * be set in the factory. If a second parameter is provided, then
612
     * be set in the factory. If a second parameter is provided, then
613
     * the method act as it previously did. This hack was done to mantain
613
     * the method act as it previously did. This hack was done to mantain
614
     * backward compatibility only.
614
     * backward compatibility only.
615
     *
615
     *
616
     * @param integer $pageID Optional pageID. If specified, links
616
     * @param integer $pageID Optional pageID. If specified, links
617
     *                for that page are provided instead of current one.  [ADDED IN NEW PAGER VERSION]
617
     *                for that page are provided instead of current one.  [ADDED IN NEW PAGER VERSION]
618
     * @param  string $next_html HTML to put inside the next link [deprecated: use the factory instead]
618
     * @param  string $next_html HTML to put inside the next link [deprecated: use the factory instead]
619
     * @return array back/next/first/last and page links
619
     * @return array back/next/first/last and page links
620
     */
620
     */
621
    function getLinks($pageID=null, $next_html='')
621
    function getLinks($pageID=null, $next_html='')
622
    {
622
    {
623
        $msg = '<b>PEAR::Pager Error:</b>'
623
        $msg = '<b>PEAR::Pager Error:</b>'
624
              .' function "getLinks()" not implemented.';
624
              .' function "getLinks()" not implemented.';
625
        return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
625
        return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
626
    }
626
    }
627
 
627
 
628
    // }}}
628
    // }}}
629
    // {{{ getCurrentPageID()
629
    // {{{ getCurrentPageID()
630
 
630
 
631
    /**
631
    /**
632
     * Returns ID of current page
632
     * Returns ID of current page
633
     *
633
     *
634
     * @return integer ID of current page
634
     * @return integer ID of current page
635
     */
635
     */
636
    function getCurrentPageID()
636
    function getCurrentPageID()
637
    {
637
    {
638
        return $this->_currentPage;
638
        return $this->_currentPage;
639
    }
639
    }
640
 
640
 
641
    // }}}
641
    // }}}
642
    // {{{ getNextPageID()
642
    // {{{ getNextPageID()
643
 
643
 
644
    /**
644
    /**
645
     * Returns next page ID. If current page is last page
645
     * Returns next page ID. If current page is last page
646
	 * this function returns FALSE
646
	 * this function returns FALSE
647
	 *
647
	 *
648
	 * @return mixed Next page ID
648
	 * @return mixed Next page ID
649
     */
649
     */
650
	function getNextPageID()
650
	function getNextPageID()
651
	{
651
	{
652
		return ($this->getCurrentPageID() == $this->numPages() ? false : $this->getCurrentPageID() + 1);
652
		return ($this->getCurrentPageID() == $this->numPages() ? false : $this->getCurrentPageID() + 1);
653
	}
653
	}
654
 
654
 
655
	// }}}
655
	// }}}
656
    // {{{ getPreviousPageID()
656
    // {{{ getPreviousPageID()
657
 
657
 
658
    /**
658
    /**
659
     * Returns previous page ID. If current page is first page
659
     * Returns previous page ID. If current page is first page
660
	 * this function returns FALSE
660
	 * this function returns FALSE
661
	 *
661
	 *
662
	 * @return mixed Previous pages' ID
662
	 * @return mixed Previous pages' ID
663
     */
663
     */
664
	function getPreviousPageID()
664
	function getPreviousPageID()
665
	{
665
	{
666
		return $this->isFirstPage() ? false : $this->getCurrentPageID() - 1;
666
		return $this->isFirstPage() ? false : $this->getCurrentPageID() - 1;
667
	}
667
	}
668
 
668
 
669
    // }}}
669
    // }}}
670
    // {{{ numItems()
670
    // {{{ numItems()
671
 
671
 
672
    /**
672
    /**
673
     * Returns number of items
673
     * Returns number of items
674
     *
674
     *
675
     * @return int Number of items
675
     * @return int Number of items
676
     */
676
     */
677
    function numItems()
677
    function numItems()
678
    {
678
    {
679
        return $this->_totalItems;
679
        return $this->_totalItems;
680
    }
680
    }
681
 
681
 
682
    // }}}
682
    // }}}
683
    // {{{ numPages()
683
    // {{{ numPages()
684
 
684
 
685
    /**
685
    /**
686
     * Returns number of pages
686
     * Returns number of pages
687
     *
687
     *
688
     * @return int Number of pages
688
     * @return int Number of pages
689
     */
689
     */
690
    function numPages()
690
    function numPages()
691
    {
691
    {
692
        return (int)$this->_totalPages;
692
        return (int)$this->_totalPages;
693
    }
693
    }
694
 
694
 
695
    // }}}
695
    // }}}
696
    // {{{ isFirstPage()
696
    // {{{ isFirstPage()
697
 
697
 
698
    /**
698
    /**
699
     * Returns whether current page is first page
699
     * Returns whether current page is first page
700
     *
700
     *
701
     * @return bool First page or not
701
     * @return bool First page or not
702
     */
702
     */
703
    function isFirstPage()
703
    function isFirstPage()
704
    {
704
    {
705
        return ($this->_currentPage < 2);
705
        return ($this->_currentPage < 2);
706
    }
706
    }
707
 
707
 
708
    // }}}
708
    // }}}
709
    // {{{ isLastPage()
709
    // {{{ isLastPage()
710
 
710
 
711
    /**
711
    /**
712
     * Returns whether current page is last page
712
     * Returns whether current page is last page
713
     *
713
     *
714
     * @return bool Last page or not
714
     * @return bool Last page or not
715
     */
715
     */
716
    function isLastPage()
716
    function isLastPage()
717
    {
717
    {
718
        return ($this->_currentPage == $this->_totalPages);
718
        return ($this->_currentPage == $this->_totalPages);
719
    }
719
    }
720
 
720
 
721
    // }}}
721
    // }}}
722
    // {{{ isLastPageComplete()
722
    // {{{ isLastPageComplete()
723
 
723
 
724
    /**
724
    /**
725
     * Returns whether last page is complete
725
     * Returns whether last page is complete
726
     *
726
     *
727
     * @return bool Last age complete or not
727
     * @return bool Last age complete or not
728
     */
728
     */
729
    function isLastPageComplete()
729
    function isLastPageComplete()
730
    {
730
    {
731
        return !($this->_totalItems % $this->_perPage);
731
        return !($this->_totalItems % $this->_perPage);
732
    }
732
    }
733
 
733
 
734
    // }}}
734
    // }}}
735
    // {{{ _generatePageData()
735
    // {{{ _generatePageData()
736
 
736
 
737
    /**
737
    /**
738
     * Calculates all page data
738
     * Calculates all page data
739
     * @access private
739
     * @access private
740
     */
740
     */
741
    function _generatePageData()
741
    function _generatePageData()
742
    {
742
    {
743
        // Been supplied an array of data?
743
        // Been supplied an array of data?
744
        if (!is_null($this->_itemData)) {
744
        if (!is_null($this->_itemData)) {
745
            $this->_totalItems = count($this->_itemData);
745
            $this->_totalItems = count($this->_itemData);
746
        }
746
        }
747
        $this->_totalPages = ceil((float)$this->_totalItems / (float)$this->_perPage);
747
        $this->_totalPages = ceil((float)$this->_totalItems / (float)$this->_perPage);
748
        $i = 1;
748
        $i = 1;
749
        if (!empty($this->_itemData)) {
749
        if (!empty($this->_itemData)) {
750
            foreach ($this->_itemData as $key => $value) {
750
            foreach ($this->_itemData as $key => $value) {
751
                $this->_pageData[$i][$key] = $value;
751
                $this->_pageData[$i][$key] = $value;
752
                if (count($this->_pageData[$i]) >= $this->_perPage) {
752
                if (count($this->_pageData[$i]) >= $this->_perPage) {
753
                    $i++;
753
                    $i++;
754
                }
754
                }
755
            }
755
            }
756
        } else {
756
        } else {
757
            $this->_pageData = array();
757
            $this->_pageData = array();
758
        }
758
        }
759
 
759
 
760
        //prevent URL modification
760
        //prevent URL modification
761
        $this->_currentPage = min($this->_currentPage, $this->_totalPages);
761
        $this->_currentPage = min($this->_currentPage, $this->_totalPages);
762
    }
762
    }
763
 
763
 
764
    // }}}
764
    // }}}
765
    // {{{ _renderLink()
765
    // {{{ _renderLink()
766
 
766
 
767
    /**
767
    /**
768
     * Renders a link using the appropriate method
768
     * Renders a link using the appropriate method
769
     *
769
     *
770
     * @param altText Alternative text for this link (title property)
770
     * @param altText Alternative text for this link (title property)
771
     * @param linkText Text contained by this link
771
     * @param linkText Text contained by this link
772
     * @return string The link in string form
772
     * @return string The link in string form
773
     * @access private
773
     * @access private
774
     */
774
     */
775
    function _renderLink($altText, $linkText)
775
    function _renderLink($altText, $linkText)
776
    {
776
    {
777
        if ($this->_httpMethod == 'GET') {
777
        if ($this->_httpMethod == 'GET') {
778
            if ($this->_append) {
778
            if ($this->_append) {
779
                $href = '?' . $this->_http_build_query_wrapper($this->_linkData);
779
                $href = '?' . $this->_http_build_query_wrapper($this->_linkData);
780
            } else {
780
            } else {
781
                $href = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_fileName);
781
                $href = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_fileName);
782
            }
782
            }
783
            $onclick = '';
783
            $onclick = '';
784
            if (array_key_exists($this->_urlVar, $this->_linkData)) {
784
            if (array_key_exists($this->_urlVar, $this->_linkData)) {
785
                $onclick = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_onclick);
785
                $onclick = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_onclick);
786
            }
786
            }
787
            return sprintf('<a href="%s"%s%s%s%s title="%s">%s</a>',
787
            return sprintf('<a href="%s"%s%s%s%s title="%s">%s</a>',
788
                           htmlentities($this->_url . $href),
788
                           htmlentities($this->_url . $href),
789
                           empty($this->_classString) ? '' : ' '.$this->_classString,
789
                           empty($this->_classString) ? '' : ' '.$this->_classString,
790
                           empty($this->_attributes)  ? '' : ' '.$this->_attributes,
790
                           empty($this->_attributes)  ? '' : ' '.$this->_attributes,
791
                           empty($this->_accesskey)   ? '' : ' accesskey="'.$this->_linkData[$this->_urlVar].'"',
791
                           empty($this->_accesskey)   ? '' : ' accesskey="'.$this->_linkData[$this->_urlVar].'"',
792
                           empty($onclick)            ? '' : ' onclick="'.$onclick.'"',
792
                           empty($onclick)            ? '' : ' onclick="'.$onclick.'"',
793
                           $altText,
793
                           $altText,
794
                           $linkText
794
                           $linkText
795
            );
795
            );
796
        } elseif ($this->_httpMethod == 'POST') {
796
        } elseif ($this->_httpMethod == 'POST') {
797
            return sprintf("<a href='javascript:void(0)' onclick='%s'%s%s%s title='%s'>%s</a>",
797
            return sprintf("<a href='javascript:void(0)' onclick='%s'%s%s%s title='%s'>%s</a>",
798
                           $this->_generateFormOnClick($this->_url, $this->_linkData),
798
                           $this->_generateFormOnClick($this->_url, $this->_linkData),
799
                           empty($this->_classString) ? '' : ' '.$this->_classString,
799
                           empty($this->_classString) ? '' : ' '.$this->_classString,
800
                           empty($this->_attributes)  ? '' : ' '.$this->_attributes,
800
                           empty($this->_attributes)  ? '' : ' '.$this->_attributes,
801
                           empty($this->_accesskey)   ? '' : ' accesskey=\''.$this->_linkData[$this->_urlVar].'\'',
801
                           empty($this->_accesskey)   ? '' : ' accesskey=\''.$this->_linkData[$this->_urlVar].'\'',
802
                           $altText,
802
                           $altText,
803
                           $linkText
803
                           $linkText
804
            );
804
            );
805
        }
805
        }
806
        return '';
806
        return '';
807
    }
807
    }
808
 
808
 
809
    // }}}
809
    // }}}
810
    // {{{ _generateFormOnClick()
810
    // {{{ _generateFormOnClick()
811
 
811
 
812
    /**
812
    /**
813
     * Mimics http_build_query() behavior in the way the data
813
     * Mimics http_build_query() behavior in the way the data
814
     * in $data will appear when it makes it back to the server.
814
     * in $data will appear when it makes it back to the server.
815
     *  For example:
815
     *  For example:
816
     * $arr =  array('array' => array(array('hello', 'world'),
816
     * $arr =  array('array' => array(array('hello', 'world'),
817
     *                                'things' => array('stuff', 'junk'));
817
     *                                'things' => array('stuff', 'junk'));
818
     * http_build_query($arr)
818
     * http_build_query($arr)
819
     * and _generateFormOnClick('foo.php', $arr)
819
     * and _generateFormOnClick('foo.php', $arr)
820
     * will yield
820
     * will yield
821
     * $_REQUEST['array'][0][0] === 'hello'
821
     * $_REQUEST['array'][0][0] === 'hello'
822
     * $_REQUEST['array'][0][1] === 'world'
822
     * $_REQUEST['array'][0][1] === 'world'
823
     * $_REQUEST['array']['things'][0] === 'stuff'
823
     * $_REQUEST['array']['things'][0] === 'stuff'
824
     * $_REQUEST['array']['things'][1] === 'junk'
824
     * $_REQUEST['array']['things'][1] === 'junk'
825
     *
825
     *
826
     * However, instead of  generating a query string, it generates
826
     * However, instead of  generating a query string, it generates
827
     * Javascript to create and submit a form.
827
     * Javascript to create and submit a form.
828
     *
828
     *
829
     * @param string $formAction where the form should be submitted
829
     * @param string $formAction where the form should be submitted
830
     * @param array  $data the associative array of names and values
830
     * @param array  $data the associative array of names and values
831
     * @return string A string of javascript that generates a form and submits it
831
     * @return string A string of javascript that generates a form and submits it
832
     * @access private
832
     * @access private
833
     */
833
     */
834
    function _generateFormOnClick($formAction, $data)
834
    function _generateFormOnClick($formAction, $data)
835
    {
835
    {
836
        // Check we have an array to work with
836
        // Check we have an array to work with
837
        if (!is_array($data)) {
837
        if (!is_array($data)) {
838
            trigger_error(
838
            trigger_error(
839
                '_generateForm() Parameter 1 expected to be Array or Object. Incorrect value given.',
839
                '_generateForm() Parameter 1 expected to be Array or Object. Incorrect value given.',
840
                E_USER_WARNING
840
                E_USER_WARNING
841
            );
841
            );
842
            return false;
842
            return false;
843
        }
843
        }
844
 
844
 
845
        if (!empty($this->_formID)) {
845
        if (!empty($this->_formID)) {
846
            $str = 'var form = document.getElementById("'.$this->_formID.'"); var input = ""; ';
846
            $str = 'var form = document.getElementById("'.$this->_formID.'"); var input = ""; ';
847
        } else {
847
        } else {
848
            $str = 'var form = document.createElement("form"); var input = ""; ';
848
            $str = 'var form = document.createElement("form"); var input = ""; ';
849
        }
849
        }
850
        
850
        
851
        // We /shouldn't/ need to escape the URL ...
851
        // We /shouldn't/ need to escape the URL ...
852
        $str .= sprintf('form.action = "%s"; ', htmlentities($formAction));
852
        $str .= sprintf('form.action = "%s"; ', htmlentities($formAction));
853
        $str .= sprintf('form.method = "%s"; ', $this->_httpMethod);
853
        $str .= sprintf('form.method = "%s"; ', $this->_httpMethod);
854
        foreach ($data as $key => $val) {
854
        foreach ($data as $key => $val) {
855
            $str .= $this->_generateFormOnClickHelper($val, $key);
855
            $str .= $this->_generateFormOnClickHelper($val, $key);
856
        }
856
        }
857
 
857
 
858
        if (empty($this->_formID)) {
858
        if (empty($this->_formID)) {
859
            $str .= 'document.getElementsByTagName("body")[0].appendChild(form);';
859
            $str .= 'document.getElementsByTagName("body")[0].appendChild(form);';
860
        }
860
        }
861
        
861
        
862
        $str .= 'form.submit(); return false;';
862
        $str .= 'form.submit(); return false;';
863
        return $str;
863
        return $str;
864
    }
864
    }
865
 
865
 
866
    // }}}
866
    // }}}
867
    // {{{ _generateFormOnClickHelper
867
    // {{{ _generateFormOnClickHelper
868
 
868
 
869
    /**
869
    /**
870
     * This is used by _generateFormOnClick(). 
870
     * This is used by _generateFormOnClick(). 
871
     * Recursively processes the arrays, objects, and literal values.
871
     * Recursively processes the arrays, objects, and literal values.
872
     *
872
     *
873
     * @param data Data that should be rendered
873
     * @param data Data that should be rendered
874
     * @param prev The name so far
874
     * @param prev The name so far
875
     * @return string A string of Javascript that creates form inputs
875
     * @return string A string of Javascript that creates form inputs
876
     *                representing the data
876
     *                representing the data
877
     * @access private
877
     * @access private
878
     */
878
     */
879
    function _generateFormOnClickHelper($data, $prev = '')
879
    function _generateFormOnClickHelper($data, $prev = '')
880
    {
880
    {
881
        $str = '';
881
        $str = '';
882
        if (is_array($data) || is_object($data)) {
882
        if (is_array($data) || is_object($data)) {
883
            // foreach key/visible member
883
            // foreach key/visible member
884
            foreach ((array)$data as $key => $val) {
884
            foreach ((array)$data as $key => $val) {
885
                // append [$key] to prev
885
                // append [$key] to prev
886
                $tempKey = sprintf('%s[%s]', $prev, $key);
886
                $tempKey = sprintf('%s[%s]', $prev, $key);
887
                $str .= $this->_generateFormOnClickHelper($val, $tempKey);
887
                $str .= $this->_generateFormOnClickHelper($val, $tempKey);
888
            }
888
            }
889
        } else {  // must be a literal value
889
        } else {  // must be a literal value
890
            // escape newlines and carriage returns
890
            // escape newlines and carriage returns
891
            $search  = array("\n", "\r");
891
            $search  = array("\n", "\r");
892
            $replace = array('\n', '\n');
892
            $replace = array('\n', '\n');
893
            $escapedData = str_replace($search, $replace, $data);
893
            $escapedData = str_replace($search, $replace, $data);
894
            // am I forgetting any dangerous whitespace?
894
            // am I forgetting any dangerous whitespace?
895
            // would a regex be faster?
895
            // would a regex be faster?
896
            // if it's already encoded, don't encode it again
896
            // if it's already encoded, don't encode it again
897
            if (!$this->_isEncoded($escapedData)) {
897
            if (!$this->_isEncoded($escapedData)) {
898
                $escapedData = urlencode($escapedData);
898
                $escapedData = urlencode($escapedData);
899
            }
899
            }
900
            $escapedData = htmlentities($escapedData, ENT_QUOTES, 'UTF-8');
900
            $escapedData = htmlentities($escapedData, ENT_QUOTES, 'UTF-8');
901
 
901
 
902
            $str .= 'input = document.createElement("input"); ';
902
            $str .= 'input = document.createElement("input"); ';
903
            $str .= 'input.type = "hidden"; ';
903
            $str .= 'input.type = "hidden"; ';
904
            $str .= sprintf('input.name = "%s"; ', $prev);
904
            $str .= sprintf('input.name = "%s"; ', $prev);
905
            $str .= sprintf('input.value = "%s"; ', $escapedData);
905
            $str .= sprintf('input.value = "%s"; ', $escapedData);
906
            $str .= 'form.appendChild(input); ';
906
            $str .= 'form.appendChild(input); ';
907
        }
907
        }
908
        return $str;
908
        return $str;
909
    }
909
    }
910
 
910
 
911
    // }}}
911
    // }}}
912
    // {{{ _getLinksData()
912
    // {{{ _getLinksData()
913
 
913
 
914
    /**
914
    /**
915
     * Returns the correct link for the back/pages/next links
915
     * Returns the correct link for the back/pages/next links
916
     *
916
     *
917
     * @return array Data
917
     * @return array Data
918
     * @access private
918
     * @access private
919
     */
919
     */
920
    function _getLinksData()
920
    function _getLinksData()
921
    {
921
    {
922
        $qs = array();
922
        $qs = array();
923
        if ($this->_importQuery) {
923
        if ($this->_importQuery) {
924
            if ($this->_httpMethod == 'POST') {
924
            if ($this->_httpMethod == 'POST') {
925
                $qs = $_POST;
925
                $qs = $_POST;
926
            } elseif ($this->_httpMethod == 'GET') {
926
            } elseif ($this->_httpMethod == 'GET') {
927
                $qs = $_GET;
927
                $qs = $_GET;
928
            }
928
            }
929
        }
929
        }
930
        foreach ($this->_excludeVars as $exclude) {
930
        foreach ($this->_excludeVars as $exclude) {
931
            if (array_key_exists($exclude, $qs)) {
931
            if (array_key_exists($exclude, $qs)) {
932
                unset($qs[$exclude]);
932
                unset($qs[$exclude]);
933
            }
933
            }
934
        }
934
        }
935
        if (count($this->_extraVars)){
935
        if (count($this->_extraVars)){
936
            $this->_recursive_urldecode($this->_extraVars);
936
            $this->_recursive_urldecode($this->_extraVars);
937
            $qs = array_merge($qs, $this->_extraVars);
937
            $qs = array_merge($qs, $this->_extraVars);
938
        }
938
        }
939
        if (count($qs) && get_magic_quotes_gpc()){
939
        if (count($qs) && get_magic_quotes_gpc()){
940
            $this->_recursive_stripslashes($qs);
940
            $this->_recursive_stripslashes($qs);
941
        }
941
        }
942
        return $qs;
942
        return $qs;
943
    }
943
    }
944
 
944
 
945
    // }}}
945
    // }}}
946
    // {{{ _recursive_stripslashes()
946
    // {{{ _recursive_stripslashes()
947
    
947
    
948
    /**
948
    /**
949
     * Helper method
949
     * Helper method
950
     * @param mixed $var
950
     * @param mixed $var
951
     * @access private
951
     * @access private
952
     */
952
     */
953
    function _recursive_stripslashes(&$var)
953
    function _recursive_stripslashes(&$var)
954
    {
954
    {
955
        if (is_array($var)) {
955
        if (is_array($var)) {
956
            foreach (array_keys($var) as $k) {
956
            foreach (array_keys($var) as $k) {
957
                $this->_recursive_stripslashes($var[$k]);
957
                $this->_recursive_stripslashes($var[$k]);
958
            }
958
            }
959
        } else {
959
        } else {
960
            $var = stripslashes($var);
960
            $var = stripslashes($var);
961
        }
961
        }
962
    }
962
    }
963
 
963
 
964
    // }}}
964
    // }}}
965
    // {{{ _recursive_urldecode()
965
    // {{{ _recursive_urldecode()
966
 
966
 
967
    /**
967
    /**
968
     * Helper method
968
     * Helper method
969
     * @param mixed $var
969
     * @param mixed $var
970
     * @access private
970
     * @access private
971
     */
971
     */
972
    function _recursive_urldecode(&$var)
972
    function _recursive_urldecode(&$var)
973
    {
973
    {
974
        if (is_array($var)) {
974
        if (is_array($var)) {
975
            foreach (array_keys($var) as $k) {
975
            foreach (array_keys($var) as $k) {
976
                $this->_recursive_urldecode($var[$k]);
976
                $this->_recursive_urldecode($var[$k]);
977
            }
977
            }
978
        } else {
978
        } else {
979
            $trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES));
979
            $trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES));
980
            $var = strtr($var, $trans_tbl);
980
            $var = strtr($var, $trans_tbl);
981
        }
981
        }
982
    }
982
    }
983
 
983
 
984
    // }}}
984
    // }}}
985
    // {{{ _getBackLink()
985
    // {{{ _getBackLink()
986
 
986
 
987
    /**
987
    /**
988
     * Returns back link
988
     * Returns back link
989
     *
989
     *
990
     * @param $url  URL to use in the link  [deprecated: use the factory instead]
990
     * @param $url  URL to use in the link  [deprecated: use the factory instead]
991
     * @param $link HTML to use as the link [deprecated: use the factory instead]
991
     * @param $link HTML to use as the link [deprecated: use the factory instead]
992
     * @return string The link
992
     * @return string The link
993
     * @access private
993
     * @access private
994
     */
994
     */
995
    function _getBackLink($url='', $link='')
995
    function _getBackLink($url='', $link='')
996
    {
996
    {
997
        //legacy settings... the preferred way to set an option
997
        //legacy settings... the preferred way to set an option
998
        //now is passing it to the factory
998
        //now is passing it to the factory
999
        if (!empty($url)) {
999
        if (!empty($url)) {
1000
            $this->_path = $url;
1000
            $this->_path = $url;
1001
        }
1001
        }
1002
        if (!empty($link)) {
1002
        if (!empty($link)) {
1003
            $this->_prevImg = $link;
1003
            $this->_prevImg = $link;
1004
        }
1004
        }
1005
        $back = '';
1005
        $back = '';
1006
        if ($this->_currentPage > 1) {
1006
        if ($this->_currentPage > 1) {
1007
            $this->_linkData[$this->_urlVar] = $this->getPreviousPageID();
1007
            $this->_linkData[$this->_urlVar] = $this->getPreviousPageID();
1008
            $back = $this->_renderLink($this->_altPrev, $this->_prevImg)
1008
            $back = $this->_renderLink($this->_altPrev, $this->_prevImg)
1009
                  . $this->_spacesBefore . $this->_spacesAfter;
1009
                  . $this->_spacesBefore . $this->_spacesAfter;
1010
        }
1010
        }
1011
        return $back;
1011
        return $back;
1012
    }
1012
    }
1013
 
1013
 
1014
    // }}}
1014
    // }}}
1015
    // {{{ _getPageLinks()
1015
    // {{{ _getPageLinks()
1016
 
1016
 
1017
    /**
1017
    /**
1018
     * Returns pages link
1018
     * Returns pages link
1019
     *
1019
     *
1020
     * @param $url  URL to use in the link [deprecated: use the factory instead]
1020
     * @param $url  URL to use in the link [deprecated: use the factory instead]
1021
     * @return string Links
1021
     * @return string Links
1022
     * @access private
1022
     * @access private
1023
     */
1023
     */
1024
    function _getPageLinks($url='')
1024
    function _getPageLinks($url='')
1025
    {
1025
    {
1026
        $msg = '<b>PEAR::Pager Error:</b>'
1026
        $msg = '<b>PEAR::Pager Error:</b>'
1027
              .' function "_getPageLinks()" not implemented.';
1027
              .' function "_getPageLinks()" not implemented.';
1028
        return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
1028
        return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
1029
    }
1029
    }
1030
 
1030
 
1031
    // }}}
1031
    // }}}
1032
    // {{{ _getNextLink()
1032
    // {{{ _getNextLink()
1033
 
1033
 
1034
    /**
1034
    /**
1035
     * Returns next link
1035
     * Returns next link
1036
     *
1036
     *
1037
     * @param $url  URL to use in the link  [deprecated: use the factory instead]
1037
     * @param $url  URL to use in the link  [deprecated: use the factory instead]
1038
     * @param $link HTML to use as the link [deprecated: use the factory instead]
1038
     * @param $link HTML to use as the link [deprecated: use the factory instead]
1039
     * @return string The link
1039
     * @return string The link
1040
     * @access private
1040
     * @access private
1041
     */
1041
     */
1042
    function _getNextLink($url='', $link='')
1042
    function _getNextLink($url='', $link='')
1043
    {
1043
    {
1044
        //legacy settings... the preferred way to set an option
1044
        //legacy settings... the preferred way to set an option
1045
        //now is passing it to the factory
1045
        //now is passing it to the factory
1046
        if (!empty($url)) {
1046
        if (!empty($url)) {
1047
            $this->_path = $url;
1047
            $this->_path = $url;
1048
        }
1048
        }
1049
        if (!empty($link)) {
1049
        if (!empty($link)) {
1050
            $this->_nextImg = $link;
1050
            $this->_nextImg = $link;
1051
        }
1051
        }
1052
        $next = '';
1052
        $next = '';
1053
        if ($this->_currentPage < $this->_totalPages) {
1053
        if ($this->_currentPage < $this->_totalPages) {
1054
            $this->_linkData[$this->_urlVar] = $this->getNextPageID();
1054
            $this->_linkData[$this->_urlVar] = $this->getNextPageID();
1055
            $next = $this->_spacesAfter
1055
            $next = $this->_spacesAfter
1056
                  . $this->_renderLink($this->_altNext, $this->_nextImg)
1056
                  . $this->_renderLink($this->_altNext, $this->_nextImg)
1057
                  . $this->_spacesBefore . $this->_spacesAfter;
1057
                  . $this->_spacesBefore . $this->_spacesAfter;
1058
        }
1058
        }
1059
        return $next;
1059
        return $next;
1060
    }
1060
    }
1061
 
1061
 
1062
    // }}}
1062
    // }}}
1063
    // {{{ _getFirstLinkTag()
1063
    // {{{ _getFirstLinkTag()
1064
 
1064
 
1065
    /**
1065
    /**
1066
     * @return string
1066
     * @return string
1067
     * @access private
1067
     * @access private
1068
     */
1068
     */
1069
    function _getFirstLinkTag()
1069
    function _getFirstLinkTag()
1070
    {
1070
    {
1071
        if ($this->isFirstPage() || ($this->_httpMethod != 'GET')) {
1071
        if ($this->isFirstPage() || ($this->_httpMethod != 'GET')) {
1072
            return '';
1072
            return '';
1073
        }
1073
        }
1074
        return sprintf('<link rel="first" href="%s" title="%s" />'."\n",
1074
        return sprintf('<link rel="first" href="%s" title="%s" />'."\n",
1075
            $this->_getLinkTagUrl(1),
1075
            $this->_getLinkTagUrl(1),
1076
            $this->_firstLinkTitle
1076
            $this->_firstLinkTitle
1077
        );
1077
        );
1078
    }
1078
    }
1079
 
1079
 
1080
    // }}}
1080
    // }}}
1081
    // {{{ _getPrevLinkTag()
1081
    // {{{ _getPrevLinkTag()
1082
 
1082
 
1083
    /**
1083
    /**
1084
     * Returns previous link tag
1084
     * Returns previous link tag
1085
     *
1085
     *
1086
     * @return string the link tag
1086
     * @return string the link tag
1087
     * @access private
1087
     * @access private
1088
     */
1088
     */
1089
    function _getPrevLinkTag()
1089
    function _getPrevLinkTag()
1090
    {
1090
    {
1091
        if ($this->isFirstPage() || ($this->_httpMethod != 'GET')) {
1091
        if ($this->isFirstPage() || ($this->_httpMethod != 'GET')) {
1092
            return '';
1092
            return '';
1093
        }
1093
        }
1094
        return sprintf('<link rel="previous" href="%s" title="%s" />'."\n",
1094
        return sprintf('<link rel="previous" href="%s" title="%s" />'."\n",
1095
            $this->_getLinkTagUrl($this->getPreviousPageID()),
1095
            $this->_getLinkTagUrl($this->getPreviousPageID()),
1096
            $this->_prevLinkTitle
1096
            $this->_prevLinkTitle
1097
        );
1097
        );
1098
    }
1098
    }
1099
 
1099
 
1100
    // }}}
1100
    // }}}
1101
    // {{{ _getNextLinkTag()
1101
    // {{{ _getNextLinkTag()
1102
 
1102
 
1103
    /**
1103
    /**
1104
     * Returns next link tag
1104
     * Returns next link tag
1105
     *
1105
     *
1106
     * @return string the link tag
1106
     * @return string the link tag
1107
     * @access private
1107
     * @access private
1108
     */
1108
     */
1109
    function _getNextLinkTag()
1109
    function _getNextLinkTag()
1110
    {
1110
    {
1111
        if ($this->isLastPage() || ($this->_httpMethod != 'GET')) {
1111
        if ($this->isLastPage() || ($this->_httpMethod != 'GET')) {
1112
            return '';
1112
            return '';
1113
        }
1113
        }
1114
        return sprintf('<link rel="next" href="%s" title="%s" />'."\n",
1114
        return sprintf('<link rel="next" href="%s" title="%s" />'."\n",
1115
            $this->_getLinkTagUrl($this->getNextPageID()),
1115
            $this->_getLinkTagUrl($this->getNextPageID()),
1116
            $this->_nextLinkTitle
1116
            $this->_nextLinkTitle
1117
        );
1117
        );
1118
    }
1118
    }
1119
 
1119
 
1120
    // }}}
1120
    // }}}
1121
    // {{{ _getLastLinkTag()
1121
    // {{{ _getLastLinkTag()
1122
 
1122
 
1123
    /**
1123
    /**
1124
     * @return string the link tag
1124
     * @return string the link tag
1125
     * @access private
1125
     * @access private
1126
     */
1126
     */
1127
    function _getLastLinkTag()
1127
    function _getLastLinkTag()
1128
    {
1128
    {
1129
        if ($this->isLastPage() || ($this->_httpMethod != 'GET')) {
1129
        if ($this->isLastPage() || ($this->_httpMethod != 'GET')) {
1130
            return '';
1130
            return '';
1131
        }
1131
        }
1132
        return sprintf('<link rel="last" href="%s" title="%s" />'."\n",
1132
        return sprintf('<link rel="last" href="%s" title="%s" />'."\n",
1133
            $this->_getLinkTagUrl($this->_totalPages),
1133
            $this->_getLinkTagUrl($this->_totalPages),
1134
            $this->_lastLinkTitle
1134
            $this->_lastLinkTitle
1135
        );
1135
        );
1136
    }
1136
    }
1137
 
1137
 
1138
    // }}}
1138
    // }}}
1139
    // {{{ _getLinkTagUrl()
1139
    // {{{ _getLinkTagUrl()
1140
 
1140
 
1141
    /**
1141
    /**
1142
     * Helper method
1142
     * Helper method
1143
     * @return string the link tag url
1143
     * @return string the link tag url
1144
     * @access private
1144
     * @access private
1145
     */
1145
     */
1146
    function _getLinkTagUrl($pageID)
1146
    function _getLinkTagUrl($pageID)
1147
    {
1147
    {
1148
        $this->_linkData[$this->_urlVar] = $pageID;
1148
        $this->_linkData[$this->_urlVar] = $pageID;
1149
        if ($this->_append) {
1149
        if ($this->_append) {
1150
            $href = '?' . $this->_http_build_query_wrapper($this->_linkData);
1150
            $href = '?' . $this->_http_build_query_wrapper($this->_linkData);
1151
        } else {
1151
        } else {
1152
            $href = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_fileName);
1152
            $href = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_fileName);
1153
        }
1153
        }
1154
        return htmlentities($this->_url . $href);
1154
        return htmlentities($this->_url . $href);
1155
    }
1155
    }
1156
    
1156
    
1157
    // }}}
1157
    // }}}
1158
    // {{{ getPerPageSelectBox()
1158
    // {{{ getPerPageSelectBox()
1159
 
1159
 
1160
    /**
1160
    /**
1161
     * Returns a string with a XHTML SELECT menu,
1161
     * Returns a string with a XHTML SELECT menu,
1162
     * useful for letting the user choose how many items per page should be
1162
     * useful for letting the user choose how many items per page should be
1163
     * displayed. If parameter useSessions is TRUE, this value is stored in
1163
     * displayed. If parameter useSessions is TRUE, this value is stored in
1164
     * a session var. The string isn't echoed right now so you can use it
1164
     * a session var. The string isn't echoed right now so you can use it
1165
     * with template engines.
1165
     * with template engines.
1166
     *
1166
     *
1167
     * @param integer $start
1167
     * @param integer $start
1168
     * @param integer $end
1168
     * @param integer $end
1169
     * @param integer $step
1169
     * @param integer $step
1170
     * @param boolean $showAllData If true, perPage is set equal to totalItems.
1170
     * @param boolean $showAllData If true, perPage is set equal to totalItems.
1171
     * @param array   (or string $optionText for BC reasons)
1171
     * @param array   (or string $optionText for BC reasons)
1172
     *                - 'optionText': text to show in each option.
1172
     *                - 'optionText': text to show in each option.
1173
     *                  Use '%d' where you want to see the number of pages selected.
1173
     *                  Use '%d' where you want to see the number of pages selected.
1174
     *                - 'attributes': (html attributes) Tag attributes or
1174
     *                - 'attributes': (html attributes) Tag attributes or
1175
     *                  HTML attributes (id="foo" pairs), will be inserted in the
1175
     *                  HTML attributes (id="foo" pairs), will be inserted in the
1176
     *                  <select> tag
1176
     *                  <select> tag
1177
     * @return string xhtml select box
1177
     * @return string xhtml select box
1178
     * @access public
1178
     * @access public
1179
     */
1179
     */
1180
    function getPerPageSelectBox($start=5, $end=30, $step=5, $showAllData=false, $extraParams=array())
1180
    function getPerPageSelectBox($start=5, $end=30, $step=5, $showAllData=false, $extraParams=array())
1181
    {
1181
    {
1182
        require_once 'Pager/HtmlWidgets.php';
1182
        require_once 'Pager/HtmlWidgets.php';
1183
        $widget =& new Pager_HtmlWidgets($this);
1183
        $widget = new Pager_HtmlWidgets($this);
1184
        return $widget->getPerPageSelectBox($start, $end, $step, $showAllData, $extraParams);
1184
        return $widget->getPerPageSelectBox($start, $end, $step, $showAllData, $extraParams);
1185
    }
1185
    }
1186
 
1186
 
1187
    // }}}
1187
    // }}}
1188
    // {{{ getPageSelectBox()
1188
    // {{{ getPageSelectBox()
1189
 
1189
 
1190
    /**
1190
    /**
1191
     * Returns a string with a XHTML SELECT menu with the page numbers,
1191
     * Returns a string with a XHTML SELECT menu with the page numbers,
1192
     * useful as an alternative to the links
1192
     * useful as an alternative to the links
1193
     *
1193
     *
1194
     * @param array   - 'optionText': text to show in each option.
1194
     * @param array   - 'optionText': text to show in each option.
1195
     *                  Use '%d' where you want to see the number of pages selected.
1195
     *                  Use '%d' where you want to see the number of pages selected.
1196
     *                - 'autoSubmit': if TRUE, add some js code to submit the
1196
     *                - 'autoSubmit': if TRUE, add some js code to submit the
1197
     *                  form on the onChange event
1197
     *                  form on the onChange event
1198
     * @param string   $extraAttributes (html attributes) Tag attributes or
1198
     * @param string   $extraAttributes (html attributes) Tag attributes or
1199
     *                  HTML attributes (id="foo" pairs), will be inserted in the
1199
     *                  HTML attributes (id="foo" pairs), will be inserted in the
1200
     *                  <select> tag
1200
     *                  <select> tag
1201
     * @return string xhtml select box
1201
     * @return string xhtml select box
1202
     * @access public
1202
     * @access public
1203
     */
1203
     */
1204
    function getPageSelectBox($params = array(), $extraAttributes = '')
1204
    function getPageSelectBox($params = array(), $extraAttributes = '')
1205
    {
1205
    {
1206
        require_once 'Pager/HtmlWidgets.php';
1206
        require_once 'Pager/HtmlWidgets.php';
1207
        $widget =& new Pager_HtmlWidgets($this);
1207
        $widget = new Pager_HtmlWidgets($this);
1208
        return $widget->getPageSelectBox($params, $extraAttributes);
1208
        return $widget->getPageSelectBox($params, $extraAttributes);
1209
    }
1209
    }
1210
 
1210
 
1211
    // }}}
1211
    // }}}
1212
    // {{{ _printFirstPage()
1212
    // {{{ _printFirstPage()
1213
 
1213
 
1214
    /**
1214
    /**
1215
     * Print [1]
1215
     * Print [1]
1216
     *
1216
     *
1217
     * @return string String with link to 1st page,
1217
     * @return string String with link to 1st page,
1218
     *                or empty string if this is the 1st page.
1218
     *                or empty string if this is the 1st page.
1219
     * @access private
1219
     * @access private
1220
     */
1220
     */
1221
    function _printFirstPage()
1221
    function _printFirstPage()
1222
    {
1222
    {
1223
        if ($this->isFirstPage()) {
1223
        if ($this->isFirstPage()) {
1224
            return '';
1224
            return '';
1225
        }
1225
        }
1226
        $this->_linkData[$this->_urlVar] = 1;
1226
        $this->_linkData[$this->_urlVar] = 1;
1227
        return $this->_renderLink(
1227
        return $this->_renderLink(
1228
                str_replace('%d', 1, $this->_altFirst),
1228
                str_replace('%d', 1, $this->_altFirst),
1229
                $this->_firstPagePre . $this->_firstPageText . $this->_firstPagePost
1229
                $this->_firstPagePre . $this->_firstPageText . $this->_firstPagePost
1230
        ) . $this->_spacesBefore . $this->_spacesAfter;
1230
        ) . $this->_spacesBefore . $this->_spacesAfter;
1231
    }
1231
    }
1232
 
1232
 
1233
    // }}}
1233
    // }}}
1234
    // {{{ _printLastPage()
1234
    // {{{ _printLastPage()
1235
 
1235
 
1236
    /**
1236
    /**
1237
     * Print [numPages()]
1237
     * Print [numPages()]
1238
     *
1238
     *
1239
     * @return string String with link to last page,
1239
     * @return string String with link to last page,
1240
     *                or empty string if this is the 1st page.
1240
     *                or empty string if this is the 1st page.
1241
     * @access private
1241
     * @access private
1242
     */
1242
     */
1243
    function _printLastPage()
1243
    function _printLastPage()
1244
    {
1244
    {
1245
        if ($this->isLastPage()) {
1245
        if ($this->isLastPage()) {
1246
            return '';
1246
            return '';
1247
        }
1247
        }
1248
        $this->_linkData[$this->_urlVar] = $this->_totalPages;
1248
        $this->_linkData[$this->_urlVar] = $this->_totalPages;
1249
        return $this->_renderLink(
1249
        return $this->_renderLink(
1250
                str_replace('%d', $this->_totalPages, $this->_altLast),
1250
                str_replace('%d', $this->_totalPages, $this->_altLast),
1251
                $this->_lastPagePre . $this->_lastPageText . $this->_lastPagePost
1251
                $this->_lastPagePre . $this->_lastPageText . $this->_lastPagePost
1252
        );
1252
        );
1253
    }
1253
    }
1254
 
1254
 
1255
    // }}}
1255
    // }}}
1256
    // {{{ _setFirstLastText()
1256
    // {{{ _setFirstLastText()
1257
 
1257
 
1258
    /**
1258
    /**
1259
     * sets the private _firstPageText, _lastPageText variables
1259
     * sets the private _firstPageText, _lastPageText variables
1260
     * based on whether they were set in the options
1260
     * based on whether they were set in the options
1261
     *
1261
     *
1262
     * @access private
1262
     * @access private
1263
     */
1263
     */
1264
    function _setFirstLastText()
1264
    function _setFirstLastText()
1265
    {
1265
    {
1266
        if ($this->_firstPageText == '') {
1266
        if ($this->_firstPageText == '') {
1267
            $this->_firstPageText = '1';
1267
            $this->_firstPageText = '1';
1268
        }
1268
        }
1269
        if ($this->_lastPageText == '') {
1269
        if ($this->_lastPageText == '') {
1270
            $this->_lastPageText = $this->_totalPages;
1270
            $this->_lastPageText = $this->_totalPages;
1271
        }
1271
        }
1272
    }
1272
    }
1273
 
1273
 
1274
    // }}}
1274
    // }}}
1275
    // {{{ _http_build_query_wrapper()
1275
    // {{{ _http_build_query_wrapper()
1276
    
1276
    
1277
    /**
1277
    /**
1278
     * This is a slightly modified version of the http_build_query() function;
1278
     * This is a slightly modified version of the http_build_query() function;
1279
     * it heavily borrows code from PHP_Compat's http_build_query().
1279
     * it heavily borrows code from PHP_Compat's http_build_query().
1280
     * The main change is the usage of htmlentities instead of urlencode,
1280
     * The main change is the usage of htmlentities instead of urlencode,
1281
     * since it's too aggressive
1281
     * since it's too aggressive
1282
     *
1282
     *
1283
     * @author Stephan Schmidt <schst@php.net>
1283
     * @author Stephan Schmidt <schst@php.net>
1284
     * @author Aidan Lister <aidan@php.net>
1284
     * @author Aidan Lister <aidan@php.net>
1285
     * @author Lorenzo Alberton <l dot alberton at quipo dot it>
1285
     * @author Lorenzo Alberton <l dot alberton at quipo dot it>
1286
     * @param array $data
1286
     * @param array $data
1287
     * @return string
1287
     * @return string
1288
     * @access private
1288
     * @access private
1289
     */
1289
     */
1290
    function _http_build_query_wrapper($data)
1290
    function _http_build_query_wrapper($data)
1291
    {
1291
    {
1292
        $data = (array)$data;
1292
        $data = (array)$data;
1293
        if (empty($data)) {
1293
        if (empty($data)) {
1294
            return '';
1294
            return '';
1295
        }
1295
        }
1296
        $separator = ini_get('arg_separator.output');
1296
        $separator = ini_get('arg_separator.output');
1297
        if ($separator == '&amp;') {
1297
        if ($separator == '&amp;') {
1298
            $separator = '&'; //the string is escaped by htmlentities anyway...
1298
            $separator = '&'; //the string is escaped by htmlentities anyway...
1299
        }
1299
        }
1300
        $tmp = array ();
1300
        $tmp = array ();
1301
        foreach ($data as $key => $val) {
1301
        foreach ($data as $key => $val) {
1302
            if (is_scalar($val)) {
1302
            if (is_scalar($val)) {
1303
                //array_push($tmp, $key.'='.$val);
1303
                //array_push($tmp, $key.'='.$val);
1304
                $val = urlencode($val);
1304
                $val = urlencode($val);
1305
                array_push($tmp, $key .'='. str_replace('%2F', '/', $val));
1305
                array_push($tmp, $key .'='. str_replace('%2F', '/', $val));
1306
                continue;
1306
                continue;
1307
            }
1307
            }
1308
            // If the value is an array, recursively parse it
1308
            // If the value is an array, recursively parse it
1309
            if (is_array($val)) {
1309
            if (is_array($val)) {
1310
                array_push($tmp, $this->__http_build_query($val, htmlentities($key)));
1310
                array_push($tmp, $this->__http_build_query($val, htmlentities($key)));
1311
                continue;
1311
                continue;
1312
            }
1312
            }
1313
        }
1313
        }
1314
        return implode($separator, $tmp);
1314
        return implode($separator, $tmp);
1315
    }
1315
    }
1316
 
1316
 
1317
    // }}}
1317
    // }}}
1318
    // {{{ __http_build_query()
1318
    // {{{ __http_build_query()
1319
 
1319
 
1320
    /**
1320
    /**
1321
     * Helper function
1321
     * Helper function
1322
     * @author Stephan Schmidt <schst@php.net>
1322
     * @author Stephan Schmidt <schst@php.net>
1323
     * @author Aidan Lister <aidan@php.net>
1323
     * @author Aidan Lister <aidan@php.net>
1324
     * @access private
1324
     * @access private
1325
     */
1325
     */
1326
    function __http_build_query($array, $name)
1326
    function __http_build_query($array, $name)
1327
    {
1327
    {
1328
        $tmp = array ();
1328
        $tmp = array ();
1329
        $separator = ini_get('arg_separator.output');
1329
        $separator = ini_get('arg_separator.output');
1330
        if ($separator == '&amp;') {
1330
        if ($separator == '&amp;') {
1331
            $separator = '&'; //the string is escaped by htmlentities anyway...
1331
            $separator = '&'; //the string is escaped by htmlentities anyway...
1332
        }
1332
        }
1333
        foreach ($array as $key => $value) {
1333
        foreach ($array as $key => $value) {
1334
            if (is_array($value)) {
1334
            if (is_array($value)) {
1335
                //array_push($tmp, $this->__http_build_query($value, sprintf('%s[%s]', $name, $key)));
1335
                //array_push($tmp, $this->__http_build_query($value, sprintf('%s[%s]', $name, $key)));
1336
                array_push($tmp, $this->__http_build_query($value, $name.'%5B'.$key.'%5D'));
1336
                array_push($tmp, $this->__http_build_query($value, $name.'%5B'.$key.'%5D'));
1337
            } elseif (is_scalar($value)) {
1337
            } elseif (is_scalar($value)) {
1338
                //array_push($tmp, sprintf('%s[%s]=%s', $name, htmlentities($key), htmlentities($value)));
1338
                //array_push($tmp, sprintf('%s[%s]=%s', $name, htmlentities($key), htmlentities($value)));
1339
                array_push($tmp, $name.'%5B'.htmlentities($key).'%5D='.htmlentities($value));
1339
                array_push($tmp, $name.'%5B'.htmlentities($key).'%5D='.htmlentities($value));
1340
            } elseif (is_object($value)) {
1340
            } elseif (is_object($value)) {
1341
                //array_push($tmp, $this->__http_build_query(get_object_vars($value), sprintf('%s[%s]', $name, $key)));
1341
                //array_push($tmp, $this->__http_build_query(get_object_vars($value), sprintf('%s[%s]', $name, $key)));
1342
                array_push($tmp, $this->__http_build_query(get_object_vars($value), $name.'%5B'.$key.'%5D'));
1342
                array_push($tmp, $this->__http_build_query(get_object_vars($value), $name.'%5B'.$key.'%5D'));
1343
            }
1343
            }
1344
        }
1344
        }
1345
        return implode($separator, $tmp);
1345
        return implode($separator, $tmp);
1346
    }
1346
    }
1347
 
1347
 
1348
    // }}}
1348
    // }}}
1349
    // {{{ _isEncoded()
1349
    // {{{ _isEncoded()
1350
 
1350
 
1351
    /**
1351
    /**
1352
     * Helper function
1352
     * Helper function
1353
     * Check if a string is an encoded multibyte string
1353
     * Check if a string is an encoded multibyte string
1354
     * @param string $string
1354
     * @param string $string
1355
     * @return boolean
1355
     * @return boolean
1356
     * @access private
1356
     * @access private
1357
     */
1357
     */
1358
    
1358
    
1359
    function _isEncoded($string)
1359
    function _isEncoded($string)
1360
    {
1360
    {
1361
        $hexchar = '&#[\dA-Fx]{2,};';
1361
        $hexchar = '&#[\dA-Fx]{2,};';
1362
        return preg_match("/^(\s|($hexchar))*$/Uims", $string) ? true : false;
1362
        return preg_match("/^(\s|($hexchar))*$/Uims", $string) ? true : false;
1363
    }
1363
    }
1364
 
1364
 
1365
    // }}}
1365
    // }}}
1366
    // {{{ raiseError()
1366
    // {{{ raiseError()
1367
 
1367
 
1368
    /**
1368
    /**
1369
     * conditionally includes PEAR base class and raise an error
1369
     * conditionally includes PEAR base class and raise an error
1370
     *
1370
     *
1371
     * @param string $msg  Error message
1371
     * @param string $msg  Error message
1372
     * @param int    $code Error code
1372
     * @param int    $code Error code
1373
     * @access private
1373
     * @access private
1374
     */
1374
     */
1375
    function raiseError($msg, $code)
1375
    function raiseError($msg, $code)
1376
    {
1376
    {
1377
        include_once 'PEAR.php';
1377
        include_once 'PEAR.php';
1378
        if (empty($this->_pearErrorMode)) {
1378
        if (empty($this->_pearErrorMode)) {
1379
            $this->_pearErrorMode = PEAR_ERROR_RETURN;
1379
            $this->_pearErrorMode = PEAR_ERROR_RETURN;
1380
        }
1380
        }
1381
        return PEAR::raiseError($msg, $code, $this->_pearErrorMode);
1381
        return PEAR::raiseError($msg, $code, $this->_pearErrorMode);
1382
    }
1382
    }
1383
 
1383
 
1384
    // }}}
1384
    // }}}
1385
    // {{{ setOptions()
1385
    // {{{ setOptions()
1386
 
1386
 
1387
    /**
1387
    /**
1388
     * Set and sanitize options
1388
     * Set and sanitize options
1389
     *
1389
     *
1390
     * @param mixed $options    An associative array of option names and
1390
     * @param mixed $options    An associative array of option names and
1391
     *                          their values.
1391
     *                          their values.
1392
     * @return integer error code (PAGER_OK on success)
1392
     * @return integer error code (PAGER_OK on success)
1393
     * @access public
1393
     * @access public
1394
     */
1394
     */
1395
    function setOptions($options)
1395
    function setOptions($options)
1396
    {
1396
    {
1397
        foreach ($options as $key => $value) {
1397
        foreach ($options as $key => $value) {
1398
            if (in_array($key, $this->_allowed_options) && (!is_null($value))) {
1398
            if (in_array($key, $this->_allowed_options) && (!is_null($value))) {
1399
                $this->{'_' . $key} = $value;
1399
                $this->{'_' . $key} = $value;
1400
            }
1400
            }
1401
        }
1401
        }
1402
 
1402
 
1403
        //autodetect http method
1403
        //autodetect http method
1404
        if (!isset($options['httpMethod'])
1404
        if (!isset($options['httpMethod'])
1405
            && !isset($_GET[$this->_urlVar])
1405
            && !isset($_GET[$this->_urlVar])
1406
            && isset($_POST[$this->_urlVar])
1406
            && isset($_POST[$this->_urlVar])
1407
        ) {
1407
        ) {
1408
            $this->_httpMethod = 'POST';
1408
            $this->_httpMethod = 'POST';
1409
        } else {
1409
        } else {
1410
            $this->_httpMethod = strtoupper($this->_httpMethod);
1410
            $this->_httpMethod = strtoupper($this->_httpMethod);
1411
        }
1411
        }
1412
 
1412
 
1413
        $this->_fileName = ltrim($this->_fileName, '/');  //strip leading slash
1413
        $this->_fileName = ltrim($this->_fileName, '/');  //strip leading slash
1414
        $this->_path     = rtrim($this->_path, '/');      //strip trailing slash
1414
        $this->_path     = rtrim($this->_path, '/');      //strip trailing slash
1415
 
1415
 
1416
        if ($this->_append) {
1416
        if ($this->_append) {
1417
            if ($this->_fixFileName) {
1417
            if ($this->_fixFileName) {
1418
                $this->_fileName = CURRENT_FILENAME; //avoid possible user error;
1418
                $this->_fileName = CURRENT_FILENAME; //avoid possible user error;
1419
            }
1419
            }
1420
            $this->_url = $this->_path.'/'.$this->_fileName;
1420
            $this->_url = $this->_path.'/'.$this->_fileName;
1421
        } else {
1421
        } else {
1422
            $this->_url = $this->_path;
1422
            $this->_url = $this->_path;
1423
            if (strncasecmp($this->_fileName, 'javascript', 10) != 0) {
1423
            if (strncasecmp($this->_fileName, 'javascript', 10) != 0) {
1424
                $this->_url .= '/';
1424
                $this->_url .= '/';
1425
            }
1425
            }
1426
            if (strpos($this->_fileName, '%d') === false) {
1426
            if (strpos($this->_fileName, '%d') === false) {
1427
                trigger_error($this->errorMessage(ERROR_PAGER_INVALID_USAGE), E_USER_WARNING);
1427
                trigger_error($this->errorMessage(ERROR_PAGER_INVALID_USAGE), E_USER_WARNING);
1428
            }
1428
            }
1429
        }
1429
        }
1430
 
1430
 
1431
        $this->_classString = '';
1431
        $this->_classString = '';
1432
        if (strlen($this->_linkClass)) {
1432
        if (strlen($this->_linkClass)) {
1433
            $this->_classString = 'class="'.$this->_linkClass.'"';
1433
            $this->_classString = 'class="'.$this->_linkClass.'"';
1434
        }
1434
        }
1435
 
1435
 
1436
        if (strlen($this->_curPageLinkClassName)) {
1436
        if (strlen($this->_curPageLinkClassName)) {
1437
            $this->_curPageSpanPre  = '<span class="'.$this->_curPageLinkClassName.'">';
1437
            $this->_curPageSpanPre  = '<span class="'.$this->_curPageLinkClassName.'">';
1438
            $this->_curPageSpanPost = '</span>';
1438
            $this->_curPageSpanPost = '</span>';
1439
        }
1439
        }
1440
 
1440
 
1441
        $this->_perPage = max($this->_perPage, 1); //avoid possible user errors
1441
        $this->_perPage = max($this->_perPage, 1); //avoid possible user errors
1442
 
1442
 
1443
        if ($this->_useSessions && !isset($_SESSION)) {
1443
        if ($this->_useSessions && !isset($_SESSION)) {
1444
            session_start();
1444
            session_start();
1445
        }
1445
        }
1446
        if (!empty($_REQUEST[$this->_sessionVar])) {
1446
        if (!empty($_REQUEST[$this->_sessionVar])) {
1447
            $this->_perPage = max(1, (int)$_REQUEST[$this->_sessionVar]);
1447
            $this->_perPage = max(1, (int)$_REQUEST[$this->_sessionVar]);
1448
            if ($this->_useSessions) {
1448
            if ($this->_useSessions) {
1449
                $_SESSION[$this->_sessionVar] = $this->_perPage;
1449
                $_SESSION[$this->_sessionVar] = $this->_perPage;
1450
            }
1450
            }
1451
        }
1451
        }
1452
 
1452
 
1453
        if (!empty($_SESSION[$this->_sessionVar])) {
1453
        if (!empty($_SESSION[$this->_sessionVar])) {
1454
             $this->_perPage = $_SESSION[$this->_sessionVar];
1454
             $this->_perPage = $_SESSION[$this->_sessionVar];
1455
        }
1455
        }
1456
 
1456
 
1457
        if ($this->_closeSession) {
1457
        if ($this->_closeSession) {
1458
            session_write_close();
1458
            session_write_close();
1459
        }
1459
        }
1460
 
1460
 
1461
        $this->_spacesBefore = str_repeat('&nbsp;', $this->_spacesBeforeSeparator);
1461
        $this->_spacesBefore = str_repeat('&nbsp;', $this->_spacesBeforeSeparator);
1462
        $this->_spacesAfter  = str_repeat('&nbsp;', $this->_spacesAfterSeparator);
1462
        $this->_spacesAfter  = str_repeat('&nbsp;', $this->_spacesAfterSeparator);
1463
 
1463
 
1464
        if (isset($_REQUEST[$this->_urlVar]) && empty($options['currentPage'])) {
1464
        if (isset($_REQUEST[$this->_urlVar]) && empty($options['currentPage'])) {
1465
            $this->_currentPage = (int)$_REQUEST[$this->_urlVar];
1465
            $this->_currentPage = (int)$_REQUEST[$this->_urlVar];
1466
        }
1466
        }
1467
        $this->_currentPage = max($this->_currentPage, 1);
1467
        $this->_currentPage = max($this->_currentPage, 1);
1468
        $this->_linkData = $this->_getLinksData();
1468
        $this->_linkData = $this->_getLinksData();
1469
 
1469
 
1470
        return PAGER_OK;
1470
        return PAGER_OK;
1471
    }
1471
    }
1472
 
1472
 
1473
    // }}}
1473
    // }}}
1474
    // {{{ getOption()
1474
    // {{{ getOption()
1475
    
1475
    
1476
    /**
1476
    /**
1477
     * Return the current value of a given option
1477
     * Return the current value of a given option
1478
     *
1478
     *
1479
     * @param string option name
1479
     * @param string option name
1480
     * @return mixed option value
1480
     * @return mixed option value
1481
     */
1481
     */
1482
    function getOption($name)
1482
    function getOption($name)
1483
    {
1483
    {
1484
        if (!in_array($name, $this->_allowed_options)) {
1484
        if (!in_array($name, $this->_allowed_options)) {
1485
            $msg = '<b>PEAR::Pager Error:</b>'
1485
            $msg = '<b>PEAR::Pager Error:</b>'
1486
                  .' invalid option: '.$name;
1486
                  .' invalid option: '.$name;
1487
            return $this->raiseError($msg, ERROR_PAGER_INVALID);
1487
            return $this->raiseError($msg, ERROR_PAGER_INVALID);
1488
        }
1488
        }
1489
        return $this->{'_' . $name};
1489
        return $this->{'_' . $name};
1490
    }
1490
    }
1491
 
1491
 
1492
    // }}}
1492
    // }}}
1493
    // {{{ getOptions()
1493
    // {{{ getOptions()
1494
 
1494
 
1495
    /**
1495
    /**
1496
     * Return an array with all the current pager options
1496
     * Return an array with all the current pager options
1497
     *
1497
     *
1498
     * @return array list of all the pager options
1498
     * @return array list of all the pager options
1499
     */
1499
     */
1500
    function getOptions()
1500
    function getOptions()
1501
    {
1501
    {
1502
        $options = array();
1502
        $options = array();
1503
        foreach ($this->_allowed_options as $option) {
1503
        foreach ($this->_allowed_options as $option) {
1504
            $options[$option] = $this->{'_' . $option};
1504
            $options[$option] = $this->{'_' . $option};
1505
        }
1505
        }
1506
        return $options;
1506
        return $options;
1507
    }
1507
    }
1508
 
1508
 
1509
    // }}}
1509
    // }}}
1510
    // {{{ errorMessage()
1510
    // {{{ errorMessage()
1511
 
1511
 
1512
    /**
1512
    /**
1513
     * Return a textual error message for a PAGER error code
1513
     * Return a textual error message for a PAGER error code
1514
     *
1514
     *
1515
     * @param   int     $code error code
1515
     * @param   int     $code error code
1516
     * @return  string  error message
1516
     * @return  string  error message
1517
     * @access public
1517
     * @access public
1518
     */
1518
     */
1519
    function errorMessage($code)
1519
    function errorMessage($code)
1520
    {
1520
    {
1521
        static $errorMessages;
1521
        static $errorMessages;
1522
        if (!isset($errorMessages)) {
1522
        if (!isset($errorMessages)) {
1523
            $errorMessages = array(
1523
            $errorMessages = array(
1524
                ERROR_PAGER                     => 'unknown error',
1524
                ERROR_PAGER                     => 'unknown error',
1525
                ERROR_PAGER_INVALID             => 'invalid',
1525
                ERROR_PAGER_INVALID             => 'invalid',
1526
                ERROR_PAGER_INVALID_PLACEHOLDER => 'invalid format - use "%d" as placeholder.',
1526
                ERROR_PAGER_INVALID_PLACEHOLDER => 'invalid format - use "%d" as placeholder.',
1527
                ERROR_PAGER_INVALID_USAGE       => 'if $options[\'append\'] is set to false, '
1527
                ERROR_PAGER_INVALID_USAGE       => 'if $options[\'append\'] is set to false, '
1528
                                                  .' $options[\'fileName\'] MUST contain the "%d" placeholder.',
1528
                                                  .' $options[\'fileName\'] MUST contain the "%d" placeholder.',
1529
                ERROR_PAGER_NOT_IMPLEMENTED     => 'not implemented'
1529
                ERROR_PAGER_NOT_IMPLEMENTED     => 'not implemented'
1530
            );
1530
            );
1531
        }
1531
        }
1532
 
1532
 
1533
        return '<b>PEAR::Pager error:</b> '. (isset($errorMessages[$code]) ?
1533
        return '<b>PEAR::Pager error:</b> '. (isset($errorMessages[$code]) ?
1534
            $errorMessages[$code] : $errorMessages[ERROR_PAGER]);
1534
            $errorMessages[$code] : $errorMessages[ERROR_PAGER]);
1535
    }
1535
    }
1536
 
1536
 
1537
    // }}}
1537
    // }}}
1538
}
1538
}
1539
?>
1539
?>