1 <?php
3 class divlist {
5 var $a_entries;
6 var $a_header;
7 var $b_displayPageNums;
8 var $summary;
9 var $cols;
10 var $pageid;
12 // Members for page managment
13 var $i_currentPage;
14 var $i_entriesPerPage;
17 function __construct($pageid){
18 $this->i_currentPage = 0;
19 $this->i_entriesPerPage = 10;
20 $this->s_summary = "";
21 $this->a_entries = array();
22 $this->a_header = array();
23 $this->b_displayPageNums= true;
24 $this->cols = 0;
25 $this->pageid = $pageid ;
26 }
28 function __destruct(){
30 }
32 function AddEntry($a_entriedata) {
33 $this->a_entries[] = $a_entriedata;
34 }
36 function DisablePageNums() {
37 $this->b_displayPageNums =false;
38 }
40 function SetHeader($a_headerdata) {
41 $this->a_header[] = $a_headerdata ;
42 }
44 function SetEntriesPerPage($i_num){
45 $this->i_entriesPerPage=$i_num;
46 }
48 function DrawList(){
50 $s_return = "";
52 $s_return.= "<table summary='".$this->s_summary."' width='600' cellspacing='0'>";
54 $s_return.= $this->_generateHeader();
56 $s_return.= $this->_generatePage();
57 //$s_return.= nl2br(htmlentities($this->_generatePage()));
59 $s_return.= "</table>";
61 return ($s_return);
62 }
64 function _numpages(){
65 $cnt = count($this->a_entries);
67 $tmp = $cnt % $this->i_entriesPerPage;
68 $pages = (int) ($cnt / $this->i_entriesPerPage);
69 if($tmp) $pages ++;
71 return $pages;
72 }
74 function _numentries(){
75 $cnt = count($this->a_entries);
76 return $cnt;
77 }
79 function _generateHeader(){
81 $s_return = "";
83 $s_value = "";
84 $s_key = "";
86 $s_return .= "\n<tr>";
87 foreach($this->a_header[0] as $s_key => $s_value ){
88 if(!isset($s_value['attach'])){
89 $s_value['attach'] = "";
90 }
92 $s_return .= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
93 }
95 $s_return .= "\n</tr>";
96 return $s_return;
97 }
99 function SetSummary($msg){
100 $this->s_summary = $msg;
101 }
103 function _generatePage(){
105 $s_value = "";
106 $s_key = "";
107 $s_return = "";
109 $i_alternate=0;
111 if(isset($_GET['start'])){
112 $_SESSION['start'.$this->pageid]=$_GET['start'];
113 $start = $_GET['start'];
114 }else{
115 if(isset($_SESSION['start'.$this->pageid])){
116 $start = $_SESSION['start'.$this->pageid];
117 }else{
118 $start=0;
119 }
120 }
122 while($start > $this->_numentries()){
123 $start = $start - $this->i_entriesPerPage;
124 }
126 $stop = $start + $this->i_entriesPerPage;
128 $appendempty = ($this->_numentries() -$start);
130 for($i = $start ; $i < $stop;$i++){
132 if(isset($this->a_entries[$i])){
134 $s_value = $this->a_entries[$i];
137 if($i_alternate) $i_alternate=0; else $i_alternate=1;
139 $s_return .= "\n<tr>";
141 $cnt = 0;
143 foreach($s_value as $s_key2 => $s_value2 ){
145 $this->cols = count($s_value) ;
146 $cnt++;
148 if(!isset($s_value2['class'])){
149 $class = "list".$i_alternate;
150 }else{
151 $class = $s_value2['class'];
152 }
154 if(!isset($s_value2['attach'])){
155 $style = "";
156 }else{
157 $style = " ".$s_value2['attach']." " ;
158 }
160 $s_return .= "\n<td ".$style." class='".$class."'>";
161 $s_return .= $s_value2['string'];
162 $s_return .= "\n</td>";
163 }
164 if($cnt == 0 ){
165 $s_return.="<td> </td>";
166 }
167 $s_return .= "\n</tr>";
168 }
169 }
171 if(!(($stop)<$this->_numentries())){
172 $nums = $stop - $this->_numentries();// - $stop;
173 for($i = 0 ; $i < $nums ; $i ++ ){
174 $s_return.="<tr>";
175 $cnt=0;
176 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
177 if($a ==(count($this->a_header[0])-1)){
178 $s_return.="<td class='list1' style='border:0px;' height='26'> </td>";
179 }else{
180 $s_return.="<td class='list1' height='26'> </td>";
181 }
182 }
183 $s_return.="</tr>";
184 }
185 }
187 if($this->b_displayPageNums){
188 $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
189 }
191 return $s_return;
192 }
195 }
196 ?>