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 $force_height = 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 = "600px";
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->force_height = true;
55 }
57 function SetWidth($s_width) {
58 $this->s_width= $s_width;
59 if(preg_match("/^[0-9]*$/",$this->s_width)){
60 $this->s_width .="px";
61 }
62 }
64 function SetEntriesPerPage($i_num){
65 $this->i_entriesPerPage=$i_num;
66 }
68 function DrawList(){
69 $s_return = "";
70 if(!$this->force_height){
71 $s_return.= "<table summary='".$this->s_summary."' style='width:".
72 $this->s_width.";height:".$this->s_height.
73 "px;' cellspacing='0' id='t_scrolltable'>";
74 } else {
75 $s_return.= "<table summary='".$this->s_summary."' style='width:".
76 $this->s_width.";height:".$this->s_height.
77 "px;' cellspacing='0' id='t_scrolltable_onlywidth'>";
78 }
80 $s_return.= $this->_generateHeader();
81 $s_return.=$this->_generatePage();
83 $s_return.= "</table>";
85 return ($s_return);
86 }
88 function _numpages(){
89 $cnt = count($this->a_entries);
91 $pages = (int) ($cnt / $this->i_entriesPerPage);
92 if($cnt % $this->i_entriesPerPage){
93 $pages++;
94 }
96 return $pages;
97 }
99 function _numentries(){
100 return count($this->a_entries);
101 }
103 function _generateHeader(){
104 $s_return = "";
105 $s_value = "";
106 $s_key = "";
108 // Using scrolltable?
109 if($this->i_entriesPerPage == 0) {
110 if(!$this->force_height) {
111 $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width.";' cellspacing='0' id='t_scrollhead'>";
112 } else {
113 $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width.";' cellspacing='0' id='t_scrollhead_onlywidth'>";
114 }
115 }
117 $s_return.= "\n<tr>";
119 foreach($this->a_header[0] as $s_key => $s_value ){
120 if(!isset($s_value['attach'])){
121 $s_value['attach'] = "";
122 }
124 $s_return.= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
126 // Increment column counter
127 $this->cols++;
129 }
131 // Attach a 13px-wide column (used as scrollbar space in body-table),
132 // but do this only if we are really using scrolltables.
133 if($this->i_entriesPerPage == 0) {
134 $s_return.= "\n<td class='listheader' style='width:13px;border-right:0px;'> </td>";
135 $s_return.= "\n</table></td>";
136 }
138 $s_return.= "\n</tr>";
139 return $s_return;
140 }
142 function SetSummary($msg){
143 $this->s_summary = $msg;
144 }
146 function _generatePage(){
148 $s_value = "";
149 $s_key = "";
150 $s_return = "";
152 if($this->i_entriesPerPage == 0) {
153 // We need to construct a "body"-table that is width-of-scrollbar thinner than the "head"-table.
154 if(!$this->force_height) {
155 $s_return .= "\n<tr><td colspan='".$this->cols."' class='scrollbody'><div style='width:".$this->s_width.";height:".($this->s_height-20)."px;' id='d_scrollbody' class='scrollbody'>";
156 $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>";
157 } else {
158 $s_return .= "\n<tr><td colspan='".$this->cols."' class='scrollbody'><div style='width:".$this->s_width.";height:".($this->s_height-20)."px;' id='d_scrollbody_onlywidth' class='scrollbody'>";
159 $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody_onlywidth'>";
160 }
161 }
163 $i_alternate=0;
164 if(isset($_GET['start'])){
165 $_SESSION['start'.$this->pageid]=$_GET['start'];
166 $start = $_GET['start'];
167 } else {
168 if(isset($_SESSION['start'.$this->pageid])){
169 $start = $_SESSION['start'.$this->pageid];
170 } else {
171 $start=0;
172 }
173 }
175 /* If divlist is empty, append a single white entry */
176 if(count($this->a_entries)==0){
177 $str = $s_return."<tr>";
178 $str.="<td class='list1nohighlight' colspan='".$this->cols."' style='height:100%;border-right:0px;width:100%;'> </td>";
179 $str.="</tr>";
180 if($this->i_entriesPerPage == 0) {
181 $str.="</table></div></td></tr>";
182 }
183 return($str);
184 } else {
186 //FIXME: Ahrg. I'd like to read this code without wasting my time.
187 if ($this->i_entriesPerPage > 0) {
188 while($start > $this->_numentries()){
189 $start = $start - $this->i_entriesPerPage;
190 }
192 $stop = $start + $this->i_entriesPerPage;
194 $appendempty = ($this->_numentries() -$start);
196 for($i = $start ; $i < $stop;$i++){
198 if(isset($this->a_entries[$i])){
200 $s_value = $this->a_entries[$i];
202 // Alternation of background color
203 if($i_alternate) $i_alternate=0; else $i_alternate=1;
205 $s_return .= "\n<tr>";
207 $cnt = 0;
209 foreach($s_value as $s_key2 => $s_value2 ){
211 $cnt++;
213 if(!isset($s_value2['class'])){
214 $class = "list".$i_alternate;
215 }else{
216 $class = $s_value2['class'];
217 }
219 if(!isset($s_value2['attach'])){
220 $style = "";
221 }else{
222 $style = " ".$s_value2['attach']." " ;
223 }
225 $s_return .= "\n<td ".$style." class='".$class."'>";
226 $s_return .= $s_value2['string'];
227 $s_return .= "\n</td>";
228 }
229 if($cnt == 0 ){
230 $s_return.="\n<td> </td>";
231 }
233 $s_return .= "\n</tr>";
234 }
235 }
237 if(!(($stop)<$this->_numentries())){
238 $nums = $stop - $this->_numentries();// - $stop;
239 for($i = 0 ; $i < $nums ; $i ++ ){
240 $s_return.="<tr>";
241 $cnt=0;
242 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
243 if($a ==(count($this->a_header[0])-1)){
244 $s_return.="\n<td class='list1' style='border:0px;height:26px;'> </td>";
245 } else {
246 $s_return.="\n<td class='list1' style='height:26px;'> </td>";
247 }
248 }
249 $s_return.="\n</tr>";
250 }
251 }
253 if($this->b_displayPageNums){
254 $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
255 }
256 } else {
257 // $this->i_entriesPerPage <= 0
258 // We should display all entries on one page
260 $i = $this->_numEntries();
261 foreach($this->a_entries as $s_key => $s_value){
262 $i--;
264 if($i_alternate!=0){
265 $i_alternate=0;
266 } else {
267 $i_alternate=1;
268 }
270 $s_return .= "\n<tr class='rowxp".$i_alternate."'>";
272 $cnt = 0;
274 foreach($s_value as $s_key2 => $s_value2 ){
276 $this->cols = count($s_value) ;
277 $cnt++;
279 if(!isset($s_value2['class'])){
280 $class = "list".$i_alternate;
281 } else {
282 $class = $s_value2['class'];
283 }
285 if(!isset($s_value2['attach'])){
286 $style = "";
287 } else {
288 $style = " ".$s_value2['attach']." " ;
289 }
291 $s_return .= "\n<td ".$style." class='".$class."'>";
292 $s_return .= $s_value2['string'];
293 $s_return .= "</td>";
294 }
295 $s_return .= "\n</tr>";
296 }
297 }
299 // if fewer than 22 Entries (list not full), print row to fill empty space
300 //FIXME: Why 22? Isn't the size dynamic
301 if($this->_numEntries()<=22){
302 $fill= "";
303 for ($i= 1; $i <= $this->cols; $i++){
304 if ($i == $this->cols){
305 $fill.= "<td class='list1nohighlight' style='height:100%;border-right:0px;'> </td>";
306 } else {
307 $fill.= "<td class='list1nohighlight' style='height:100%;'> </td>";
308 }
309 }
310 $s_return.="\n<tr>$fill";
311 }
312 if($this->i_entriesPerPage == 0) {
313 $s_return .= "\n</table></div></td>";
314 }
315 $s_return .= "</tr>";
316 return $s_return;
317 }
318 }
319 }
321 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
322 ?>