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;
20 var $list_footer = "";
21 var $fix_list_for_plugins = FALSE;
23 // Added php 4 constructor
24 function divlist($pageid){
26 $this->i_currentPage = 0;
27 $this->i_entriesPerPage = 10;
28 $this->s_height = "450";
29 $this->s_width = "600px";
30 $this->s_summary = "";
31 $this->a_entries = array();
32 $this->a_header = array();
33 $this->b_displayPageNums= true;
34 $this->cols = 0;
35 $this->pageid = $pageid;
36 }
38 function __destruct(){
40 }
42 function SetPluginMode($val = TRUE)
43 {
44 $this->fix_list_for_plugins = $val;
45 }
47 function SetFooter($str)
48 {
49 $this->list_footer = $str;
50 }
52 function AddEntry($a_entriedata) {
53 $this->a_entries[] = $a_entriedata;
54 }
56 function DisablePageNums() {
57 $this->b_displayPageNums =false;
58 }
60 function SetHeader($a_headerdata) {
61 $this->a_header[] = $a_headerdata ;
62 }
64 function SetHeight($s_height) {
65 $this->s_height= $s_height;
66 $this->force_height = true;
67 }
69 function SetWidth($s_width) {
70 $this->s_width= $s_width;
71 if(preg_match("/^[0-9]*$/",$this->s_width)){
72 $this->s_width .="px";
73 }
74 }
76 function SetEntriesPerPage($i_num){
77 $this->i_entriesPerPage=$i_num;
78 }
80 function DrawList(){
81 $s_return = "";
82 if(!$this->force_height){
83 $s_return.= "<table summary='".$this->s_summary."' style='width:".
84 $this->s_width.";height:".$this->s_height.
85 "px;' cellspacing='0' id='t_scrolltable'>";
86 } else {
87 $s_return.= "<table summary='".$this->s_summary."' style='width:".
88 $this->s_width.";height:".$this->s_height.
89 "px;' cellspacing='0' id='t_scrolltable_onlywidth'>";
90 }
92 $s_return.= $this->_generateHeader();
93 $s_return.= $this->_generatePage();
94 $s_return.= $this->_generateFooter();
95 $s_return.= "</table>";
97 return ($s_return);
98 }
100 function _numpages(){
101 $cnt = count($this->a_entries);
103 $pages = (int) ($cnt / $this->i_entriesPerPage);
104 if($cnt % $this->i_entriesPerPage){
105 $pages++;
106 }
108 return $pages;
109 }
111 function _numentries(){
112 return count($this->a_entries);
113 }
115 function _generateFooter()
116 {
117 $s_return = "";
118 if(!empty($this->list_footer)){
120 // Using scrolltable?
121 if($this->i_entriesPerPage == 0) {
122 if(!$this->force_height) {
123 $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:100%' cellspacing='0' id='t_scrollfoot'>";
124 } else {
125 $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:100%' cellspacing='0' id='t_scrollfoot_onlywidth'>";
126 }
127 }
128 $s_return .= "<tr><td class='listfooter' style='border-bottom:0px;'>".$this->list_footer."</td>";
129 // Attach a 13px-wide column (used as scrollbar space in body-table),
130 // but do this only if we are really using scrolltables.
131 if($this->i_entriesPerPage == 0) {
132 $s_return.= "\n<td class='listfooter' style='width:13px;border-right:0px;'> </td>";
133 $s_return.= "\n</table></td>";
134 }
136 $s_return.= "\n</tr>";
138 }
139 return($s_return);
140 }
142 function _generateHeader(){
143 $s_return = "";
144 $s_value = "";
145 $s_key = "";
147 // Using scrolltable?
148 if($this->i_entriesPerPage == 0) {
149 if(!$this->force_height) {
150 $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width.";' cellspacing='0' id='t_scrollhead'>";
151 } else {
152 $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width.";' cellspacing='0' id='t_scrollhead_onlywidth'>";
153 }
154 }
156 $s_return.= "\n<tr>";
158 foreach($this->a_header[0] as $s_key => $s_value ){
159 if(!isset($s_value['attach'])){
160 $s_value['attach'] = "";
161 }
163 $s_return.= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
165 // Increment column counter
166 $this->cols++;
168 }
170 // Attach a 13px-wide column (used as scrollbar space in body-table),
171 // but do this only if we are really using scrolltables.
172 if($this->i_entriesPerPage == 0) {
173 $s_return.= "\n<td class='listheader' style='width:13px;border-right:0px;'> </td>";
174 $s_return.= "\n</table></td>";
175 }
177 $s_return.= "\n</tr>";
178 return $s_return;
179 }
181 function SetSummary($msg){
182 $this->s_summary = $msg;
183 }
185 function _generatePage(){
187 $s_value = "";
188 $s_key = "";
189 $s_return = "";
191 if($this->i_entriesPerPage == 0) {
192 // We need to construct a "body"-table that is width-of-scrollbar thinner than the "head"-table.
193 if(!$this->force_height || $this->fix_list_for_plugins) {
194 $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'>";
195 $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>";
196 } else {
197 $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'>";
198 $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody_onlywidth'>";
199 }
200 }
202 $i_alternate=0;
203 if(isset($_GET['start'])){
204 $_SESSION['start'.$this->pageid]=$_GET['start'];
205 $start = $_GET['start'];
206 } else {
207 if(isset($_SESSION['start'.$this->pageid])){
208 $start = $_SESSION['start'.$this->pageid];
209 } else {
210 $start=0;
211 }
212 }
214 /* If divlist is empty, append a single white entry */
215 if(count($this->a_entries)==0){
216 $str = $s_return."<tr>";
217 $str.="<td class='list1nohighlight' colspan='".$this->cols."' style='height:100%;border-right:0px;width:100%;'> </td>";
218 $str.="</tr>";
219 if($this->i_entriesPerPage == 0) {
220 $str.="</table></div></td></tr>";
221 }
222 return($str);
223 } else {
225 //FIXME: Ahrg. I'd like to read this code without wasting my time.
226 if ($this->i_entriesPerPage > 0) {
227 while($start > $this->_numentries()){
228 $start = $start - $this->i_entriesPerPage;
229 }
231 $stop = $start + $this->i_entriesPerPage;
233 $appendempty = ($this->_numentries() -$start);
235 for($i = $start ; $i < $stop;$i++){
237 if(isset($this->a_entries[$i])){
239 $s_value = $this->a_entries[$i];
241 // Alternation of background color
242 if($i_alternate) $i_alternate=0; else $i_alternate=1;
244 $s_return .= "\n<tr class='rowxp".$i_alternate."'>";
246 $cnt = 0;
248 foreach($s_value as $s_key2 => $s_value2 ){
250 $cnt++;
252 if(!isset($s_value2['class'])){
253 $class = "list".$i_alternate;
254 }else{
255 $class = $s_value2['class'];
256 }
258 if(!isset($s_value2['attach'])){
259 $style = "";
260 }else{
261 $style = " ".$s_value2['attach']." " ;
262 }
264 $s_return .= "\n<td ".$style." class='".$class."'>";
265 $s_return .= $s_value2['string'];
266 $s_return .= "\n</td>";
267 }
268 if($cnt == 0 ){
269 $s_return.="\n<td> </td>";
270 }
272 $s_return .= "\n</tr>";
273 }
274 }
276 if(!(($stop)<$this->_numentries())){
277 $nums = $stop - $this->_numentries();// - $stop;
278 for($i = 0 ; $i < $nums ; $i ++ ){
279 $s_return.="<tr>";
280 $cnt=0;
281 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
282 if($a ==(count($this->a_header[0])-1)){
283 $s_return.="\n<td class='list1' style='border:0px;height:26px;'> </td>";
284 } else {
285 $s_return.="\n<td class='list1' style='height:26px;'> </td>";
286 }
287 }
288 $s_return.="\n</tr>";
289 }
290 }
292 if($this->b_displayPageNums){
293 $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
294 }
295 } else {
296 // $this->i_entriesPerPage <= 0
297 // We should display all entries on one page
299 $i = $this->_numEntries();
300 foreach($this->a_entries as $s_key => $s_value){
301 $i--;
303 if($i_alternate!=0){
304 $i_alternate=0;
305 } else {
306 $i_alternate=1;
307 }
309 $s_return .= "\n<tr class='rowxp".$i_alternate."'>";
311 $cnt = 0;
313 foreach($s_value as $s_key2 => $s_value2 ){
315 $this->cols = count($s_value) ;
316 $cnt++;
318 if(!isset($s_value2['class'])){
319 $class = "list".$i_alternate;
320 } else {
321 $class = $s_value2['class'];
322 }
324 if(!isset($s_value2['attach'])){
325 $style = "";
326 } else {
327 $style = " ".$s_value2['attach']." " ;
328 }
330 $s_return .= "\n<td ".$style." class='".$class."'>";
331 $s_return .= $s_value2['string'];
332 $s_return .= "</td>";
333 }
334 $s_return .= "\n</tr>";
335 }
336 }
338 // if fewer than 22 Entries (list not full), print row to fill empty space
339 //FIXME: Why 22? Isn't the size dynamic
340 if($this->_numEntries()<=22){
341 $fill= "";
342 for ($i= 1; $i <= $this->cols; $i++){
343 if ($i == $this->cols){
344 $fill.= "<td class='list1nohighlight' style='height:100%;border-right:0px;'> </td>";
345 } else {
346 $fill.= "<td class='list1nohighlight' style='height:100%;'> </td>";
347 }
348 }
349 $s_return.="\n<tr>$fill";
350 }
351 if($this->i_entriesPerPage == 0) {
352 $s_return .= "\n</table></div></td>";
353 }
354 $s_return .= "</tr>";
355 return $s_return;
356 }
357 }
358 }
360 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
361 ?>