Code

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