changed git call from https to git readonly
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / Smarty-2.6.0 / libs / plugins / function.html_radios.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_radios} function plugin\r
11  *\r
12  * File:       function.html_radios.php<br>\r
13  * Type:       function<br>\r
14  * Name:       html_radios<br>\r
15  * Date:       24.Feb.2003<br>\r
16  * Purpose:    Prints out a list of radio input types<br>\r
17  * Input:<br>\r
18  *           - name       (optional) - string default "radio"\r
19  *           - values     (required) - array\r
20  *           - options    (optional) - associative array\r
21  *           - checked    (optional) - array default not set\r
22  *           - separator  (optional) - ie <br> or &nbsp;\r
23  *           - output     (optional) - without this one the buttons don't have names\r
24  * Examples:\r
25  * <pre>\r
26  * {html_radios values=$ids output=$names}\r
27  * {html_radios values=$ids name='box' separator='<br>' output=$names}\r
28  * {html_radios values=$ids checked=$checked separator='<br>' output=$names}\r
29  * </pre>\r
30  * @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios}\r
31  *      (Smarty online manual)\r
32  * @author     Christopher Kvarme <christopher.kvarme@flashjab.com>\r
33  * @author credits to Monte Ohrt <monte@ispi.net>\r
34  * @version    1.0\r
35  * @param array\r
36  * @param Smarty\r
37  * @return string\r
38  * @uses smarty_function_escape_special_chars()\r
39  */\r
40 function smarty_function_html_radios($params, &$smarty)\r
41 {\r
42    require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');\r
43    \r
44    $name = 'radio';\r
45    $values = null;\r
46    $options = null;\r
47    $selected = null;\r
48    $separator = '';\r
49    $labels = true;\r
50    $output = null;\r
51    $extra = '';\r
52 \r
53    foreach($params as $_key => $_val) {\r
54                 switch($_key) {\r
55                 case 'name':\r
56                 case 'separator':\r
57                     $$_key = (string)$_val;\r
58                     break;\r
59 \r
60                 case 'checked':\r
61                 case 'selected':\r
62                         if(is_array($_val)) {\r
63                                 $smarty->trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING);\r
64                         } else {\r
65                                 $selected = (string)$_val;\r
66                         }\r
67                         break;\r
68 \r
69         case 'labels':\r
70             $$_key = (bool)$_val;\r
71             break;\r
72 \r
73                 case 'options':\r
74                         $$_key = (array)$_val;\r
75                         break;\r
76 \r
77                 case 'values':\r
78                 case 'output':\r
79                         $$_key = array_values((array)$_val);\r
80                         break;\r
81 \r
82                 case 'radios':\r
83                         $smarty->trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING);\r
84                         $options = (array)$_val;\r
85                         break;\r
86 \r
87 \r
88                 default:\r
89                         if(!is_array($_val)) {\r
90                                 $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';\r
91                         } else {\r
92                                 $smarty->trigger_error("html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE);\r
93                         }\r
94                         break;\r
95                 }\r
96    }\r
97 \r
98    if (!isset($options) && !isset($values))\r
99       return ''; /* raise error here? */\r
100 \r
101    $_html_result = '';\r
102 \r
103    if (isset($options) && is_array($options)) {\r
104 \r
105       foreach ((array)$options as $_key=>$_val)\r
106          $_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels);\r
107 \r
108    } else {\r
109 \r
110       foreach ((array)$values as $_i=>$_key) {\r
111          $_val = isset($output[$_i]) ? $output[$_i] : '';\r
112          $_html_result .= smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels);\r
113       }\r
114 \r
115    }\r
116 \r
117    return $_html_result;\r
118 \r
119 }\r
120 \r
121 function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels) {\r
122    $_output = '';\r
123    if ($labels) $_output .= '<label>';\r
124    $_output .= '<input type="radio" name="'\r
125       . smarty_function_escape_special_chars($name) . '" value="'\r
126       . smarty_function_escape_special_chars($value) . '"';\r
127 \r
128    if ($value==$selected) {\r
129       $_output .= ' checked="checked"';\r
130    }\r
131    $_output .= $extra . ' />' . $output;\r
132    if ($labels) $_output .= '</label>';\r
133    $_output .=  $separator . "\n";\r
134 \r
135    return $_output;\r
136 }\r
137 \r
138 ?>\r