Code

Updated language detection code
[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 $s_summary;
9         var $cols;
10         var $pageid;
11   //FIXME: Ignoring the fact, that they were missing - height and width are numeric...
12   var $s_height;
13   var $s_width;
14   
15         // Members for page managment
16         var $i_currentPage;
17         var $i_entriesPerPage;
19   var $force_height = false;
20   var $list_footer = "";
21   
22         // Added php 4 constructor
23         function divlist($pageid){
25                 $this->i_currentPage    = 0;
26                 $this->i_entriesPerPage = 10;
27     $this->s_height         = "450";
28     $this->s_width          = "600px";
29                 $this->s_summary        = "";
30                 $this->a_entries        = array();
31                 $this->a_header         = array();
32                 $this->b_displayPageNums= true;
33                 $this->cols             = 0;
34                 $this->pageid           = $pageid;
35         }
37         function __destruct(){
38         
39         }
41   function SetFooter($str)
42   {
43     $this->list_footer = $str;
44   }
46         function AddEntry($a_entriedata) {
47                 $this->a_entries[] = $a_entriedata;
48         }
50         function DisablePageNums() {
51                 $this->b_displayPageNums =false;
52         }
54         function SetHeader($a_headerdata) {
55                 $this->a_header[] = $a_headerdata ;
56         }
57         
58   function SetHeight($s_height) {
59                 $this->s_height= $s_height;
60     $this->force_height = true;
61         }
62   
63   function SetWidth($s_width) {
64                 $this->s_width= $s_width;
65     if(preg_match("/^[0-9]*$/",$this->s_width)){
66       $this->s_width .="px";
67     }
68         }
70         function SetEntriesPerPage($i_num){
71                 $this->i_entriesPerPage=$i_num;
72         }
73         
74         function DrawList(){
75                 $s_return = "";
76     if(!$this->force_height){
77                   $s_return.= "<table summary='".$this->s_summary."' style='width:".
78                   $this->s_width.";height:".$this->s_height.
79                   "px;' cellspacing='0' id='t_scrolltable'>";
80     } else {
81                   $s_return.= "<table summary='".$this->s_summary."' style='width:".
82                   $this->s_width.";height:".$this->s_height.
83                   "px;' cellspacing='0' id='t_scrolltable_onlywidth'>";
84     }
86     $s_return.= $this->_generateHeader();
87     $s_return.= $this->_generatePage();
88           $s_return.= $this->_generateFooter(); 
89                 $s_return.= "</table>";
90                 
91                 return ($s_return);
92         }
93         
94         function _numpages(){
95                 $cnt = count($this->a_entries);
96                 
97                 $pages  = (int) ($cnt / $this->i_entriesPerPage);
98                 if($cnt % $this->i_entriesPerPage){
99       $pages++;
100     }
101                 
102                 return $pages;
103         }
104         
105         function _numentries(){
106                 return count($this->a_entries);
107         }
109   function _generateFooter()
110   {
111     $s_return = "";
112     if(!empty($this->list_footer)){
114       // Using scrolltable?
115       if($this->i_entriesPerPage == 0) {
116         if(!$this->force_height) {
117           $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:100%' cellspacing='0' id='t_scrollfoot'>";
118         } else {
119           $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:100%' cellspacing='0'                      id='t_scrollfoot_onlywidth'>";
120         }
121       }
122       $s_return .= "<tr><td class='listfooter' style='border-bottom:0px;'>".$this->list_footer."</td>";
123           // Attach a 13px-wide column (used as scrollbar space in body-table),
124     // but do this only if we are really using scrolltables.
125     if($this->i_entriesPerPage == 0) {
126       $s_return.= "\n<td class='listfooter' style='width:13px;border-right:0px;'>&nbsp;</td>";
127       $s_return.= "\n</table></td>";
128     }
130     $s_return.= "\n</tr>";
132     }
133     return($s_return);
134   }
135         
136         function _generateHeader(){
137                 $s_return = "";
138                 $s_value        = "";
139                 $s_key          = "";
140                 
141     // Using scrolltable?
142     if($this->i_entriesPerPage == 0) {
143       if(!$this->force_height) {
144         $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width.";' cellspacing='0' id='t_scrollhead'>";
145       } else {
146         $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width.";' cellspacing='0' id='t_scrollhead_onlywidth'>";
147       }
148     }
150                 $s_return.= "\n<tr>";
152                 foreach($this->a_header[0] as $s_key => $s_value ){
153                         if(!isset($s_value['attach'])){
154                                 $s_value['attach'] = "";
155                         }
157                 $s_return.= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
159       // Increment column counter
160       $this->cols++;
162                 }
163                 
164     // Attach a 13px-wide column (used as scrollbar space in body-table),
165     // but do this only if we are really using scrolltables.
166     if($this->i_entriesPerPage == 0) {
167       $s_return.= "\n<td class='listheader' style='width:13px;border-right:0px;'>&nbsp;</td>";
168       $s_return.= "\n</table></td>";
169     }
171         $s_return.= "\n</tr>";
172                 return $s_return;
173         }
174         
175         function SetSummary($msg){
176                 $this->s_summary = $msg;
177         }
179         function _generatePage(){
180                 
181                 $s_value        = "";
182                 $s_key          = "";
183                 $s_return       = "";
184    
185     if($this->i_entriesPerPage == 0) {
186       // We need to construct a "body"-table that is width-of-scrollbar thinner than the "head"-table.
187       if(!$this->force_height) {
188         $s_return .= "\n<tr><td colspan='".$this->cols."' class='scrollbody'><div style='width:".$this->s_width.";height:".($this->s_height-20)."px;' id='d_scrollbody' class='scrollbody'>";
189         $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>";
190       } else {
191         $s_return .= "\n<tr><td colspan='".$this->cols."' class='scrollbody'><div style='width:".$this->s_width.";height:".($this->s_height-20)."px;' id='d_scrollbody_onlywidth' class='scrollbody'>";
192         $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody_onlywidth'>";
193       }
194         }
195  
196     $i_alternate=0;
197                 if(isset($_GET['start'])){
198                         $_SESSION['start'.$this->pageid]=$_GET['start'];
199                         $start = $_GET['start'];
200                 } else {
201                         if(isset($_SESSION['start'.$this->pageid])){
202                                 $start = $_SESSION['start'.$this->pageid];
203                         } else {
204                                 $start=0;
205                         }
206                 }
208     /* If divlist is empty, append a single white entry */
209     if(count($this->a_entries)==0){
210       $str = $s_return."<tr>";
211       $str.="<td class='list1nohighlight' colspan='".$this->cols."' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td>";
212       $str.="</tr>";
213       if($this->i_entriesPerPage == 0) {
214         $str.="</table></div></td></tr>";
215       }
216       return($str);
217     } else {
218     
219       //FIXME: Ahrg. I'd like to read this code without wasting my time.
220       if ($this->i_entriesPerPage > 0) {
221                 while($start > $this->_numentries()){
222                         $start = $start - $this->i_entriesPerPage;
223                 }       
224     
225                 $stop  = $start + $this->i_entriesPerPage;
226     
227                 $appendempty = ($this->_numentries() -$start);
228     
229                 for($i = $start ; $i < $stop;$i++){
230                         
231                         if(isset($this->a_entries[$i])){
232                                                         
233                                 $s_value = $this->a_entries[$i];
234                                 
235                     // Alternation of background color          
236                                 if($i_alternate) $i_alternate=0; else $i_alternate=1;
237                                 
238                                 $s_return .= "\n<tr>";
239                                 
240                                 $cnt = 0;                                       
241                                         
242                                 foreach($s_value as $s_key2 => $s_value2 ){                             
243     
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 .= "\n</td>";
261                                 }
262                                 if($cnt == 0 ){
263                                         $s_return.="\n<td>&nbsp;</td>";
264                                 }
265   
266                                 $s_return .= "\n</tr>";
267                         }       
268                 }
269     
270                 if(!(($stop)<$this->_numentries())){
271                         $nums = $stop - $this->_numentries();// - $stop;
272                         for($i = 0 ; $i < $nums ; $i ++ ){
273                                 $s_return.="<tr>";
274                                 $cnt=0;
275                                 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
276                                         if($a ==(count($this->a_header[0])-1)){
277                                                 $s_return.="\n<td class='list1' style='border:0px;height:26px;'>&nbsp;</td>";
278                                         } else {
279                                                 $s_return.="\n<td class='list1' style='height:26px;'>&nbsp;</td>";
280                                         }
281                                 }
282                                 $s_return.="\n</tr>";
283                         }       
284                 }
285     
286                 if($this->b_displayPageNums){
287                         $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
288                 }
289       } else {
290         // $this->i_entriesPerPage <= 0
291         // We should display all entries on one page
292   
293         $i = $this->_numEntries();
294             foreach($this->a_entries as $s_key => $s_value){
295                           $i--;
296   
297           if($i_alternate!=0){ 
298             $i_alternate=0; 
299           } else {
300             $i_alternate=1;
301           }
302                   
303           $s_return .= "\n<tr class='rowxp".$i_alternate."'>";
304                                   
305                     $cnt = 0;                                   
306                                           
307                           foreach($s_value as $s_key2 => $s_value2 ){                           
308   
309                                   $this->cols = count($s_value) ;                                               
310                                   $cnt++;                                       
311   
312                                   if(!isset($s_value2['class'])){
313                                           $class = "list".$i_alternate; 
314                                   } else {
315                                           $class = $s_value2['class'];
316                                   }
317   
318                                   if(!isset($s_value2['attach'])){
319                                           $style = "";
320                                   } else {
321                                           $style = " ".$s_value2['attach']." "  ;
322                                   }
323             
324             $s_return .= "\n<td ".$style." class='".$class."'>";
325                                   $s_return .= $s_value2['string'];
326                                   $s_return .= "</td>";
327                           }
328                           $s_return .= "\n</tr>";
329                   }
330       }
331   
332       // if fewer than 22 Entries (list not full), print row to fill empty space
333       //FIXME: Why 22? Isn't the size dynamic
334       if($this->_numEntries()<=22){
335         $fill= "";
336         for ($i= 1; $i <= $this->cols; $i++){
337           if ($i == $this->cols){
338            $fill.= "<td class='list1nohighlight' style='height:100%;border-right:0px;'>&nbsp;</td>";
339           } else {
340            $fill.= "<td class='list1nohighlight' style='height:100%;'>&nbsp;</td>";
341           }
342         }
343         $s_return.="\n<tr>$fill";
344       }
345       if($this->i_entriesPerPage == 0) {
346         $s_return .= "\n</table></div></td>";
347       }
348       $s_return .= "</tr>";
349       return $s_return;
350     }
351   }
354 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
355 ?>