5 Modification information for LGPL compliance
7 r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync
9 r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover
11 r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex
13 r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3 tags and updated the build system
15 r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
17 r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
19 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
21 r8230 - 2005-10-03 17:47:19 -0700 (Mon, 03 Oct 2005) - majed - Added Sugar_Smarty to the code tree.
35 * Smarty {html_table} function plugin
38 * Name: html_table<br>
39 * Date: Feb 17, 2003<br>
40 * Purpose: make an html table from an array of data<br>
42 * - loop = array to loop through
43 * - cols = number of columns
44 * - rows = number of rows
45 * - table_attr = table attributes
46 * - tr_attr = table row attributes (arrays are cycled)
47 * - td_attr = table cell attributes (arrays are cycled)
48 * - trailpad = value to pad trailing cells with
49 * - vdir = vertical direction (default: "down", means top-to-bottom)
50 * - hdir = horizontal direction (default: "right", means left-to-right)
51 * - inner = inner loop (default "cols": print $loop line by line,
52 * $loop will be printed column by column otherwise)
58 * {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
59 * {table loop=$data cols=4 tr_attr=$colors}
61 * @author Monte Ohrt <monte at ohrt dot com>
63 * @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table}
64 * (Smarty online manual)
69 function smarty_function_html_table($params, &$smarty)
71 $table_attr = 'border="1"';
81 if (!isset($params['loop'])) {
82 $smarty->trigger_error("html_table: missing 'loop' parameter");
86 foreach ($params as $_key=>$_value) {
89 $$_key = (array)$_value;
94 $$_key = (int)$_value;
102 $$_key = (string)$_value;
112 $loop_count = count($loop);
113 if (empty($params['rows'])) {
114 /* no rows specified */
115 $rows = ceil($loop_count/$cols);
116 } elseif (empty($params['cols'])) {
117 if (!empty($params['rows'])) {
118 /* no cols specified, but rows */
119 $cols = ceil($loop_count/$rows);
123 $output = "<table $table_attr>\n";
125 for ($r=0; $r<$rows; $r++) {
126 $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
127 $rx = ($vdir == 'down') ? $r*$cols : ($rows-1-$r)*$cols;
129 for ($c=0; $c<$cols; $c++) {
130 $x = ($hdir == 'right') ? $rx+$c : $rx+$cols-1-$c;
131 if ($inner!='cols') {
132 /* shuffle x to loop over rows*/
133 $x = floor($x/$cols) + ($x%$cols)*$rows;
136 if ($x<$loop_count) {
137 $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n";
139 $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">$trailpad</td>\n";
142 $output .= "</tr>\n";
144 $output .= "</table>\n";
149 function smarty_function_html_table_cycle($name, $var, $no) {
150 if(!is_array($var)) {
153 $ret = $var[$no % count($var)];
156 return ($ret) ? ' '.$ret : '';
160 /* vim: set expandtab: */