5 * @subpackage plugins
\r
10 * Smarty {html_table} function plugin
\r
12 * Type: function<br>
\r
13 * Name: html_table<br>
\r
14 * Date: Feb 17, 2003<br>
\r
15 * Purpose: make an html table from an array of data<br>
\r
17 * - loop = array to loop through
\r
18 * - cols = number of columns
\r
19 * - rows = number of rows
\r
20 * - table_attr = table attributes
\r
21 * - tr_attr = table row attributes (arrays are cycled)
\r
22 * - td_attr = table cell attributes (arrays are cycled)
\r
23 * - trailpad = value to pad trailing cells with
\r
24 * - vdir = vertical direction (default: "down", means top-to-bottom)
\r
25 * - hdir = horizontal direction (default: "right", means left-to-right)
\r
26 * - inner = inner loop (default "cols": print $loop line by line,
\r
27 * $loop will be printed column by column otherwise)
\r
32 * {table loop=$data}
\r
33 * {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
\r
34 * {table loop=$data cols=4 tr_attr=$colors}
\r
36 * @author Monte Ohrt <monte@ispi.net>
\r
38 * @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table}
\r
39 * (Smarty online manual)
\r
44 function smarty_function_html_table($params, &$smarty)
\r
46 $table_attr = 'border="1"';
\r
51 $trailpad = ' ';
\r
58 if (!isset($loop)) {
\r
59 $smarty->trigger_error("html_table: missing 'loop' parameter");
\r
63 $loop_count = count($loop);
\r
64 if (empty($params['rows'])) {
\r
65 /* no rows specified */
\r
66 $rows = ceil($loop_count/$cols);
\r
67 } elseif (empty($params['cols'])) {
\r
68 if (!empty($params['rows'])) {
\r
69 /* no cols specified, but rows */
\r
70 $cols = ceil($loop_count/$rows);
\r
74 $output = "<table $table_attr>\n";
\r
76 for ($r=0; $r<$rows; $r++) {
\r
77 $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
\r
78 $rx = ($vdir == 'down') ? $r*$cols : ($rows-1-$r)*$cols;
\r
80 for ($c=0; $c<$cols; $c++) {
\r
81 $x = ($hdir == 'right') ? $rx+$c : $rx+$cols-1-$c;
\r
82 if ($inner!='cols') {
\r
83 /* shuffle x to loop over rows*/
\r
84 $x = floor($x/$cols) + ($x%$cols)*$rows;
\r
87 if ($x<$loop_count) {
\r
88 $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n";
\r
90 $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">$trailpad</td>\n";
\r
93 $output .= "</tr>\n";
\r
95 $output .= "</table>\n";
\r
100 function smarty_function_html_table_cycle($name, $var, $no) {
\r
101 if(!is_array($var)) {
\r
104 $ret = $var[$no % count($var)];
\r
107 return ($ret) ? ' '.$ret : '';
\r
111 /* vim: set expandtab: */
\r