changed git call from https to git readonly
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / Smarty-2.6.0 / libs / plugins / function.html_table.php
1 <?php\r
2 /**\r
3  * Smarty plugin\r
4  * @package Smarty\r
5  * @subpackage plugins\r
6  */\r
7 \r
8 \r
9 /**\r
10  * Smarty {html_table} function plugin\r
11  *\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
16  * Input:<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
28  *\r
29  *\r
30  * Examples:\r
31  * <pre>\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
35  * </pre>\r
36  * @author   Monte Ohrt <monte@ispi.net>\r
37  * @version  1.0\r
38  * @link http://smarty.php.net/manual/en/language.function.html.table.php {html_table}\r
39  *          (Smarty online manual)\r
40  * @param array\r
41  * @param Smarty\r
42  * @return string\r
43  */\r
44 function smarty_function_html_table($params, &$smarty)\r
45 {\r
46     $table_attr = 'border="1"';\r
47     $tr_attr = '';\r
48     $td_attr = '';\r
49     $cols = 3;\r
50     $rows = 3;\r
51     $trailpad = '&nbsp;';\r
52     $vdir = 'down';\r
53     $hdir = 'right';\r
54     $inner = 'cols';\r
55 \r
56     extract($params);\r
57 \r
58     if (!isset($loop)) {\r
59         $smarty->trigger_error("html_table: missing 'loop' parameter");\r
60         return;\r
61     }\r
62 \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
71         }\r
72     }\r
73 \r
74     $output = "<table $table_attr>\n";\r
75 \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
79 \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
85             }\r
86 \r
87             if ($x<$loop_count) {\r
88                 $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n";\r
89             } else {\r
90                 $output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">$trailpad</td>\n";\r
91             }\r
92         }\r
93         $output .= "</tr>\n";\r
94     }            \r
95     $output .= "</table>\n";\r
96     \r
97     return $output;\r
98 }\r
99 \r
100 function smarty_function_html_table_cycle($name, $var, $no) {\r
101     if(!is_array($var)) {\r
102         $ret = $var;\r
103     } else {\r
104         $ret = $var[$no % count($var)];\r
105     }\r
106     \r
107     return ($ret) ? ' '.$ret : '';\r
108 }\r
109 \r
110 \r
111 /* vim: set expandtab: */\r
112 \r
113 ?>\r