File: HTML_Listing.class.inc

package info (click to toggle)
opendb 0.81p18-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,716 kB
  • ctags: 6,787
  • sloc: php: 50,213; sql: 3,098; sh: 272; makefile: 54; xml: 48
file content (1121 lines) | stat: -rw-r--r-- 36,248 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
<?php
include_once("./functions/database.php");
include_once("./functions/logging.php");
include_once("./functions/listutils.php");
include_once("./functions/utils.php");
include_once("./functions/theme.php");
include_once("./functions/widgets.php");
include_once("./functions/Listing.class.inc");

/*
* A utility function which can be used to ascertain whether
* Listing checked vars are included in the $HTTP_VARS array,
* and that there is at least one processable value included.
* 
* This includes the plain checkbox column, as well as the
* 'checked_'.$check_box_name.'_list' value.
*/
function is_checked_listing_vars($HTTP_VARS, $check_box_name)
{
	if(is_not_empty_array($HTTP_VARS[$check_box_name]) || strlen(trim($HTTP_VARS['checked_'.$check_box_name.'_list']))>0)
		return TRUE;
	else
		return FALSE;
}

class HTML_Listing extends Listing
{
	// display printable link
	var $_include_printable_href = TRUE;
	var $_include_items_per_page_control = TRUE;
	var $_include_listing_footer = TRUE;
	var $_include_href_links = TRUE;
	
	// Checkbox management
	var $_check_box_name = NULL;
	var $_display_check_box_column = NULL;
	var $_check_box_count = 0;
	
	var $_no_rows_checked_msg = NULL;
	
	// between page state
	var $_cache_checked_count = 0;
	var $_checked_list_checked_count = 0;
	
	// by default the _write method automatically spools out straight out via echo()
	// command.  This setting can force it to be cached, and thus accessible via
	// the getContents() method.
	var $_buffer_output = FALSE;
	var $_buffer = NULL;
	
	// Array of all navigation controls at the top of the page.
	var $_navigate_controls;
	
	// listing row CSS class tracking
	var $rowclass = '';
	
	// What type of form navigation are we using.
	var $_header_controls_form;
	var $_footer_controls_form;
	var $_listing_form;
	
	// Array of all Op Actions that need to be displayed at the bottom of the page.
	var $_list_actions;
	
	var $_checked_list;	
	var $_session_var_list;
	
	var $_back_to_listing_text = NULL;
	
	/*
	* @param $PHP_SELF
	* @param $HTTP_VARS
	* 
	* @param $mode - 'printable' or not
	*/
	function HTML_Listing($PHP_SELF, $HTTP_VARS, $mode=NULL)
	{
		parent::Listing($PHP_SELF, $HTTP_VARS, $mode);
		
		// The item listing
		$this->_listing_form = 
				array('name'=>'listings', 
					'method'=>'POST');
		
		global $CONFIG_VARS;
		
		if($CONFIG_VARS['listings.navigation_form_method'] == 'POST')
		{
			// The Alpha list, item type, item group, etc restrictions
			$this->_header_controls_form = 
					array('name'=>'listings', 
						'method'=>'POST');
		
			// The next/previous and page_no links
			$this->_footer_controls_form = 
					array('name'=>'listings', 
						'method'=>'POST');
		}
		else if($CONFIG_VARS['listings.navigation_form_method'] == 'GET')
		{
			// The Alpha list, item type, item group, etc restrictions
			$this->_header_controls_form = 
					array('name'=>'navigate', 
						'method'=>'GET');
		
			// The next/previous and page_no links
			$this->_footer_controls_form = 
					array('name'=>'navigate', 
						'method'=>'GET');
		}
	}
	
	function setPrintableLinkVisible($boolean)
	{
		if($boolean === TRUE)//in case $boolean is not actually a boolean.
			$this->_include_printable_href = TRUE;
		else
			$this->_include_printable_href = FALSE;
	}
	
	function setItemsPerPageControlVisible($boolean)
	{
		if($boolean === TRUE)//in case $boolean is not actually a boolean.
			$this->_include_items_per_page_control = TRUE;
		else
			$this->_include_items_per_page_control = FALSE;
	}
	
	/*
	* Message to display in JavaScript alert, if No Rows are checked, and a Op Action is selected
	* which acts on Checked Items.  The default message is $LANG_VARS['no_items_checked']
	*/
	function setNoRowsCheckedMessage($message)
	{
		$this->_no_rows_checked_msg = $message;
	}
	
	function setBackToListingText($text)
	{
		$this->_back_to_listing_text = $text;
	}
	
	function setIncludeFooter($boolean)
	{
		$this->_include_listing_footer = $boolean;
	}
	
	function setIncludeHrefLinks($boolean)
	{
		$this->_include_href_links = $boolean;
	}
	
	function setBufferOutput($boolean)
	{
		$this->_buffer_output = $boolean;
	}
	
	/*
	* The $this->_http_vars['checked_'.$this->_check_box_name.'_list'] should be reset to EMPTY
	* once the update operation is performed against the list of items.
	*/
	function setCheckBoxColumnAndInitList($check_box_name, $display_check_box_column = FALSE, $session_var_list = NULL)
	{
		global $LANG_VARS;
		
		$this->_check_box_name = $check_box_name;
		$this->_display_check_box_column = $display_check_box_column;

		if($this->_check_box_name !== NULL)
		{
			if($session_var_list !== NULL)
			{
				$this->_session_var_list = $session_var_list;
			}
		
			if(strlen(trim($this->_http_vars['checked_'.$this->_check_box_name.'_list'])))
			{
				$this->_checked_list = explode(",", $this->_http_vars['checked_'.$this->_check_box_name.'_list']);
				unset($this->_http_vars['checked_'.$this->_check_box_name.'_list']);
			}
		
			if(is_array($this->_http_vars['checked_'.$this->_check_box_name]))
			{
				reset($this->_http_vars['checked_'.$this->_check_box_name]);
				while(list(,$value) = each($this->_http_vars['checked_'.$this->_check_box_name]))
				{
					if( !is_array($this->_http_vars[$this->_check_box_name]) || !in_array($value, $this->_http_vars[$this->_check_box_name]) )
					{
						if( is_array($this->_checked_list) && ($key = array_search2($value, $this->_checked_list))!==FALSE )
						{
							// Remove element
							array_splice($this->_checked_list, $key, 1);
						}
					}
				}
				unset($this->_http_vars['checked_'.$this->_check_box_name]);
			}
		
			if(is_array($this->_http_vars[$this->_check_box_name]))
			{
				reset($this->_http_vars[$this->_check_box_name]);
				while(list(,$value) = each($this->_http_vars[$this->_check_box_name]))
				{
					if( (!is_array($this->_checked_list) || !in_array($value, $this->_checked_list)) )
					{
						$this->_checked_list[] = $value;
					}
				}
				unset($this->_http_vars[$this->_check_box_name]);
			}
		}
	}
	
	/*
	* Removes checked items from internal list.
	*/
	function resetCheckedList()
	{
		$this->_checked_list = NULL;
	}
	
	function isCheckBoxColumn()
	{
		return ($this->_mode!='printable' && $this->_display_check_box_column!==FALSE && $this->_check_box_name!==NULL);
	}
	
	//
	// Getters
	//
	
	function getContents()
	{
		return $this->_buffer;
	}
	
	/*
	* Do not call before:
	* 	setCheckBoxColumnAndInitList($session_var_list)
	*/
	function getCheckedList()
	{
		return $this->_checked_list;
	}
	
	/*
	* Count of items CHECKED on current page, before page is generated, that are already
	* in the Checked List.
	* 
 	* Do not call before:
	* 	setCheckBoxColumnAndInitList($session_var_list)
	* 	
	* 	And all rows must be written out, to get an accurate value.
	*/
	function getCheckedListPageCount()
	{
		return $this->_checked_list_checked_count;
	}
	
	/**
	* Returns number of rows on the current page which are
	* in the Session var.
	*/
	function getCacheCheckedCount()
	{
		return $this->_cache_checked_count;
	}
	
	/*
	* Do not call before:
	* 	setCheckBoxColumnAndInitList($session_var_list)
	*/
	function getCheckedListCount()
	{
		if(is_array($this->_checked_list))
			return count($this->_checked_list);
		else
			return 0;
	}
	
	function getCheckBoxColumn()
	{
		return $this->_check_box_name;
	}
	
	/*
	* Number of rows with checkboxes included, whether checked or not.
	*/
	function getCheckBoxCount()
	{
		return $this->_check_box_count;
	}
	
	/*
	* @param $text
	* @param $script_url - If blank will default to $PHP_SELF
	* @param $operation 
	* @param $do_checked_test - If TRUE, will do logic to check if items are selected
	* 							in the listing.
	*/
	function addListOpAction($text, $script_uri, $operation, $do_checked_test=TRUE)
	{
		$this->_list_actions[] = array('text'=>$text, 
										'type'=>'operation',
										'script_uri'=>$script_uri,
										'operation'=>$operation,
										'do_checked_test'=>$do_checked_test);
	}
	
	function addListFieldValueAction($text, $script_uri, $operation, $field, $value)
	{
		$this->_list_actions[] = array('text'=>$text, 
										'type'=>'operation',
										'script_uri'=>$script_uri,
										'operation'=>$operation,
										'do_checked_test'=>FALSE,
										'field'=>$field,
										'value'=>$value);
	}
	
	function addListHrefAction($text, $src)
	{
		$this->_list_actions[] = array('text'=>$text, 
									'type'=>'href',
									'src'=>$src);
	}
	
	function addSelectControl($text, $fieldname, $results, $display_mask, $value=NULL, $valkey=NULL)
	{
		$this->_navigate_controls[] = array(
						'type'=>'select',
						'field'=>$fieldname,
						'block'=>"<select name=\"$fieldname\" class=\"footer\" onChange=\"restrictSubmit(this.form);\">".
									"\n<option value=\"\">- ".$text." -".
									custom_select($fieldname, 
											$results,
											$display_mask,
											'NA',
											$value,
											$valkey).
								"\n</select>");
	}
	
	/*
	* @param $toggle_options - Format should be
	* 				array('value'=>'display', 'value'=>'display')
	*/
	function addToggleControl($text, $fieldname, $value)
	{
		global $LANG_VARS;
		
		$this->_navigate_controls[] = array(
						'type'=>'toggle',
						'field'=>$fieldname,
						'block'=>"<table><tr><td align=center class=\"footer\">".
								$text.":</td></tr>".
								"<tr><td class=\"footer\" nowrap>".
									"<input type=radio class=\"footer\" name=\"$fieldname\" value=\"Y\" onclick=\"toggleSubmit(this.form); return true;\"".(strcasecmp($value, 'Y')===0?" CHECKED":"").">".$LANG_VARS['yes'].
									"&nbsp;".
									"<input type=radio class=\"footer\" name=\"$fieldname\" value=\"N\" onclick=\"toggleSubmit(this.form); return true;\"".(strcasecmp($value, 'N')===0?" CHECKED":"").">".$LANG_VARS['no'].
								"</td></tr></table>");
	}
	
	function addAlphaList($letter)
	{
		global $LANG_VARS;
	
		$buffer = "\n<i>".$LANG_VARS['alpha_listing']." </i>[&nbsp;";

		// There is an even better way to do this: foreach(range('A','Z') as $letter) -- not supported before 4.07
		foreach(array(1 => "#","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z") as $char)
		{
			if($letter == $char)
				$buffer .= "<u>$char</u>&nbsp; ";//letter chosen does not have a link.
			else
			{
				$buffer .= "<a href=\"javascript:restrictLetter(document.forms['".$this->_header_controls_form['name']."'], '$char')\" class=\"alphalist\">$char</a>&nbsp; ";
			}
		}

		// So we can reset display to everything.
		if(strlen($letter)>0)
		{
			$buffer .= "<a href=\"javascript:restrictLetter(document.forms['".$this->_header_controls_form['name']."'], '')\" class=\"alphalist\">".$LANG_VARS['all']."</a>&nbsp; ";
		}
			
		$buffer .= "]&nbsp;";
	
		$this->_navigate_controls[] = 
				array(
					'type'=>'alphalist',
					'field'=>'letter',
					'block'=>$buffer,
					'value'=>$letter
				);
	}
	
	/*
	* Do not call this function until the following methods have
	* been called:
	* 
	* These only if you want to do paging,
	*	setTotalItems($total_items)	
	* 
	* Thes only if you are supporting Checked Box handling.
	* 	setCheckBoxColumnAndInitList($name, $enable, $session_list_vars)	
	* 
	* These only if you are providing navigation control.
	*	addSelectControl($text, $fieldname, $results, $display_mask, $value=NULL, $valkey=NULL)
	*	addToggleControl($text, $fieldname, $value)
	*	addAlphaList($letter)
	*/
	function startListingImpl()
	{
		global $CONFIG_VARS;
		global $LANG_VARS;
		
		if($this->_mode == 'printable')
		{
			$this->_write("\n<table width=100% cellspacing=0 border=0><tr><td>".
					"<table width=100% cellspacing=0 border=1>");
		}
		else
		{
			if(is_array($this->_navigate_controls) || 
					is_array($this->_list_actions) ||
					$this->_include_items_per_page_control!==FALSE || 
					$this->_include_listing_footer !== FALSE)
			{
				$this->_write(get_checked_javascript());
				$this->_write(get_navigation_javascript());
			
				$this->_write("\n<form action=\"".$this->_php_self."\" name=\"".$this->_header_controls_form['name'].
							"\" method=\"".$this->_header_controls_form['method']."\">");
			
				$exclude_vars_r = array();
			
				if(is_array($this->_navigate_controls))
				{
					reset($this->_navigate_controls);
					while(list(,$control) = each($this->_navigate_controls))
					{
						$exclude_vars_r[] = $control['field'];
						if($control['type'] == 'alphalist')//only one that does not use form fields
							$this->_write("\n<input type=hidden name=\"".$control['field']."\" value=\"".$control['value']."\">");
					}
				}
					
				$this->_write("\n<table width=100% cellspacing=2 cellpadding=0 border=0>");
				$this->_write("\n<tr>");
		
				$this->_write("<td class=\"footer\">");
				if(is_array($this->_navigate_controls))
				{
					$type = NULL;
					reset($this->_navigate_controls);
					while(list(,$control) = @each($this->_navigate_controls))
					{
						if($control['type'] == 'select')
						{
							if($type != NULL && $control['type'] === $type)
								$this->_write("<br>\n");
							$type = $control['type'];
							$this->_write($control['block']);
						}
					}
				}
				$this->_write("</td>");
			
				$this->_write("<td align=right class=\"footer\">");
				if(is_array($this->_navigate_controls))
				{
					$type = NULL;
					reset($this->_navigate_controls);
					while(list(,$control) = each($this->_navigate_controls))
					{
						if($control['type'] == 'toggle')
						{
							$this->_write($control['block']);
						}
					}
				}
			
				if($this->_include_items_per_page_control !== FALSE && is_not_empty_array($CONFIG_VARS['listings.items_per_page_options']))
				{
					$exclude_vars_r[] = 'items_per_page';
				
					if(is_array($this->_navigate_controls))
					{
						$this->_write("<br>\n");
					}
				
					$this->_write($LANG_VARS['items_per_page'].": ".
							"<select name=\"items_per_page\" class=\"footer\" onChange=\"restrictSubmit(this.form);\">".
								custom_select('items_per_page', 
										$CONFIG_VARS['listings.items_per_page_options'],
										'%value%',
										'NA',
										ifempty($this->_http_vars['items_per_page'],$this->getItemsPerPage()),
										'valkey').
							"\n</select>");
				}
					
				$this->_write("</td>");
				$this->_write("\n</tr>");
			
				$this->_write("\n<tr>");
				$this->_write("<td colspan=2 class=\"footer\" align=center>");
				if(is_array($this->_navigate_controls))
				{
					$type = NULL;
					reset($this->_navigate_controls);
					while(list(,$control) = each($this->_navigate_controls))
					{
						if($control['type'] == 'alphalist')
						{
							$this->_write($control['block']);
						}
					}
				}
				$this->_write("</td>");
				$this->_write("\n</tr>");
			
				$this->_write("</table>");
			
				if($this->_header_controls_form['name'] !== $this->_listing_form['name'])
				{
					$this->_write(
						get_url_fields(
							$this->_http_vars,
							array( // required
								'page_no'=>$this->_page_no,
								'order_by'=>$this->_http_vars['order_by'],
								'sortorder'=>$this->_http_vars['sortorder'],
								'internal_link'=>'true'),
							array_merge(
								$exclude_vars_r,
								array( // exclude
									$this->_check_box_name, 
									'checked_'.$this->_check_box_name, 
									'checked_'.$this->_check_box_name.'_list')
								)
							));
	
					$this->_write("\n</form>");
			
					$this->_write("\n<form action=\"".$this->_php_self."\" name=\"".$this->_listing_form['name'].
								"\" method=\"".$this->_listing_form['method']."\">");
				}
			
				$this->_write(
					get_url_fields(
						$this->_http_vars, 
						array( // required
							'op'=>$this->_http_vars['op'],
							'page_no'=>$this->_page_no,
							'order_by'=>$this->_http_vars['order_by'],
							'sortorder'=>$this->_http_vars['sortorder'],
							'internal_link'=>'true',
						'checked_'.$this->_check_box_name.'_list'=>convert_array_to_csv_list($this->_checked_list)),
							array_merge(
								$exclude_vars_r,
							array( //exclude
								$this->_check_box_name, 
								'checked_'.$this->_check_box_name)
							)
						));
			}
			
			$this->_write("\n<table width=100% cellspacing=1 border=0>");
		}

		// take care of the checkbox here.		
		if($this->isCheckBoxColumn())
		{
			$this->addHeaderColumn(NULL, $this->_check_box_name);
		}
	}
	
	/*
	* Ensure the following methods have been called:
 	* 	setCheckBoxColumnAndInitList($name, $enable, $session_list_vars)	
	*	setTotalItems($total_items)
	* 	startListing()
	*/
	function endListingImpl($first_item=NULL, $last_item=NULL, $start_page=NULL, $end_page=NULL, $total_pages=NULL)
	{
		global $LANG_VARS;
		global $CONFIG_VARS;
		
		// Output navigation footer!
		if($this->_mode == 'printable')
		{
			$this->_write("\n</table>");
		}
		
		if($this->_include_listing_footer)
		{
			if($this->getRowCount() > 0)
			{
				$this->_write("\n<tr><td colspan=".$this->getNoOfColumns().">");
				$this->_write("\n<table width=100% cellspacing=5 border=0>");
			
				$this->_write("\n<tr><td align=left width=33% class=\"footer\">".
							replace_lang_vars(array('first_row'=>$first_item,'last_row'=>$last_item,'total'=>$this->_total_items), $LANG_VARS['page_listing_index']).
							"</td>");

				// Pages
				$this->_write("<td align=center width=33% class=\"footer\">");
				if($first_item>1 || $last_item < $this->_total_items)// Only if more than one page.
				{
					$this->_write("\n[&nbsp;");

					// Check if we need to supply << arrows.
					if($start_page > 1)
					{
						if($start_page > 10)
							$this->_write("<a href=\"javascript:gotoPage(document.forms['".$this->_footer_controls_form['name']."'], '".($start_page - 10)."');\" class=\"footer\">&lt;&lt;</a>&nbsp;");
						else
							$this->_write("<a href=\"javascript:gotoPage(document.forms['".$this->_footer_controls_form['name']."'], '1');\" class=\"footer\">&lt;&lt;</a>&nbsp;");
					}

					for($i=$start_page; $i<=$end_page; $i++)
					{
						if($i>$start_page)
							$this->_write(",&nbsp;");

						if($i == $this->_page_no)
							$this->_write("<u>$i</u>");
						else
							$this->_write("<a href=\"javascript:gotoPage(document.forms['".$this->_footer_controls_form['name']."'], '$i');\" class=\"footer\">".$i."</a>");
					}
	
					// If more than 10 pages to end.
					if($end_page < $total_pages)
					{
						$this->_write("&nbsp;<a href=\"javascript:gotoPage(document.forms['".$this->_footer_controls_form['name']."'], '".($end_page+1)."');\" class=\"footer\">&gt;&gt;</a>");
					}
	
					$this->_write("&nbsp;]".
						"\n</td>".
						"<td align=right width=33% class=\"footer\">");
	
					// A bit of a kludge, but it does work.
					if($this->_page_no>1)
						$this->_write("<a href=\"javascript:gotoPage(document.forms['".$this->_footer_controls_form['name']."'], '".($this->_page_no-1)."');\" class=\"footer\">"._theme_image("left.gif", "<=", NULL, "absmiddle")." ".$LANG_VARS['previous_page']."</a>");
					else
						$this->_write("&nbsp;");

					if($this->_page_no>1 && $this->_page_no < $total_pages)
					{
						$this->_write("&nbsp;/&nbsp;");
					}

					if($this->_page_no < $total_pages)
						$this->_write("<a href=\"javascript:gotoPage(document.forms['".$this->_footer_controls_form['name']."'], '".($this->_page_no+1)."');\" class=\"footer\">".$LANG_VARS['next_page']." "._theme_image("right.gif", "=>", NULL, "absmiddle")."</a>");
					else
						$this->_write("&nbsp;");
				}
				$this->_write("</td>");
				
				$this->_write("</tr>");
				$this->_write("</table>");
				$this->_write("\n</td></tr>");
			} // if($this->getRowCount() > 0)
			else
			{
				$this->_write("\n<tr><td align=\"center\" colspan=".$this->getNoOfColumns().">");
				$this->_write("<div class=\"error\"><b>- ".$this->_no_rows_message." -</b></div>");
				$this->_write("\n</td></tr>");
			}
		}
		
		if(is_not_empty_array($this->_list_actions))
		{
			$this->_write("\n<tr><td colspan=".$this->getNoOfColumns()." align=\"center\">");
			while(list(,$action_r) = each($this->_list_actions))
			{
				if($action_r['type'] == 'operation')
				{
					if(strlen($action_r['script_uri'])>0)
						$doOperationAction = "doOperation(this.form, '".$action_r['script_uri']."', '".$action_r['operation']."')";
					else
						$doOperationAction = "doInternalOperation(this.form, '".$action_r['operation']."')";
				
					if(strlen($action_r['field'])>0)
					{
						$doOperationAction = 'this.form[\''.$action_r['field'].'\'].value=\''.$action_r['value'].'\'; '.$doOperationAction;
					}
					
					if($action_r['do_checked_test']!==FALSE)
						$this->_write("\n<input type=\"button\" onclick=\"if(!isChecked(this.form, '".$this->_check_box_name."[]')){alert('".ifempty($this->_no_rows_checked_msg, $LANG_VARS['no_items_checked'])."');}else{".$doOperationAction.";}\" value=\"".$action_r['text']."\">");
					else
						$this->_write("\n<input type=\"button\" onclick=\"".$doOperationAction.";\" value=\"".$action_r['text']."\">");
				}
				else if($action_r['type'] == 'href')
				{
					$this->_write('<a href="'.$action_r['src'].'">'.$action_r['text'].'</a>');
				}
			}
			$this->_write("\n</td></tr>");
		}
		
		$this->_write("\n</table>");
		if($this->_mode != 'printable')
		{
			if(is_array($this->_navigate_controls) || 
					is_array($this->_list_actions) ||
					$this->_include_items_per_page_control!==FALSE || 
					$this->_include_listing_footer !== FALSE)
			{
				$this->_write("\n</form>");
			}
		}
		
		if($this->getRowCount() > 0)
		{
			if($this->_mode != 'printable' && 
					$this->_include_printable_href !== FALSE && 
					$this->getTotalItemCount() > $this->getRowCount())
			{
				$this->addHelpEntry(
					replace_lang_var("total", $this->getTotalItemCount(), $LANG_VARS['printable_version_notes']));
			}
		
			// now output the help entries.
			if(is_array($this->_help_entry_rs))
			{
				$this->_write(format_help_block($this->_help_entry_rs));
			}
		
			if($this->_mode != 'printable' && $this->_include_printable_href !== FALSE)
			{
				echo("\n<p align=center class=\"footer\"><i><a href=\"".$this->_php_self."?".
						get_url_string(
							$this->_http_vars, 
							array('mode'=>'printable'), //include
							array( //exclude
								'page_no',
								'listing_link',
								'internal_link',
								'items_per_page')).
					"\" target=_blank>"._theme_image('printable.gif', '', NULL, 'absmiddle').$LANG_VARS['printable_version']."</a></i></p>");
			}
		}//if($this->getRowCount() > 0)
	}
		
	function writeHeaderRowImpl($header_column_rs)
	{
		global $LANG_VARS;
			
		$this->_write("\n<tr>");
		for($i=0; $i<count($header_column_rs); $i++)
		{
			if($i == 0 && $header_column_rs[$i]['title'] === NULL && $header_column_rs[$i]['fieldname'] == $this->_check_box_name)
			{
				$this->_write("<td class=\"navbar\"><input type=checkbox onclick=\"doChecks(this.checked, this.form, '".$this->_check_box_name."[]');return true;\"></td>");
			}
			else
			{
				if(is_numeric($this->_header_column_rs[$i]['width']))
					$width = $this->_header_column_rs[$i]['width'];
				else if(is_numeric($this->_header_column_rs[$i]['width_percentage']))
					$width = $this->_header_column_rs[$i]['width_percentage'].'%';
				else
					$width = NULL;

				$this->_write("<td class=\"navbar\" ".($width?"width=\"$width\"":"")." nowrap>");
	
				if($this->_header_column_rs[$i]['fieldname'] !== NULL)
				{
					// Pass the opposite of $sortorder to next instance, for the header links only.
					if(strlen($this->_current_sortorder)==0 || strcasecmp($this->_current_sortorder, "desc")===0)
						$sortorder = 'ASC';
					else
						$sortorder = 'DESC';

					$column_value = '';
					// Only display the order image if current orderby matches.
					if($this->_current_orderby == $header_column_rs[$i]['fieldname'])
					{ 
						if($this->_mode != 'printable')
						{
							$column_value = "<a href=\"javascript:sortOrder(document.forms['".$this->_header_controls_form['name']."'], '".$this->_header_column_rs[$i]['fieldname']."', '".$sortorder."');\" class=\"navbar\">";
						}

						$column_value .= nl2br($header_column_rs[$i]['title']);
	
						if(strcasecmp($this->_current_sortorder, "asc")===0)
							$column_value .= '&nbsp;'._theme_image("asc_order.gif", NULL, NULL, "absmiddle");
						else if(strcasecmp($this->_current_sortorder, "desc")===0)
							$column_value .= '&nbsp;'._theme_image("desc_order.gif", NULL, NULL, "absmiddle");
					
						if($this->_mode != 'printable')
						{
							$column_value .= '</a>';
						}
					}
					else
					{
						if(strlen($this->_current_sortorder)==0)
							$this->_current_sortorder = 'ASC';

						if($this->_mode != 'printable')
						{
							// For new sort order columns, we want to sort by current sortorder instead.
							$column_value = "<a href=\"javascript:sortOrder(document.forms['".$this->_header_controls_form['name']."'], '".$header_column_rs[$i]['fieldname']."', '".$this->_current_sortorder."');\" class=\"navbar\">".$header_column_rs[$i]['title']."</a>";
						}
						else
						{
							$column_value = nl2br($header_column_rs[$i]['title']);
						}
					}
					$this->_write($column_value);
				}
				else
				{
					$this->_write(nl2br($header_column_rs[$i]['title']));
				}
				$this->_write("</td>");
			}
		}//for($i=0; $i<count($this->_header_column_rs); $i++)
		$this->_write("\n</tr>");
	}
		
	function writeRowImpl($row_column_rs, $render_row_checkbox = TRUE)
	{
		global $LANG_VARS;
		global $CONFIG_VARS;
		global $HTTP_SESSION_VARS;
		
		if($this->_toggle)
			$this->rowclass = "top";
		else
			$this->rowclass = "top2";
		
		// store a reference to the item title, if encountered for a row.
		$item_title = NULL;
		
		$this->_write("\n<tr>");
		for($i=0; $i < count($row_column_rs); $i++)
		{
			$colspan = 1;
			if( ($i+1) == count($row_column_rs)) // if this is the last for loop iteration
			{
				$colspan = ($this->getNoOfColumns() - count($row_column_rs))+1; // the _+1 is to include the current column
			}
				
			if($row_column_rs[$i]['column_type'] == 'action_links')
			{
				$this->_write(
					format_action_links(
						$row_column_rs[$i]['action_links'],
						"\n<td align=\"center\" class=\"".$this->rowclass."\" %nowrap%><font class=\"smlink\">%field%</font></td>",
						$LANG_VARS['not_applicable']));
			}
			else
			{
				switch($row_column_rs[$i]['column_type'])
				{
					case 'username':
						$this->_write('<td align="center" class="'.$this->rowclass.'"'.($colspan>1?' colspan="'.$colspan.'"':'').'>');
						$user_id = $row_column_rs[$i]['user_id'];
						$fullname = $row_column_rs[$i]['fullname'];
					
						if($user_id == $HTTP_SESSION_VARS['user_id'])
						{
							$this->_write(replace_lang_vars(array('fullname'=>str_replace(" ", "&nbsp;", $fullname), 'user_id'=>$user_id), str_replace(" ", "&nbsp;", $LANG_VARS['current_user'])));
						}
						else
						{
							$user_name = replace_lang_vars(array('fullname'=>str_replace(" ", "&nbsp;", $fullname), 'user_id'=>$user_id), $LANG_VARS['user_name']);
							if($this->_mode != 'printable' && $this->_include_href_links && $CONFIG_VARS['listing.user_email_link']!==FALSE && is_user_allowed_to_borrow($HTTP_SESSION_VARS['user_id'], $HTTP_SESSION_VARS['user_type']))
							{
								// if the title column has not been encountered yet, we want to find it in the rest of
								// the columns (after this one).
								if($item_title===NULL)
								{
									// lets find the title column.
									for($j=$i; $j < count($row_column_rs); $j++)
									{
										if($row_column_rs[$j]['column_type'] == 'title')
										{
											$item_r = $row_column_rs[$j]['item_record'];
											if(is_array($item_r))
												$item_title = $item_r['title'];
											break;
										}
									}
								}
								
								$this->_write("<a href=\"email.php?op=send_to_uid&uid=".$user_id."&subject=".urlencode(ifempty($item_title,$LANG_VARS['no_subject']))."&redirect_link=".urlencode(ifempty($this->_back_to_listing_text, $LANG_VARS['back_to_listing']))."&redirect_url=".urlencode($this->_php_self.'?'.get_url_string($this->_http_vars))."\" title=\"".htmlspecialchars($LANG_VARS['send_email'])."\">$user_name</a>");
							}
							else
							{
								$this->_write($user_name);
							}
						}
						$this->_write('</td>');
						break;
					
					case 'item_type_image':
						$this->_write('<td align="center" class="'.$this->rowclass.'"'.($colspan>1?' colspan="'.$colspan.'"':'').'>');
						$s_item_type = $row_column_rs[$i]['s_item_type'];
						$is_linked_item = $row_column_rs[$i]['is_linked_item'];
						
						if(!is_array($this->_item_type_rs[$s_item_type]) || strlen($this->_item_type_rs[$s_item_type]['image'])==0)
						{
							$this->_item_type_rs[$s_item_type] = fetch_item_type_r($s_item_type);

							// expand to the actual location once only.
							if(strlen($this->_item_type_rs[$s_item_type]['image'])>0)
								$this->_item_type_rs[$s_item_type]['image'] = _theme_image_src($this->_item_type_rs[$s_item_type]['image']);
							else
								$this->_item_type_rs[$s_item_type]['image'] = 'none';
							
							if(strlen($this->_item_type_rs[$s_item_type]['description'])>0)
								$this->_item_type_rs[$s_item_type]['description'] = htmlspecialchars($this->_item_type_rs[$s_item_type]['description']);
							else
								$this->_item_type_rs[$s_item_type]['description'] = NULL;
						}
		
						if(strlen($this->_item_type_rs[$s_item_type]['image'])>0 && $this->_item_type_rs[$s_item_type]['image'] != 'none')
						{
							$this->_write(
								_theme_image(
										$this->_item_type_rs[$s_item_type]['image'],
										$s_item_type,
										$this->_item_type_rs[$s_item_type]['description'],
										'absmiddle',
										's_item_type'));
						}
						else
						{
							// otherwise write the item type itself in place of the image.
							$this->_write($s_item_type);
						}
						
						if($is_linked_item)
						{
							$this->addHelpEntry($LANG_VARS['linked_item'], 'linked.gif', 'linked_item');
								
							$this->_write(
								_theme_image('linked.gif', 'L', $LANG_VARS['linked_item'], 'top'));
						}
						$this->_write('</td>');
						break;
						
					case 'theme_image':
						$this->_write('<td align="center" class="'.$this->rowclass.'"'.($colspan>1?' colspan="'.$colspan.'"':'').'>');
						if(is_array($row_column_rs[$i]['images']))
						{
							for($j=0; $j<count($row_column_rs[$i]['images']); $j++)
							{
								$this->_write(
									_theme_image(
										$row_column_rs[$i]['images'][$j]['src'], 
										htmlspecialchars($row_column_rs[$i]['images'][$j]['alt']),
										htmlspecialchars($row_column_rs[$i]['images'][$j]['title']),
										$row_column_rs[$i]['images'][$j]['align'],
										$row_column_rs[$i]['images'][$j]['type'],
										NULL,
										$row_column_rs[$i]['images'][$j]['width'],
										$row_column_rs[$i]['images'][$j]['height']));
							}
						}
						else
						{	
							$this->_write(
								_theme_image(
									$row_column_rs[$i]['src'], 
									htmlspecialchars($row_column_rs[$i]['alt']),
									htmlspecialchars($row_column_rs[$i]['title']),
									$row_column_rs[$i]['align'],
									$row_column_rs[$i]['type'],
									NULL,
									$row_column_rs[$i]['width'],
									$row_column_rs[$i]['height']));
						}
						$this->_write('</td>');
						break;
					
					case 'title':
						$this->_write('<td align="center" class="'.$this->rowclass.'"'.($colspan>1?' colspan="'.$colspan.'"':'').'>');
						$item_r = $row_column_rs[$i]['item_record'];
						$item_cover_image = $row_column_rs[$i]['item_cover_image'];
						$is_item_reviewed = $row_column_rs[$i]['is_item_reviewed'];
						$is_borrowed_or_returned = $row_column_rs[$i]['is_borrowed_or_returned'];
						
						// store a reference for the username column if defined.
						$item_title = $item_r['title'];
						
						if($this->_mode != 'printable' && $this->_include_href_links)
						{
							$item_r['title'] = 
								'<a href="item_display.php?item_id='.(is_numeric($item_r['parent_id'])?$item_r['parent_id']:$item_r['item_id']).
									'&instance_no='.$item_r['instance_no'].
									(strlen($this->_http_vars['listing_link'])>0?'&listing_link='.$this->_http_vars['listing_link']:'').
									(is_numeric($item_r['parent_id'])?'#linked_item':'').'">'.
									$item_r['title'].
								'</a>';
						}
				
						$append_to_title = '';
				
						if($is_item_reviewed)
						{
							// show star if rated - Add it to the actual title, so we can do a bit more with title masks
							$this->addHelpEntry($LANG_VARS['item_reviewed'], 'rs.gif', 'item_reviewed');
							$append_to_title .= _theme_image('rs.gif', NULL, $LANG_VARS['item_reviewed'], 'top');
						}
				
						if($is_borrowed_or_returned)
						{
							$this->addHelpEntry($LANG_VARS['youve_borrow_or_return'], 'tick.gif', 'borrow_or_return');
							$append_to_title .= _theme_image("tick.gif", NULL, $LANG_VARS['youve_borrow_or_return'], 'top'); // show tick if previously borrowed or returned.
						}
						
						$cover_image_tag = get_cover_image($item_cover_image, NULL, $CONFIG_VARS['listings.item_image_size']);
						if(strlen($cover_image_tag)>0)
						{
							$this->_write(
								"<table width=100% border=0 cellpadding=0 cellspacing=0><tr><td width=10% class=\"".$this->rowclass."\">".
								$cover_image_tag.
								"</td>".
								"<td align=\"center\" class=\"".$this->rowclass."\">".
								$item_r['title'].(strlen($append_to_title)>0?"&nbsp;".$append_to_title:"").
								"</td></tr></table>");
						}	
						else
						{
							$this->_write(
								$item_r['title'].(strlen($append_to_title)>0?"&nbsp;".$append_to_title:""));
						}
						$this->_write('</td>');
						break;
						
					case 'attribute_display_type':
						$this->_write('<td align="center" class="'.$this->rowclass.'"'.($colspan>1?' colspan="'.$colspan.'"':'').'>');
						
						$this->_write(
							ifempty(
								get_display_field(
									$row_column_rs[$i]['attribute_type'], 
									$row_column_rs[$i]['prompt'], 
									$row_column_rs[$i]['display_type'], 
									$row_column_rs[$i]['value'], 
									FALSE), // dowrap false!
								'&nbsp;'));
						$this->_write('</td>');
						break;
					
					default:
						$this->_write('<td align="center" class="'.$this->rowclass.'"'.($colspan>1?' colspan="'.$colspan.'"':'').'>');
						$value = $row_column_rs[$i]['value'];

						$column_buffer = '';
						if($value !== NULL && $i == 0 && $this->isCheckBoxColumn())
						{
						    if($render_row_checkbox!==FALSE)
						    {
								if(is_array($this->_session_var_list) && in_array($value, $this->_session_var_list))
								{
									$column_buffer .= _theme_image("gs.gif", NULL, $LANG_VARS['item_in_reserve_list'], "absmiddle");
									$this->addHelpEntry($LANG_VARS['item_in_reserve_list'], 'gs.gif', 'item_in_reserve_list');
									$this->_cache_checked_count++;
								}
								else if(is_array($this->_checked_list) && in_array($value, $this->_checked_list))
								{
									$column_buffer .= "<input type=hidden name=\"checked_".$this->_check_box_name."[]\" value=\"".$value."\">";
									$column_buffer .= "<input type=checkbox name=\"".$this->_check_box_name."[]\" value=\"".$value."\" CHECKED>";
									$this->_checked_list_checked_count++;
									$this->_check_box_count++;
								}
								else
								{
									$column_buffer .= "<input type=checkbox name=\"".$this->_check_box_name."[]\" value=\"".$value."\">";
									$this->_check_box_count++;
								}
							}
							else
							{
							    $column_buffer .= '&nbsp;';
							}
						}
						else
						{
							if(strlen($value)>0)
								$column_buffer .= $value;
							else
								$column_buffer .= '&nbsp;';
						}
						$this->_write($column_buffer);
						$this->_write('</td>');
						break;
				}
				$this->_write('</td>');
			}
		}//for($i=0; $i<count($this->_row_column_rs); $i++)
		$this->_write("\n</tr>");	
	}
	
	//
	// Hidden worker methods
	//
	
	/*
	* Hidden method to write out content
	*/
	function _write($s)
	{
		if($this->_buffer_output)
		{
			$this->_buffer .= $s;
		}
		else
		{
			echo($s);
		}
	}
}
?>