Code

Add readme for xls export
[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                 
52                 $s_return = "";
53                 
54                 $s_return.= "<table summary='".$this->s_summary."' width='600' cellspacing='0'>";
55                 
56                 $s_return.= $this->_generateHeader();
57                 
58                 $s_return.= $this->_generatePage();
59                 //$s_return.= nl2br(htmlentities($this->_generatePage()));
60                 
61                 $s_return.= "</table>";
62                 
63                 return ($s_return);
64         }
65         
66         function _numpages(){
67                 $cnt = count($this->a_entries);
68                 
69                 $tmp    = $cnt % $this->i_entriesPerPage;
70                 $pages  = (int) ($cnt / $this->i_entriesPerPage);
71                 if($tmp) $pages ++;
72                 
73                 return $pages;
74         }
75         
76         function _numentries(){
77                 $cnt = count($this->a_entries);
78                 return $cnt;
79         }
80         
81         function _generateHeader(){
82                 
83                 $s_return = "";
84                 
85                 $s_value        = "";
86                 $s_key          = "";
87                                 
88                 $s_return .= "\n<tr>";
89                 foreach($this->a_header[0] as $s_key => $s_value ){
90                         if(!isset($s_value['attach'])){
91                                 $s_value['attach'] = "";
92                         }
93                         
94                         $s_return .= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
95                 }
96                 
97                 $s_return .= "\n</tr>";
98                 return $s_return;
99         }
100         
101         function         SetSummary($msg){
102                 $this->s_summary = $msg;
103         }
105         function  _generatePage(){
106                 
107                 $s_value        = "";
108                 $s_key          = "";
109                 $s_return       = "";
110                 
111                 $i_alternate=0;
112         
113                 if(isset($_GET['start'])){
114                         $_SESSION['start'.$this->pageid]=$_GET['start'];
115                         $start = $_GET['start'];
116                 }else{
117                         if(isset($_SESSION['start'.$this->pageid])){
118                                 $start = $_SESSION['start'.$this->pageid];
119                         }else{
120                                 $start=0;
121                         }
122                 }
123                 
124                 while($start > $this->_numentries()){
125                         $start = $start - $this->i_entriesPerPage;
126                 }       
128                 $stop  = $start + $this->i_entriesPerPage;
130                 $appendempty = ($this->_numentries() -$start);
132                 for($i = $start ; $i < $stop;$i++){
133                         
134                         if(isset($this->a_entries[$i])){
135                                                         
136                                 $s_value = $this->a_entries[$i];
137                                 
138                                 
139                                 if($i_alternate) $i_alternate=0; else $i_alternate=1;
140                                 
141                                 $s_return .= "\n<tr>";
142                                 
143                                 $cnt = 0;                                       
144                                         
145                                 foreach($s_value as $s_key2 => $s_value2 ){                             
147                                         $this->cols = count($s_value) ;                                         
148                                         $cnt++;                                 
150                                         if(!isset($s_value2['class'])){
151                                                 $class = "list".$i_alternate; 
152                                         }else{
153                                                 $class = $s_value2['class'];
154                                         }
156                                         if(!isset($s_value2['attach'])){
157                                                 $style = "";
158                                         }else{
159                                                 $style = " ".$s_value2['attach']." "    ;
160                                         }
162                                         $s_return .= "\n<td ".$style." class='".$class."'>";
163                                         $s_return .= $s_value2['string'];
164                                         $s_return .= "\n</td>";
165                                 }
166                                 if($cnt == 0 ){
167                                         $s_return.="<td>&nbsp;</td>";
168                                 }
169                                 $s_return .= "\n</tr>";
170                         }       
171                 }
173                 if(!(($stop)<$this->_numentries())){
174                         $nums = $stop - $this->_numentries();// - $stop;
175                         for($i = 0 ; $i < $nums ; $i ++ ){
176                                 $s_return.="<tr>";
177                                 $cnt=0;
178                                 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
179                                         if($a ==(count($this->a_header[0])-1)){
180                                                 $s_return.="<td class='list1' style='border:0px;' height='26'>&nbsp; </td>";
181                                         }else{
182                                                 $s_return.="<td class='list1' height='26'>&nbsp; </td>";
183                                         }
184                                 }
185                                 $s_return.="</tr>";
186                         }       
187                 }
189                 if($this->b_displayPageNums){
190                         $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
191                 }
193                 return $s_return;
194         }
195         
196         
198 ?>