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 // Added php 4 constructor
20 function divlist($pageid){
22 $this->i_currentPage = 0;
23 $this->i_entriesPerPage = 10;
24 $this->s_height = "450";
25 $this->s_width = "600";
26 $this->s_summary = "";
27 $this->a_entries = array();
28 $this->a_header = array();
29 $this->b_displayPageNums= true;
30 $this->cols = 0;
31 $this->pageid = $pageid;
32 }
34 function __destruct(){
36 }
38 function AddEntry($a_entriedata) {
39 $this->a_entries[] = $a_entriedata;
40 }
42 function DisablePageNums() {
43 $this->b_displayPageNums =false;
44 }
46 function SetHeader($a_headerdata) {
47 $this->a_header[] = $a_headerdata ;
48 }
50 function SetHeight($s_height) {
51 $this->s_height= $s_height;
52 }
54 function SetWidth($s_width) {
55 $this->s_width= $s_width;
56 }
58 function SetEntriesPerPage($i_num){
59 $this->i_entriesPerPage=$i_num;
60 }
62 function DrawList(){
63 $s_return = "";
64 $s_return.= "<table summary='".$this->s_summary."' style='width:".
65 $this->s_width."px;height:".$this->s_height.
66 "px;' cellspacing='0' id='t_scrolltable'>";
68 $s_return.= $this->_generateHeader();
69 $s_return.=$this->_generatePage();
71 $s_return.= "</table>";
73 return ($s_return);
74 }
76 function _numpages(){
77 $cnt = count($this->a_entries);
79 $pages = (int) ($cnt / $this->i_entriesPerPage);
80 if($cnt % $this->i_entriesPerPage){
81 $pages++;
82 }
84 return $pages;
85 }
87 function _numentries(){
88 return count($this->a_entries);
89 }
91 function _generateHeader(){
92 $s_return = "";
93 $s_value = "";
94 $s_key = "";
96 // Using scrolltable?
97 if($this->i_entriesPerPage == 0) {
98 $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width."px;' cellspacing='0' id='t_scrollhead'>";
99 }
101 $s_return.= "\n<tr>";
103 foreach($this->a_header[0] as $s_key => $s_value ){
104 if(!isset($s_value['attach'])){
105 $s_value['attach'] = "";
106 }
108 $s_return.= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
110 // Increment column counter
111 $this->cols++;
113 }
115 // Attach a 13px-wide column (used as scrollbar space in body-table),
116 // but do this only if we are really using scrolltables.
117 if($this->i_entriesPerPage == 0) {
118 $s_return.= "\n<td class='listheader' style='width:13px;border-right:0px;'> </td>";
119 $s_return.= "\n</table></td>";
120 }
122 $s_return.= "\n</tr>";
123 return $s_return;
124 }
126 function SetSummary($msg){
127 $this->s_summary = $msg;
128 }
130 function _generatePage(){
132 $s_value = "";
133 $s_key = "";
134 $s_return = "";
136 if($this->i_entriesPerPage == 0) {
137 // We need to construct a "body"-table that is width-of-scrollbar thinner than the "head"-table.
138 $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'>";
139 $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>";
140 }
142 $i_alternate=0;
143 if(isset($_GET['start'])){
144 $_SESSION['start'.$this->pageid]=$_GET['start'];
145 $start = $_GET['start'];
146 } else {
147 if(isset($_SESSION['start'.$this->pageid])){
148 $start = $_SESSION['start'.$this->pageid];
149 } else {
150 $start=0;
151 }
152 }
154 /* If divlist is empty, append a single white entry */
155 if(count($this->a_entries)==0){
156 $str = $s_return."<tr>";
157 $str.="<td class='list1nohighlight' colspan='".$this->cols."' style='height:100%;border-right:0px;width:100%;'> </td>";
158 $str.="</tr>";
159 if($this->i_entriesPerPage == 0) {
160 $str.="</table></div></td></tr>";
161 }
162 return($str);
163 } else {
165 //FIXME: Ahrg. I'd like to read this code without wasting my time.
166 if ($this->i_entriesPerPage > 0) {
167 while($start > $this->_numentries()){
168 $start = $start - $this->i_entriesPerPage;
169 }
171 $stop = $start + $this->i_entriesPerPage;
173 $appendempty = ($this->_numentries() -$start);
175 for($i = $start ; $i < $stop;$i++){
177 if(isset($this->a_entries[$i])){
179 $s_value = $this->a_entries[$i];
182 if($i_alternate) $i_alternate=0; else $i_alternate=1;
184 $s_return .= "\n<tr>";
186 $cnt = 0;
188 foreach($s_value as $s_key2 => $s_value2 ){
190 $cnt++;
192 if(!isset($s_value2['class'])){
193 $class = "list".$i_alternate;
194 }else{
195 $class = $s_value2['class'];
196 }
198 if(!isset($s_value2['attach'])){
199 $style = "";
200 }else{
201 $style = " ".$s_value2['attach']." " ;
202 }
204 $s_return .= "\n<td ".$style." class='".$class."'>";
205 $s_return .= $s_value2['string'];
206 $s_return .= "\n</td>";
207 }
208 if($cnt == 0 ){
209 $s_return.="\n<td> </td>";
210 }
212 $s_return .= "\n</tr>";
213 }
214 }
216 if(!(($stop)<$this->_numentries())){
217 $nums = $stop - $this->_numentries();// - $stop;
218 for($i = 0 ; $i < $nums ; $i ++ ){
219 $s_return.="<tr>";
220 $cnt=0;
221 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
222 if($a ==(count($this->a_header[0])-1)){
223 $s_return.="\n<td class='list1' style='border:0px;height:26px;'> </td>";
224 } else {
225 $s_return.="\n<td class='list1' style='height:26px;'> </td>";
226 }
227 }
228 $s_return.="\n</tr>";
229 }
230 }
232 if($this->b_displayPageNums){
233 $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
234 }
235 } else {
236 // $this->i_entriesPerPage <= 0
237 // We should display all entries on one page
239 $i = $this->_numEntries();
240 foreach($this->a_entries as $s_key => $s_value){
241 $i--;
243 if($i_alternate!=0){
244 $i_alternate=0;
245 } else {
246 $i_alternate=1;
247 }
249 $s_return .= "\n<tr class='rowxp".$i_alternate."'>";
251 $cnt = 0;
253 foreach($s_value as $s_key2 => $s_value2 ){
255 $this->cols = count($s_value) ;
256 $cnt++;
258 if(!isset($s_value2['class'])){
259 $class = "list".$i_alternate;
260 } else {
261 $class = $s_value2['class'];
262 }
264 if(!isset($s_value2['attach'])){
265 $style = "";
266 } else {
267 $style = " ".$s_value2['attach']." " ;
268 }
270 $s_return .= "\n<td ".$style." class='".$class."'>";
271 $s_return .= $s_value2['string'];
272 $s_return .= "</td>";
273 }
274 $s_return .= "\n</tr>";
275 }
276 }
278 // if fewer than 22 Entries (list not full), print row to fill empty space
279 //FIXME: Why 22? Isn't the size dynamic
280 if($this->_numEntries()<=22){
281 $fill= "";
282 for ($i= 1; $i <= $this->cols; $i++){
283 if ($i == $this->cols){
284 $fill.= "<td class='list1nohighlight' style='height:100%;border-right:0px;'> </td>";
285 } else {
286 $fill.= "<td class='list1nohighlight' style='height:100%;'> </td>";
287 }
288 }
289 $s_return.="\n<tr>$fill";
290 }
291 if($this->i_entriesPerPage == 0) {
292 $s_return .= "\n</table></div></td>";
293 }
294 $s_return .= "</tr>";
295 return $s_return;
296 }
297 }
298 }
300 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
301 ?>