debbfd9b182ecf32f1c2e1825bab334eb9098029
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_height = "500";
22 $this->s_width = "600";
23 $this->s_summary = "";
24 $this->a_entries = array();
25 $this->a_header = array();
26 $this->b_displayPageNums= true;
27 $this->cols = 0;
28 $this->pageid = $pageid ;
30 }
32 function __destruct(){
34 }
36 function AddEntry($a_entriedata) {
37 $this->a_entries[] = $a_entriedata;
38 }
40 function DisablePageNums() {
41 $this->b_displayPageNums =false;
42 }
44 function SetHeader($a_headerdata) {
45 $this->a_header[] = $a_headerdata ;
46 }
48 function SetHeight($s_height) {
49 $this->s_height= $s_height;
50 }
52 function SetWidth($s_width) {
53 $this->s_width= $s_width;
54 }
56 function SetEntriesPerPage($i_num){
57 $this->i_entriesPerPage=$i_num;
58 }
60 function DrawList(){
61 $s_return = "";
62 $s_return.= "<table summary='".$this->s_summary."' style='width:".$this->s_width."px;height:".$this->s_height."px;' cellspacing='0'>";
64 $s_return.= $this->_generateHeader();
65 $s_return.=$this->_generatePage();
67 $s_return.= "</table>";
69 return ($s_return);
70 }
72 function _numpages(){
73 $cnt = count($this->a_entries);
75 $tmp = $cnt % $this->i_entriesPerPage;
76 $pages = (int) ($cnt / $this->i_entriesPerPage);
77 if($tmp) $pages ++;
79 return $pages;
80 }
82 function _numentries(){
83 $cnt = count($this->a_entries);
84 return $cnt;
85 }
87 function _generateHeader(){
89 $s_return = "";
90 $s_value = "";
91 $s_key = "";
93 // Using scrolltable?
94 if($this->i_entriesPerPage == 0) {
95 $s_return .= "\n<tr><td class='scrollhead'><table style='width:".$this->s_width."px;' cellspacing='0'>";
96 }
98 $s_return .= "\n<tr>";
100 foreach($this->a_header[0] as $s_key => $s_value ){
101 if(!isset($s_value['attach'])){
102 $s_value['attach'] = "";
103 }
105 $s_return.= "\n<td class='listheader' ".$s_value['attach'].">".$s_value['string']."</td>";
107 // Increment column counter
108 $this->cols++;
110 }
112 // Attach a 18px-wide column (used as scrollbar space in body-table),
113 // but do this only if we are really using scrolltables.
114 if($this->i_entriesPerPage == 0) {
115 $s_return .= "\n<td class='listheader' style='width:13px;border-right:0px;'> </td>";
116 $s_return .= "\n</table></td>";
117 }
119 $s_return .= "\n</tr>";
120 return $s_return;
121 }
123 function SetSummary($msg){
124 $this->s_summary = $msg;
125 }
127 function _generatePage(){
129 $s_value = "";
130 $s_key = "";
131 $s_return = "";
133 if($this->i_entriesPerPage == 0) {
134 // We need to construct a "body"-table that is width-of-scrollbar thinner than the "head"-table.
135 $s_return .= "\n<tr><td colspan='".$this->cols."' class='scrollbody'><div style='align:left;width:".$this->s_width."px;height:".($this->s_height-20)."px;overflow:auto;background-color:#ffffff;'>";
137 $s_return .= "<table style='height:100%;width:581px;' cellspacing='0'>";
138 }
140 $i_alternate=0;
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 = $s_return."<tr>";
155 $str.="<td class='list1' colspan='".$this->cols."' style='height:100%;border-right:0px;width:100%;'> </td>";
156 $str.="</tr>";
157 if($this->i_entriesPerPage == 0) {
158 $str.="</table></div></td></tr>";
159 }
160 return($str);
161 } else {
163 if ($this->i_entriesPerPage > 0) {
164 while($start > $this->_numentries()){
165 $start = $start - $this->i_entriesPerPage;
166 }
168 $stop = $start + $this->i_entriesPerPage;
170 $appendempty = ($this->_numentries() -$start);
172 for($i = $start ; $i < $stop;$i++){
174 if(isset($this->a_entries[$i])){
176 $s_value = $this->a_entries[$i];
179 if($i_alternate) $i_alternate=0; else $i_alternate=1;
181 $s_return .= "\n<tr>";
183 $cnt = 0;
185 foreach($s_value as $s_key2 => $s_value2 ){
187 $cnt++;
189 if(!isset($s_value2['class'])){
190 $class = "list".$i_alternate;
191 }else{
192 $class = $s_value2['class'];
193 }
195 if(!isset($s_value2['attach'])){
196 $style = "";
197 }else{
198 $style = " ".$s_value2['attach']." " ;
199 }
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> </td>";
207 }
209 $s_return .= "\n</tr>";
210 }
211 }
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'> </td>";
221 } else {
222 $s_return.="\n<td class='list1' height='26'> </td>";
223 }
224 }
225 $s_return.="\n</tr>";
226 }
227 }
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 // $this->i_entriesPerPage <= 0
234 // We should display all entries on one page
236 $i = $this->_numEntries();
237 foreach($this->a_entries as $s_key => $s_value){
238 $i--;
240 if($i_alternate!=0){
241 $i_alternate=0;
242 } else {
243 $i_alternate=1;
244 }
246 $s_return .= "\n<tr>";
248 $cnt = 0;
250 foreach($s_value as $s_key2 => $s_value2 ){
252 $this->cols = count($s_value) ;
253 $cnt++;
255 if(!isset($s_value2['class'])){
256 $class = "list".$i_alternate;
257 } else {
258 $class = $s_value2['class'];
259 }
261 if(!isset($s_value2['attach'])){
262 $style = "";
263 } else {
264 $style = " ".$s_value2['attach']." " ;
265 }
267 $s_return .= "\n<td ".$style." class='".$class."'>";
268 $s_return .= $s_value2['string'];
269 $s_return .= "</td>";
270 }
271 $s_return .= "\n</tr>";
272 }
273 }
275 // if fewer than 22 Entries (list not full), print row to fill empty space
276 if($this->_numEntries()<=22){
277 $fill= "";
278 for ($i= 1; $i <= $this->cols; $i++){
279 if ($i == $this->cols){
280 $fill.= "<td class='list1' style='height:100%;border-right:0px';> </td>";
281 } else {
282 $fill.= "<td class='list1' style='height:100%;'> </td>";
283 }
284 }
285 $s_return.="\n<tr>$fill</tr>";
286 }
287 if($this->i_entriesPerPage == 0) {
288 $s_return .= "\n</table></div></td>";
289 }
290 $s_return .= "</tr>";
291 return $s_return;
292 }
293 }
294 }
295 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
296 ?>