6b32c59466013ca3f7380ae49283cdd4820cf537
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / Smarty-2.6.0 / libs / plugins / function.html_checkboxes.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_checkboxes} function plugin\r
11  *\r
12  * File:       function.html_checkboxes.php<br>\r
13  * Type:       function<br>\r
14  * Name:       html_checkboxes<br>\r
15  * Date:       24.Feb.2003<br>\r
16  * Purpose:    Prints out a list of checkbox input types<br>\r
17  * Input:<br>\r
18  *           - name       (optional) - string default "checkbox"\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_checkboxes values=$ids output=$names}\r
27  * {html_checkboxes values=$ids name='box' separator='<br>' output=$names}\r
28  * {html_checkboxes values=$ids checked=$checked separator='<br>' output=$names}\r
29  * </pre>\r
30  * @link http://smarty.php.net/manual/en/language.function.html.checkboxes.php {html_checkboxes}\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_checkboxes($params, &$smarty)\r
41 {\r
42    require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');\r
43 \r
44    $name = 'checkbox';\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  \r
52    $extra = '';\r
53    \r
54    foreach($params as $_key => $_val) {\r
55       switch($_key) {\r
56       case 'name':\r
57       case 'separator':\r
58          $$_key = $_val;\r
59          break;\r
60 \r
61       case 'labels':\r
62          $$_key = (bool)$_val;\r
63          break;\r
64 \r
65       case 'options':\r
66          $$_key = (array)$_val;\r
67          break;\r
68 \r
69       case 'values':\r
70       case 'output':\r
71          $$_key = array_values((array)$_val);\r
72          break;\r
73 \r
74       case 'checked':\r
75       case 'selected':\r
76          $selected = array_values((array)$_val);\r
77          break;\r
78 \r
79       case 'checkboxes':\r
80          $smarty->trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING);\r
81          $options = (array)$_val;\r
82          break;\r
83 \r
84       default:\r
85                 if(!is_array($_val)) {\r
86                         $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"';\r
87                 } else {\r
88                         $smarty->trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE);\r
89                 }\r
90          break;\r
91       }\r
92    }\r
93 \r
94    if (!isset($options) && !isset($values))\r
95       return ''; /* raise error here? */\r
96 \r
97    settype($selected, 'array');\r
98    $_html_result = '';\r
99 \r
100    if (is_array($options)) {\r
101 \r
102       foreach ($options as $_key=>$_val)\r
103          $_html_result .= smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels);\r
104 \r
105 \r
106    } else {\r
107       foreach ($values as $_i=>$_key) {\r
108          $_val = isset($output[$_i]) ? $output[$_i] : '';\r
109          $_html_result .= smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels);\r
110       }\r
111 \r
112    }\r
113 \r
114    return $_html_result;\r
115 \r
116 }\r
117 \r
118 function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels) {\r
119    $_output = '';\r
120    if ($labels) $_output .= '<label>';\r
121    $_output .= '<input type="checkbox" name="'\r
122       . smarty_function_escape_special_chars($name) . '[]" value="'\r
123       . smarty_function_escape_special_chars($value) . '"';\r
124 \r
125    if (in_array($value, $selected)) {\r
126       $_output .= ' checked="checked"';\r
127    }\r
128    $_output .= $extra . ' />' . $output;\r
129    if ($labels) $_output .= '</label>';\r
130    $_output .=  $separator . "\n";\r
131 \r
132    return $_output;\r
133 }\r
134 \r
135 ?>\r