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 = "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->force_height = 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 if(!$this->force_height){
68 $s_return.= "<table summary='".$this->s_summary."' style='width:".
69 $this->s_width."px;height:".$this->s_height.
70 "px;' cellspacing='0' id='t_scrolltable'>";
71 } else {
72 $s_return.= "<table summary='".$this->s_summary."' style='width:".
73 $this->s_width."px;height:".$this->s_height.
74 "px;' cellspacing='0' id='t_scrolltable_onlywidth'>";
75 }
77 $s_return.= $this->_generateHeader();
78 $s_return.=$this->_generatePage();
80 $s_return.= "</table>";
82 return ($s_return);
83 }
85 function _numpages(){
86 $cnt = count($this->a_entries);
88 $pages = (int) ($cnt / $this->i_entriesPerPage);
89 if($cnt % $this->i_entriesPerPage){
90 $pages++;
91 }
93 return $pages;
94 }
96 function _numentries(){
97 return count($this->a_entries);
98 }
100 function _generateHeader(){
101 $s_return = "";
102 $s_value = "";
103 $s_key = "";
105 // Using scrolltable?
106 if($this->i_entriesPerPage == 0) {
107 if(!$this->force_height) {
108 $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width."px;' cellspacing='0' id='t_scrollhead'>";
109 } else {
110 $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width."px;' cellspacing='0' id='t_scrollhead_onlywidth'>";
111 }
112 }
114 $s_return.= "\n<tr>";
116 foreach($this->a_header[0] as $s_key => $s_value ){
117 if(!isset($s_value['attach'])){
118 $s_value['attach'] = "";
119 }
121 $s_return.= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
123 // Increment column counter
124 $this->cols++;
126 }
128 // Attach a 13px-wide column (used as scrollbar space in body-table),
129 // but do this only if we are really using scrolltables.
130 if($this->i_entriesPerPage == 0) {
131 $s_return.= "\n<td class='listheader' style='width:13px;border-right:0px;'> </td>";
132 $s_return.= "\n</table></td>";
133 }
135 $s_return.= "\n</tr>";
136 return $s_return;
137 }
139 function SetSummary($msg){
140 $this->s_summary = $msg;
141 }
143 function _generatePage(){
145 $s_value = "";
146 $s_key = "";
147 $s_return = "";
149 if($this->i_entriesPerPage == 0) {
150 // We need to construct a "body"-table that is width-of-scrollbar thinner than the "head"-table.
151 if(!$this->force_height) {
152 $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'>";
153 $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>";
154 } else {
155 $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_onlywidth' class='scrollbody'>";
156 $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody_onlywidth'>";
157 }
158 }
160 $i_alternate=0;
161 if(isset($_GET['start'])){
162 $_SESSION['start'.$this->pageid]=$_GET['start'];
163 $start = $_GET['start'];
164 } else {
165 if(isset($_SESSION['start'.$this->pageid])){
166 $start = $_SESSION['start'.$this->pageid];
167 } else {
168 $start=0;
169 }
170 }
172 /* If divlist is empty, append a single white entry */
173 if(count($this->a_entries)==0){
174 $str = $s_return."<tr>";
175 $str.="<td class='list1nohighlight' colspan='".$this->cols."' style='height:100%;border-right:0px;width:100%;'> </td>";
176 $str.="</tr>";
177 if($this->i_entriesPerPage == 0) {
178 $str.="</table></div></td></tr>";
179 }
180 return($str);
181 } else {
183 //FIXME: Ahrg. I'd like to read this code without wasting my time.
184 if ($this->i_entriesPerPage > 0) {
185 while($start > $this->_numentries()){
186 $start = $start - $this->i_entriesPerPage;
187 }
189 $stop = $start + $this->i_entriesPerPage;
191 $appendempty = ($this->_numentries() -$start);
193 for($i = $start ; $i < $stop;$i++){
195 if(isset($this->a_entries[$i])){
197 $s_value = $this->a_entries[$i];
199 // Alternation of background color
200 if($i_alternate) $i_alternate=0; else $i_alternate=1;
202 $s_return .= "\n<tr>";
204 $cnt = 0;
206 foreach($s_value as $s_key2 => $s_value2 ){
208 $cnt++;
210 if(!isset($s_value2['class'])){
211 $class = "list".$i_alternate;
212 }else{
213 $class = $s_value2['class'];
214 }
216 if(!isset($s_value2['attach'])){
217 $style = "";
218 }else{
219 $style = " ".$s_value2['attach']." " ;
220 }
222 $s_return .= "\n<td ".$style." class='".$class."'>";
223 $s_return .= $s_value2['string'];
224 $s_return .= "\n</td>";
225 }
226 if($cnt == 0 ){
227 $s_return.="\n<td> </td>";
228 }
230 $s_return .= "\n</tr>";
231 }
232 }
234 if(!(($stop)<$this->_numentries())){
235 $nums = $stop - $this->_numentries();// - $stop;
236 for($i = 0 ; $i < $nums ; $i ++ ){
237 $s_return.="<tr>";
238 $cnt=0;
239 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
240 if($a ==(count($this->a_header[0])-1)){
241 $s_return.="\n<td class='list1' style='border:0px;height:26px;'> </td>";
242 } else {
243 $s_return.="\n<td class='list1' style='height:26px;'> </td>";
244 }
245 }
246 $s_return.="\n</tr>";
247 }
248 }
250 if($this->b_displayPageNums){
251 $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
252 }
253 } else {
254 // $this->i_entriesPerPage <= 0
255 // We should display all entries on one page
257 $i = $this->_numEntries();
258 foreach($this->a_entries as $s_key => $s_value){
259 $i--;
261 if($i_alternate!=0){
262 $i_alternate=0;
263 } else {
264 $i_alternate=1;
265 }
267 $s_return .= "\n<tr class='rowxp".$i_alternate."'>";
269 $cnt = 0;
271 foreach($s_value as $s_key2 => $s_value2 ){
273 $this->cols = count($s_value) ;
274 $cnt++;
276 if(!isset($s_value2['class'])){
277 $class = "list".$i_alternate;
278 } else {
279 $class = $s_value2['class'];
280 }
282 if(!isset($s_value2['attach'])){
283 $style = "";
284 } else {
285 $style = " ".$s_value2['attach']." " ;
286 }
288 $s_return .= "\n<td ".$style." class='".$class."'>";
289 $s_return .= $s_value2['string'];
290 $s_return .= "</td>";
291 }
292 $s_return .= "\n</tr>";
293 }
294 }
296 // if fewer than 22 Entries (list not full), print row to fill empty space
297 //FIXME: Why 22? Isn't the size dynamic
298 if($this->_numEntries()<=22){
299 $fill= "";
300 for ($i= 1; $i <= $this->cols; $i++){
301 if ($i == $this->cols){
302 $fill.= "<td class='list1nohighlight' style='height:100%;border-right:0px;'> </td>";
303 } else {
304 $fill.= "<td class='list1nohighlight' style='height:100%;'> </td>";
305 }
306 }
307 $s_return.="\n<tr>$fill";
308 }
309 if($this->i_entriesPerPage == 0) {
310 $s_return .= "\n</table></div></td>";
311 }
312 $s_return .= "</tr>";
313 return $s_return;
314 }
315 }
316 }
318 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
319 ?>