Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.Table.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Generated Header (not documented yet)
8  *
9  * @author Anakeen
10  * @version $Id: Class.Table.php,v 1.2 2003/08/18 15:46:42 eric Exp $
11  * @package FDL
12  * @subpackage CORE
13  */
14 /**
15  */
16 //
17 include_once ('Class.Log.php');
18 
20 /**
21  * @deprecated not necessary and not used now
22  */
23 class Table
24 {
25  // ---------------------------------------------------------------------------
26  // Public var
27  //
28  var $array; // THE Array (2 dimensionnal)
29  var $arrayobj = "FALSE"; // if set to TRUE, Table can manage array of i
30  // Objects, it means that fields are considered as
31  // Object Attributes
32  // Fields attributes
33  var $fields; // array of the field names to show
34  var $filter = "/[A-Za-z0-9][A-Za-z0-9_]*/"; // Regexp: Field names to show
35  var $sortable_fields; // array of the fields you can sort using the
36  // sort_link
37  var $ordered_by; // the current ordering field
38  var $sort_link; // the URL used to perform a reordering of the table
39  // this URL is a format string with a %s where we
40  // should give the column name
41  var $fieldsattr; // array, foreach field gives the align attr
42  // Header attributes
43  var $heading = 0; // if set, create a <th> section
44  var $headcontent; // the content of the header
45  // if not set, the field string is used
46  var $headattr; // foreach element of the header gives the spanning
47  // and align attributes
48  var $headcolor; // Background color of header line, if not set,
49  // we use the first color of colortab
50  var $indexcolor; // Background color of index line
51  // Footer attributes
52  var $footing = 0; // Do we use a footer ?
53  var $footcontent; // content of the footer
54  // if not set, the field string is used
55  var $footattr; // foreach element of the footer gives the spanning
56  // and align attributes
57  var $footcolor; // background color of the footer, if not set,
58  // we use the color from colortab
59  // Hyperlinks
60  var $links; // array of links associated with fields, each link
61  // is a composed with a dynamic url + an array of
62  // value that should replace %s format tag
63  // in the url using an sprintff function
64  // General Layout
65  var $class; // the class (CSS) associated with <table, <tr, <td
66  var $index_class; // the class (CSS) associated with the index
67  var $head_class; // the class (CSS) associated with the header
68  var $width = "100%"; // table width
69  var $colortab; // table of alternate colors used for each row
70  var $border = 0; // border size
71  var $cellspacing = 0; // cellspacing size
72  var $defaultcolor = "#FFFFFF"; // too easy
73  var $page_bgcolor = "#FFFFFF"; // background color for nav fields
74  // Page Layout
75  var $start = 0; // the start index
76  var $slice = 20; // the slice size, zero means all
77  var $alpha_index = 0; // do you want an alphabetical index before the table
78  // it's a bitstream :
79  // 1 : UpperCase letter
80  // 2 : lowerCase letter
81  var $page_numbering = 0; // if true a page number is displayed
82  var $previous = "prev"; // the text (can be <img...) used to link to the
83  // previous page
84  var $next = "next"; // the text (can be <img...) used to link to the
85  // next page
86  var $first = "first"; // the text (can be <img...) used to link to the
87  // first page
88  var $last = "last"; // the text (can be <img...) used to link to the
89  // last page
90  var $page_link; // the URL used to turn pages. This URL is a format
91  // string with two %s in it the first on gives the
92  // index of the page start, the second gives the
93  // page size
94  // ---------------------------------------------------------------------------
95  // Private var
96  var $row = 0; // index of the current displayed row
97  var $out; // the output string
98  //
99  // ---------------------------------------------------------------------------
100  // Public methods
101  // ---------------------------------------------------------------------------
102  //
103  function show()
104  {
105  $this->construct_table();
107  }
108 
109  function get()
110  {
111  $this->construct_table();
112  return ($this->out);
113  }
114  //
115  // ---------------------------------------------------------------------------
116  // Private methods
117  // ---------------------------------------------------------------------------
118  //
119  function construct_table()
120  {
121  $this->out = "";
122  // check the table
123  if (!is_array($this->array)) return;
124  if (($this->arrayobj == "FALSE") && !is_array($this->array[$this->start])) {
125  return;
126  }
127  if (($this->arrayobj == "TRUE") && !is_object($this->array[$this->start])) {
128  return;
129  }
130  // init the fields to display
131  $this->select_colnames();
132  // show the table
133  $this->show_alpha();
134 
135  $this->table_open();
136  $this->show_header();
137  $this->show_table();
138  $this->show_footer();
139  $this->table_close();
140 
141  $this->show_navbar();
142 
143  return;
144  }
145  // ----------------------------------------------
146  function show_alpha()
147  {
148 
149  if (!isset($this->alpha_index)) return;
150  if (!isset($this->ordered_by)) return;
151  $ind = 0;
152  $lettre = array();
153  reset($this->array);
154  foreach ($this->array as $k => $v) {
155  if ($this->arrayobj == "TRUE") {
156  $initiale = substr($v->$this->ordered_by, 0, 1);
157  } else {
158  $initiale = substr($v[$this->ordered_by], 0, 1);
159  }
160 
161  if ($initiale != '') {
162  if (!isset($lettre[$initiale])) {
163  $lettre[$initiale] = $this->slice * (int)($ind / $this->slice);
164  }
165  }
166  $ind++;
167  }
168 
169  $alpha_up = array(
170  "A",
171  "B",
172  "C",
173  "D",
174  "E",
175  "F",
176  "G",
177  "H",
178  "I",
179  "J",
180  "K",
181  "L",
182  "M",
183  "N",
184  "O",
185  "P",
186  "Q",
187  "R",
188  "S",
189  "T",
190  "U",
191  "V",
192  "W",
193  "X",
194  "Y",
195  "Z"
196  );
197  $alpha_low = array(
198  "a",
199  "b",
200  "c",
201  "d",
202  "e",
203  "f",
204  "g",
205  "h",
206  "i",
207  "j",
208  "k",
209  "l",
210  "m",
211  "n",
212  "o",
213  "p",
214  "q",
215  "r",
216  "s",
217  "t",
218  "u",
219  "v",
220  "w",
221  "x",
222  "y",
223  "z"
224  );
225 
226  if (($this->alpha_index & 1)) $alpha_list = $alpha_up;
227  if (($this->alpha_index & 2)) $alpha_list = $alpha_low;
228  $this->table_open();
229  $this->table_index_row_open();
230  $idx = "[";
231  $prev = 0;
232  foreach ($alpha_list as $k => $car) {
233  if ($prev) $idx = $idx . "|";
234  if (!isset($lettre[$car])) {
235  $idx = $idx . "&nbsp;$car&nbsp;";
236  $prev = 1;
237  } else {
238  $value[0] = $lettre[$car];
239  $value[1] = $this->slice;
240  $link = $this->create_link($this->page_link, $value, $car);
241  $idx = $idx . "&nbsp;$link&nbsp;";
242  $prev = 1;
243  }
244  }
245  $idx = $idx . "]";
246  #################
247  $this->table_cell($idx, 1, "center", "", isset($this->index_class) ? $this->index_class : '', "100%");
248  $this->table_row_close();
249  $this->table_row_open();
250  $this->table_cell("&nbsp;", 1, "", "", "", "100%");
251  $this->table_row_close();
252  $this->table_close();
253  }
254  // ----------------------------------------------
255  function show_header()
256  {
257 
258  if (!$this->heading) return;
259  $this->row = 0;
260 
261  $this->table_heading_row_open();
262 
263  reset($this->fields);
264  foreach ($this->fields as $k => $v) {
265  if (isset($this->headcontent)) {
266  if (isset($this->headcontent[$v])) {
267  $val = $this->headcontent[$v];
268  } else {
269  continue;
270  }
271  } else {
272  $val = $v;
273  }
274  /* link ? */
275  if (isset($this->sortable_fields[$v])) {
276  $value[0] = $v;
277  $val = $this->create_link($this->sort_link, $value, $val);
278  }
279 
280  $this->table_heading_cell($val, isset($this->headattr[$v]["span"]) ? $this->headattr[$v]["span"] : '', isset($this->headattr[$v]["class"]) ? $this->headattr[$v]["class"] : '', isset($this->headattr[$v]["align"]) ? $this->headattr[$v]["align"] : '');
281  }
282  $this->table_row_close();
283  }
284  // ----------------------------------------------
285  function show_table()
286  {
287  $ind = 0;
288  reset($this->array);
289  foreach ($this->array as $key => $val) {
290  if ($ind++ < $this->start) continue;
291  if (($this->slice > 0) && ($ind > ($this->start + $this->slice))) break;
292 
293 
294  if ((!is_array($val)) && (!is_object($val))) continue;
295 
296  $this->table_row_open();
297 
298  reset($this->fields);
299  foreach ($this->fields as $k => $v) {
300  if ($this->arrayobj == "TRUE") {
301  $curval = $val->$v;
302  ######## BUG ########### echo $val->Parents->nomp;
303 
304  } else {
305  if (isset($val[$v])) {
306  $curval = $val[$v];
307  } else {
308  $curval = "";
309  }
310  }
311  if (!isset($this->links[$v])) {
312  $this->table_cell($curval, 1, isset($this->fieldsattr[$v]["align"]) ? $this->fieldsattr[$v]["align"] : '', isset($this->fieldsattr[$v]["wrap"]) ? $this->fieldsattr[$v]["wrap"] : '', isset($this->fieldsattr[$v]["class"]) ? $this->fieldsattr[$v]["class"] : '', isset($this->fieldsattr[$v]["width"]) ? $this->fieldsattr[$v]["width"] : '');
313  } else {
314  reset($this->links[$v][1]);
315  foreach ($this->links[$v][1] as $kk => $var) {
316  if ($this->arrayobj == "TRUE") {
317  $value[$kk] = $val->$var;
318  } else {
319  if (isset($val[$var])) {
320  $value[$kk] = $val[$var];
321  } else {
322  $value[$kk] = "";
323  }
324  }
325  }
326  $link = $this->create_link($this->links[$v][0], $value, $curval);
327  $this->table_cell($link, 1, isset($this->fieldsattr[$v]["align"]) ? $this->fieldsattr[$v]["align"] : '', isset($this->fieldsattr[$v]["wrap"]) ? $this->fieldsattr[$v]["wrap"] : '', isset($this->fieldsattr[$v]["class"]) ? $this->fieldsattr[$v]["class"] : '', isset($this->fieldsattr[$v]["width"]) ? $this->fieldsattr[$v]["width"] : '');
328  }
329  }
330  $this->table_row_close();
331  }
332  }
333  // ----------------------------------------------
334  function show_footer()
335  {
336  if ($this->footing) {
337  $this->table_row_open("", $this->footcolor);
338  reset($this->fields);
339  foreach ($this->fields as $k => $v) {
340  if (isset($this->footcontent)) {
341  if (isset($this->footcontent[$v])) {
342  $val = $this->footcontent[$v];
343  } else {
344  continue;
345  }
346  } else {
347  $val = $v;
348  }
349 
350  $this->table_cell($val, isset($this->footattr[$v]["span"]) ? $this->footattr[$v]["span"] : '', isset($this->footattr[$v]["align"]) ? $this->footattr[$v]["align"] : '', isset($this->footattr[$v]["wrap"]) ? $this->footattr[$v]["wrap"] : '', isset($this->footattr[$v]["class"]) ? $this->footattr[$v]["class"] : '', isset($this->footattr[$v]["width"]) ? $this->footattr[$v]["width"] : '');
351  }
352  $this->table_row_close();
353  }
354  return;
355  }
356  // ----------------------------------------------
357  function show_navbar()
358  {
359  // Next/Prev pages
360  if (!$this->slice || ($this->slice >= sizeof($this->array))) return;
361  $this->table_open();
362  $this->table_row_open("", $this->page_bgcolor);
363  $nbcol = 5;
364  $link_prev = "&nbsp;";
365  $link_next = "&nbsp;";
366  $link_first = "&nbsp;";
367  $link_last = "&nbsp;";
368  $this->table_cell($link_prev, 5, "", "", "", "");
369  $this->table_row_close();
370 
371  $page_tot = (((int)(sizeof($this->array) / $this->slice)) * $this->slice) == sizeof($this->array) ? (int)(sizeof($this->array) / $this->slice) : (int)(sizeof($this->array) / $this->slice) + 1;
372  $page_num = (int)($this->start / $this->slice) + 1;
373 
374  $this->table_row_open("", $this->page_bgcolor);
375 
376  $values_first[0] = 0;
377  $values_first[1] = $this->slice;
378  $values_last[0] = sizeof($this->array) - (sizeof($this->array) - (($page_tot - 1) * ($this->slice)));
379  $values_last[1] = $this->slice;
380  if ($this->start - $this->slice >= 0) {
381  $value[0] = $this->start - $this->slice;
382  $value[1] = $this->slice;
383  $link_first = $this->create_link($this->page_link, $values_first, $this->first);
384  $link_prev = $this->create_link($this->page_link, $value, $this->previous);
385  }
386  if ($this->start + $this->slice < sizeof($this->array)) {
387  $value[0] = $this->start + $this->slice;
388  $value[1] = $this->slice;
389  $link_next = $this->create_link($this->page_link, $value, $this->next);
390  $link_last = $this->create_link($this->page_link, $values_last, $this->last);
391  }
392 
393  $this->table_cell($link_first, 1, "left", "", "", "10%");
394  $this->table_cell($link_prev, 1, "left", "", "", "20%");
395  $this->table_cell("$page_num/$page_tot", 1, "center", "", "", "20%");
396  $this->table_cell($link_next, 1, "right", "", "", "20%");
397  $this->table_cell($link_last, 1, "right", "", "", "10%");
398  $this->table_row_close();
399  $this->table_close();
400  }
401  // ----------------------------------------------
402  function select_colnames()
403  {
404  if (isset($this->fields) || ($this->arrayobj == "TRUE")) return;
405  reset($this->array);
406  list($key, $val) = each($this->array);
407  reset($val);
408  foreach ($val as $k => $v) {
409  if (preg_match($this->filter, $k)) $this->fields[] = $k;
410  }
411  }
412  // ----------------------------------------------
413  function table_open()
414  {
415  $this->out = $this->out . sprintf("<table%s %s cellpadding=\"0\" %s %s >\n", isset($this->class) ? " class=$this->class" : "", isset($this->border) ? " border=$this->border" : "", isset($this->cellspacing) ? " cellspacing=$this->cellspacing" : "", isset($this->width) ? " width=$this->width" : "");
416  }
417  // ----------------------------------------------
418  function table_close()
419  {
420  $this->out = $this->out . "</table>\n";
421  }
422  // ----------------------------------------------
423  function table_row_open($nbcol = "", $color = "")
424  {
425  if (!$color && (isset($this->colortab))) {
426  $color = $this->colortab[$this->row % sizeof($this->colortab) ];
427  }
428  $this->out = $this->out . sprintf(" <tr%s%s%s>\n", $color ? " bgcolor=$color" : "", isset($this->class) ? " class=$this->class" : "", $nbcol ? " cols=$nbcol" : "");
429  }
430  // ----------------------------------------------
431  function table_row_close()
432  {
433  $this->out = $this->out . " </tr>\n";
434  $this->row++;
435  }
436  // ----------------------------------------------
438  {
439  $this->out = $this->out . sprintf(" <tr%s%s>\n", isset($this->index_class) ? " class=\"$this->index_class\"" : "", isset($this->indexcolor) ? " bgcolor=$this->indexcolor" : "");
440  }
441  // ----------------------------------------------
443  {
444  $this->out = $this->out . sprintf(" <tr%s%s>\n", isset($this->head_class) ? " class=\"$this->head_class\"" : "", isset($this->headcolor) ? " bgcolor=$this->headcolor" : "");
445  }
446  // ----------------------------------------------
447  function table_heading_cell($val, $colspan = 1, $class = "", $align = "left")
448  {
449  $w_class = "";
450  if (isset($class)) {
451  $w_class = " class=$class";
452  } else {
453  if (isset($this->class)) {
454  $w_class = " class=$this->class";
455  }
456  }
457  $this->out = $this->out . sprintf(" <th%s%s%s><p>%s</p></th>\n", $w_class, $colspan ? " colspan=$colspan" : "", $align ? " align=$align" : "", $val);
458  }
459  // ----------------------------------------------
460  function table_cell($val, $colspan = 1, $align = "left", $wrap = "", $class = "", $width = "")
461  {
462  $w_class = "";
463  if ($class != "") {
464  $w_class = " class=$class";
465  } else {
466  if (isset($this->class)) {
467  $w_class = " class=$this->class";
468  }
469  }
470  $this->out = $this->out . sprintf(" <td%s%s%s%s%s><p>%s&nbsp;</p></td>\n", $w_class, $colspan ? " colspan=$colspan" : "", $align ? " align=$align" : "", $wrap ? " $wrap" : "", $width ? " width=$width" : "", $val);
471  }
472  ////////////////////////////////////////////////////////////////
473  // create_link : should be usefull for other classes
474  // this function is here because we don't know where we should put it
475  // so !!
476  //
477  function create_link($template, $values, $text)
478  {
479  $link = "\$link = sprintf (\"\n<a href=\\\"" . $template . "\\\">\"";
480  reset($values);
481  foreach ($values as $key => $val) {
482  $link = $link . ",\"" . $val . "\"";
483  }
484  $link = $link . ");";
485  eval($link);
486  $link = $link . $text . "</a>";
487  return ($link);
488  }
489 }
490 ?>
$page_numbering
Definition: Class.Table.php:81
table_row_open($nbcol="", $color="")
select_colnames()
show_table()
$s slice
show_alpha()
table_heading_row_open()
create_link($template, $values, $text)
$cellspacing
Definition: Class.Table.php:71
table_heading_cell($val, $colspan=1, $class="", $align="left")
$headcontent
Definition: Class.Table.php:44
table_row_close()
show_footer()
show_header()
$alpha_index
Definition: Class.Table.php:77
$footcontent
Definition: Class.Table.php:53
$CLASS_TABLE_PHP
Definition: Class.Table.php:19
construct_table()
table_close()
print
Definition: checklist.php:49
show_navbar()
$s start
$sortable_fields
Definition: Class.Table.php:35
table_cell($val, $colspan=1, $align="left", $wrap="", $class="", $width="")
table_index_row_open()
$page_bgcolor
Definition: Class.Table.php:73
$value
table_open()
$defaultcolor
Definition: Class.Table.php:72
$index_class
Definition: Class.Table.php:66
first($a)
← centre documentaire © anakeen