Code

Added branches container for old stuff
[gosa.git] / gosa-core / include / class_divlist.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class divlist {
25         var $a_entries;
26         var $a_header;
27         var $b_displayPageNums;         
28         var $s_summary;
29         var $cols;
30         var $pageid;
31   //FIXME: Ignoring the fact, that they were missing - height and width are numeric...
32   var $s_height;
33   var $s_width;
34   
35         // Members for page managment
36         var $i_currentPage;
37         var $i_entriesPerPage;
39   var $force_height = false;
40   var $list_footer = "";
41   var $fix_list_for_plugins = FALSE;
42   
43         // Added php 4 constructor
44         function divlist($pageid){
46                 $this->i_currentPage    = 0;
47                 $this->i_entriesPerPage = 10;
48     $this->s_height         = "450";
49     $this->s_width          = "600px";
50                 $this->s_summary        = "";
51                 $this->a_entries        = array();
52                 $this->a_header         = array();
53                 $this->b_displayPageNums= true;
54                 $this->cols             = 0;
55                 $this->pageid           = $pageid;
56         }
58         function __destruct(){
59         
60         }
62   function SetPluginMode($val = TRUE)
63   {
64     $this->fix_list_for_plugins = $val;
65   }
67   function SetFooter($str)
68   {
69     $this->list_footer = $str;
70   }
72         function AddEntry($a_entriedata) {
73                 $this->a_entries[] = $a_entriedata;
74         }
76         function DisablePageNums() {
77                 $this->b_displayPageNums =false;
78         }
80         function SetHeader($a_headerdata) {
81                 $this->a_header[] = $a_headerdata ;
82         }
83         
84   function SetHeight($s_height) {
85                 $this->s_height= $s_height;
86     $this->force_height = true;
87         }
88   
89   function SetWidth($s_width) {
90                 $this->s_width= $s_width;
91     if(preg_match("/^[0-9]*$/",$this->s_width)){
92       $this->s_width .="px";
93     }
94         }
96         function SetEntriesPerPage($i_num){
97                 $this->i_entriesPerPage=$i_num;
98         }
99         
100         function DrawList(){
101                 $s_return = "";
102     if(!$this->force_height){
103                   $s_return.= "<table summary='".$this->s_summary."' style='width:".
104                   $this->s_width.";height:".$this->s_height.
105                   "px;' cellspacing='0' id='t_scrolltable'>";
106     } else {
107                   $s_return.= "<table summary='".$this->s_summary."' style='width:".
108                   $this->s_width.";height:".$this->s_height.
109                   "px;' cellspacing='0' id='t_scrolltable_onlywidth'>";
110     }
112     $s_return.= $this->_generateHeader();
113     $s_return.= $this->_generatePage();
114           $s_return.= $this->_generateFooter(); 
115                 $s_return.= "</table>";
116                 
117                 return ($s_return);
118         }
119         
120         function _numpages(){
121                 $cnt = count($this->a_entries);
122                 
123                 $pages  = (int) ($cnt / $this->i_entriesPerPage);
124                 if($cnt % $this->i_entriesPerPage){
125       $pages++;
126     }
127                 
128                 return $pages;
129         }
130         
131         function _numentries(){
132                 return count($this->a_entries);
133         }
135   function _generateFooter()
136   {
137     $s_return = "";
138     if(!empty($this->list_footer)){
140       // Using scrolltable?
141       if($this->i_entriesPerPage == 0) {
142         if(!$this->force_height) {
143           $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:100%' cellspacing='0' id='t_scrollfoot'>";
144         } else {
145           $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:100%' cellspacing='0'                      id='t_scrollfoot_onlywidth'>";
146         }
147       }
148       $s_return .= "<tr><td class='listfooter' style='border-bottom:0px;'>".$this->list_footer."</td>";
149           // Attach a 13px-wide column (used as scrollbar space in body-table),
150     // but do this only if we are really using scrolltables.
151     if($this->i_entriesPerPage == 0) {
152       $s_return.= "\n<td class='listfooter' style='width:13px;border-right:0px;'>&nbsp;</td>";
153       $s_return.= "\n</table></td>";
154     }
156     $s_return.= "\n</tr>";
158     }
159     return($s_return);
160   }
161         
162         function _generateHeader(){
163                 $s_return = "";
164                 $s_value        = "";
165                 $s_key          = "";
166                 
167     // Using scrolltable?
168     if($this->i_entriesPerPage == 0) {
169       if(!$this->force_height) {
170         $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width.";' cellspacing='0' id='t_scrollhead'>";
171       } else {
172         $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width.";' cellspacing='0' id='t_scrollhead_onlywidth'>";
173       }
174     }
176                 $s_return.= "\n<tr>";
178                 foreach($this->a_header[0] as $s_key => $s_value ){
179                         if(!isset($s_value['attach'])){
180                                 $s_value['attach'] = "";
181                         }
183                 $s_return.= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
185       // Increment column counter
186       $this->cols++;
188                 }
189                 
190     // Attach a 13px-wide column (used as scrollbar space in body-table),
191     // but do this only if we are really using scrolltables.
192     if($this->i_entriesPerPage == 0) {
193       $s_return.= "\n<td class='listheader' style='width:13px;border-right:0px;'>&nbsp;</td>";
194       $s_return.= "\n</table></td>";
195     }
197         $s_return.= "\n</tr>";
198                 return $s_return;
199         }
200         
201         function SetSummary($msg){
202                 $this->s_summary = $msg;
203         }
205         function _generatePage(){
206                 
207                 $s_value        = "";
208                 $s_key          = "";
209                 $s_return       = "";
210    
211     if($this->i_entriesPerPage == 0) {
212       // We need to construct a "body"-table that is width-of-scrollbar thinner than the "head"-table.
213       if(!$this->force_height || $this->fix_list_for_plugins) {
214         $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'>";
215         $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>";
216       } else {
217         $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'>";
218         $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody_onlywidth'>";
219       }
220         }
221  
222     $i_alternate=0;
223                 if(isset($_GET['start'])){
224                         session::set('start'.$this->pageid,$_GET['start']);
225                         $start = $_GET['start'];
226                 } else {
227                         if(session::is_set('start'.$this->pageid)){
228                                 $start = session::get('start'.$this->pageid);
229                         } else {
230                                 $start=0;
231                         }
232                 }
234     /* If divlist is empty, append a single white entry */
235     if(count($this->a_entries)==0){
236       $str = $s_return."<tr>";
237       $str.="<td class='list1nohighlight' colspan='".$this->cols."' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td>";
238       $str.="</tr>";
239       if($this->i_entriesPerPage == 0) {
240         $str.="</table></div></td></tr>";
241       }
242       return($str);
243     } else {
244     
245       //FIXME: Ahrg. I'd like to read this code without wasting my time.
246       if ($this->i_entriesPerPage > 0) {
247                 while($start > $this->_numentries()){
248                         $start = $start - $this->i_entriesPerPage;
249                 }       
250     
251                 $stop  = $start + $this->i_entriesPerPage;
252     
253                 $appendempty = ($this->_numentries() -$start);
254     
255                 for($i = $start ; $i < $stop;$i++){
256                         
257                         if(isset($this->a_entries[$i])){
258                                                         
259                                 $s_value = $this->a_entries[$i];
260                                 
261                     // Alternation of background color          
262                                 if($i_alternate) $i_alternate=0; else $i_alternate=1;
263                                 
264           $s_return .= "\n<tr class='rowxp".$i_alternate."'>";
265                                 
266                                 $cnt = 0;                                       
267                                         
268                                 foreach($s_value as $s_key2 => $s_value2 ){                             
269     
270                                         $cnt++;                                 
271     
272                                         if(!isset($s_value2['class'])){
273                                                 $class = "list".$i_alternate; 
274                                         }else{
275                                                 $class = $s_value2['class'];
276                                         }
277     
278                                         if(!isset($s_value2['attach'])){
279                                                 $style = "";
280                                         }else{
281                                                 $style = " ".$s_value2['attach']." "    ;
282                                         }
283     
284                                         $s_return .= "\n<td ".$style." class='".$class."'>";
285                                         $s_return .= $s_value2['string'];
286                                         $s_return .= "\n</td>";
287                                 }
288                                 if($cnt == 0 ){
289                                         $s_return.="\n<td>&nbsp;</td>";
290                                 }
291   
292                                 $s_return .= "\n</tr>";
293                         }       
294                 }
295     
296                 if(!(($stop)<$this->_numentries())){
297                         $nums = $stop - $this->_numentries();// - $stop;
298                         for($i = 0 ; $i < $nums ; $i ++ ){
299                                 $s_return.="<tr>";
300                                 $cnt=0;
301                                 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
302                                         if($a ==(count($this->a_header[0])-1)){
303                                                 $s_return.="\n<td class='list1' style='border:0px;height:26px;'>&nbsp;</td>";
304                                         } else {
305                                                 $s_return.="\n<td class='list1' style='height:26px;'>&nbsp;</td>";
306                                         }
307                                 }
308                                 $s_return.="\n</tr>";
309                         }       
310                 }
311     
312                 if($this->b_displayPageNums){
313                         $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
314                 }
315       } else {
316         // $this->i_entriesPerPage <= 0
317         // We should display all entries on one page
318   
319         $i = $this->_numEntries();
320             foreach($this->a_entries as $s_key => $s_value){
321                           $i--;
322   
323           if($i_alternate!=0){ 
324             $i_alternate=0; 
325           } else {
326             $i_alternate=1;
327           }
328                   
329           $s_return .= "\n<tr class='rowxp".$i_alternate."'>";
330                                   
331                     $cnt = 0;                                   
332                                           
333                           foreach($s_value as $s_key2 => $s_value2 ){                           
334   
335                                   $this->cols = count($s_value) ;                                               
336                                   $cnt++;                                       
337   
338                                   if(!isset($s_value2['class'])){
339                                           $class = "list".$i_alternate; 
340                                   } else {
341                                           $class = $s_value2['class'];
342                                   }
343   
344                                   if(!isset($s_value2['attach'])){
345                                           $style = "";
346                                   } else {
347                                           $style = " ".$s_value2['attach']." "  ;
348                                   }
349             
350             $s_return .= "\n<td ".$style." class='".$class."'>";
351                                   $s_return .= $s_value2['string'];
352                                   $s_return .= "</td>";
353                           }
354                           $s_return .= "\n</tr>";
355                   }
356       }
357   
358       // if fewer than 22 Entries (list not full), print row to fill empty space
359       //FIXME: Why 22? Isn't the size dynamic
360       if($this->_numEntries()<=22){
361         $fill= "";
362         for ($i= 1; $i <= $this->cols; $i++){
363           if ($i == $this->cols){
364            $fill.= "<td class='list1nohighlight' style='height:100%;border-right:0px;'>&nbsp;</td>";
365           } else {
366            $fill.= "<td class='list1nohighlight' style='height:100%;'>&nbsp;</td>";
367           }
368         }
369         $s_return.="\n<tr>$fill";
370       }
371       if($this->i_entriesPerPage == 0) {
372         $s_return .= "\n</table></div></td>";
373       }
374       $s_return .= "</tr>";
375       return $s_return;
376     }
377   }
380 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
381 ?>