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