2019-02-14 10:56:25 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2019-02-26 17:41:42 +01:00
|
|
|
* Extension to schedule tasks on Pandora FMS Console
|
|
|
|
*
|
|
|
|
* @category Wizard
|
|
|
|
* @package Pandora FMS
|
|
|
|
* @subpackage Wizard skel
|
|
|
|
* @version 1.0.0
|
|
|
|
* @license See below
|
|
|
|
*
|
|
|
|
* ______ ___ _______ _______ ________
|
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
|
|
|
* Please see http://pandorafms.org for full contribution list
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation for version 2.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* ============================================================================
|
2019-02-14 10:56:25 +01:00
|
|
|
*/
|
2019-02-21 15:35:44 +01:00
|
|
|
|
2019-03-14 18:51:48 +01:00
|
|
|
// Begin.
|
2019-02-21 15:35:44 +01:00
|
|
|
|
2019-03-14 18:51:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Global Wizard generic class. Needs to be inherited.
|
|
|
|
*
|
|
|
|
* Used in Hostdevices class, Applications class and others, is the core of
|
|
|
|
* Discovery proyect.
|
|
|
|
*/
|
2019-02-14 10:56:25 +01:00
|
|
|
class Wizard
|
|
|
|
{
|
|
|
|
|
2019-02-14 11:32:07 +01:00
|
|
|
/**
|
|
|
|
* Breadcrum
|
|
|
|
*
|
|
|
|
* @var array.
|
|
|
|
*/
|
|
|
|
public $breadcrum;
|
|
|
|
|
2019-02-14 17:56:10 +01:00
|
|
|
/**
|
2019-02-26 17:41:42 +01:00
|
|
|
* Current page
|
2019-02-14 17:56:10 +01:00
|
|
|
*
|
2019-02-26 17:41:42 +01:00
|
|
|
* @var integer
|
2019-02-14 17:56:10 +01:00
|
|
|
*/
|
|
|
|
public $page;
|
|
|
|
|
2019-02-15 18:05:59 +01:00
|
|
|
/**
|
|
|
|
* Target icon to be shown in discovery wizard list.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $icon;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Target label to be shown in discovery wizard list.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $label;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This wizard's url.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $url;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Result of wizard execution (0 - ok, 1 - not ok).
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
*/
|
|
|
|
public $result;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Message to be delivered to user.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $msg;
|
|
|
|
|
2019-10-09 15:45:02 +02:00
|
|
|
/**
|
|
|
|
* Defines access level to use this util.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $access = 'AR';
|
|
|
|
|
2019-02-14 11:32:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setter for breadcrum
|
|
|
|
*
|
|
|
|
* @param array $str Breadcrum.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setBreadcrum(array $str)
|
|
|
|
{
|
|
|
|
$this->breadcrum = $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for breadcrum
|
|
|
|
*
|
|
|
|
* @return array Breadcrum.
|
|
|
|
*/
|
|
|
|
public function getBreadcrum()
|
|
|
|
{
|
|
|
|
return $this->breadcrum;
|
|
|
|
}
|
|
|
|
|
2019-02-18 14:30:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an element to breadcrum array.
|
|
|
|
*
|
2019-02-20 16:47:29 +01:00
|
|
|
* @param string $breads Elements to add to breadcrum.
|
2019-02-18 14:30:03 +01:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-02-20 16:47:29 +01:00
|
|
|
protected function addBreadcrum($breads)
|
2019-02-20 13:57:54 +01:00
|
|
|
{
|
2019-02-20 16:47:29 +01:00
|
|
|
if (empty($breads)) {
|
2019-02-18 14:30:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-20 16:47:29 +01:00
|
|
|
$this->breadcrum = array_merge($this->breadcrum, $breads);
|
2019-02-18 14:30:03 +01:00
|
|
|
}
|
2019-02-14 11:32:07 +01:00
|
|
|
|
2019-02-14 10:56:25 +01:00
|
|
|
|
2019-02-19 20:27:05 +01:00
|
|
|
/**
|
|
|
|
* Setter for label
|
|
|
|
*
|
|
|
|
* @param string $str Label.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setLabel(string $str)
|
|
|
|
{
|
|
|
|
$this->label = $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for label
|
|
|
|
*
|
|
|
|
* @return array Breadcrum.
|
|
|
|
*/
|
|
|
|
public function getLabel()
|
|
|
|
{
|
|
|
|
return $this->label;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-20 14:38:00 +01:00
|
|
|
/**
|
|
|
|
* Return units associated to target interval (in seconds).
|
|
|
|
*
|
|
|
|
* @param integer $interval Target interval.
|
|
|
|
*
|
|
|
|
* @return integer Unit.
|
|
|
|
*/
|
|
|
|
public function getTimeUnit($interval)
|
|
|
|
{
|
|
|
|
$units = [
|
|
|
|
1,
|
|
|
|
60,
|
|
|
|
3600,
|
|
|
|
86400,
|
|
|
|
604800,
|
|
|
|
2592000,
|
|
|
|
31104000,
|
|
|
|
];
|
|
|
|
|
|
|
|
$size = count($units);
|
|
|
|
for ($i = 0; $i < $size; $i++) {
|
|
|
|
if ($interval < $units[$i]) {
|
|
|
|
if (($i - 1) < 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $units[($i - 1)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $units[-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-19 20:27:05 +01:00
|
|
|
/**
|
|
|
|
* Builder for breadcrum
|
|
|
|
*
|
2019-02-20 16:47:29 +01:00
|
|
|
* @param array $urls Array of urls to be stored in breadcrum.
|
2019-04-09 18:33:02 +02:00
|
|
|
* @param boolean $add True if breadcrum should be added
|
|
|
|
* instead of overwrite it.
|
2019-02-19 20:27:05 +01:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-09 18:33:02 +02:00
|
|
|
public function prepareBreadcrum(
|
|
|
|
array $urls,
|
|
|
|
bool $add=false
|
|
|
|
) {
|
2019-02-19 20:27:05 +01:00
|
|
|
$bc = [];
|
|
|
|
$i = 0;
|
2019-03-26 15:42:33 +01:00
|
|
|
|
2019-02-19 20:27:05 +01:00
|
|
|
foreach ($urls as $url) {
|
2019-02-20 14:38:00 +01:00
|
|
|
if ($url['selected'] == 1) {
|
|
|
|
$class = 'selected';
|
|
|
|
} else {
|
|
|
|
$class = '';
|
|
|
|
}
|
|
|
|
|
2019-03-26 15:42:33 +01:00
|
|
|
$bc[$i] = '';
|
2019-04-09 18:33:02 +02:00
|
|
|
$bc[$i] .= '<span><a class="breadcrumb_link '.$class.'" href="'.$url['link'].'">';
|
|
|
|
$bc[$i] .= $url['label'];
|
|
|
|
$bc[$i] .= '</a>';
|
2019-03-26 15:42:33 +01:00
|
|
|
$bc[$i] .= '</span>';
|
|
|
|
$i++;
|
2019-02-19 20:27:05 +01:00
|
|
|
}
|
|
|
|
|
2019-02-20 16:47:29 +01:00
|
|
|
if ($add === true) {
|
|
|
|
$this->addBreadcrum($bc);
|
|
|
|
} else {
|
|
|
|
$this->setBreadcrum($bc);
|
|
|
|
}
|
2019-02-19 20:27:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-14 10:56:25 +01:00
|
|
|
/**
|
|
|
|
* To be overwritten.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
2019-02-14 13:27:49 +01:00
|
|
|
ui_require_css_file('wizard');
|
2019-10-09 15:45:02 +02:00
|
|
|
// Check access.
|
|
|
|
check_login();
|
|
|
|
|
|
|
|
if (! $this->aclMulticheck()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check multiple acl perms.
|
|
|
|
*
|
|
|
|
* @param string $access Access in PM|AR|RR format. Optional.
|
|
|
|
*
|
|
|
|
* @return boolean Alowed or not.
|
|
|
|
*/
|
|
|
|
public function aclMulticheck($access=null)
|
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
if (isset($access)) {
|
|
|
|
$perms = explode('|', $access);
|
|
|
|
} else {
|
|
|
|
$perms = explode('|', $this->access);
|
|
|
|
}
|
|
|
|
|
|
|
|
$allowed = false;
|
|
|
|
foreach ($perms as $perm) {
|
|
|
|
$allowed = $allowed || (bool) check_acl(
|
|
|
|
$config['id_user'],
|
|
|
|
0,
|
|
|
|
$perm
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $allowed;
|
2019-02-14 10:56:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-19 14:36:16 +01:00
|
|
|
* Checks if environment is ready,
|
|
|
|
* returns array
|
|
|
|
* icon: icon to be displayed
|
|
|
|
* label: label to be displayed
|
2019-02-14 10:56:25 +01:00
|
|
|
*
|
2019-02-19 14:36:16 +01:00
|
|
|
* @return array With data.
|
|
|
|
**/
|
2019-02-14 10:56:25 +01:00
|
|
|
public function load()
|
|
|
|
{
|
2019-10-09 15:45:02 +02:00
|
|
|
global $config;
|
|
|
|
// Check access.
|
|
|
|
check_login();
|
|
|
|
|
|
|
|
if (! $this->aclMulticheck()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-02-19 14:36:16 +01:00
|
|
|
return [
|
|
|
|
'icon' => $this->icon,
|
|
|
|
'label' => $this->label,
|
|
|
|
'url' => $this->url,
|
|
|
|
];
|
2019-02-14 10:56:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-14 11:32:07 +01:00
|
|
|
/**
|
|
|
|
* Print breadcrum to follow flow.
|
|
|
|
*
|
|
|
|
* @return string Breadcrum HTML code.
|
|
|
|
*/
|
|
|
|
public function printBreadcrum()
|
|
|
|
{
|
2019-04-09 18:33:02 +02:00
|
|
|
return implode(
|
|
|
|
'<span class="breadcrumb_link"> / </span>',
|
|
|
|
$this->breadcrum
|
|
|
|
);
|
2019-02-14 11:32:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prints a header for current wizard.
|
|
|
|
*
|
|
|
|
* @param boolean $return Return HTML or print it.
|
|
|
|
*
|
|
|
|
* @return string HTML code for header.
|
|
|
|
*/
|
|
|
|
public function printHeader(bool $return=false)
|
|
|
|
{
|
|
|
|
$output = $this->printBreadcrum();
|
|
|
|
if ($return === false) {
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-14 10:56:25 +01:00
|
|
|
/**
|
|
|
|
* Print input using functions html lib.
|
|
|
|
*
|
|
|
|
* @param array $data Input definition.
|
|
|
|
*
|
|
|
|
* @return string HTML code for desired input.
|
|
|
|
*/
|
2019-02-14 17:14:01 +01:00
|
|
|
public function printInput($data)
|
2019-02-14 10:56:25 +01:00
|
|
|
{
|
2019-07-10 23:59:09 +02:00
|
|
|
global $config;
|
|
|
|
|
|
|
|
include_once $config['homedir'].'/include/functions_html.php';
|
|
|
|
|
2019-02-14 10:56:25 +01:00
|
|
|
if (is_array($data) === false) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2019-07-10 23:59:09 +02:00
|
|
|
$input = html_print_input(($data + ['return' => true]), 'div', true);
|
|
|
|
if ($input === false) {
|
|
|
|
return '';
|
2019-02-14 10:56:25 +01:00
|
|
|
}
|
|
|
|
|
2019-07-10 23:59:09 +02:00
|
|
|
return $input;
|
2019-02-14 10:56:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-15 18:05:59 +01:00
|
|
|
/**
|
|
|
|
* Prints a go back button redirecting to main page.
|
|
|
|
*
|
2019-02-26 17:42:12 +01:00
|
|
|
* @param string $url Optional target url.
|
|
|
|
*
|
2019-02-15 18:05:59 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2019-02-20 12:32:12 +01:00
|
|
|
public function printGoBackButton($url=null)
|
2019-02-15 18:05:59 +01:00
|
|
|
{
|
2019-02-20 10:53:54 +01:00
|
|
|
if (isset($url) === false) {
|
2019-02-20 10:58:56 +01:00
|
|
|
$url = ui_get_full_url(
|
|
|
|
'index.php?sec=gservers&sec2=godmode/servers/discovery'
|
|
|
|
);
|
2019-02-20 10:53:54 +01:00
|
|
|
}
|
|
|
|
|
2019-02-15 18:05:59 +01:00
|
|
|
$form = [
|
|
|
|
'form' => [
|
|
|
|
'method' => 'POST',
|
2019-02-20 10:58:56 +01:00
|
|
|
'action' => $url,
|
2019-02-15 18:05:59 +01:00
|
|
|
],
|
|
|
|
'inputs' => [
|
|
|
|
[
|
2019-07-11 13:25:29 +02:00
|
|
|
'class' => 'w100p',
|
2019-02-15 18:05:59 +01:00
|
|
|
'arguments' => [
|
|
|
|
'name' => 'submit',
|
|
|
|
'label' => __('Go back'),
|
|
|
|
'type' => 'submit',
|
|
|
|
'attributes' => 'class="sub cancel"',
|
|
|
|
'return' => true,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2019-05-17 14:46:19 +02:00
|
|
|
$this->printForm($form);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a block of inputs.
|
2019-10-15 12:16:50 +02:00
|
|
|
* 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()',
|
|
|
|
* ],
|
|
|
|
* ],
|
|
|
|
* ],
|
|
|
|
* ].
|
2019-05-17 14:46:19 +02:00
|
|
|
*
|
|
|
|
* @param array $input Definition of target block to be printed.
|
|
|
|
* @param boolean $return Return as string or direct output.
|
|
|
|
*
|
|
|
|
* @return string HTML content.
|
|
|
|
*/
|
2019-10-15 12:16:50 +02:00
|
|
|
public function printBlock(array $input, bool $return=false, bool $not_direct=false)
|
2019-05-17 14:46:19 +02:00
|
|
|
{
|
|
|
|
$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) {
|
2019-10-15 12:16:50 +02:00
|
|
|
$not_direct = (bool) $input['direct'];
|
|
|
|
|
2019-05-17 14:46:19 +02:00
|
|
|
// Print independent block of inputs.
|
2019-10-15 12:16:50 +02:00
|
|
|
$output .= '<li id="li-'.$input['block_id'].'" class="'.$class.'">';
|
|
|
|
|
2019-07-11 19:25:49 +02:00
|
|
|
if ($input['wrapper']) {
|
|
|
|
$output .= '<'.$input['wrapper'].' id="'.$input['block_id'].'" class="'.$class.'">';
|
|
|
|
}
|
|
|
|
|
2019-10-15 12:16:50 +02:00
|
|
|
if (!$not_direct) {
|
|
|
|
// Avoid encapsulation if input is direct => 1.
|
|
|
|
$output .= '<ul class="wizard '.$input['block_class'].'">';
|
|
|
|
}
|
|
|
|
|
2019-05-17 14:46:19 +02:00
|
|
|
foreach ($input['block_content'] as $input) {
|
2019-10-15 12:16:50 +02:00
|
|
|
$output .= $this->printBlock($input, $return, (bool) $not_direct);
|
2019-05-17 14:46:19 +02:00
|
|
|
}
|
|
|
|
|
2019-07-11 19:25:49 +02:00
|
|
|
// Close block.
|
2019-10-15 12:16:50 +02:00
|
|
|
if (!$not_direct) {
|
|
|
|
$output .= '</ul>';
|
|
|
|
}
|
|
|
|
|
2019-07-11 19:25:49 +02:00
|
|
|
if ($input['wrapper']) {
|
2019-10-15 12:16:50 +02:00
|
|
|
$output .= '</'.$input['wrapper'].'>';
|
2019-07-11 19:25:49 +02:00
|
|
|
}
|
2019-10-15 12:16:50 +02:00
|
|
|
|
|
|
|
$output .= '</li>';
|
2019-05-17 14:46:19 +02:00
|
|
|
} else {
|
|
|
|
if ($input['arguments']['type'] != 'hidden') {
|
2019-10-15 12:16:50 +02:00
|
|
|
if (!$not_direct) {
|
|
|
|
$output .= '<li id="'.$input['id'].'" class="'.$class.'">';
|
|
|
|
}
|
|
|
|
|
2019-05-17 14:46:19 +02:00
|
|
|
$output .= '<label>'.$input['label'].'</label>';
|
|
|
|
$output .= $this->printInput($input['arguments']);
|
|
|
|
// Allow dynamic content.
|
|
|
|
$output .= $input['extra'];
|
2019-10-15 12:16:50 +02:00
|
|
|
if (!$not_direct) {
|
|
|
|
$output .= '</li>';
|
|
|
|
}
|
2019-05-17 14:46:19 +02:00
|
|
|
} else {
|
|
|
|
$output .= $this->printInput($input['arguments']);
|
|
|
|
// Allow dynamic content.
|
|
|
|
$output .= $input['extra'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($return === false) {
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
2019-02-15 18:05:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-14 17:14:01 +01:00
|
|
|
/**
|
2019-05-16 11:37:48 +02:00
|
|
|
* Print a block of inputs with grid format.
|
2019-02-14 17:14:01 +01:00
|
|
|
*
|
|
|
|
* @param array $input Definition of target block to be printed.
|
|
|
|
* @param boolean $return Return as string or direct output.
|
|
|
|
*
|
|
|
|
* @return string HTML content.
|
|
|
|
*/
|
2019-05-16 11:37:48 +02:00
|
|
|
public function printBlockAsGrid(array $input, bool $return=false)
|
2019-02-14 17:14:01 +01:00
|
|
|
{
|
|
|
|
$output = '';
|
|
|
|
if ($input['hidden'] == 1) {
|
2019-03-06 17:14:32 +01:00
|
|
|
$class = ' hidden';
|
2019-02-14 17:14:01 +01:00
|
|
|
} else {
|
|
|
|
$class = '';
|
|
|
|
}
|
|
|
|
|
2019-03-06 17:14:32 +01:00
|
|
|
if (isset($input['class']) === true) {
|
|
|
|
$class = $input['class'].$class;
|
|
|
|
}
|
|
|
|
|
2019-02-14 17:14:01 +01:00
|
|
|
if (is_array($input['block_content']) === true) {
|
|
|
|
// Print independent block of inputs.
|
2019-03-06 17:14:32 +01:00
|
|
|
$output .= '<li id="'.$input['block_id'].'" class="'.$class.'">';
|
2019-07-15 19:37:04 +02:00
|
|
|
$output .= '<ul class="wizard '.$input['block_class'].'">';
|
2019-02-14 17:14:01 +01:00
|
|
|
foreach ($input['block_content'] as $input) {
|
2019-05-16 11:37:48 +02:00
|
|
|
$output .= $this->printBlockAsGrid($input, $return);
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= '</ul></li>';
|
|
|
|
} else {
|
|
|
|
if ($input['arguments']['type'] != 'hidden') {
|
2019-05-17 14:20:01 +02:00
|
|
|
if ($input['arguments']['inline'] != 'true') {
|
|
|
|
$output .= '<div class="edit_discovery_input">';
|
|
|
|
} else {
|
2019-06-12 16:44:09 +02:00
|
|
|
$output .= '<div style="display: flex; margin-bottom: 25px; flex-wrap: wrap;">';
|
2019-05-17 14:20:01 +02:00
|
|
|
if (!isset($input['extra'])) {
|
|
|
|
$output .= '<div style="width: 50%;">';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($input['extra'])) {
|
2019-06-12 16:44:09 +02:00
|
|
|
$output .= '<div style="display: flex; margin-right:10px;">';
|
2019-05-17 14:20:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($input['arguments']['inline'] == 'true' && isset($input['extra'])) {
|
2019-06-12 16:44:09 +02:00
|
|
|
$output .= '<div style="margin-right:10px;">';
|
2019-05-17 14:20:01 +02:00
|
|
|
}
|
|
|
|
|
2019-05-16 11:37:48 +02:00
|
|
|
$output .= '<div class="label_select">';
|
|
|
|
$output .= $input['label'];
|
|
|
|
$output .= '</div>';
|
2019-05-17 14:20:01 +02:00
|
|
|
|
|
|
|
if ($input['arguments']['inline'] == 'true' && isset($input['extra'])) {
|
|
|
|
$output .= '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($input['arguments']['inline'] == 'true' && !isset($input['extra'])) {
|
|
|
|
$output .= '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($input['arguments']['type'] == 'text' || $input['arguments']['type'] == 'text_extended') {
|
2019-05-16 11:37:48 +02:00
|
|
|
$output .= '<div class="discovery_text_input">';
|
|
|
|
$output .= $this->printInput($input['arguments']);
|
|
|
|
$output .= '</div>';
|
2019-05-17 14:20:01 +02:00
|
|
|
} else if ($input['arguments']['inline'] == 'true') {
|
|
|
|
if (isset($input['extra'])) {
|
2019-06-12 16:44:09 +02:00
|
|
|
$output .= '<div style="">';
|
|
|
|
$output .= '<div style="float: left;">';
|
2019-05-17 14:20:01 +02:00
|
|
|
} else {
|
2019-06-12 16:47:53 +02:00
|
|
|
$output .= '<div style="width:50%;">';
|
2019-05-17 14:20:01 +02:00
|
|
|
$output .= '<div style="float: right;">';
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= $this->printInput($input['arguments']);
|
|
|
|
$output .= '</div>';
|
|
|
|
$output .= '</div>';
|
|
|
|
|
|
|
|
if (isset($input['extra'])) {
|
|
|
|
$output .= '</div>';
|
|
|
|
}
|
2019-05-16 11:37:48 +02:00
|
|
|
} else {
|
|
|
|
$output .= $this->printInput($input['arguments']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow dynamic content.
|
|
|
|
$output .= $input['extra'];
|
|
|
|
$output .= '</div>';
|
|
|
|
} 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 .= '<li id="'.$input['block_id'].'" class="'.$class.'">';
|
2019-07-15 19:37:04 +02:00
|
|
|
$output .= '<ul class="wizard '.$input['block_class'].'">';
|
2019-05-16 11:37:48 +02:00
|
|
|
foreach ($input['block_content'] as $input) {
|
|
|
|
$output .= $this->printBlockAsList($input, $return);
|
2019-02-14 17:14:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$output .= '</ul></li>';
|
|
|
|
} else {
|
|
|
|
if ($input['arguments']['type'] != 'hidden') {
|
2019-03-06 17:14:32 +01:00
|
|
|
$output .= '<li id="'.$input['id'].'" class="'.$class.'">';
|
2019-02-14 17:14:01 +01:00
|
|
|
$output .= '<label>'.$input['label'].'</label>';
|
|
|
|
$output .= $this->printInput($input['arguments']);
|
|
|
|
// Allow dynamic content.
|
|
|
|
$output .= $input['extra'];
|
|
|
|
$output .= '</li>';
|
|
|
|
} else {
|
|
|
|
$output .= $this->printInput($input['arguments']);
|
|
|
|
// Allow dynamic content.
|
|
|
|
$output .= $input['extra'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($return === false) {
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-17 14:46:19 +02:00
|
|
|
/**
|
|
|
|
* Print a form.
|
|
|
|
*
|
2019-05-27 18:03:56 +02:00
|
|
|
* @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.
|
2019-05-17 14:46:19 +02:00
|
|
|
*
|
|
|
|
* @return string HTML code.
|
|
|
|
*/
|
2019-05-27 18:03:56 +02:00
|
|
|
public function printForm(
|
|
|
|
array $data,
|
|
|
|
bool $return=false,
|
|
|
|
bool $print_white_box=false
|
|
|
|
) {
|
2019-05-17 14:46:19 +02:00
|
|
|
$form = $data['form'];
|
|
|
|
$inputs = $data['inputs'];
|
|
|
|
$js = $data['js'];
|
2019-07-11 19:25:49 +02:00
|
|
|
$rawjs = $data['js_block'];
|
2019-05-17 14:46:19 +02:00
|
|
|
$cb_function = $data['cb_function'];
|
|
|
|
$cb_args = $data['cb_args'];
|
|
|
|
|
2019-07-12 18:29:58 +02:00
|
|
|
$output_head = '<form id="'.$form['id'].'" class="discovery '.$form['class'].'" onsubmit="'.$form['onsubmit'].'" enctype="'.$form['enctype'].'" action="'.$form['action'].'" method="'.$form['method'];
|
2019-05-17 14:46:19 +02:00
|
|
|
$output_head .= '" '.$form['extra'].'>';
|
|
|
|
|
|
|
|
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 .= '<div class="white_box">';
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= '<ul class="wizard">';
|
|
|
|
|
|
|
|
foreach ($inputs as $input) {
|
|
|
|
if ($input['arguments']['type'] != 'submit') {
|
|
|
|
$output .= $this->printBlock($input, true);
|
|
|
|
} else {
|
|
|
|
$output_submit .= $this->printBlock($input, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= '</ul>';
|
|
|
|
|
|
|
|
if ($print_white_box === true) {
|
|
|
|
$output .= '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= '<ul class="wizard">'.$output_submit.'</ul>';
|
|
|
|
$output .= '</form>';
|
|
|
|
$output .= '<script>'.$js.'</script>';
|
2019-07-11 19:25:49 +02:00
|
|
|
if ($rawjs) {
|
|
|
|
$output .= $rawjs;
|
|
|
|
}
|
2019-05-17 14:46:19 +02:00
|
|
|
|
|
|
|
if ($return === false) {
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output_head.$output;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-14 10:56:25 +01:00
|
|
|
/**
|
2019-05-16 11:37:48 +02:00
|
|
|
* Print a form as a grid of inputs.
|
2019-02-14 10:56:25 +01:00
|
|
|
*
|
2019-02-14 17:14:01 +01:00
|
|
|
* @param array $data Definition of target form to be printed.
|
|
|
|
* @param boolean $return Return as string or direct output.
|
2019-02-14 10:56:25 +01:00
|
|
|
*
|
2019-02-14 11:32:07 +01:00
|
|
|
* @return string HTML code.
|
2019-02-14 10:56:25 +01:00
|
|
|
*/
|
2019-05-16 11:37:48 +02:00
|
|
|
public function printFormAsGrid(array $data, bool $return=false)
|
2019-02-14 10:56:25 +01:00
|
|
|
{
|
|
|
|
$form = $data['form'];
|
2019-05-16 11:37:48 +02:00
|
|
|
|
|
|
|
$rows = $data['rows'];
|
|
|
|
|
2019-02-14 10:56:25 +01:00
|
|
|
$js = $data['js'];
|
2019-07-11 19:25:49 +02:00
|
|
|
$rawjs = $data['js_block'];
|
2019-02-19 18:23:20 +01:00
|
|
|
$cb_function = $data['cb_function'];
|
|
|
|
$cb_args = $data['cb_args'];
|
2019-02-14 10:56:25 +01:00
|
|
|
|
2019-07-10 23:59:09 +02:00
|
|
|
$output_head = '<form class="discovery" onsubmit="'.$form['onsubmit'].'" enctype="'.$form['enctype'].'" action="'.$form['action'].'" method="'.$form['method'];
|
2019-02-19 18:29:59 +01:00
|
|
|
$output_head .= '" '.$form['extra'].'>';
|
2019-02-14 10:56:25 +01:00
|
|
|
|
2019-02-19 18:29:59 +01:00
|
|
|
if ($return === false) {
|
|
|
|
echo $output_head;
|
2019-02-14 10:56:25 +01:00
|
|
|
}
|
|
|
|
|
2019-02-19 18:23:20 +01:00
|
|
|
try {
|
|
|
|
if (isset($cb_function) === true) {
|
2019-02-19 20:14:14 +01:00
|
|
|
call_user_func_array(
|
2019-02-19 18:23:20 +01:00
|
|
|
$cb_function,
|
|
|
|
(isset($cb_args) === true) ? $cb_args : []
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
error_log('Error executing wizard callback: ', $e->getMessage());
|
|
|
|
}
|
|
|
|
|
2019-04-22 17:46:04 +02:00
|
|
|
$output_submit = '';
|
|
|
|
$output = '';
|
|
|
|
|
2019-05-17 14:20:01 +02:00
|
|
|
$first_block_printed = false;
|
2019-05-16 11:37:48 +02:00
|
|
|
|
2019-07-11 19:25:49 +02:00
|
|
|
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 .= '</div>';
|
|
|
|
$output .= '<div class="white_box" style="margin-top: 30px;">';
|
|
|
|
} else {
|
|
|
|
$output .= '<div class="white_box">';
|
|
|
|
}
|
2019-05-17 14:20:01 +02:00
|
|
|
|
2019-07-11 19:25:49 +02:00
|
|
|
$first_block_printed = true;
|
|
|
|
}
|
2019-05-17 14:20:01 +02:00
|
|
|
|
2019-07-11 19:25:49 +02:00
|
|
|
$output .= '<div class="edit_discovery_info" style="'.$row['style'].'">';
|
2019-05-16 11:37:48 +02:00
|
|
|
|
2019-07-11 19:25:49 +02:00
|
|
|
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'] : '';
|
2019-05-16 11:37:48 +02:00
|
|
|
|
2019-07-11 19:25:49 +02:00
|
|
|
$output .= '<div style="'.$width.$padding_left.$padding_right.$extra_styles.'">';
|
2019-05-16 11:37:48 +02:00
|
|
|
|
2019-07-11 19:25:49 +02:00
|
|
|
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);
|
|
|
|
}
|
2019-05-16 11:37:48 +02:00
|
|
|
} else {
|
2019-07-11 19:25:49 +02:00
|
|
|
$output .= $input;
|
2019-05-16 11:37:48 +02:00
|
|
|
}
|
|
|
|
}
|
2019-07-11 19:25:49 +02:00
|
|
|
|
|
|
|
$output .= '</div>';
|
2019-05-16 11:37:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$output .= '</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= '</div>';
|
|
|
|
|
|
|
|
$output .= '<ul class="wizard">'.$output_submit.'</ul>';
|
|
|
|
$output .= '</form>';
|
|
|
|
$output .= '<script>'.$js.'</script>';
|
2019-07-11 19:25:49 +02:00
|
|
|
if ($rawjs) {
|
|
|
|
$output .= $rawjs;
|
|
|
|
}
|
2019-05-16 11:37:48 +02:00
|
|
|
|
|
|
|
if ($return === false) {
|
|
|
|
echo $output;
|
2019-04-24 16:20:42 +02:00
|
|
|
}
|
2019-04-22 17:46:04 +02:00
|
|
|
|
2019-05-16 11:37:48 +02:00
|
|
|
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'];
|
2019-07-11 19:25:49 +02:00
|
|
|
$rawjs = $data['js_block'];
|
2019-05-16 11:37:48 +02:00
|
|
|
$cb_function = $data['cb_function'];
|
|
|
|
$cb_args = $data['cb_args'];
|
|
|
|
|
2019-07-10 23:59:09 +02:00
|
|
|
$output_head = '<form class="discovery" onsubmit="'.$form['onsubmit'].'" enctype="'.$form['enctype'].'" action="'.$form['action'].'" method="'.$form['method'];
|
2019-05-16 11:37:48 +02:00
|
|
|
$output_head .= '" '.$form['extra'].'>';
|
|
|
|
|
|
|
|
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 = '<div class="white_box">';
|
2019-04-22 17:46:04 +02:00
|
|
|
$output .= '<ul class="wizard">';
|
2019-02-19 18:29:59 +01:00
|
|
|
|
|
|
|
foreach ($inputs as $input) {
|
2019-04-24 16:20:42 +02:00
|
|
|
if ($input['arguments']['type'] != 'submit') {
|
2019-05-16 11:37:48 +02:00
|
|
|
$output .= $this->printBlockAsList($input, true);
|
2019-04-24 16:20:42 +02:00
|
|
|
} else {
|
2019-05-16 11:37:48 +02:00
|
|
|
$output_submit .= $this->printBlockAsList($input, true);
|
2019-04-24 16:20:42 +02:00
|
|
|
}
|
2019-02-19 18:29:59 +01:00
|
|
|
}
|
|
|
|
|
2019-02-14 10:56:25 +01:00
|
|
|
$output .= '</ul>';
|
2019-05-16 11:37:48 +02:00
|
|
|
$output .= '</div>';
|
2019-04-22 17:46:04 +02:00
|
|
|
$output .= '<ul class="wizard">'.$output_submit.'</ul>';
|
2019-02-14 10:56:25 +01:00
|
|
|
$output .= '</form>';
|
2019-02-14 13:27:49 +01:00
|
|
|
$output .= '<script>'.$js.'</script>';
|
2019-07-11 19:25:49 +02:00
|
|
|
if ($rawjs) {
|
|
|
|
$output .= $rawjs;
|
|
|
|
}
|
2019-02-14 10:56:25 +01:00
|
|
|
|
2019-02-14 11:53:06 +01:00
|
|
|
if ($return === false) {
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
|
2019-02-19 18:29:59 +01:00
|
|
|
return $output_head.$output;
|
2019-02-14 10:56:25 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-18 10:24:19 +01:00
|
|
|
/**
|
|
|
|
* Print a big button element (huge image, big text and link).
|
|
|
|
*
|
|
|
|
* @param array $data Element data (link, image...).
|
|
|
|
*
|
|
|
|
* @return void Only prints the element.
|
|
|
|
*/
|
|
|
|
public static function printBigButtonElement($data)
|
|
|
|
{
|
|
|
|
if (isset($data['url']) === false) {
|
|
|
|
$data['url'] = '#';
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
<li class="discovery">
|
|
|
|
<a href="<?php echo $data['url']; ?>">
|
|
|
|
<div class="data_container">
|
|
|
|
<?php html_print_image($data['icon']); ?>
|
|
|
|
<br><label id="text_wizard">
|
|
|
|
<?php echo io_safe_output($data['label']); ?>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a list of big buttons elements.
|
|
|
|
*
|
|
|
|
* @param array $list_data Array of data for printBigButtonElement.
|
|
|
|
*
|
|
|
|
* @return void Print the full list.
|
|
|
|
*/
|
2019-02-19 08:58:30 +01:00
|
|
|
public static function printBigButtonsList($list_data)
|
|
|
|
{
|
2019-06-22 01:10:05 +02:00
|
|
|
echo '<ul class="bigbuttonlist">';
|
2019-02-18 10:24:19 +01:00
|
|
|
array_map('self::printBigButtonElement', $list_data);
|
|
|
|
echo '</ul>';
|
|
|
|
}
|
2019-02-18 14:30:03 +01:00
|
|
|
|
|
|
|
|
2019-02-14 10:56:25 +01:00
|
|
|
}
|