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