2003-02-24 21:10:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Smarty plugin
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
* File: function.html_checkboxes.php
|
|
|
|
* Type: function
|
|
|
|
* Name: html_checkboxes
|
|
|
|
* Version: 1.0
|
|
|
|
* Date: 24.Feb.2003
|
|
|
|
* Purpose: Prints out a list of checkbox input types
|
|
|
|
* Input: name (optional) - string default "checkbox"
|
|
|
|
* values (required) - array
|
2003-02-28 15:08:15 +00:00
|
|
|
* checkboxes (optional) - associative array
|
2003-02-24 21:10:01 +00:00
|
|
|
* checked (optional) - array default not set
|
|
|
|
* separator (optional) - ie <br> or
|
|
|
|
* output (optional) - without this one the buttons don't have names
|
|
|
|
* Author: Christopher Kvarme <christopher.kvarme@flashjab.com>
|
|
|
|
* Credits: Monte Ohrt <monte@ispi.net>
|
|
|
|
* Examples: {html_checkboxes values=$ids output=$names}
|
|
|
|
* {html_checkboxes values=$ids name='box' separator='<br>' output=$names}
|
|
|
|
* {html_checkboxes values=$ids checked=$checked separator='<br>' output=$names}
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
function smarty_function_html_checkboxes($params, &$smarty)
|
|
|
|
{
|
2003-02-28 15:08:15 +00:00
|
|
|
require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');
|
|
|
|
|
2003-02-24 21:10:01 +00:00
|
|
|
extract($params);
|
|
|
|
|
|
|
|
$_html_result = '';
|
|
|
|
if(!isset($name)){
|
|
|
|
$name = 'checkbox';
|
|
|
|
}
|
|
|
|
settype($checked, 'array');
|
|
|
|
if (isset($checkboxes)) {
|
|
|
|
settype($checkboxes, 'array');
|
|
|
|
foreach ($checkboxes as $_key => $_val) {
|
|
|
|
$_html_result .= smarty_function_html_checkboxes_output($name, $_key, $_val, $checked, $separator);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
settype($output, 'array');
|
|
|
|
settype($values, 'array');
|
|
|
|
for ($_i = 0, $_for_max = count($output); $_i < $_for_max; $_i++) {
|
|
|
|
$_html_result .= smarty_function_html_checkboxes_output($name, $values[$_i], $output[$_i], $checked, $separator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $_html_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function smarty_function_html_checkboxes_output($name, $value, $output, $checked, $separator) {
|
2003-02-24 21:45:19 +00:00
|
|
|
$_output = '<input type="checkbox" name="' . smarty_function_escape_special_chars($name) . '[]' .'" value="' . smarty_function_escape_special_chars($value) . '"';
|
2003-02-24 21:10:01 +00:00
|
|
|
|
|
|
|
if (in_array($value, $checked)) {
|
|
|
|
$_output .= " checked=\"checked\"";
|
|
|
|
}
|
2003-02-24 21:45:19 +00:00
|
|
|
$_output .= '>' . $output . $separator . "\n";
|
2003-02-24 21:10:01 +00:00
|
|
|
|
|
|
|
return $_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|