diff --git a/extras/pandora_gotty/deb/pandora_gotty/DEBIAN/control b/extras/pandora_gotty/deb/pandora_gotty/DEBIAN/control index f715ee1b49..fda06b3e36 100644 --- a/extras/pandora_gotty/deb/pandora_gotty/DEBIAN/control +++ b/extras/pandora_gotty/deb/pandora_gotty/DEBIAN/control @@ -1,6 +1,6 @@ Source: pandora_gotty Section: utils -Version: 1.0.0 +Version: 1.1.0 Priority: optional Maintainer: PandoraFMS Build-Depends: debhelper (>= 12) diff --git a/extras/pandora_gotty/pandora_gotty.spec b/extras/pandora_gotty/pandora_gotty.spec index 813c9726c9..d322fae653 100644 --- a/extras/pandora_gotty/pandora_gotty.spec +++ b/extras/pandora_gotty/pandora_gotty.spec @@ -1,5 +1,5 @@ %define name pandora_gotty -%define version 1.0 +%define version 1.1 %define release 1%{?dist} Summary: pandora_gptty for Pandora FMS Name: %{name} diff --git a/extras/pandora_gotty/src/pandora_gotty_exec.py b/extras/pandora_gotty/src/pandora_gotty_exec.py index 1f7756745f..2444d88363 100644 --- a/extras/pandora_gotty/src/pandora_gotty_exec.py +++ b/extras/pandora_gotty/src/pandora_gotty_exec.py @@ -74,7 +74,7 @@ def exec_ssh (user:str, add:str, port:int): try: print("> Starting SSH connection...") ssh_command = f"ssh {user}@{add} -p {port}" - subprocess.run(ssh_command, shell=True) + subprocess.run(ssh_command, shell=True, encoding='utf-8', text=True) except subprocess.CalledProcessError as e: raise SystemExit(e) @@ -88,7 +88,7 @@ def exec_telnet (add:str, port:int): try: print("> Starting Telnet connection...") ssh_command = f"telnet -E {add} {port}" - subprocess.run(ssh_command, shell=True) + subprocess.run(ssh_command, shell=True, encoding='utf-8', text=True) except subprocess.CalledProcessError as e: raise SystemExit(e) diff --git a/extras/pandora_update_version.sh b/extras/pandora_update_version.sh index 29dee8f0ce..06de8cc2b1 100755 --- a/extras/pandora_update_version.sh +++ b/extras/pandora_update_version.sh @@ -22,13 +22,16 @@ else fi SPEC_FILES="$CODEHOME/pandora_console/pandora_console.spec \ $CODEHOME/pandora_agents/unix/pandora_agent.spec \ +$CODEHOME/pandora_agents/unix/pandora_agent.redhat_bin.el8.spec \ +$CODEHOME/pandora_agents/unix/pandora_agent.redhat_bin.el9.spec \ +$CODEHOME/pandora_agents/unix/pandora_agent.redhat_bin.spec \ +$CODEHOME/pandora_agents/unix/pandora_agent.redhat.spec \ $CODEHOME/pandora_server/pandora_server.spec \ $PANDHOME_ENT/pandora_console/enterprise/pandora_console_enterprise.spec \ $PANDHOME_ENT/pandora_server/PandoraFMS-Enterprise/pandora_server_enterprise.spec \ $CODEHOME/pandora_console/pandora_console.redhat.spec \ $CODEHOME/pandora_console/pandora_console.rhel7.spec \ $CODEHOME/pandora_agents/unix/pandora_agent.redhat.spec \ -$CODEHOME/pandora_agents/unix/pandora_agent.redhat_bin.spec \ $CODEHOME/pandora_server/pandora_server.redhat.spec \ $PANDHOME_ENT/pandora_agents/pandora_agent.spec \ $PANDHOME_ENT/pandora_server/pandora_server_enterprise.redhat.spec \ diff --git a/pandora_agents/pc/AIX/pandora_agent.conf b/pandora_agents/pc/AIX/pandora_agent.conf index 5c5ec2d3b6..37fb9b0854 100644 --- a/pandora_agents/pc/AIX/pandora_agent.conf +++ b/pandora_agents/pc/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.773.3, AIX version +# Version 7.0NG.774, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # http://www.pandorafms.com diff --git a/pandora_agents/pc/FreeBSD/pandora_agent.conf b/pandora_agents/pc/FreeBSD/pandora_agent.conf index ed33c06e4d..5a36cea140 100644 --- a/pandora_agents/pc/FreeBSD/pandora_agent.conf +++ b/pandora_agents/pc/FreeBSD/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.773.3, FreeBSD Version +# Version 7.0NG.774, FreeBSD Version # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # http://www.pandorafms.com diff --git a/pandora_agents/pc/HP-UX/pandora_agent.conf b/pandora_agents/pc/HP-UX/pandora_agent.conf index 784c729f73..52cd8e1774 100644 --- a/pandora_agents/pc/HP-UX/pandora_agent.conf +++ b/pandora_agents/pc/HP-UX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.773.3, HP-UX Version +# Version 7.0NG.774, HP-UX Version # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # http://www.pandorafms.com diff --git a/pandora_agents/pc/Linux/pandora_agent.conf b/pandora_agents/pc/Linux/pandora_agent.conf index 6284c748f9..4ad837f943 100644 --- a/pandora_agents/pc/Linux/pandora_agent.conf +++ b/pandora_agents/pc/Linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.773.3, GNU/Linux +# Version 7.0NG.774, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # http://www.pandorafms.com diff --git a/pandora_agents/pc/NT4/pandora_agent.conf b/pandora_agents/pc/NT4/pandora_agent.conf index 28ee6bd21f..efa9d79f34 100644 --- a/pandora_agents/pc/NT4/pandora_agent.conf +++ b/pandora_agents/pc/NT4/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.773.3, GNU/Linux +# Version 7.0NG.774, GNU/Linux # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # http://www.pandorafms.com diff --git a/pandora_agents/pc/SunOS/pandora_agent.conf b/pandora_agents/pc/SunOS/pandora_agent.conf index 3d17139780..3a97e4a011 100644 --- a/pandora_agents/pc/SunOS/pandora_agent.conf +++ b/pandora_agents/pc/SunOS/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.773.3, Solaris Version +# Version 7.0NG.774, Solaris Version # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # http://www.pandorafms.com diff --git a/pandora_agents/pc/Win32/pandora_agent.conf b/pandora_agents/pc/Win32/pandora_agent.conf index edf5a7847a..621c1d24ac 100644 --- a/pandora_agents/pc/Win32/pandora_agent.conf +++ b/pandora_agents/pc/Win32/pandora_agent.conf @@ -1,6 +1,6 @@ # Base config file for Pandora FMS Windows Agent # (c) 2006-2023 Pandora FMS -# Version 7.0NG.773.3 +# Version 7.0NG.774 # This program is Free Software, you can redistribute it and/or modify it # under the terms of the GNU General Public Licence as published by the Free Software # Foundation; either version 2 of the Licence or any later version diff --git a/pandora_agents/shellscript/aix/pandora_agent.conf b/pandora_agents/shellscript/aix/pandora_agent.conf index d2c1806dc0..74841e0515 100644 --- a/pandora_agents/shellscript/aix/pandora_agent.conf +++ b/pandora_agents/shellscript/aix/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.773.3, AIX version +# Version 7.0NG.774, AIX version # General Parameters # ================== diff --git a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf index 69b39f6a25..7ba120ca70 100644 --- a/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf +++ b/pandora_agents/shellscript/bsd-ipso/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.773.3 +# Version 7.0NG.774 # FreeBSD/IPSO version # Licenced under GPL licence, 2003-2007 Sancho Lerena diff --git a/pandora_agents/shellscript/hp-ux/pandora_agent.conf b/pandora_agents/shellscript/hp-ux/pandora_agent.conf index b27bfe9167..bcbd2dbb35 100644 --- a/pandora_agents/shellscript/hp-ux/pandora_agent.conf +++ b/pandora_agents/shellscript/hp-ux/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.773.3, HPUX Version +# Version 7.0NG.774, HPUX Version # General Parameters # ================== diff --git a/pandora_agents/shellscript/linux/pandora_agent.conf b/pandora_agents/shellscript/linux/pandora_agent.conf index 23dff46fb5..98c137741e 100644 --- a/pandora_agents/shellscript/linux/pandora_agent.conf +++ b/pandora_agents/shellscript/linux/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.773.3 +# Version 7.0NG.774 # Licensed under GPL license v2, # (c) 2003-2023 Pandora FMS # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/mac_osx/pandora_agent.conf b/pandora_agents/shellscript/mac_osx/pandora_agent.conf index 3250232611..b4b3c35ac8 100644 --- a/pandora_agents/shellscript/mac_osx/pandora_agent.conf +++ b/pandora_agents/shellscript/mac_osx/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.773.3 +# Version 7.0NG.774 # Licensed under GPL license v2, # (c) 2003-2023 Pandora FMS # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/openWRT/pandora_agent.conf b/pandora_agents/shellscript/openWRT/pandora_agent.conf index 29fd1d64da..9ea0d9a2aa 100644 --- a/pandora_agents/shellscript/openWRT/pandora_agent.conf +++ b/pandora_agents/shellscript/openWRT/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.773.3 +# Version 7.0NG.774 # Licensed under GPL license v2, # please visit http://pandora.sourceforge.net diff --git a/pandora_agents/shellscript/solaris/pandora_agent.conf b/pandora_agents/shellscript/solaris/pandora_agent.conf index a4b43f1944..954c52853b 100644 --- a/pandora_agents/shellscript/solaris/pandora_agent.conf +++ b/pandora_agents/shellscript/solaris/pandora_agent.conf @@ -1,6 +1,6 @@ # Fichero de configuracion base de agentes de Pandora # Base config file for Pandora agents -# Version 7.0NG.773.3, Solaris version +# Version 7.0NG.774, Solaris version # General Parameters # ================== diff --git a/pandora_agents/unix/AIX/pandora_agent.conf b/pandora_agents/unix/AIX/pandora_agent.conf index 29fb0051d5..c3bea470ac 100644 --- a/pandora_agents/unix/AIX/pandora_agent.conf +++ b/pandora_agents/unix/AIX/pandora_agent.conf @@ -1,5 +1,5 @@ # Base config file for Pandora FMS agents -# Version 7.0NG.773.3, AIX version +# Version 7.0NG.774, AIX version # Licensed under GPL license v2, # Copyright (c) 2003-2023 Pandora FMS # http://www.pandorafms.com diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index a70887de92..43dd282881 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.773.3-231031 +Version: 7.0NG.774-231108 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 93fe95d24c..b5f0984fc4 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.773.3-231031" +pandora_version="7.0NG.774-231108" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/Darwin/dmg/build_darwin_dmg.sh b/pandora_agents/unix/Darwin/dmg/build_darwin_dmg.sh index 91907dbd82..b1d0fea6db 100644 --- a/pandora_agents/unix/Darwin/dmg/build_darwin_dmg.sh +++ b/pandora_agents/unix/Darwin/dmg/build_darwin_dmg.sh @@ -31,7 +31,7 @@ fi if [ "$#" -ge 2 ]; then VERSION="$2" else - VERSION="7.0NG.773.3" + VERSION="7.0NG.774" fi # Path for the generated DMG file diff --git a/pandora_agents/unix/Darwin/dmg/extras/distribution.xml b/pandora_agents/unix/Darwin/dmg/extras/distribution.xml index 94266e09e4..708d31a47a 100644 --- a/pandora_agents/unix/Darwin/dmg/extras/distribution.xml +++ b/pandora_agents/unix/Darwin/dmg/extras/distribution.xml @@ -19,11 +19,11 @@ - pandorafms_src.pdk + pandorafms_src.pdk - pandorafms_uninstall.pdk + pandorafms_uninstall.pdk + Dark / 20 / alert@svg + Created with Sketch. + + + + \ No newline at end of file diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 593fa9a975..7e8341c4a1 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -2065,14 +2065,6 @@ if ($table_events) { // (propagate ACL funct!). $groups = users_get_groups($config['id_user']); - $tags_condition = tags_get_acl_tags( - $config['id_user'], - array_keys($groups), - 'ER', - 'event_condition', - 'AND' - ); - $tableEvents24h = new stdClass(); $tableEvents24h->class = 'filter_table'; $tableEvents24h->styleTable = 'border: 0;padding: 0;margin: 0 0 10px;'; @@ -2107,7 +2099,7 @@ if ($table_events) { ); } else { events_print_event_table( - 'estado <> 1 '.$tags_condition, + 'estado <> 1', 200, '100%', false, diff --git a/pandora_console/include/class/SnmpConsole.class.php b/pandora_console/include/class/SnmpConsole.class.php index 86132d3956..6945d9b1fb 100644 --- a/pandora_console/include/class/SnmpConsole.class.php +++ b/pandora_console/include/class/SnmpConsole.class.php @@ -738,7 +738,7 @@ class SnmpConsole extends HTML $sql_count = sprintf($sql_count, $whereSubquery); $traps = db_get_all_rows_sql($sql, true); - $total = (int) db_get_value_sql($sql_count, false, true); + $total = (int) db_get_value_sql($sql_count, false, false); if (empty($traps) === false) { $data = $traps; diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 8ffdc71c33..91729f7c8a 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -20,8 +20,8 @@ /** * Pandora build version and version */ -$build_version = 'PC231031'; -$pandora_version = 'v7.0NG.773.3'; +$build_version = 'PC231108'; +$pandora_version = 'v7.0NG.774'; // Do not overwrite default timezone set if defined. $script_tz = @date_default_timezone_get(); diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 2c738a6578..94dcb97f6c 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -22,7 +22,7 @@ require_once $config['homedir'].'/include/functions_modules.php'; require_once $config['homedir'].'/include/functions_users.php'; -function alerts_get_alerts($id_group=0, $free_search='', $status='all', $standby=-1, $acl=false, $total=false, $id_agent=0) +function alerts_get_alerts($id_group=0, $free_search='', $status='all', $standby=-1, $acl=false, $total=false, $id_agent=0, $only_enabled=false) { $sql = ''; $alerts = []; @@ -121,6 +121,10 @@ function alerts_get_alerts($id_group=0, $free_search='', $status='all', $standby // Only enabled agent. $sql .= ' AND t3.disabled = 0'; + if ($only_enabled === true) { + $sql .= ' AND t0.disabled = 0'; + } + $row_alerts = db_get_all_rows_sql($sql); if ($total) { diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 63b5db5143..c9e4aa2226 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -1572,6 +1572,10 @@ function config_update_config() $error_update[] = __('Use data multiplier'); } + if (config_update_value('disable_general_statistics', get_parameter('disable_general_statistics', 0), true) === false) { + $error_update[] = __('Hide general stats for non admin users in tactical view'); + } + if (config_update_value('decimal_separator', (string) get_parameter('decimal_separator', '.'), true) === false) { $error_update[] = __('Decimal separator'); } else { @@ -3711,6 +3715,10 @@ function config_process_config() config_update_value('use_data_multiplier', '1'); } + if (!isset($config['disable_general_statistics'])) { + config_update_value('disable_general_statistics', 0); + } + if (!isset($config['command_snapshot'])) { config_update_value('command_snapshot', 1); } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index f709fe2b4c..5534897e84 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -2593,7 +2593,7 @@ function events_print_type_img( switch ($type) { case 'alert_recovered': - $style .= ' alert_module_background_state icon_background_normal '; + $icon = 'images/alert_recovered@svg.svg'; break; case 'alert_manual_validation': @@ -2609,20 +2609,16 @@ function events_print_type_img( case 'going_up_normal': case 'going_down_normal': // This is to be backwards compatible. - // $style .= ' event_module_background_state icon_background_normal'; $icon = 'images/module_ok.png'; break; case 'going_up_warning': $icon = 'images/module_warning.png'; - // $style .= ' event_module_background_state icon_background_warning'; case 'going_down_warning': $icon = 'images/module_warning.png'; - // $style .= ' event_module_background_state icon_background_warning'; break; case 'going_unknown': - // $style .= ' event_module_background_state icon_background_unknown'; $icon = 'images/module_unknown.png'; break; diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 3ba76b17d0..d1c31f95b0 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -27,6 +27,8 @@ * ============================================================================ */ +use Models\VisualConsole\Items\Percentile; + require_once $config['homedir'].'/include/graphs/fgraph.php'; require_once $config['homedir'].'/include/functions_reporting.php'; require_once $config['homedir'].'/include/functions_agents.php'; @@ -2686,7 +2688,9 @@ function graph_agent_status( $return=false, $show_not_init=false, $data_agents=false, - $donut_narrow_graph=false + $donut_narrow_graph=false, + $onClick='', + $data_in_percentage=false, ) { global $config; @@ -2766,6 +2770,25 @@ function graph_agent_status( 'labels' => array_keys($data), ]; + if (empty($onClick) === false) { + $options['onClick'] = $onClick; + } + + if ($data_in_percentage === true) { + $percentages = []; + $total = array_sum($data); + foreach ($data as $key => $value) { + $percentage = (($value / $total) * 100); + if ($percentage < 1 && $percentage > 0) { + $percentage = 1; + } + + $percentages[$key] = format_numeric($percentage, 0); + } + + $data = $percentages; + } + if ($donut_narrow_graph == true) { $out = ring_graph( $data, @@ -4625,9 +4648,15 @@ function graph_nodata_image($options) return base64_encode($dataImg); } - $widthImage = '200px'; + $style = ''; if (isset($options['nodata_image']['width']) === true) { - $widthImage = $options['nodata_image']['width']; + $style .= 'width: '.$options['nodata_image']['width'].'; '; + } else { + $style .= 'width: 200px; '; + } + + if (isset($options['nodata_image']['height']) === true) { + $style .= 'height: '.$options['nodata_image']['height'].'; '; } return html_print_image( @@ -4635,7 +4664,7 @@ function graph_nodata_image($options) true, [ 'title' => __('No data'), - 'style' => 'width: '.$widthImage.';', + 'style' => $style, ] ); } diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 1ba36b5045..5839e0784b 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -669,6 +669,12 @@ function get_build_setup_charts($type, $options, $data) $chart->setId($id); + if (isset($options['onClick']) === true + && empty($options['onClick']) === false + ) { + $chart->options()->setOnClick($options['onClick']); + } + // Height is null maximum possible. if (isset($options['height']) === true && empty($options['height']) === false diff --git a/pandora_console/include/javascript/alert.js b/pandora_console/include/javascript/alert.js index 435649833d..06f3223df7 100644 --- a/pandora_console/include/javascript/alert.js +++ b/pandora_console/include/javascript/alert.js @@ -1,5 +1,5 @@ /* eslint-disable no-unused-vars */ -/* global $, load_modal, generalShowMsg, confirmDialog */ +/* global $, load_modal, generalShowMsg, confirmDialog, jQuery */ function allowDrop(ev) { ev.preventDefault(); @@ -172,3 +172,317 @@ function disabled_alert(settings) { } }); } + +function ajax_get_integria_custom_fields( + ticket_type_id, + values, + recovery_values, + max_macro_fields +) { + values = values || []; + recovery_values = recovery_values || []; + + if ( + ticket_type_id === null || + ticket_type_id === "" || + (Array.isArray(values) && + values.length === 0 && + Array.isArray(recovery_values) && + recovery_values.length === 0) + ) { + for (let i = 8; i <= max_macro_fields; i++) { + $("[name=field" + i + "_value\\[\\]").val(""); + $("[name=field" + i + "_recovery_value\\[\\]").val(""); + } + } + + // On ticket type change, hide all table rows and inputs corresponding to custom fields, regardless of what its type is. + for (let i = 8; i <= max_macro_fields; i++) { + $("[name=field" + i + "_value\\[\\]").hide(); + $("[name=field" + i + "_recovery_value\\[\\]").hide(); + $("#table_macros-field" + i).hide(); + $("[name=field" + i + "_value_container").hide(); + $("[name=field" + i + "_recovery_value_container").hide(); + } + + jQuery.post( + "ajax.php", + { + page: "godmode/alerts/configure_alert_action", + get_integria_ticket_custom_types: 1, + ticket_type_id: ticket_type_id + }, + function(data) { + data.forEach(function(custom_field, key) { + var custom_field_key = key + 8; // Custom fields start from field 8. + + if (custom_field_key > max_macro_fields) { + return; + } + + // Display field row for current input. + var custom_field_row = $("#table_macros-field" + custom_field_key); + custom_field_row.show(); + + // Replace label text of field row for current input. + var label_html = $("#table_macros-field" + custom_field_key + " td") + .first() + .html(); + var label_name = label_html.split("
")[0]; + var new_html_content = custom_field_row + .html() + .replace(label_name, custom_field.label); + custom_field_row.html(new_html_content); + + switch (custom_field.type) { + case "CHECKBOX": + var checkbox_selector = $( + 'input[type="checkbox"][name=field' + + custom_field_key + + "_value\\[\\]]" + ); + var checkbox_recovery_selector = $( + 'input[type="checkbox"][name=field' + + custom_field_key + + "_recovery_value\\[\\]]" + ); + + checkbox_selector.on("change", function() { + if (checkbox_selector.prop("checked")) { + checkbox_selector.attr("value", "1"); + } else { + checkbox_selector.attr("value", "0"); + } + }); + + checkbox_recovery_selector.on("change", function() { + if (checkbox_recovery_selector.prop("checked")) { + checkbox_recovery_selector.attr("value", "1"); + } else { + checkbox_recovery_selector.attr("value", "0"); + } + }); + + if (typeof values[key] !== "undefined") { + if (values[key] == 1) { + checkbox_selector.prop("checked", true); + checkbox_selector.attr("value", "1"); + } else { + checkbox_selector.prop("checked", false); + checkbox_selector.attr("value", "0"); + } + } + + if (typeof recovery_values[key] !== "undefined") { + if (recovery_values[key] == 1) { + checkbox_recovery_selector.prop("checked", true); + checkbox_recovery_selector.attr("value", "1"); + } else { + checkbox_recovery_selector.prop("checked", false); + checkbox_recovery_selector.attr("value", "0"); + } + } + + $("[name=field" + custom_field_key + "_value_container]").show(); + $( + "[name=field" + custom_field_key + "_recovery_value_container]" + ).show(); + $( + 'input[type="checkbox"][name=field' + + custom_field_key + + "_value\\[\\]]" + ).show(); + $( + 'input[type="checkbox"][name=field' + + custom_field_key + + "_recovery_value\\[\\]]" + ).show(); + break; + case "COMBO": + var combo_input = $( + "select[name=field" + custom_field_key + "_value\\[\\]]" + ); + var combo_input_recovery = $( + "select[name=field" + custom_field_key + "_recovery_value\\[\\]]" + ); + + combo_input.find("option").remove(); + combo_input_recovery.find("option").remove(); + + var combo_values_array = custom_field.comboValue.split(","); + + combo_values_array.forEach(function(value) { + combo_input.append( + $("