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;
29 }
31 function __destruct(){
33 }
35 function AddEntry($a_entriedata) {
36 $this->a_entries[] = $a_entriedata;
37 }
39 function DisablePageNums() {
40 $this->b_displayPageNums =false;
41 }
43 function SetHeader($a_headerdata) {
44 $this->a_header[] = $a_headerdata ;
45 }
47 function SetHeight($s_height) {
48 $this->s_height= $s_height;
49 }
51 function SetWidth($s_width) {
52 $this->s_width= $s_width;
53 }
55 function SetEntriesPerPage($i_num){
56 $this->i_entriesPerPage=$i_num;
57 }
59 function DrawList(){
60 $s_return = "";
61 $s_return.= "<table summary='".$this->s_summary."' style='width:".$this->s_width."px;height:".$this->s_height."px;' cellspacing='0' id='t_scrolltable'>";
63 $s_return.= $this->_generateHeader();
64 $s_return.=$this->_generatePage();
66 $s_return.= "</table>";
68 return ($s_return);
69 }
71 function _numpages(){
72 $cnt = count($this->a_entries);
74 $tmp = $cnt % $this->i_entriesPerPage;
75 $pages = (int) ($cnt / $this->i_entriesPerPage);
76 if($tmp) $pages ++;
78 return $pages;
79 }
81 function _numentries(){
82 $cnt = count($this->a_entries);
83 return $cnt;
84 }
86 function _generateHeader(){
88 $s_return = "";
89 $s_value = "";
90 $s_key = "";
92 // Using scrolltable?
93 if($this->i_entriesPerPage == 0) {
94 $s_return .= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width."px;' cellspacing='0' id='t_scrollhead'>";
95 }
97 $s_return .= "\n<tr>";
99 foreach($this->a_header[0] as $s_key => $s_value ){
100 if(!isset($s_value['attach'])){
101 $s_value['attach'] = "";
102 }
104 $s_return.= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
106 // Increment column counter
107 $this->cols++;
109 }
111 // Attach a 13px-wide column (used as scrollbar space in body-table),
112 // but do this only if we are really using scrolltables.
113 if($this->i_entriesPerPage == 0) {
114 $s_return .= "\n<td class='listheader' style='width:13px;border-right:0px;'> </td>";
115 $s_return .= "\n</table></td>";
116 }
118 $s_return .= "\n</tr>";
119 return $s_return;
120 }
122 function SetSummary($msg){
123 $this->s_summary = $msg;
124 }
126 function _generatePage(){
128 $s_value = "";
129 $s_key = "";
130 $s_return = "";
132 if($this->i_entriesPerPage == 0) {
133 // We need to construct a "body"-table that is width-of-scrollbar thinner than the "head"-table.
134 $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'>";
135 $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>";
136 }
138 $i_alternate=0;
139 if(isset($_GET['start'])){
140 $_SESSION['start'.$this->pageid]=$_GET['start'];
141 $start = $_GET['start'];
142 } else {
143 if(isset($_SESSION['start'.$this->pageid])){
144 $start = $_SESSION['start'.$this->pageid];
145 } else {
146 $start=0;
147 }
148 }
150 /* If divlist is empty, append a single white entry */
151 if(count($this->a_entries)==0){
152 $str = $s_return."<tr>";
153 $str.="<td class='list1nohighlight' colspan='".$this->cols."' style='height:100%;border-right:0px;width:100%;'> </td>";
154 $str.="</tr>";
155 if($this->i_entriesPerPage == 0) {
156 $str.="</table></div></td></tr>";
157 }
158 return($str);
159 } else {
161 if ($this->i_entriesPerPage > 0) {
162 while($start > $this->_numentries()){
163 $start = $start - $this->i_entriesPerPage;
164 }
166 $stop = $start + $this->i_entriesPerPage;
168 $appendempty = ($this->_numentries() -$start);
170 for($i = $start ; $i < $stop;$i++){
172 if(isset($this->a_entries[$i])){
174 $s_value = $this->a_entries[$i];
177 if($i_alternate) $i_alternate=0; else $i_alternate=1;
179 $s_return .= "\n<tr>";
181 $cnt = 0;
183 foreach($s_value as $s_key2 => $s_value2 ){
185 $cnt++;
187 if(!isset($s_value2['class'])){
188 $class = "list".$i_alternate;
189 }else{
190 $class = $s_value2['class'];
191 }
193 if(!isset($s_value2['attach'])){
194 $style = "";
195 }else{
196 $style = " ".$s_value2['attach']." " ;
197 }
199 $s_return .= "\n<td ".$style." class='".$class."'>";
200 $s_return .= $s_value2['string'];
201 $s_return .= "\n</td>";
202 }
203 if($cnt == 0 ){
204 $s_return.="\n<td> </td>";
205 }
207 $s_return .= "\n</tr>";
208 }
209 }
211 if(!(($stop)<$this->_numentries())){
212 $nums = $stop - $this->_numentries();// - $stop;
213 for($i = 0 ; $i < $nums ; $i ++ ){
214 $s_return.="<tr>";
215 $cnt=0;
216 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
217 if($a ==(count($this->a_header[0])-1)){
218 $s_return.="\n<td class='list1' style='border:0px;height:26px;'> </td>";
219 } else {
220 $s_return.="\n<td class='list1' style='height:26px;'> </td>";
221 }
222 }
223 $s_return.="\n</tr>";
224 }
225 }
227 if($this->b_displayPageNums){
228 $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
229 }
230 } else {
231 // $this->i_entriesPerPage <= 0
232 // We should display all entries on one page
234 $i = $this->_numEntries();
235 foreach($this->a_entries as $s_key => $s_value){
236 $i--;
238 if($i_alternate!=0){
239 $i_alternate=0;
240 } else {
241 $i_alternate=1;
242 }
244 $s_return .= "\n<tr class='rowxp".$i_alternate."'>";
246 $cnt = 0;
248 foreach($s_value as $s_key2 => $s_value2 ){
250 $this->cols = count($s_value) ;
251 $cnt++;
253 if(!isset($s_value2['class'])){
254 $class = "list".$i_alternate;
255 } else {
256 $class = $s_value2['class'];
257 }
259 if(!isset($s_value2['attach'])){
260 $style = "";
261 } else {
262 $style = " ".$s_value2['attach']." " ;
263 }
265 $s_return .= "\n<td ".$style." class='".$class."'>";
266 $s_return .= $s_value2['string'];
267 $s_return .= "</td>";
268 }
269 $s_return .= "\n</tr>";
270 }
271 }
273 // if fewer than 22 Entries (list not full), print row to fill empty space
274 if($this->_numEntries()<=22){
275 $fill= "";
276 for ($i= 1; $i <= $this->cols; $i++){
277 if ($i == $this->cols){
278 $fill.= "<td class='list1nohighlight' style='height:100%;border-right:0px;'> </td>";
279 } else {
280 $fill.= "<td class='list1nohighlight' style='height:100%;'> </td>";
281 }
282 }
283 $s_return.="\n<tr>$fill";
284 }
285 if($this->i_entriesPerPage == 0) {
286 $s_return .= "\n</table></div></td>";
287 }
288 $s_return .= "</tr>";
289 return $s_return;
290 }
291 }
292 }
293 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
294 ?>