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(){
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 }
50 function DrawList(){
52 $s_return = "";
54 $s_return.= "<table summary='".$this->s_summary."' width='600' cellspacing='0'>";
56 if($this->i_entriesPerPage==0) {
58 $s_return.= "<thead>".$this->_generateHeader()."</thead>";
60 // Define an alternate style for IE
61 $s_return.= "<!--[if IE]><style type='text/css'>tbody.scrollcontent {overflow-y:scroll;max-height:480px;}</style><![endif]-->";
63 $s_return.= "<tbody class='scrollcontent'>".$this->_generatePage()."</tbody>";
64 } else {
65 $s_return.=$this->_generateHeader();
67 $s_return.=$this->_generatePage();
68 }
69 //$s_return.= nl2br(htmlentities($this->_generatePage()));
71 $s_return.= "</table>";
73 return ($s_return);
74 }
76 function _numpages(){
77 $cnt = count($this->a_entries);
79 $tmp = $cnt % $this->i_entriesPerPage;
80 $pages = (int) ($cnt / $this->i_entriesPerPage);
81 if($tmp) $pages ++;
83 return $pages;
84 }
86 function _numentries(){
87 $cnt = count($this->a_entries);
88 return $cnt;
89 }
91 function _generateHeader(){
93 $s_return = "";
95 $s_value = "";
96 $s_key = "";
98 $s_return .= "\n<tr>";
100 $i_count = count($this->a_header[0])-1;
101 foreach($this->a_header[0] as $s_key => $s_value ){
102 if(!isset($s_value['attach'])){
103 $s_value['attach'] = "";
104 }
106 if($i_count == 0) {
107 $s_return .= "\n<td class='listheader' style='border-right:0px;border-bottom:1px solid #b0b0b0;'".$s_value['attach'].">".$s_value['string']."</td>";
108 } else {
109 $s_return .= "\n<td class='listheader' style='border-bottom:1px solid #b0b0b0;'".$s_value['attach'].">".$s_value['string']."</td>";
110 }
111 $i_count--;
112 }
114 // Only create additional column if we're using scrollbars
115 if($this->i_entriesPerPage==0) {
116 $s_return .= "<td class='listheader' style='border-right:0px;padding:0px;border-bottom:1px solid #b0b0b0;width:16px;'> </td>";
117 }
118 $s_return .= "\n</tr>";
119 return $s_return;
120 }
122 function SetSummary($msg){
123 $this->s_summary = $msg;
124 }
126 function _generatePage(){
128 $s_value = "";
129 $s_key = "";
130 $s_return = "";
132 $i_alternate=0;
134 if(isset($_GET['start'])){
135 $_SESSION['start'.$this->pageid]=$_GET['start'];
136 $start = $_GET['start'];
137 } else {
138 if(isset($_SESSION['start'.$this->pageid])){
139 $start = $_SESSION['start'.$this->pageid];
140 } else {
141 $start=0;
142 }
143 }
145 if ($this->i_entriesPerPage > 0) {
146 while($start > $this->_numentries()){
147 $start = $start - $this->i_entriesPerPage;
148 }
150 $stop = $start + $this->i_entriesPerPage;
152 $appendempty = ($this->_numentries() -$start);
154 for($i = $start ; $i < $stop;$i++){
156 if(isset($this->a_entries[$i])){
158 $s_value = $this->a_entries[$i];
161 if($i_alternate) $i_alternate=0; else $i_alternate=1;
163 $s_return .= "\n<tr>";
165 $cnt = 0;
167 foreach($s_value as $s_key2 => $s_value2 ){
169 $this->cols = count($s_value) ;
170 $cnt++;
172 if(!isset($s_value2['class'])){
173 $class = "list".$i_alternate;
174 }else{
175 $class = $s_value2['class'];
176 }
178 if(!isset($s_value2['attach'])){
179 $style = "";
180 }else{
181 $style = " ".$s_value2['attach']." " ;
182 }
184 $s_return .= "\n<td ".$style." class='".$class."'>";
185 $s_return .= $s_value2['string'];
186 $s_return .= "\n</td>";
187 }
188 if($cnt == 0 ){
189 $s_return.="\n<td> </td>";
190 }
192 $s_return .= "\n</tr>";
193 }
194 }
196 if(!(($stop)<$this->_numentries())){
197 $nums = $stop - $this->_numentries();// - $stop;
198 for($i = 0 ; $i < $nums ; $i ++ ){
199 $s_return.="<tr>";
200 $cnt=0;
201 for($a = 0 ; $a < (count($this->a_header[0])) ; $a ++ ) {
202 if($a ==(count($this->a_header[0])-1)){
203 $s_return.="\n<td class='list1' style='border:0px;' height='26'> </td>";
204 } else {
205 $s_return.="\n<td class='list1' height='26'> </td>";
206 }
207 }
208 $s_return.="\n</tr>";
209 }
210 }
212 if($this->b_displayPageNums){
213 $s_return .= "<tr><td colspan='".$this->cols."' align='center'>".range_selector($this->_numentries(),$start,$this->i_entriesPerPage)."</td></tr>";
214 }
215 } else {
216 // We should display all entries on one page
217 foreach($this->a_entries as $s_key => $s_value){
219 if($i_alternate){
220 $i_alternate=0;
221 } else {
222 $i_alternate=1;
223 }
225 $s_return .= "\n<tr>";
227 $cnt = 0;
229 foreach($s_value as $s_key2 => $s_value2 ){
231 $this->cols = count($s_value) ;
232 $cnt++;
234 if(!isset($s_value2['class'])){
235 $class = "list".$i_alternate;
236 } else {
237 $class = $s_value2['class'];
238 }
240 if(!isset($s_value2['attach'])){
241 $style = "";
242 } else {
243 $style = " ".$s_value2['attach']." " ;
244 }
246 $s_return .= "\n<td ".$style." class='".$class."'>";
247 $s_return .= $s_value2['string'];
248 $s_return .= "</td>";
249 }
251 if($cnt == 0 ){
252 $s_return.="\n<td> </td>";
253 } else {
254 //$s_return.="\n<td style='border:0px;padding:0px;' class='list".$i_alternate."'> </td>";
255 }
256 $s_return .= "\n</tr>";
257 }
258 }
260 return $s_return;
261 }
262 }
263 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
264 ?>