Code

Fixed height of lists
[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                 
52                 $s_return = "";
53                 
54                 $s_return.= "<table summary='".$this->s_summary."' width='600' cellspacing='0'>";
56     if($this->i_entriesPerPage==0) {
57     
58       $s_return.= "<thead>".$this->_generateHeader()."</thead>";
60       // Define an alternate style for IE
61       $s_return.= "<!--[if IE]><style type='text/css'>tbody.scrollcontent {overflow-y:scroll;max-height:480px;}</style><![endif]-->";
62     
63       $s_return.= "<tbody class='scrollcontent'>".$this->_generatePage()."</tbody>";
64     } else {
65       $s_return.=$this->_generateHeader();
67       $s_return.=$this->_generatePage();
68     }
69                 //$s_return.= nl2br(htmlentities($this->_generatePage()));
70                 
71                 $s_return.= "</table>";
72                 
73                 return ($s_return);
74         }
75         
76         function _numpages(){
77                 $cnt = count($this->a_entries);
78                 
79                 $tmp    = $cnt % $this->i_entriesPerPage;
80                 $pages  = (int) ($cnt / $this->i_entriesPerPage);
81                 if($tmp) $pages ++;
82                 
83                 return $pages;
84         }
85         
86         function _numentries(){
87                 $cnt = count($this->a_entries);
88                 return $cnt;
89         }
90         
91         function _generateHeader(){
92                 
93                 $s_return = "";
94                 
95                 $s_value        = "";
96                 $s_key          = "";
97                                 
98                 $s_return .= "\n<tr>";
100     $i_count = count($this->a_header[0])-1;
101                 foreach($this->a_header[0] as $s_key => $s_value ){
102                         if(!isset($s_value['attach'])){
103                                 $s_value['attach'] = "";
104                         }
105                         
106       if($i_count == 0) {
107                         $s_return .= "\n<td class='listheader' style='border-right:0px;border-bottom:1px solid #b0b0b0;'".$s_value['attach'].">".$s_value['string']."</td>";
108       } else {
109                         $s_return .= "\n<td class='listheader' style='border-bottom:1px solid #b0b0b0;'".$s_value['attach'].">".$s_value['string']."</td>";
110       }
111       $i_count--;
112                 }
113                 
114     // Only create additional column if we're using scrollbars
115     if($this->i_entriesPerPage==0) {
116       $s_return .= "<td class='listheader' style='border-right:0px;padding:0px;border-bottom:1px solid #b0b0b0;width:16px;'>&nbsp;</td>";
117     }
118                 $s_return .= "\n</tr>";
119                 return $s_return;
120         }
121         
122         function SetSummary($msg){
123                 $this->s_summary = $msg;
124         }
126         function _generatePage(){
127                 
128                 $s_value        = "";
129                 $s_key          = "";
130                 $s_return       = "";
131                 
132                 $i_alternate=0;
133         
134                 if(isset($_GET['start'])){
135                         $_SESSION['start'.$this->pageid]=$_GET['start'];
136                         $start = $_GET['start'];
137                 } else {
138                         if(isset($_SESSION['start'.$this->pageid])){
139                                 $start = $_SESSION['start'.$this->pageid];
140                         } else {
141                                 $start=0;
142                         }
143                 }
144                 
145     if ($this->i_entriesPerPage > 0) {
146                 while($start > $this->_numentries()){
147                         $start = $start - $this->i_entriesPerPage;
148                 }       
149   
150                 $stop  = $start + $this->i_entriesPerPage;
151   
152                 $appendempty = ($this->_numentries() -$start);
153   
154                 for($i = $start ; $i < $stop;$i++){
155                         
156                         if(isset($this->a_entries[$i])){
157                                                         
158                                 $s_value = $this->a_entries[$i];
159                                 
160                                 
161                                 if($i_alternate) $i_alternate=0; else $i_alternate=1;
162                                 
163                                 $s_return .= "\n<tr>";
164                                 
165                                 $cnt = 0;                                       
166                                         
167                                 foreach($s_value as $s_key2 => $s_value2 ){                             
168   
169                                         $this->cols = count($s_value) ;                                         
170                                         $cnt++;                                 
171   
172                                         if(!isset($s_value2['class'])){
173                                                 $class = "list".$i_alternate; 
174                                         }else{
175                                                 $class = $s_value2['class'];
176                                         }
177   
178                                         if(!isset($s_value2['attach'])){
179                                                 $style = "";
180                                         }else{
181                                                 $style = " ".$s_value2['attach']." "    ;
182                                         }
183   
184                                         $s_return .= "\n<td ".$style." class='".$class."'>";
185                                         $s_return .= $s_value2['string'];
186                                         $s_return .= "\n</td>";
187                                 }
188                                 if($cnt == 0 ){
189                                         $s_return.="\n<td>&nbsp;</td>";
190                                 }
192                                 $s_return .= "\n</tr>";
193                         }       
194                 }
195   
196                 if(!(($stop)<$this->_numentries())){
197                         $nums = $stop - $this->_numentries();// - $stop;
198                         for($i = 0 ; $i < $nums ; $i ++ ){
199                                 $s_return.="<tr>";
200                                 $cnt=0;
201                                 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
202                                         if($a ==(count($this->a_header[0])-1)){
203                                                 $s_return.="\n<td class='list1' style='border:0px;' height='26'>&nbsp;</td>";
204                                         } else {
205                                                 $s_return.="\n<td class='list1' height='26'>&nbsp;</td>";
206                                         }
207                                 }
208                                 $s_return.="\n</tr>";
209                         }       
210                 }
211   
212                 if($this->b_displayPageNums){
213                         $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
214                 }
215     } else {
216       // We should display all entries on one page
217                 foreach($this->a_entries as $s_key => $s_value){
218                         
219                         if($i_alternate){ 
220           $i_alternate=0; 
221         } else {
222           $i_alternate=1;
223         }
224                 
225         $s_return .= "\n<tr>";
226                                 
227                 $cnt = 0;                                       
228                                         
229                         foreach($s_value as $s_key2 => $s_value2 ){                             
230   
231                                 $this->cols = count($s_value) ;                                         
232                                 $cnt++;                                 
233   
234                                 if(!isset($s_value2['class'])){
235                                         $class = "list".$i_alternate; 
236                                 } else {
237                                         $class = $s_value2['class'];
238                                 }
239   
240                                 if(!isset($s_value2['attach'])){
241                                         $style = "";
242                                 } else {
243                                         $style = " ".$s_value2['attach']." "    ;
244                                 }
245   
246                                 $s_return .= "\n<td ".$style." class='".$class."'>";
247                                 $s_return .= $s_value2['string'];
248                                 $s_return .= "</td>";
249                         }
250                         
251         if($cnt == 0 ){
252                                 $s_return.="\n<td>&nbsp;</td>";
253                         } else {
254                                 //$s_return.="\n<td style='border:0px;padding:0px;' class='list".$i_alternate."'>&nbsp;</td>";
255         }
256                         $s_return .= "\n</tr>";
257                 }
258     }
259           
260     $fill= "";
261     for ($i= 1; $i <= $this->cols; $i++){
262       if ($i == $this->cols){
263         $fill.= "<td class='list1' style='height:100%;border-right:0px'>&nbsp;</td>";
264       } else {
265         $fill.= "<td class='list1' style='height:100%'>&nbsp;</td>";
266       }
267     }
268     return $s_return."\n<tr>$fill</tr>";
269   }
271 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
272 ?>