1 <?php
3 class divlist {
5 var $a_entries;
6 var $a_header;
7 var $b_displayPageNums;
8 var $s_summary;
9 var $cols;
10 var $pageid;
11 //FIXME: Ignoring the fact, that they were missing - height and width are numeric...
12 var $s_height;
13 var $s_width;
15 // Members for page managment
16 var $i_currentPage;
17 var $i_entriesPerPage;
19 var $height_forced = false;
21 // Added php 4 constructor
22 function divlist($pageid){
24 $this->i_currentPage = 0;
25 $this->i_entriesPerPage = 10;
26 $this->s_height = "450";
27 $this->s_width = "600";
28 $this->s_summary = "";
29 $this->a_entries = array();
30 $this->a_header = array();
31 $this->b_displayPageNums= true;
32 $this->cols = 0;
33 $this->pageid = $pageid;
34 }
36 function __destruct(){
38 }
40 function AddEntry($a_entriedata) {
41 $this->a_entries[] = $a_entriedata;
42 }
44 function DisablePageNums() {
45 $this->b_displayPageNums =false;
46 }
48 function SetHeader($a_headerdata) {
49 $this->a_header[] = $a_headerdata ;
50 }
52 function SetHeight($s_height) {
53 $this->s_height= $s_height;
54 $this->height_forced =true;
55 }
57 function SetWidth($s_width) {
58 $this->s_width= $s_width;
59 }
61 function SetEntriesPerPage($i_num){
62 $this->i_entriesPerPage=$i_num;
63 }
65 function DrawList(){
66 $s_return = "";
67 $s_return.= "<table summary='".$this->s_summary."' style='width:".
68 $this->s_width."px;height:".$this->s_height.
69 "px;' cellspacing='0' id='t_scrolltable'>";
71 $s_return.= $this->_generateHeader();
72 $s_return.=$this->_generatePage();
74 $s_return.= "</table>";
76 return ($s_return);
77 }
79 function _numpages(){
80 $cnt = count($this->a_entries);
82 $pages = (int) ($cnt / $this->i_entriesPerPage);
83 if($cnt % $this->i_entriesPerPage){
84 $pages++;
85 }
87 return $pages;
88 }
90 function _numentries(){
91 return count($this->a_entries);
92 }
94 function _generateHeader(){
95 $s_return = "";
96 $s_value = "";
97 $s_key = "";
99 // Using scrolltable?
100 if($this->i_entriesPerPage == 0) {
101 $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width."px;' cellspacing='0' id='t_scrollhead'>";
102 }
104 $s_return.= "\n<tr>";
106 foreach($this->a_header[0] as $s_key => $s_value ){
107 if(!isset($s_value['attach'])){
108 $s_value['attach'] = "";
109 }
111 $s_return.= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
113 // Increment column counter
114 $this->cols++;
116 }
118 // Attach a 13px-wide column (used as scrollbar space in body-table),
119 // but do this only if we are really using scrolltables.
120 if($this->i_entriesPerPage == 0) {
121 $s_return.= "\n<td class='listheader' style='width:13px;border-right:0px;'> </td>";
122 $s_return.= "\n</table></td>";
123 }
125 $s_return.= "\n</tr>";
126 return $s_return;
127 }
129 function SetSummary($msg){
130 $this->s_summary = $msg;
131 }
133 function _generatePage(){
135 $s_value = "";
136 $s_key = "";
137 $s_return = "";
139 if($this->i_entriesPerPage == 0) {
140 // We need to construct a "body"-table that is width-of-scrollbar thinner than the "head"-table.
141 $s_return .= "\n<tr><td colspan='".$this->cols."' class='scrollbody'><div style='width:".$this->s_width."px;height:".($this->s_height-20)."px;' id='d_scrollbody' class='scrollbody'>";
142 $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>";
143 }
145 $i_alternate=0;
146 if(isset($_GET['start'])){
147 $_SESSION['start'.$this->pageid]=$_GET['start'];
148 $start = $_GET['start'];
149 } else {
150 if(isset($_SESSION['start'.$this->pageid])){
151 $start = $_SESSION['start'.$this->pageid];
152 } else {
153 $start=0;
154 }
155 }
157 /* If divlist is empty, append a single white entry */
158 if(count($this->a_entries)==0){
159 $str = $s_return."<tr>";
160 $str.="<td class='list1nohighlight' colspan='".$this->cols."' style='height:100%;border-right:0px;width:100%;'> </td>";
161 $str.="</tr>";
162 if($this->i_entriesPerPage == 0) {
163 $str.="</table></div></td></tr>";
164 }
165 return($str);
166 } else {
168 //FIXME: Ahrg. I'd like to read this code without wasting my time.
169 if ($this->i_entriesPerPage > 0) {
170 while($start > $this->_numentries()){
171 $start = $start - $this->i_entriesPerPage;
172 }
174 $stop = $start + $this->i_entriesPerPage;
176 $appendempty = ($this->_numentries() -$start);
178 for($i = $start ; $i < $stop;$i++){
180 if(isset($this->a_entries[$i])){
182 $s_value = $this->a_entries[$i];
185 if($i_alternate) $i_alternate=0; else $i_alternate=1;
187 $s_return .= "\n<tr>";
189 $cnt = 0;
191 foreach($s_value as $s_key2 => $s_value2 ){
193 $cnt++;
195 if(!isset($s_value2['class'])){
196 $class = "list".$i_alternate;
197 }else{
198 $class = $s_value2['class'];
199 }
201 if(!isset($s_value2['attach'])){
202 $style = "";
203 }else{
204 $style = " ".$s_value2['attach']." " ;
205 }
207 $s_return .= "\n<td ".$style." class='".$class."'>";
208 $s_return .= $s_value2['string'];
209 $s_return .= "\n</td>";
210 }
211 if($cnt == 0 ){
212 $s_return.="\n<td> </td>";
213 }
215 $s_return .= "\n</tr>";
216 }
217 }
219 if(!(($stop)<$this->_numentries())){
220 $nums = $stop - $this->_numentries();// - $stop;
221 for($i = 0 ; $i < $nums ; $i ++ ){
222 $s_return.="<tr>";
223 $cnt=0;
224 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
225 if($a ==(count($this->a_header[0])-1)){
226 $s_return.="\n<td class='list1' style='border:0px;height:26px;'> </td>";
227 } else {
228 $s_return.="\n<td class='list1' style='height:26px;'> </td>";
229 }
230 }
231 $s_return.="\n</tr>";
232 }
233 }
235 if($this->b_displayPageNums){
236 $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
237 }
238 } else {
239 // $this->i_entriesPerPage <= 0
240 // We should display all entries on one page
242 $i = $this->_numEntries();
243 foreach($this->a_entries as $s_key => $s_value){
244 $i--;
246 if($i_alternate!=0){
247 $i_alternate=0;
248 } else {
249 $i_alternate=1;
250 }
252 $s_return .= "\n<tr class='rowxp".$i_alternate."'>";
254 $cnt = 0;
256 foreach($s_value as $s_key2 => $s_value2 ){
258 $this->cols = count($s_value) ;
259 $cnt++;
261 if(!isset($s_value2['class'])){
262 $class = "list".$i_alternate;
263 } else {
264 $class = $s_value2['class'];
265 }
267 if(!isset($s_value2['attach'])){
268 $style = "";
269 } else {
270 $style = " ".$s_value2['attach']." " ;
271 }
273 $s_return .= "\n<td ".$style." class='".$class."'>";
274 $s_return .= $s_value2['string'];
275 $s_return .= "</td>";
276 }
277 $s_return .= "\n</tr>";
278 }
279 }
281 // if fewer than 22 Entries (list not full), print row to fill empty space
282 //FIXME: Why 22? Isn't the size dynamic
283 if($this->_numEntries()<=22){
284 $fill= "";
285 for ($i= 1; $i <= $this->cols; $i++){
286 if ($i == $this->cols){
287 $fill.= "<td class='list1nohighlight' style='height:100%;border-right:0px;'> </td>";
288 } else {
289 $fill.= "<td class='list1nohighlight' style='height:100%;'> </td>";
290 }
291 }
292 $s_return.="\n<tr>$fill";
293 }
294 if($this->i_entriesPerPage == 0) {
295 $s_return .= "\n</table></div></td>";
296 }
297 $s_return .= "</tr>";
298 return $s_return;
299 }
300 }
301 }
303 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
304 ?>