+++ /dev/null
-<?php\r
-/**\r
- * Smarty plugin\r
- * @package Smarty\r
- * @subpackage plugins\r
- */\r
-\r
-\r
-/**\r
- * Smarty {html_table} function plugin\r
- *\r
- * Type: function<br>\r
- * Name: html_table<br>\r
- * Date: Feb 17, 2003<br>\r
- * Purpose: make an html table from an array of data<br>\r
- * Input:<br>\r
- * - loop = array to loop through\r
- * - cols = number of columns\r
- * - rows = number of rows\r
- * - table_attr = table attributes\r
- * - tr_attr = table row attributes (arrays are cycled)\r
- * - td_attr = table cell attributes (arrays are cycled)\r
- * - trailpad = value to pad trailing cells with\r
- * - vdir = vertical direction (default: "down", means top-to-bottom)\r
- * - hdir = horizontal direction (default: "right", means left-to-right)\r
- * - inner = inner loop (default "cols": print $loop line by line,\r
- * $loop will be printed column by column otherwise)\r
- *\r
- *\r
- * Examples:\r
- * <pre>\r
- * {table loop=$data}\r
- * {table loop=$data cols=4 tr_attr='"bgcolor=red"'}\r
- * {table loop=$data cols=4 tr_attr=$colors}\r
- * </pre>\r
- * @author Monte Ohrt <monte@ispi.net>\r
- * @version 1.0\r
- * @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table}\r
- * (Smarty online manual)\r
- * @param array\r
- * @param Smarty\r
- * @return string\r
- */\r
-function smarty_function_html_table($params, &$smarty)\r
-{\r
- $table_attr = 'border="1"';\r
- $tr_attr = '';\r
- $td_attr = '';\r
- $cols = 3;\r
- $rows = 3;\r
- $trailpad = ' ';\r
- $vdir = 'down';\r
- $hdir = 'right';\r
- $inner = 'cols';\r
-\r
- extract($params);\r
-\r
- if (!isset($loop)) {\r
- $smarty->trigger_error("html_table: missing 'loop' parameter");\r
- return;\r
- }\r
-\r
- $loop_count = count($loop);\r
- if (empty($params['rows'])) {\r
- /* no rows specified */\r
- $rows = ceil($loop_count/$cols);\r
- } elseif (empty($params['cols'])) {\r
- if (!empty($params['rows'])) {\r
- /* no cols specified, but rows */\r
- $cols = ceil($loop_count/$rows);\r
- }\r
- }\r
-\r
- $output = "<table $table_attr>\n";\r
-\r
- for ($r=0; $r<$rows; $r++) {\r
- $output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";\r
- $rx = ($vdir == 'down') ? $r*$cols : ($rows-1-$r)*$cols;\r
-\r
- for ($c=0; $c<$cols; $c++) {\r
- $x = ($hdir == 'right') ? $rx+$c : $rx+$cols-1-$c;\r
- if ($inner!='cols') {\r
- /* shuffle x to loop over rows*/\r
- $x = floor($x/$cols) + ($x%$cols)*$rows;\r
- }\r
-\r
- if ($x<$loop_count) {\r
- $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n";\r
- } else {\r
- $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">$trailpad</td>\n";\r
- }\r
- }\r
- $output .= "</tr>\n";\r
- } \r
- $output .= "</table>\n";\r
- \r
- return $output;\r
-}\r
-\r
-function smarty_function_html_table_cycle($name, $var, $no) {\r
- if(!is_array($var)) {\r
- $ret = $var;\r
- } else {\r
- $ret = $var[$no % count($var)];\r
- }\r
- \r
- return ($ret) ? ' '.$ret : '';\r
-}\r
-\r
-\r
-/* vim: set expandtab: */\r
-\r
-?>\r