1 <?php
3 class divlist {
5 var $a_entries;
6 var $a_header;
7 var $b_displayPageNums;
8 var $summary;
9 var $cols;
10 var $pageid;
12 // Members for page managment
13 var $i_currentPage;
14 var $i_entriesPerPage;
16 // Added php 4 constructor
17 function divlist($pageid){
19 $this->i_currentPage = 0;
20 $this->i_entriesPerPage = 10;
21 $this->s_height = "500";
22 $this->s_width = "600";
23 $this->s_summary = "";
24 $this->a_entries = array();
25 $this->a_header = array();
26 $this->b_displayPageNums= true;
27 $this->cols = 0;
28 $this->pageid = $pageid ;
30 }
32 function __destruct(){
34 }
36 function AddEntry($a_entriedata) {
37 $this->a_entries[] = $a_entriedata;
38 }
40 function DisablePageNums() {
41 $this->b_displayPageNums =false;
42 }
44 function SetHeader($a_headerdata) {
45 $this->a_header[] = $a_headerdata ;
46 }
48 function SetHeight($s_height) {
49 $this->s_height= $s_height;
50 }
52 function SetWidth($s_width) {
53 $this->s_width= $s_width;
54 }
56 function SetEntriesPerPage($i_num){
57 $this->i_entriesPerPage=$i_num;
58 }
60 function DrawList(){
61 $s_return = "";
62 $s_return.= "<table summary='".$this->s_summary."' style='width:".$this->s_width."px;height:".$this->s_height."px;' cellspacing='0'>";
64 $s_return.= $this->_generateHeader();
65 $s_return.=$this->_generatePage();
67 $s_return.= "</table>";
69 return ($s_return);
70 }
72 function _numpages(){
73 $cnt = count($this->a_entries);
75 $tmp = $cnt % $this->i_entriesPerPage;
76 $pages = (int) ($cnt / $this->i_entriesPerPage);
77 if($tmp) $pages ++;
79 return $pages;
80 }
82 function _numentries(){
83 $cnt = count($this->a_entries);
84 return $cnt;
85 }
87 function _generateHeader(){
89 $s_return = "";
90 $s_value = "";
91 $s_key = "";
93 // Using scrolltable?
94 if($this->i_entriesPerPage == 0) {
95 $s_return .= "\n<tr><td class='scrollhead'><table style='width:".$this->s_width."px;' cellspacing='0'>";
96 }
98 $s_return .= "\n<tr>";
100 foreach($this->a_header[0] as $s_key => $s_value ){
101 if(!isset($s_value['attach'])){
102 $s_value['attach'] = "";
103 }
105 $s_return.= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
106 }
108 // Attach a 18px-wide column (used as scrollbar space in body-table),
109 // but do this only if we are really using scrolltables.
110 if($this->i_entriesPerPage == 0) {
111 if($this->_numEntries()>=20) {
112 $s_return .= "\n<td class='listheader' style='width:13px;border-right:0px;'> </td>";
113 }
114 $s_return .= "\n</table></td>";
115 }
117 $s_return .= "\n</tr>";
118 return $s_return;
119 }
121 function SetSummary($msg){
122 $this->s_summary = $msg;
123 }
125 function _generatePage(){
127 $s_value = "";
128 $s_key = "";
129 $s_return = "";
131 // We need to construct a "body"-table that is width-of-scrollbar thinner than the "head"-table.
132 $s_return .= "\n<tr><td colspan=".$this->cols." class='scrollbody'><div style='align:left;width:".$this->s_width."px;height:".($this->s_height-20)."px;overflow:auto;'>";
134 // Only reduce width if we need a scrollbar (>19 Entries)
135 if($this->_numEntries()>19) {
136 $s_return .= "<table style='height:100%;width:581px;' cellspacing='0'>";
137 } else {
138 $s_return .= "<table style='height:100%;width:600px;' cellspacing='0'>";
139 }
140 $i_alternate=0;
142 if(isset($_GET['start'])){
143 $_SESSION['start'.$this->pageid]=$_GET['start'];
144 $start = $_GET['start'];
145 } else {
146 if(isset($_SESSION['start'.$this->pageid])){
147 $start = $_SESSION['start'.$this->pageid];
148 } else {
149 $start=0;
150 }
151 }
153 /* If divlist is empty, append a single white entry */
154 if(count($this->a_entries)==0){
155 $str = $s_return."<tr>";
156 //for($i = 0 ; $i < count($this->a_header[0]); $i++){
157 $str.="<td class='list1' style='height:100%;border-right:0px;'> </td>";
158 //}
159 $str.="</tr></table></div></td></tr>";
160 return($str);
161 } else {
163 if ($this->i_entriesPerPage > 0) {
164 while($start > $this->_numentries()){
165 $start = $start - $this->i_entriesPerPage;
166 }
168 $stop = $start + $this->i_entriesPerPage;
170 $appendempty = ($this->_numentries() -$start);
172 for($i = $start ; $i < $stop;$i++){
174 if(isset($this->a_entries[$i])){
176 $s_value = $this->a_entries[$i];
179 if($i_alternate) $i_alternate=0; else $i_alternate=1;
181 $s_return .= "\n<tr>";
183 $cnt = 0;
185 foreach($s_value as $s_key2 => $s_value2 ){
187 $this->cols = count($s_value) ;
188 $cnt++;
190 if(!isset($s_value2['class'])){
191 $class = "list".$i_alternate;
192 }else{
193 $class = $s_value2['class'];
194 }
196 if(!isset($s_value2['attach'])){
197 $style = "";
198 }else{
199 $style = " ".$s_value2['attach']." " ;
200 }
202 $s_return .= "\n<td ".$style." class='".$class."'>";
203 $s_return .= $s_value2['string'];
204 $s_return .= "\n</td>";
205 }
206 if($cnt == 0 ){
207 $s_return.="\n<td> </td>";
208 }
210 $s_return .= "\n</tr>";
211 }
212 }
214 if(!(($stop)<$this->_numentries())){
215 $nums = $stop - $this->_numentries();// - $stop;
216 for($i = 0 ; $i < $nums ; $i ++ ){
217 $s_return.="<tr>";
218 $cnt=0;
219 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
220 if($a ==(count($this->a_header[0])-1)){
221 $s_return.="\n<td class='list1' style='border:0px;' height='26'> </td>";
222 } else {
223 $s_return.="\n<td class='list1' height='26'> </td>";
224 }
225 }
226 $s_return.="\n</tr>";
227 }
228 }
230 if($this->b_displayPageNums){
231 $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
232 }
233 } else {
234 // $this->i_entriesPerPage <= 0
235 // We should display all entries on one page
237 $i = $this->_numEntries();
238 foreach($this->a_entries as $s_key => $s_value){
239 $i--;
241 if($i_alternate!=0){
242 $i_alternate=0;
243 } else {
244 $i_alternate=1;
245 }
247 $s_return .= "\n<tr>";
249 $cnt = 0;
251 foreach($s_value as $s_key2 => $s_value2 ){
253 $this->cols = count($s_value) ;
254 $cnt++;
256 if(!isset($s_value2['class'])){
257 $class = "list".$i_alternate;
258 } else {
259 $class = $s_value2['class'];
260 }
262 if(!isset($s_value2['attach'])){
263 $style = "";
264 } else {
265 $style = " ".$s_value2['attach']." " ;
266 }
268 $s_return .= "\n<td ".$style." class='".$class."'>";
269 $s_return .= $s_value2['string'];
270 $s_return .= "</td>";
271 }
272 $s_return .= "\n</tr>";
273 }
274 }
276 // if fewer than 19 Entries (list not full), print row to fill empty space
277 if($this->_numEntries()<19){
278 $fill= "";
279 for ($i= 1; $i <= $this->cols; $i++){
280 if ($i == $this->cols){
281 $fill.= "<td class='list1' style='height:100%;border-right:0px';> </td>";
282 } else {
283 $fill.= "<td class='list1' style='height:100%;'> </td>";
284 }
285 }
286 $s_return.="\n<tr>$fill</tr>";
287 }
288 $s_return .= "\n</table></div></td></tr>";
289 return $s_return;
290 }
291 }
292 }
293 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
294 ?>