Code

fixed style
[gosa.git] / include / class_divlist.inc
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_summary                = "";
22                 $this->a_entries                = array();
23                 $this->a_header                 = array();
24                 $this->b_displayPageNums= true;
25                 $this->cols                     = 0;
26                 $this->pageid                   = $pageid ;
28         }
30         function __destruct(){
31         
32         }
34         function AddEntry($a_entriedata) {
35                 $this->a_entries[] = $a_entriedata;
36         }
38         function DisablePageNums() {
39                 $this->b_displayPageNums =false;
40         }
42         function SetHeader($a_headerdata) {
43                 $this->a_header[] = $a_headerdata ;
44         }
46         function SetEntriesPerPage($i_num){
47                 $this->i_entriesPerPage=$i_num;
48         }
49         
50         function DrawList(){
51                 $s_return = "";
52                 $s_return.= "<table summary='".$this->s_summary."' style='width:600px;height:500px;' cellspacing='0'>";
54     $s_return.= $this->_generateHeader();
55     $s_return.=$this->_generatePage();
56                 
57                 $s_return.= "</table>";
58                 
59                 return ($s_return);
60         }
61         
62         function _numpages(){
63                 $cnt = count($this->a_entries);
64                 
65                 $tmp    = $cnt % $this->i_entriesPerPage;
66                 $pages  = (int) ($cnt / $this->i_entriesPerPage);
67                 if($tmp) $pages ++;
68                 
69                 return $pages;
70         }
71         
72         function _numentries(){
73                 $cnt = count($this->a_entries);
74                 return $cnt;
75         }
76         
77         function _generateHeader(){
78                 
79                 $s_return = "";
80                 $s_value        = "";
81                 $s_key          = "";
82                 
83     // Using scrolltable?
84     if($this->i_entriesPerPage == 0) {
85       $s_return .= "\n<tr><td class='scrollhead'><table style='width:600px;' cellspacing='0'>";
86     }
88                 $s_return .= "\n<tr>";
90                 foreach($this->a_header[0] as $s_key => $s_value ){
91                         if(!isset($s_value['attach'])){
92                                 $s_value['attach'] = "";
93                         }
95                 $s_return.= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
96                 }
97                 
98     // Attach a 18px-wide column (used as scrollbar space in body-table),
99     // but do this only if we are really using scrolltables.
100     if($this->i_entriesPerPage == 0) {
101       if($this->_numEntries()>=20) {
102         $s_return .= "\n<td class='listheader' style='width:13px;border-right:0px;'>&nbsp;</td>";
103       }
104       $s_return .= "\n</table></td>";
105     }
107         $s_return .= "\n</tr>";
108                 return $s_return;
109         }
110         
111         function SetSummary($msg){
112                 $this->s_summary = $msg;
113         }
115         function _generatePage(){
116                 
117                 $s_value        = "";
118                 $s_key          = "";
119                 $s_return       = "";
120    
121     // We need to construct a "body"-table that is width-of-scrollbar thinner than the "head"-table.
122     $s_return .= "\n<tr><td class='scrollbody'><div style='align:left;width:600px;height:480px;overflow:auto;'>";
124     // Only reduce width if we need a scrollbar (>19 Entries)
125     if($this->_numEntries()>19) {
126       $s_return .= "<table style='height:100%;width:581px;' cellspacing='0'>";
127                 } else {
128       $s_return .= "<table style='height:100%;width:600px;' cellspacing='0'>";
129     }
130                 $i_alternate=0;
131         
132                 if(isset($_GET['start'])){
133                         $_SESSION['start'.$this->pageid]=$_GET['start'];
134                         $start = $_GET['start'];
135                 } else {
136                         if(isset($_SESSION['start'.$this->pageid])){
137                                 $start = $_SESSION['start'.$this->pageid];
138                         } else {
139                                 $start=0;
140                         }
141                 }
143     /* If divlist is empty, append a single white entry */
144     if(count($this->a_entries)==0){
145       $str = $s_return."<tr>";
146       //for($i = 0 ; $i < count($this->a_header[0]); $i++){
147         $str.="<td class='list1' style='height:100%;border-right:0px;'>&nbsp;</td>";
148       //}
149       $str.="</tr></table></div></td></tr>";
150       return($str);
151     } else {
152     
153       if ($this->i_entriesPerPage > 0) {
154                 while($start > $this->_numentries()){
155                         $start = $start - $this->i_entriesPerPage;
156                 }       
157     
158                 $stop  = $start + $this->i_entriesPerPage;
159     
160                 $appendempty = ($this->_numentries() -$start);
161     
162                 for($i = $start ; $i < $stop;$i++){
163                         
164                         if(isset($this->a_entries[$i])){
165                                                         
166                                 $s_value = $this->a_entries[$i];
167                                 
168                                 
169                                 if($i_alternate) $i_alternate=0; else $i_alternate=1;
170                                 
171                                 $s_return .= "\n<tr>";
172                                 
173                                 $cnt = 0;                                       
174                                         
175                                 foreach($s_value as $s_key2 => $s_value2 ){                             
176     
177                                         $this->cols = count($s_value) ;                                         
178                                         $cnt++;                                 
179     
180                                         if(!isset($s_value2['class'])){
181                                                 $class = "list".$i_alternate; 
182                                         }else{
183                                                 $class = $s_value2['class'];
184                                         }
185     
186                                         if(!isset($s_value2['attach'])){
187                                                 $style = "";
188                                         }else{
189                                                 $style = " ".$s_value2['attach']." "    ;
190                                         }
191     
192                                         $s_return .= "\n<td ".$style." class='".$class."'>";
193                                         $s_return .= $s_value2['string'];
194                                         $s_return .= "\n</td>";
195                                 }
196                                 if($cnt == 0 ){
197                                         $s_return.="\n<td>&nbsp;</td>";
198                                 }
199   
200                                 $s_return .= "\n</tr>";
201                         }       
202                 }
203     
204                 if(!(($stop)<$this->_numentries())){
205                         $nums = $stop - $this->_numentries();// - $stop;
206                         for($i = 0 ; $i < $nums ; $i ++ ){
207                                 $s_return.="<tr>";
208                                 $cnt=0;
209                                 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
210                                         if($a ==(count($this->a_header[0])-1)){
211                                                 $s_return.="\n<td class='list1' style='border:0px;' height='26'>&nbsp;</td>";
212                                         } else {
213                                                 $s_return.="\n<td class='list1' height='26'>&nbsp;</td>";
214                                         }
215                                 }
216                                 $s_return.="\n</tr>";
217                         }       
218                 }
219     
220                 if($this->b_displayPageNums){
221                         $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
222                 }
223       } else {
224         // $this->i_entriesPerPage <= 0
225         // We should display all entries on one page
226   
227         $i = $this->_numEntries();
228             foreach($this->a_entries as $s_key => $s_value){
229                           $i--;
230   
231           if($i_alternate!=0){ 
232             $i_alternate=0; 
233           } else {
234             $i_alternate=1;
235           }
236                   
237           $s_return .= "\n<tr>";
238                                   
239                     $cnt = 0;                                   
240                                           
241                           foreach($s_value as $s_key2 => $s_value2 ){                           
242   
243                                   $this->cols = count($s_value) ;                                               
244                                   $cnt++;                                       
245   
246                                   if(!isset($s_value2['class'])){
247                                           $class = "list".$i_alternate; 
248                                   } else {
249                                           $class = $s_value2['class'];
250                                   }
251   
252                                   if(!isset($s_value2['attach'])){
253                                           $style = "";
254                                   } else {
255                                           $style = " ".$s_value2['attach']." "  ;
256                                   }
257             
258             $s_return .= "\n<td ".$style." class='".$class."'>";
259                                   $s_return .= $s_value2['string'];
260                                   $s_return .= "</td>";
261                           }
262                           $s_return .= "\n</tr>";
263                   }
264       }
265   
266       // if fewer than 19 Entries (list not full), print row to fill empty space
267       if($this->_numEntries()<19){
268         $fill= "";
269         for ($i= 1; $i <= $this->cols; $i++){
270           if ($i == $this->cols){
271            $fill.= "<td class='list1' style='height:100%;border-right:0px';>&nbsp;</td>";
272           } else {
273            $fill.= "<td class='list1' style='height:100%;'>&nbsp;</td>";
274           }
275         }
276         $s_return.="\n<tr>$fill</tr>";
277       }
278       $s_return .= "\n</table></div></td></tr>";
279       return $s_return;
280     }
281   }
283 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
284 ?>