FusionDirectory
class_divSelectBox.inc
Go to the documentation of this file.
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4  Copyright (C) 2003-2010 Cajus Pollmeier
5  Copyright (C) 2011-2018 FusionDirectory
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
32 {
33  protected $headers = FALSE;
34  protected $a_entries;
35  protected $s_summary;
36  protected $cols;
37 
38  protected $id;
39 
40  protected $height = '200px';
41 
45  function __construct ($id)
46  {
47  $this->s_summary = '';
48  $this->a_entries = [];
49  $this->cols = 0;
50  $this->id = $id;
51  }
52 
58  function setHeight ($h)
59  {
60  if (is_numeric($h)) {
61  $this->height = $h.'px';
62  } else {
63  $this->height = $h;
64  }
65  }
66 
72  function addEntry ($a_entriedata)
73  {
74  $this->a_entries[] = $a_entriedata;
75  }
76 
82  function setHeaders ($headers)
83  {
84  $this->headers = $headers;
85  }
86 
90  function drawList ()
91  {
92  $s_return = '';
93  $s_return .= '<div style="border:1px solid rgb(170,170,170);padding-right:1px;height:'.$this->height.';width:100%">'."\n";
94  $s_return .= '<div style="overflow:auto; width:100%; height:100%;">'."\n";
95  $s_return .= '<table '.
96  'class="listingTable" '.
97  'id="'.$this->id.'" '.
98  'style="overflow:scroll; '.
99  'height:98%; '.
100  'width:100%; '.
101  'border:none; '.
102  '"'.
103  ">\n";
104  $s_return .= $this->generatePage();
105  $s_return .= '</table></div></div>';
106  if ($this->headers !== FALSE) {
107  $s_return .=
108  '<script>
109  var sorter'.$this->id.' = tsorter.create(\''.$this->id.'\');
110  </script>';
111  }
112  return $s_return;
113  }
114 
120  function setSummary ($msg)
121  {
122  $this->s_summary = $msg;
123  }
124 
128  protected function generatePage ()
129  {
130  $display = '';
131  if ($this->headers !== FALSE) {
132  $display .= '<thead><tr>';
133  foreach ($this->headers as $header) {
134  if ($header === '') {
135  $header = '&nbsp;';
136  }
137  $display .= '<th>'.$header.'</th>';
138  }
139  $display .= '</tr></thead>'."\n";
140  }
141  return $display.'<tbody>'.$this->generateBody().'</tbody>';
142  }
143 
147  protected function generateBody ()
148  {
149  /* If divselectbox is empty, append a single white entry */
150  if (count($this->a_entries) == 0) {
151  $str = '';
152  if ($this->headers !== FALSE) {
153  $this->cols = count($this->headers);
154  $str .= '<tr>';
155  for ($i = 0; $i < ($this->cols); $i++) {
156  if ($i >= ($this->cols - 1)) {
157  $str .= '<td style="height:100%;border:0px;">&nbsp;</td>';
158  } else {
159  $str .= '<td style="height:100%;">&nbsp;</td>';
160  }
161  }
162  $str .= '</tr>';
163  } else {
164  $str .= '<tr><td style="height:100%; border-right:0px;">&nbsp;</td></tr>';
165  }
166  return $str;
167  }
168 
169  $s_return = '';
170  $i = count($this->a_entries);
171  foreach ($this->a_entries as $s_value) {
172  $i--;
173 
174  $s_return .= "\n<tr>";
175 
176  $cnt = 0;
177 
178  $this->cols = count($s_value);
179  foreach ($s_value as $s_value2) {
180  $cnt++;
181 
182  if (!isset($s_value2['class'])) {
183  $class = "";
184  } else {
185  $class = "class='".$s_value2['class']."'";
186  }
187 
188  if (!isset($s_value2['attach'])) {
189  $style = "";
190  } else {
191  $style = " ".$s_value2['attach']." ";
192  }
193 
194  $s_return .= "\n<td".$style.$class.">";
195  if (isset($s_value2['string'])) {
196  if ($s_value2['string'] === '') {
197  $s_return .= '&nbsp;';
198  } else {
199  $s_return .= htmlescape($s_value2['string']);
200  }
201  } else {
202  $s_return .= $s_value2['html'];
203  }
204  $s_return .= '</td>';
205  }
206  $s_return .= "\n</tr>";
207  }
208  $s_return .= "\n<tr>";
209  for ($i = 0; $i < ($this->cols); $i++) {
210  if ($i >= ($this->cols - 1)) {
211  $s_return .= '<td style="height:100%;border:0px;"><div style="font-size:1px;">&nbsp;</div></td>';
212  } else {
213  $s_return .= '<td style="height:100%;"><div style="font-size:1px;">&nbsp;</div></td>';
214  }
215  }
216  $s_return .= '</tr>';
217  return $s_return;
218  }
219 }
generatePage()
Generate the page.
setHeight($h)
Set new height value.
drawList()
Draw the list.
__construct($id)
Default divSelectBox constructor.
setHeaders($headers)
Set column headers.
addEntry($a_entriedata)
Add an entry.
This class contains all the functions to manage select box.