diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index fa88e5df8b..6783ba20e1 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -27,7 +27,12 @@ */ // Begin. +global $config; +require_once $config['homedir'].'/vendor/autoload.php'; +require_once $config['homedir'].'/include/class/HTML.class.php'; + +use \HTML; /** * Global Wizard generic class. Needs to be inherited. @@ -423,281 +428,6 @@ class Wizard } - /** - * Print a block of inputs. - * Example, using direct to 'anidate' inputs directly to wrapper: - * [ - * 'wrapper' => 'div', - * 'block_id' => 'example_id', - * 'class' => 'your class', - * 'direct' => 1, - * 'block_content' => [ - * [ - * 'arguments' => [ - * 'label' => __('Sugesstion'), - * 'type' => 'button', - * 'attributes' => 'class="sub ok btn_sug"', - * 'name' => 'option_1', - * 'id' => 'option_1', - * 'script' => 'change_option1()', - * ], - * ], - * [ - * 'arguments' => [ - * 'label' => __('Something is not quite right'), - * 'type' => 'button', - * 'attributes' => 'class="sub ok btn_something"', - * 'name' => 'option_2', - * 'id' => 'option_2', - * 'script' => 'change_option2()', - * ], - * ], - * ], - * ]. - * - * @param array $input Definition of target block to be printed. - * @param boolean $return Return as string or direct output. - * @param boolean $direct Avoid encapsulation if input print is direct. - * - * @return string HTML content. - */ - public function printBlock( - array $input, - bool $return=false, - bool $direct=false - ) { - $output = ''; - if ($input['hidden'] == 1) { - $class = ' hidden'; - } else { - $class = ''; - } - - if (isset($input['class']) === true) { - $class = $input['class'].$class; - } - - if (is_array($input['block_content']) === true) { - $direct = (bool) $input['direct']; - $toggle = (bool) $input['toggle']; - - // Print independent block of inputs. - $output .= '
  • '; - - if ($input['wrapper']) { - $output .= '<'.$input['wrapper'].' id="'.$input['block_id'].'" class="'.$class.'">'; - } - - if (!$direct) { - // Avoid encapsulation if input is direct => 1. - $output .= ''; - } - - if ($input['wrapper']) { - $output .= ''; - } - - $output .= '
  • '; - } else { - if ($input['arguments']['type'] != 'hidden' - && $input['arguments']['type'] != 'hidden_extended' - ) { - if (!$direct) { - $output .= '
  • '; - } - - $output .= ''; - $output .= $this->printInput($input['arguments']); - // Allow dynamic content. - $output .= $input['extra']; - if (!$direct) { - $output .= '
  • '; - } - } else { - $output .= $this->printInput($input['arguments']); - // Allow dynamic content. - $output .= $input['extra']; - } - } - - if ($return === false) { - echo $output; - } - - return $output; - } - - - /** - * Print a block of inputs with grid format. - * - * @param array $input Definition of target block to be printed. - * @param boolean $return Return as string or direct output. - * - * @return string HTML content. - */ - public function printBlockAsGrid(array $input, bool $return=false) - { - $output = ''; - if ($input['hidden'] == 1) { - $class = ' hidden'; - } else { - $class = ''; - } - - if (isset($input['class']) === true) { - $class = $input['class'].$class; - } - - if (is_array($input['block_content']) === true) { - // Print independent block of inputs. - $output .= '
    '; - $output .= '
    '; - } else { - if ($input['arguments']['type'] != 'hidden' - && $input['arguments']['type'] != 'hidden_extended' - ) { - $id = ''; - if ($input['id']) { - $id = $input['id']; - } - - if ($input['arguments']['inline'] != 'true') { - $output .= '
    '; - } else { - $output .= '
    '; - } - - $output .= '
    '; - $output .= $input['label']; - $output .= '
    '; - - if ($input['arguments']['type'] == 'text' || $input['arguments']['type'] == 'text_extended') { - $output .= '
    '; - $output .= $this->printInput($input['arguments']); - $output .= '
    '; - } else if ($input['arguments']['inline'] == 'true') { - $output .= '
    '; - $output .= $this->printInput($input['arguments']); - $output .= '
    '; - } else { - $output .= $this->printInput($input['arguments']); - } - - // Allow dynamic content. - $output .= $input['extra']; - $output .= '
    '; - } else { - $output .= $this->printInput($input['arguments']); - // Allow dynamic content. - $output .= $input['extra']; - } - } - - if ($return === false) { - echo $output; - } - - return $output; - } - - - /** - * Print a block of inputs as a list element. - * - * @param array $input Definition of target block to be printed. - * @param boolean $return Return as string or direct output. - * - * @return string HTML content. - */ - public function printBlockAsList(array $input, bool $return=false) - { - $output = ''; - if ($input['hidden'] == 1) { - $class = ' hidden'; - } else { - $class = ''; - } - - if (isset($input['class']) === true) { - $class = $input['class'].$class; - } - - if (is_array($input['block_content']) === true) { - // Print independent block of inputs. - $output .= '
  • '; - $output .= '
  • '; - } else { - if ($input['arguments']['type'] != 'hidden' - && $input['arguments']['type'] != 'hidden_extended' - ) { - $output .= '
  • '; - $output .= ''; - $output .= $this->printInput($input['arguments']); - // Allow dynamic content. - $output .= $input['extra']; - $output .= '
  • '; - } else { - $output .= $this->printInput($input['arguments']); - // Allow dynamic content. - $output .= $input['extra']; - } - } - - if ($return === false) { - echo $output; - } - - return $output; - } - - /** * Print a form. * @@ -712,67 +442,7 @@ class Wizard bool $return=false, bool $print_white_box=false ) { - $form = $data['form']; - $inputs = $data['inputs']; - $js = $data['js']; - $rawjs = $data['js_block']; - $cb_function = $data['cb_function']; - $cb_args = $data['cb_args']; - - $output_head = '
    '; - - if ($return === false) { - echo $output_head; - } - - try { - if (isset($cb_function) === true) { - call_user_func_array( - $cb_function, - (isset($cb_args) === true) ? $cb_args : [] - ); - } - } catch (Exception $e) { - error_log('Error executing wizard callback: ', $e->getMessage()); - } - - $output_submit = ''; - $output = ''; - - if ($print_white_box === true) { - $output .= '
    '; - } - - $output .= '
      '; - - foreach ($inputs as $input) { - if ($input['arguments']['type'] != 'submit') { - $output .= $this->printBlock($input, true); - } else { - $output_submit .= $this->printBlock($input, true); - } - } - - $output .= '
    '; - - if ($print_white_box === true) { - $output .= '
    '; - } - - $output .= ''; - $output .= '
    '; - $output .= ''; - if ($rawjs) { - $output .= $rawjs; - } - - if ($return === false) { - echo $output; - } - - return $output_head.$output; - + return HTML::printForm($data, $return, $print_white_box); } @@ -786,112 +456,7 @@ class Wizard */ public function printFormAsGrid(array $data, bool $return=false) { - $form = $data['form']; - - $rows = $data['rows']; - - $js = $data['js']; - $rawjs = $data['js_block']; - $cb_function = $data['cb_function']; - $cb_args = $data['cb_args']; - - $output_head = '
    '; - - if ($return === false) { - echo $output_head; - } - - try { - if (isset($cb_function) === true) { - call_user_func_array( - $cb_function, - (isset($cb_args) === true) ? $cb_args : [] - ); - } - } catch (Exception $e) { - error_log('Error executing wizard callback: ', $e->getMessage()); - } - - $output_submit = ''; - $output = ''; - - $first_block_printed = false; - - if (is_array($rows)) { - foreach ($rows as $row) { - if ($row['new_form_block'] == true) { - if ($first_block_printed === true) { - // If first form block has been placed, then close it before starting a new one. - $output .= '
    '; - $output .= '
    '; - } else { - $output .= '
    '; - } - - $first_block_printed = true; - } - - $row_output = '
    '; - - foreach ($row['columns'] as $column) { - $width = isset($column['width']) ? 'width: '.$column['width'].';' : 'width: 100%;'; - $padding_left = isset($column['padding-left']) ? 'padding-left: '.$column['padding-left'].';' : 'padding-left: 0;'; - $padding_right = isset($column['padding-right']) ? 'padding-right: '.$column['padding-right'].';' : 'padding-right: 0;'; - $extra_styles = isset($column['style']) ? $column['style'] : ''; - $class = isset($column['class']) ? $column['class'] : ''; - - $row_output .= '
    '; - - foreach ($column['inputs'] as $input) { - if (is_array($input)) { - if ($input['arguments']['type'] != 'submit') { - $row_output .= $this->printBlockAsGrid($input, true); - } else { - $output_submit .= $this->printBlockAsGrid($input, true); - } - } else { - $row_output .= $input; - } - } - - $row_output .= '
    '; - } - - if (isset($row['toggle'])) { - $output .= ui_print_toggle( - [ - 'content' => $row_output, - 'name' => $row['toggle_label'], - 'hidden_default' => ! (bool) $row['toggle'], - 'return' => true, - ] - ); - } else { - $output .= $row_output; - } - - $output .= '
    '; - } - } - - $output .= '
    '; - - $output .= ''; - $output .= ''; - $output .= ''; - if ($rawjs) { - $output .= $rawjs; - } - - if ($return === false) { - echo $output; - } - - return $output_head.$output; - + return HTML::printFormAsGrid($data, $return); } @@ -905,57 +470,7 @@ class Wizard */ public function printFormAsList(array $data, bool $return=false) { - $form = $data['form']; - $inputs = $data['inputs']; - $js = $data['js']; - $rawjs = $data['js_block']; - $cb_function = $data['cb_function']; - $cb_args = $data['cb_args']; - - $output_head = '
    '; - - if ($return === false) { - echo $output_head; - } - - try { - if (isset($cb_function) === true) { - call_user_func_array( - $cb_function, - (isset($cb_args) === true) ? $cb_args : [] - ); - } - } catch (Exception $e) { - error_log('Error executing wizard callback: ', $e->getMessage()); - } - - $output = '
    '; - $output .= '
      '; - - foreach ($inputs as $input) { - if ($input['arguments']['type'] != 'submit') { - $output .= $this->printBlockAsList($input, true); - } else { - $output_submit .= $this->printBlockAsList($input, true); - } - } - - $output .= '
    '; - $output .= '
    '; - $output .= ''; - $output .= '
    '; - $output .= ''; - if ($rawjs) { - $output .= $rawjs; - } - - if ($return === false) { - echo $output; - } - - return $output_head.$output; - + return HTML::printFormAsList($data, $return); } diff --git a/pandora_console/include/class/HTML.class.php b/pandora_console/include/class/HTML.class.php index dd6bb79ca2..ed9d1fa459 100644 --- a/pandora_console/include/class/HTML.class.php +++ b/pandora_console/include/class/HTML.class.php @@ -610,9 +610,15 @@ class HTML } if (is_array($input['block_content']) === true) { + if (empty($input['label']) === false) { + $output .= '
    '; + $output .= $input['label']; + $output .= '
    '; + } + // Print independent block of inputs. - $output .= '
  • '; $output .= '