first commit
This commit is contained in:
71
admin/class/smarty_plugins/function.print_toggle.php
Normal file
71
admin/class/smarty_plugins/function.print_toggle.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty plugin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {print_toggle} plugin.
|
||||
*
|
||||
* Type: function<br>
|
||||
* Name: url<br>
|
||||
* Purpose: print toggle with hidden button for get Y/N value
|
||||
*
|
||||
* @param array $params parameters
|
||||
* @param Smarty_Internal_Template $smarty
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function smarty_function_print_toggle($params, &$smarty)
|
||||
{
|
||||
$name = null;
|
||||
$nameRaw = null;
|
||||
$disabled = null;
|
||||
$class = '';
|
||||
$attrs = '';
|
||||
$value = null;
|
||||
$numeric = false;
|
||||
$onOff = false;
|
||||
|
||||
extract($params);
|
||||
|
||||
if (empty($name) && empty($nameRaw)) {
|
||||
throw new InvalidArgumentException('print_toggle: \'name\' parameter empty');
|
||||
}
|
||||
|
||||
if (is_null($value)) {
|
||||
$data = $smarty->getTemplateVars('body');
|
||||
|
||||
if (!empty($data['data'])) {
|
||||
$data = $data['data'];
|
||||
}
|
||||
|
||||
$value = getVal($name, $data);
|
||||
}
|
||||
|
||||
$class .= ' toggle';
|
||||
|
||||
if ($disabled) {
|
||||
$attrs .= ' disabled ';
|
||||
}
|
||||
|
||||
if ($value == 'Y' || $value == '1') {
|
||||
$attrs .= 'checked="checked" ';
|
||||
}
|
||||
|
||||
$attrName = $name ? "data[{$name}]" : $nameRaw;
|
||||
|
||||
if ($onOff) {
|
||||
$valueTrue = 'ON';
|
||||
$valueFalse = 'OFF';
|
||||
} else {
|
||||
$valueTrue = $numeric ? 1 : 'Y';
|
||||
$valueFalse = $numeric ? 0 : 'N';
|
||||
}
|
||||
|
||||
$ret = "<input type='hidden' name='{$attrName}' value='{$valueFalse}'/>
|
||||
<label class='{$class}'><input name='{$attrName}' type='checkbox' {$attrs} value='{$valueTrue}'/>
|
||||
<span class=\"handle\"></span></label>";
|
||||
|
||||
return $ret;
|
||||
}
|
||||
Reference in New Issue
Block a user