| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * Smarty plugin | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * @subpackage PluginsFunction | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * Smarty {html_radios} function plugin | 
					
						
							|  |  |  |  * File:       function.html_radios.php<br> | 
					
						
							|  |  |  |  * Type:       function<br> | 
					
						
							|  |  |  |  * Name:       html_radios<br> | 
					
						
							|  |  |  |  * Date:       24.Feb.2003<br> | 
					
						
							|  |  |  |  * Purpose:    Prints out a list of radio input types<br> | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * Params: | 
					
						
							|  |  |  |  * <pre> | 
					
						
							|  |  |  |  * - name       (optional) - string default "radio" | 
					
						
							|  |  |  |  * - values     (required) - array | 
					
						
							|  |  |  |  * - options    (required) - associative array | 
					
						
							|  |  |  |  * - checked    (optional) - array default not set | 
					
						
							|  |  |  |  * - separator  (optional) - ie <br> or   | 
					
						
							|  |  |  |  * - output     (optional) - the output next to each radio button | 
					
						
							|  |  |  |  * - assign     (optional) - assign the output as an array to this variable | 
					
						
							| 
									
										
										
										
											2011-11-16 11:28:35 +00:00
										 |  |  |  * - escape     (optional) - escape the content (not value), defaults to true | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * </pre> | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * Examples: | 
					
						
							|  |  |  |  * <pre> | 
					
						
							|  |  |  |  * {html_radios values=$ids output=$names} | 
					
						
							|  |  |  |  * {html_radios values=$ids name='box' separator='<br>' output=$names} | 
					
						
							|  |  |  |  * {html_radios values=$ids checked=$checked separator='<br>' output=$names} | 
					
						
							|  |  |  |  * </pre> | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @link    http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios} | 
					
						
							|  |  |  |  *          (Smarty online manual) | 
					
						
							|  |  |  |  * @author  Christopher Kvarme <christopher.kvarme@flashjab.com> | 
					
						
							|  |  |  |  * @author  credits to Monte Ohrt <monte at ohrt dot com> | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * @version 1.0 | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @param array                    $params   parameters | 
					
						
							|  |  |  |  * @param Smarty_Internal_Template $template template object | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |  * @return string | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @uses    smarty_function_escape_special_chars() | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-11-12 23:42:32 +00:00
										 |  |  | function smarty_function_html_radios($params, $template) | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-27 11:04:00 +02:00
										 |  |  |     if (!isset($template->smarty->_cache[ '_required_sesc' ])) { | 
					
						
							| 
									
										
										
										
											2016-09-02 01:08:50 +02:00
										 |  |  |         require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); | 
					
						
							| 
									
										
										
										
											2017-05-27 11:04:00 +02:00
										 |  |  |         $template->smarty->_cache[ '_required_sesc' ] = true; | 
					
						
							| 
									
										
										
										
											2016-09-02 01:08:50 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $name = 'radio'; | 
					
						
							|  |  |  |     $values = null; | 
					
						
							|  |  |  |     $options = null; | 
					
						
							|  |  |  |     $selected = null; | 
					
						
							|  |  |  |     $separator = ''; | 
					
						
							| 
									
										
										
										
											2011-11-16 11:28:35 +00:00
										 |  |  |     $escape = true; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     $labels = true; | 
					
						
							|  |  |  |     $label_ids = false; | 
					
						
							|  |  |  |     $output = null; | 
					
						
							|  |  |  |     $extra = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |     foreach ($params as $_key => $_val) { | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         switch ($_key) { | 
					
						
							|  |  |  |             case 'name': | 
					
						
							|  |  |  |             case 'separator': | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |                 $$_key = (string) $_val; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case 'checked': | 
					
						
							|  |  |  |             case 'selected': | 
					
						
							|  |  |  |                 if (is_array($_val)) { | 
					
						
							| 
									
										
										
										
											2009-12-01 20:34:32 +00:00
										 |  |  |                     trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING); | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |                 } elseif (is_object($_val)) { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |                     if (method_exists($_val, '__toString')) { | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |                         $selected = smarty_function_escape_special_chars((string) $_val->__toString()); | 
					
						
							|  |  |  |                     } else { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |                         trigger_error('html_radios: selected attribute is an object of class \'' . get_class($_val) . | 
					
						
							|  |  |  |                                       '\' without __toString() method', E_USER_NOTICE); | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |                     $selected = (string) $_val; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-16 11:28:35 +00:00
										 |  |  |             case 'escape': | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             case 'labels': | 
					
						
							|  |  |  |             case 'label_ids': | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |                 $$_key = (bool) $_val; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case 'options': | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |                 $$_key = (array) $_val; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case 'values': | 
					
						
							|  |  |  |             case 'output': | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |                 $$_key = array_values((array) $_val); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case 'radios': | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                 trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', | 
					
						
							|  |  |  |                               E_USER_WARNING); | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |                 $options = (array) $_val; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             case 'assign': | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |             case 'strict': | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2012-11-13 18:31:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             case 'disabled': | 
					
						
							|  |  |  |             case 'readonly': | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                 if (!empty($params[ 'strict' ])) { | 
					
						
							| 
									
										
										
										
											2012-11-13 18:31:48 +00:00
										 |  |  |                     if (!is_scalar($_val)) { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |                         trigger_error("html_options: {$_key} attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                                       E_USER_NOTICE); | 
					
						
							| 
									
										
										
										
											2012-11-13 18:31:48 +00:00
										 |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if ($_val === true || $_val === $_key) { | 
					
						
							|  |  |  |                         $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"'; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |             // omit break; to fall through!
 | 
					
						
							| 
									
										
										
										
											2012-11-13 18:31:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             default: | 
					
						
							|  |  |  |                 if (!is_array($_val)) { | 
					
						
							|  |  |  |                     $extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"'; | 
					
						
							|  |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |                     trigger_error("html_radios: extra attribute '{$_key}' cannot be an array", E_USER_NOTICE); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |     if (!isset($options) && !isset($values)) { | 
					
						
							|  |  |  |         /* raise error here? */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         return ''; | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $_html_result = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (isset($options)) { | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |         foreach ($options as $_key => $_val) { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             $_html_result[] = | 
					
						
							|  |  |  |                 smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, | 
					
						
							|  |  |  |                                                    $label_ids, $escape); | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         foreach ($values as $_i => $_key) { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             $_val = isset($output[ $_i ]) ? $output[ $_i ] : ''; | 
					
						
							|  |  |  |             $_html_result[] = | 
					
						
							|  |  |  |                 smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, | 
					
						
							|  |  |  |                                                    $label_ids, $escape); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |     if (!empty($params[ 'assign' ])) { | 
					
						
							|  |  |  |         $template->assign($params[ 'assign' ], $_html_result); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         return implode("\n", $_html_result); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param $name | 
					
						
							|  |  |  |  * @param $value | 
					
						
							|  |  |  |  * @param $output | 
					
						
							|  |  |  |  * @param $selected | 
					
						
							|  |  |  |  * @param $extra | 
					
						
							|  |  |  |  * @param $separator | 
					
						
							|  |  |  |  * @param $labels | 
					
						
							|  |  |  |  * @param $label_ids | 
					
						
							|  |  |  |  * @param $escape | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @return string | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  | function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |                                                $escape) | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     $_output = ''; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |     if (is_object($value)) { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         if (method_exists($value, '__toString')) { | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |             $value = (string) $value->__toString(); | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |             trigger_error('html_options: value is an object of class \'' . get_class($value) . | 
					
						
							|  |  |  |                           '\' without __toString() method', E_USER_NOTICE); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |             return ''; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $value = (string) $value; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |     if (is_object($output)) { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |         if (method_exists($output, '__toString')) { | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |             $output = (string) $output->__toString(); | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |             trigger_error('html_options: output is an object of class \'' . get_class($output) . | 
					
						
							|  |  |  |                          '\' without __toString() method', E_USER_NOTICE); | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |             return ''; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $output = (string) $output; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     if ($labels) { | 
					
						
							|  |  |  |         if ($label_ids) { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', | 
					
						
							|  |  |  |                                                                      $name . '_' . $value)); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             $_output .= '<label for="' . $_id . '">'; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $_output .= '<label>'; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |     $name = smarty_function_escape_special_chars($name); | 
					
						
							|  |  |  |     $value = smarty_function_escape_special_chars($value); | 
					
						
							| 
									
										
										
										
											2011-11-16 11:28:35 +00:00
										 |  |  |     if ($escape) { | 
					
						
							|  |  |  |         $output = smarty_function_escape_special_chars($output); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |     $_output .= '<input type="radio" name="' . $name . '" value="' . $value . '"'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($labels && $label_ids) { | 
					
						
							|  |  |  |         $_output .= ' id="' . $_id . '"'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($value === $selected) { | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         $_output .= ' checked="checked"'; | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     $_output .= $extra . ' />' . $output; | 
					
						
							| 
									
										
										
										
											2011-10-07 13:39:45 +00:00
										 |  |  |     if ($labels) { | 
					
						
							|  |  |  |         $_output .= '</label>'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     $_output .= $separator; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |     return $_output; | 
					
						
							|  |  |  | } |