diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 80b1ed0717..f916bb917a 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -3322,36 +3322,70 @@ function html_print_input_color($name, $value, $id='', $class=false, $return=fal * @param string $label Input label. * @param string $name Input name. * @param boolean $disabled Whether to disable by default or not. Enabled by default. - * @param array $attributes Additional HTML attributes. + * @param mixed $attributes Additional HTML attributes. * @param boolean $return Whether to return an output string or echo now (optional, echo by default). * * @return string HTML code if return parameter is true. */ function html_print_submit_button($label='OK', $name='', $disabled=false, $attributes='', $return=false) { - if (!$name) { + if (empty($name) === true) { $name = 'unnamed'; } - if (is_array($attributes)) { + // Icon for show in button. + $iconToUse = ''; + if (is_array($attributes) === true) { $attr_array = $attributes; $attributes = ''; foreach ($attr_array as $attribute => $value) { - $attributes .= $attribute.'="'.$value.'" '; + if ($attribute === 'icon') { + $iconToUse = $value; + } else if ($attribute === 'secondary') { + $secondary = true; + } else { + $attributes .= $attribute.'="'.$value.'" '; + } } + } else if (empty($attributes) === false && is_string($attributes) === true) { + $tmpData = explode(' ', $attributes); + $iconToUse = $tmpData[(array_search('sub', $tmpData) + 1)]; + $iconToUse = preg_replace('([^A-Za-z])', '', $iconToUse); } - $output = ' '', + 'class' => sprintf( + 'subIcon %s%s', + $iconToUse, + $secondary + ), + ], + true + ); + } else { + $iconDiv = ''; } - $output .= ' />'; - if (!$return) { + $output = sprintf( + '', + $secondary, + ($disabled === true) ? ' disabled' : '', + $label, + $iconDiv + ); + + if ($return === false) { echo $output; + } else { + return $output; } - - return $output; } @@ -3364,7 +3398,7 @@ function html_print_submit_button($label='OK', $name='', $disabled=false, $attri * @param string $name Input name. * @param boolean $disabled Whether to disable by default or not. Enabled by default. * @param string $script JavaScript to attach - * @param string $attributes Additional HTML attributes. + * @param mixed $attributes Additional HTML attributes. * @param boolean $return Whether to return an output string or echo now (optional, echo by default). * @param boolean $imageButton Set the button as a image button without text, by default is false. * @@ -3374,30 +3408,80 @@ function html_print_button($label='OK', $name='', $disabled=false, $script='', $ { $output = ''; - $alt = $title = ''; - if ($imageButton) { - $alt = $title = $label; - $label = ''; + if (empty($name) === true) { + $name = 'unnamed'; } - $output .= ' $value) { + if ($attribute === 'icon') { + $iconToUse = $value; + } else if ($attribute === 'secondary') { + $secondary = true; + } else { + $attributes .= $attribute.'="'.$value.'" '; + } + } + } else if (empty($attributes) === false && is_string($attributes) === true) { + $tmpData = explode(' ', $attributes); + $iconToUse = $tmpData[(array_search('sub', $tmpData) + 1)]; + $iconToUse = preg_replace('([^A-Za-z])', '', $iconToUse); } - $output .= ' />'; + // $secondary = true; + // Transform secondary boolean to string. + $secondary = ($secondary === true) ? ' secondary' : ''; - if ($modal && !enterprise_installed()) { + if (empty($iconToUse) === false) { + $iconDiv = html_print_div( + [ + 'style' => '', + 'class' => sprintf( + 'subIcon %s%s', + $iconToUse, + $secondary + ), + ], + true + ); + } else { + $iconDiv = ''; + } + + if ($imageButton === false) { + $content = $label; + $content .= $iconDiv; + } else { + $content = $iconDiv; + } + + $output = sprintf( + '', + $secondary, + (empty($name) === false) ? ' name="'.$name.'"' : '', + (empty($name) === false) ? ' id="button-'.$name.'"' : '', + (empty($label) === false) ? ' value="'.$label.'"' : '', + ($disabled === true) ? ' disabled' : '', + (empty($script) === false) ? ' onClick="'.$script.'"' : '', + $content + ); + + if ($modal !== false && enterprise_installed() === false) { $output .= "