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' id='scrollbar'> </td>";
103 }
104 $s_return .= "\n</table></td></tr>";
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. I assume 18px as max.
122 $s_return .= "\n<tr><td class='scrollbody'><div style='align:left;width:600px;height:480px;overflow:auto;'>";
123 // Only reduce width if we need a scrollbar (>20 Entries)
124 if($this->_numEntries()>20) {
125 $s_return .= "<table style='height:100%;width:581px;' cellspacing='0'>";
126 } else {
127 $s_return .= "<table style='height:100%;width:600px;' cellspacing='0'>";
128 }
129 $i_alternate=0;
131 if(isset($_GET['start'])){
132 $_SESSION['start'.$this->pageid]=$_GET['start'];
133 $start = $_GET['start'];
134 } else {
135 if(isset($_SESSION['start'.$this->pageid])){
136 $start = $_SESSION['start'.$this->pageid];
137 } else {
138 $start=0;
139 }
140 }
142 /* If divlist is empty, append a single white entry */
143 if(count($this->a_entries)==0){
144 $str = "<tr>";
145 for($i = 0 ; $i < count($this->a_header[0]); $i++){
146 $str.="<td class='list1' style='height:100%';> </td>";
147 }
148 $str .="</tr>";
149 return($str);
150 }
152 if ($this->i_entriesPerPage > 0) {
153 while($start > $this->_numentries()){
154 $start = $start - $this->i_entriesPerPage;
155 }
157 $stop = $start + $this->i_entriesPerPage;
159 $appendempty = ($this->_numentries() -$start);
161 for($i = $start ; $i < $stop;$i++){
163 if(isset($this->a_entries[$i])){
165 $s_value = $this->a_entries[$i];
168 if($i_alternate) $i_alternate=0; else $i_alternate=1;
170 $s_return .= "\n<tr>";
172 $cnt = 0;
174 foreach($s_value as $s_key2 => $s_value2 ){
176 $this->cols = count($s_value) ;
177 $cnt++;
179 if(!isset($s_value2['class'])){
180 $class = "list".$i_alternate;
181 }else{
182 $class = $s_value2['class'];
183 }
185 if(!isset($s_value2['attach'])){
186 $style = "";
187 }else{
188 $style = " ".$s_value2['attach']." " ;
189 }
191 $s_return .= "\n<td ".$style." class='".$class."'>";
192 $s_return .= $s_value2['string'];
193 $s_return .= "\n</td>";
194 }
195 if($cnt == 0 ){
196 $s_return.="\n<td> </td>";
197 }
199 $s_return .= "\n</tr>";
200 }
201 }
203 if(!(($stop)<$this->_numentries())){
204 $nums = $stop - $this->_numentries();// - $stop;
205 for($i = 0 ; $i < $nums ; $i ++ ){
206 $s_return.="<tr>";
207 $cnt=0;
208 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
209 if($a ==(count($this->a_header[0])-1)){
210 $s_return.="\n<td class='list1' style='border:0px;' height='26'> </td>";
211 } else {
212 $s_return.="\n<td class='list1' height='26'> </td>";
213 }
214 }
215 $s_return.="\n</tr>";
216 }
217 }
219 if($this->b_displayPageNums){
220 $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
221 }
222 } else {
223 // $this->i_entriesPerPage <= 0
224 // We should display all entries on one page
226 $i = $this->_numEntries();
227 foreach($this->a_entries as $s_key => $s_value){
228 $i--;
230 if($i_alternate!=0){
231 $i_alternate=0;
232 } else {
233 $i_alternate=1;
234 }
236 $s_return .= "\n<tr>";
238 $cnt = 0;
240 foreach($s_value as $s_key2 => $s_value2 ){
242 $this->cols = count($s_value) ;
243 $cnt++;
245 if(!isset($s_value2['class'])){
246 $class = "list".$i_alternate;
247 } else {
248 $class = $s_value2['class'];
249 }
251 if(!isset($s_value2['attach'])){
252 $style = "";
253 } else {
254 $style = " ".$s_value2['attach']." " ;
255 }
257 $s_return .= "\n<td ".$style." class='".$class."'>";
258 $s_return .= $s_value2['string'];
259 $s_return .= "</td>";
260 }
261 $s_return .= "\n</tr>";
262 }
263 }
265 // if fewer than 20 Entries (list not full), print row to fill empty space
266 if($this->_numEntries()<20){
267 $fill= "";
268 for ($i= 1; $i <= $this->cols; $i++){
269 if ($i == $this->cols){
270 $fill.= "<td class='list1' id='fill' style='border-right:0px';> </td>";
271 } else {
272 $fill.= "<td class='list1' id='fill'> </td>";
273 }
274 }
275 $s_return.="\n<tr>$fill</tr>";
276 }
277 $s_return .= "\n</table></div></td></tr>";
278 return $s_return;
279 }
280 }
281 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
282 ?>