breadcrum = $str; } /** * Getter for breadcrum * * @return array Breadcrum. */ public function getBreadcrum() { return $this->breadcrum; } /** * Add an element to breadcrum array. * * @param string $breads Elements to add to breadcrum. * * @return void */ protected function addBreadcrum($breads) { if (empty($breads)) { return; } $this->breadcrum = array_merge($this->breadcrum, $breads); } /** * Breadcrum builder. * * @param array $urls Array of urls to be transformed into a breadcrum. * * @return array Breadcrum prepared. */ public function prepareBreadcrum( array $urls ) { $bc = []; $i = 0; foreach ($urls as $url) { if ($url['selected'] == 1) { $class = 'selected'; } else { $class = ''; } $bc[$i] = ''; $bc[$i] .= ''; $bc[$i] .= $url['label']; $bc[$i] .= ''; $bc[$i] .= ''; $i++; } return $bc; } /** * Print breadcrum to follow flow. * * @return string Breadcrum HTML code. */ public function printBreadcrum() { return implode( ' / ', $this->breadcrum ); } /** * Prints a go back button redirecting to main page. * * @param string $url Optional target url. * * @return void */ public function printGoBackButton($url=null) { if (isset($url) === false) { $url = ui_get_full_url('index.php'); } $form = [ 'form' => [ 'method' => 'POST', 'action' => $url, ], 'inputs' => [ [ 'class' => 'w100p', 'arguments' => [ 'name' => 'submit', 'label' => __('Go back'), 'type' => 'submit', 'attributes' => 'class="sub cancel"', 'return' => true, ], ], ], ]; $this->printForm($form); } /** * Print input using functions html lib. * * @param array $data Input definition. * * @return string HTML code for desired input. */ public function printInput(array $data) { global $config; include_once $config['homedir'].'/include/functions_html.php'; if (is_array($data) === false) { return ''; } $input = html_print_input(($data + ['return' => true]), 'div', true); if ($input === false) { return ''; } return $input; } /** * Print a block of inputs. * * @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 printBlock( 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. if (isset($input['wrapper']) === true) { $output .= '
  • '; $output .= '<'.$input['wrapper'].' id="'.$input['block_id'].'"'; $output .= ' class="'.$class.'">'; } else { $output .= '
  • '; } $output .= ''; } else { $output .= '
  • '; } } else { if ($input['arguments']['type'] != 'hidden') { $output .= '
  • '; $output .= ''; $output .= self::printInput($input['arguments']); // Allow dynamic content. $output .= $input['extra']; $output .= '
  • '; } else { $output .= self::printInput($input['arguments']); // Allow dynamic content. $output .= $input['extra']; } } if ($return === false) { echo $output; } return $output; } /** * Print a form. * * @param array $data Definition of target form to be printed. * @param boolean $return Return as string or direct output. * @param boolean $print_white_box Print a white box. * * @return string HTML code. */ public function printForm( array $data, 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 .= ''; if ($print_white_box === true) { $output .= '
    '; } $output .= ''; $output .= '
    '; $output .= ''; if ($rawjs) { $output .= $rawjs; } if ($return === false) { echo $output; } return $output_head.$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') { if ($input['arguments']['inline'] != 'true') { $output .= '
    '; } else { $output .= '
    '; if (!isset($input['extra'])) { $output .= '
    '; } if (isset($input['extra'])) { $output .= '
    '; } } if ($input['arguments']['inline'] == 'true' && isset($input['extra'])) { $output .= '
    '; } $output .= '
    '; $output .= $input['label']; $output .= '
    '; if ($input['arguments']['inline'] == 'true' && isset($input['extra'])) { $output .= '
    '; } if ($input['arguments']['inline'] == 'true' && !isset($input['extra'])) { $output .= '
    '; } if ($input['arguments']['type'] == 'text' || $input['arguments']['type'] == 'text_extended') { $output .= '
    '; $output .= $this->printInput($input['arguments']); $output .= '
    '; } else if ($input['arguments']['inline'] == 'true') { if (isset($input['extra'])) { $output .= '
    '; $output .= '
    '; } else { $output .= '
    '; $output .= '
    '; } $output .= $this->printInput($input['arguments']); $output .= '
    '; $output .= '
    '; if (isset($input['extra'])) { $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 .= '
      '; foreach ($input['block_content'] as $input) { $output .= $this->printBlockAsList($input, $return); } $output .= '
  • '; } else { if ($input['arguments']['type'] != 'hidden') { $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 as a grid of inputs. * * @param array $data Definition of target form to be printed. * @param boolean $return Return as string or direct output. * * @return string HTML code. */ 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; } $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'] : ''; $output .= '
    '; foreach ($column['inputs'] as $input) { if (is_array($input)) { if ($input['arguments']['type'] != 'submit') { $output .= $this->printBlockAsGrid($input, true); } else { $output_submit .= $this->printBlockAsGrid($input, true); } } else { $output .= $input; } } $output .= '
    '; } $output .= '
    '; } } $output .= '
    '; $output .= '
      '.$output_submit.'
    '; $output .= ''; $output .= ''; if ($rawjs) { $output .= $rawjs; } if ($return === false) { echo $output; } return $output_head.$output; } /** * Print a form as a list. * * @param array $data Definition of target form to be printed. * @param boolean $return Return as string or direct output. * * @return string HTML code. */ 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_submit.'
    '; $output .= '
    '; $output .= ''; if ($rawjs) { $output .= $rawjs; } if ($return === false) { echo $output; } return $output_head.$output; } /** * Dumps html string to output. * * @param mixed $html HTML content to be printed. * * @return void */ public function render($html) { echo $html; } }