Code

Added divlist to FAIscript dialog, with sorting parameter
[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   
21         // Added php 4 constructor
22         function divlist($pageid){
24                 $this->i_currentPage    = 0;
25                 $this->i_entriesPerPage = 10;
26     $this->s_height         = "450";
27     $this->s_width          = "600px";
28                 $this->s_summary        = "";
29                 $this->a_entries        = array();
30                 $this->a_header         = array();
31                 $this->b_displayPageNums= true;
32                 $this->cols             = 0;
33                 $this->pageid           = $pageid;
34         }
36         function __destruct(){
37         
38         }
40         function AddEntry($a_entriedata) {
41                 $this->a_entries[] = $a_entriedata;
42         }
44         function DisablePageNums() {
45                 $this->b_displayPageNums =false;
46         }
48         function SetHeader($a_headerdata) {
49                 $this->a_header[] = $a_headerdata ;
50         }
51         
52   function SetHeight($s_height) {
53                 $this->s_height= $s_height;
54     $this->force_height = true;
55         }
56   
57   function SetWidth($s_width) {
58                 $this->s_width= $s_width;
59     if(preg_match("/^[0-9]*$/",$this->s_width)){
60       $this->s_width .="px";
61     }
62         }
64         function SetEntriesPerPage($i_num){
65                 $this->i_entriesPerPage=$i_num;
66         }
67         
68         function DrawList(){
69                 $s_return = "";
70     if(!$this->force_height){
71                   $s_return.= "<table summary='".$this->s_summary."' style='width:".
72                   $this->s_width.";height:".$this->s_height.
73                   "px;' cellspacing='0' id='t_scrolltable'>";
74     } else {
75                   $s_return.= "<table summary='".$this->s_summary."' style='width:".
76                   $this->s_width.";height:".$this->s_height.
77                   "px;' cellspacing='0' id='t_scrolltable_onlywidth'>";
78     }
80     $s_return.= $this->_generateHeader();
81     $s_return.=$this->_generatePage();
82                 
83                 $s_return.= "</table>";
84                 
85                 return ($s_return);
86         }
87         
88         function _numpages(){
89                 $cnt = count($this->a_entries);
90                 
91                 $pages  = (int) ($cnt / $this->i_entriesPerPage);
92                 if($cnt % $this->i_entriesPerPage){
93       $pages++;
94     }
95                 
96                 return $pages;
97         }
98         
99         function _numentries(){
100                 return count($this->a_entries);
101         }
102         
103         function _generateHeader(){
104                 $s_return = "";
105                 $s_value        = "";
106                 $s_key          = "";
107                 
108     // Using scrolltable?
109     if($this->i_entriesPerPage == 0) {
110       if(!$this->force_height) {
111         $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width.";' cellspacing='0' id='t_scrollhead'>";
112       } else {
113         $s_return.= "\n<tr><td class='scrollhead'><table summary='' style='width:".$this->s_width.";' cellspacing='0' id='t_scrollhead_onlywidth'>";
114       }
115     }
117                 $s_return.= "\n<tr>";
119                 foreach($this->a_header[0] as $s_key => $s_value ){
120                         if(!isset($s_value['attach'])){
121                                 $s_value['attach'] = "";
122                         }
124                 $s_return.= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
126       // Increment column counter
127       $this->cols++;
129                 }
130                 
131     // Attach a 13px-wide column (used as scrollbar space in body-table),
132     // but do this only if we are really using scrolltables.
133     if($this->i_entriesPerPage == 0) {
134       $s_return.= "\n<td class='listheader' style='width:13px;border-right:0px;'>&nbsp;</td>";
135       $s_return.= "\n</table></td>";
136     }
138         $s_return.= "\n</tr>";
139                 return $s_return;
140         }
141         
142         function SetSummary($msg){
143                 $this->s_summary = $msg;
144         }
146         function _generatePage(){
147                 
148                 $s_value        = "";
149                 $s_key          = "";
150                 $s_return       = "";
151    
152     if($this->i_entriesPerPage == 0) {
153       // We need to construct a "body"-table that is width-of-scrollbar thinner than the "head"-table.
154       if(!$this->force_height) {
155         $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'>";
156         $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>";
157       } else {
158         $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'>";
159         $s_return .= "<table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody_onlywidth'>";
160       }
161         }
162  
163     $i_alternate=0;
164                 if(isset($_GET['start'])){
165                         $_SESSION['start'.$this->pageid]=$_GET['start'];
166                         $start = $_GET['start'];
167                 } else {
168                         if(isset($_SESSION['start'.$this->pageid])){
169                                 $start = $_SESSION['start'.$this->pageid];
170                         } else {
171                                 $start=0;
172                         }
173                 }
175     /* If divlist is empty, append a single white entry */
176     if(count($this->a_entries)==0){
177       $str = $s_return."<tr>";
178       $str.="<td class='list1nohighlight' colspan='".$this->cols."' style='height:100%;border-right:0px;width:100%;'>&nbsp;</td>";
179       $str.="</tr>";
180       if($this->i_entriesPerPage == 0) {
181         $str.="</table></div></td></tr>";
182       }
183       return($str);
184     } else {
185     
186       //FIXME: Ahrg. I'd like to read this code without wasting my time.
187       if ($this->i_entriesPerPage > 0) {
188                 while($start > $this->_numentries()){
189                         $start = $start - $this->i_entriesPerPage;
190                 }       
191     
192                 $stop  = $start + $this->i_entriesPerPage;
193     
194                 $appendempty = ($this->_numentries() -$start);
195     
196                 for($i = $start ; $i < $stop;$i++){
197                         
198                         if(isset($this->a_entries[$i])){
199                                                         
200                                 $s_value = $this->a_entries[$i];
201                                 
202                     // Alternation of background color          
203                                 if($i_alternate) $i_alternate=0; else $i_alternate=1;
204                                 
205                                 $s_return .= "\n<tr>";
206                                 
207                                 $cnt = 0;                                       
208                                         
209                                 foreach($s_value as $s_key2 => $s_value2 ){                             
210     
211                                         $cnt++;                                 
212     
213                                         if(!isset($s_value2['class'])){
214                                                 $class = "list".$i_alternate; 
215                                         }else{
216                                                 $class = $s_value2['class'];
217                                         }
218     
219                                         if(!isset($s_value2['attach'])){
220                                                 $style = "";
221                                         }else{
222                                                 $style = " ".$s_value2['attach']." "    ;
223                                         }
224     
225                                         $s_return .= "\n<td ".$style." class='".$class."'>";
226                                         $s_return .= $s_value2['string'];
227                                         $s_return .= "\n</td>";
228                                 }
229                                 if($cnt == 0 ){
230                                         $s_return.="\n<td>&nbsp;</td>";
231                                 }
232   
233                                 $s_return .= "\n</tr>";
234                         }       
235                 }
236     
237                 if(!(($stop)<$this->_numentries())){
238                         $nums = $stop - $this->_numentries();// - $stop;
239                         for($i = 0 ; $i < $nums ; $i ++ ){
240                                 $s_return.="<tr>";
241                                 $cnt=0;
242                                 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
243                                         if($a ==(count($this->a_header[0])-1)){
244                                                 $s_return.="\n<td class='list1' style='border:0px;height:26px;'>&nbsp;</td>";
245                                         } else {
246                                                 $s_return.="\n<td class='list1' style='height:26px;'>&nbsp;</td>";
247                                         }
248                                 }
249                                 $s_return.="\n</tr>";
250                         }       
251                 }
252     
253                 if($this->b_displayPageNums){
254                         $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
255                 }
256       } else {
257         // $this->i_entriesPerPage <= 0
258         // We should display all entries on one page
259   
260         $i = $this->_numEntries();
261             foreach($this->a_entries as $s_key => $s_value){
262                           $i--;
263   
264           if($i_alternate!=0){ 
265             $i_alternate=0; 
266           } else {
267             $i_alternate=1;
268           }
269                   
270           $s_return .= "\n<tr class='rowxp".$i_alternate."'>";
271                                   
272                     $cnt = 0;                                   
273                                           
274                           foreach($s_value as $s_key2 => $s_value2 ){                           
275   
276                                   $this->cols = count($s_value) ;                                               
277                                   $cnt++;                                       
278   
279                                   if(!isset($s_value2['class'])){
280                                           $class = "list".$i_alternate; 
281                                   } else {
282                                           $class = $s_value2['class'];
283                                   }
284   
285                                   if(!isset($s_value2['attach'])){
286                                           $style = "";
287                                   } else {
288                                           $style = " ".$s_value2['attach']." "  ;
289                                   }
290             
291             $s_return .= "\n<td ".$style." class='".$class."'>";
292                                   $s_return .= $s_value2['string'];
293                                   $s_return .= "</td>";
294                           }
295                           $s_return .= "\n</tr>";
296                   }
297       }
298   
299       // if fewer than 22 Entries (list not full), print row to fill empty space
300       //FIXME: Why 22? Isn't the size dynamic
301       if($this->_numEntries()<=22){
302         $fill= "";
303         for ($i= 1; $i <= $this->cols; $i++){
304           if ($i == $this->cols){
305            $fill.= "<td class='list1nohighlight' style='height:100%;border-right:0px;'>&nbsp;</td>";
306           } else {
307            $fill.= "<td class='list1nohighlight' style='height:100%;'>&nbsp;</td>";
308           }
309         }
310         $s_return.="\n<tr>$fill";
311       }
312       if($this->i_entriesPerPage == 0) {
313         $s_return .= "\n</table></div></td>";
314       }
315       $s_return .= "</tr>";
316       return $s_return;
317     }
318   }
321 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
322 ?>