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;
16 // Added php 4 constructor
17 function divlist($pageid){
19 $this->i_currentPage = 0;
20 $this->i_entriesPerPage = 10;
21 $this->s_summary = "";
22 $this->a_entries = array();
23 $this->a_header = array();
24 $this->b_displayPageNums= true;
25 $this->cols = 0;
26 $this->pageid = $pageid ;
28 }
30 function __destruct(){
32 }
34 function AddEntry($a_entriedata) {
35 $this->a_entries[] = $a_entriedata;
36 }
38 function DisablePageNums() {
39 $this->b_displayPageNums =false;
40 }
42 function SetHeader($a_headerdata) {
43 $this->a_header[] = $a_headerdata ;
44 }
46 function SetEntriesPerPage($i_num){
47 $this->i_entriesPerPage=$i_num;
48 }
50 function DrawList(){
51 $s_return = "";
52 $s_return.= "<table summary='".$this->s_summary."' style='width:600px;height:500px;' cellspacing='0'>";
54 $s_return.= $this->_generateHeader();
55 $s_return.=$this->_generatePage();
57 $s_return.= "</table>";
59 return ($s_return);
60 }
62 function _numpages(){
63 $cnt = count($this->a_entries);
65 $tmp = $cnt % $this->i_entriesPerPage;
66 $pages = (int) ($cnt / $this->i_entriesPerPage);
67 if($tmp) $pages ++;
69 return $pages;
70 }
72 function _numentries(){
73 $cnt = count($this->a_entries);
74 return $cnt;
75 }
77 function _generateHeader(){
79 $s_return = "";
80 $s_value = "";
81 $s_key = "";
83 // Using scrolltable?
84 if($this->i_entriesPerPage == 0) {
85 $s_return .= "\n<tr><td class='scrollhead'><table style='width:600px;' cellspacing='0'>";
86 }
88 $s_return .= "\n<tr>";
90 foreach($this->a_header[0] as $s_key => $s_value ){
91 if(!isset($s_value['attach'])){
92 $s_value['attach'] = "";
93 }
95 $s_return.= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
96 }
98 // Attach a 18px-wide column (used as scrollbar space in body-table),
99 // but do this only if we are really using scrolltables.
100 if($this->i_entriesPerPage == 0) {
101 if($this->_numEntries()>=20) {
102 $s_return .= "\n<td class='listheader' style='width:13px;border-right:0px;'> </td>";
103 }
104 $s_return .= "\n</table></td>";
105 }
107 $s_return .= "\n</tr>";
108 return $s_return;
109 }
111 function SetSummary($msg){
112 $this->s_summary = $msg;
113 }
115 function _generatePage(){
117 $s_value = "";
118 $s_key = "";
119 $s_return = "";
121 // We need to construct a "body"-table that is width-of-scrollbar thinner than the "head"-table.
122 $s_return .= "\n<tr><td class='scrollbody'><div style='align:left;width:600px;height:480px;overflow:auto;'>";
124 // Only reduce width if we need a scrollbar (>19 Entries)
125 if($this->_numEntries()>19) {
126 $s_return .= "<table style='height:100%;width:581px;' cellspacing='0'>";
127 } else {
128 $s_return .= "<table style='height:100%;width:600px;' cellspacing='0'>";
129 }
130 $i_alternate=0;
132 if(isset($_GET['start'])){
133 $_SESSION['start'.$this->pageid]=$_GET['start'];
134 $start = $_GET['start'];
135 } else {
136 if(isset($_SESSION['start'.$this->pageid])){
137 $start = $_SESSION['start'.$this->pageid];
138 } else {
139 $start=0;
140 }
141 }
143 /* If divlist is empty, append a single white entry */
144 if(count($this->a_entries)==0){
145 $str = $s_return."<tr>";
146 //for($i = 0 ; $i < count($this->a_header[0]); $i++){
147 $str.="<td class='list1' style='height:100%;border-right:0px;'> </td>";
148 //}
149 $str.="</tr></table></div></td></tr>";
150 return($str);
151 } else {
153 if ($this->i_entriesPerPage > 0) {
154 while($start > $this->_numentries()){
155 $start = $start - $this->i_entriesPerPage;
156 }
158 $stop = $start + $this->i_entriesPerPage;
160 $appendempty = ($this->_numentries() -$start);
162 for($i = $start ; $i < $stop;$i++){
164 if(isset($this->a_entries[$i])){
166 $s_value = $this->a_entries[$i];
169 if($i_alternate) $i_alternate=0; else $i_alternate=1;
171 $s_return .= "\n<tr>";
173 $cnt = 0;
175 foreach($s_value as $s_key2 => $s_value2 ){
177 $this->cols = count($s_value) ;
178 $cnt++;
180 if(!isset($s_value2['class'])){
181 $class = "list".$i_alternate;
182 }else{
183 $class = $s_value2['class'];
184 }
186 if(!isset($s_value2['attach'])){
187 $style = "";
188 }else{
189 $style = " ".$s_value2['attach']." " ;
190 }
192 $s_return .= "\n<td ".$style." class='".$class."'>";
193 $s_return .= $s_value2['string'];
194 $s_return .= "\n</td>";
195 }
196 if($cnt == 0 ){
197 $s_return.="\n<td> </td>";
198 }
200 $s_return .= "\n</tr>";
201 }
202 }
204 if(!(($stop)<$this->_numentries())){
205 $nums = $stop - $this->_numentries();// - $stop;
206 for($i = 0 ; $i < $nums ; $i ++ ){
207 $s_return.="<tr>";
208 $cnt=0;
209 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
210 if($a ==(count($this->a_header[0])-1)){
211 $s_return.="\n<td class='list1' style='border:0px;' height='26'> </td>";
212 } else {
213 $s_return.="\n<td class='list1' height='26'> </td>";
214 }
215 }
216 $s_return.="\n</tr>";
217 }
218 }
220 if($this->b_displayPageNums){
221 $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
222 }
223 } else {
224 // $this->i_entriesPerPage <= 0
225 // We should display all entries on one page
227 $i = $this->_numEntries();
228 foreach($this->a_entries as $s_key => $s_value){
229 $i--;
231 if($i_alternate!=0){
232 $i_alternate=0;
233 } else {
234 $i_alternate=1;
235 }
237 $s_return .= "\n<tr>";
239 $cnt = 0;
241 foreach($s_value as $s_key2 => $s_value2 ){
243 $this->cols = count($s_value) ;
244 $cnt++;
246 if(!isset($s_value2['class'])){
247 $class = "list".$i_alternate;
248 } else {
249 $class = $s_value2['class'];
250 }
252 if(!isset($s_value2['attach'])){
253 $style = "";
254 } else {
255 $style = " ".$s_value2['attach']." " ;
256 }
258 $s_return .= "\n<td ".$style." class='".$class."'>";
259 $s_return .= $s_value2['string'];
260 $s_return .= "</td>";
261 }
262 $s_return .= "\n</tr>";
263 }
264 }
266 // if fewer than 19 Entries (list not full), print row to fill empty space
267 if($this->_numEntries()<19){
268 $fill= "";
269 for ($i= 1; $i <= $this->cols; $i++){
270 if ($i == $this->cols){
271 $fill.= "<td class='list1' style='height:100%;border-right:0px';> </td>";
272 } else {
273 $fill.= "<td class='list1' style='height:100%;'> </td>";
274 }
275 }
276 $s_return.="\n<tr>$fill</tr>";
277 }
278 $s_return .= "\n</table></div></td></tr>";
279 return $s_return;
280 }
281 }
282 }
283 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
284 ?>