From 9a57cc550ec99fbe9b063124dbecdc46e7ec1233 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Wed, 11 Oct 2023 16:31:48 +0200 Subject: [PATCH 01/48] #12192 Fix pandora itsm url --- pandora_console/godmode/setup/setup_ITSM.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandora_console/godmode/setup/setup_ITSM.php b/pandora_console/godmode/setup/setup_ITSM.php index 3196ef677c..50aee8631e 100644 --- a/pandora_console/godmode/setup/setup_ITSM.php +++ b/pandora_console/godmode/setup/setup_ITSM.php @@ -558,7 +558,7 @@ $table_cr_settings->data[4][0] = html_print_label_input_block( // Print. echo '
'; -echo ''; +echo ''; html_print_image( 'images/pandoraITSM_logo.png', false, @@ -569,8 +569,8 @@ echo '
'; echo '
'; echo __('Pandora ITSM'); echo '
'; -echo '
'; -echo 'https://pandorafms.com/es/itsm/'; +echo ''; +echo 'https://pandorafms.com/itsm/'; echo ''; echo '
'; From 28820f4471f1812f6d8ff06d5b2c59f29bc5ef4e Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Wed, 29 Nov 2023 11:04:48 +0100 Subject: [PATCH 02/48] #12543 fixed pagination metaconsole --- pandora_console/include/functions_events.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 2a91641315..7a106ead7f 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1907,7 +1907,7 @@ function events_get_all( // -1 For pagination 'All'. ((int) $limit === -1) ? $end = count($data) - : $end = ((int) $offset !== 0) ? ($offset + $limit) : $limit; + : $end = $limit; $finally = array_slice($data, $offset, $end, true); $return = [ 'buffers' => $buffers, From 24c8e606f48751d24ff8832d7ec16eb9bd232cbd Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Thu, 30 Nov 2023 16:29:18 +0100 Subject: [PATCH 03/48] #12569 fixed button credential boxes --- pandora_console/godmode/servers/modificar_server.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/servers/modificar_server.php b/pandora_console/godmode/servers/modificar_server.php index c51c0476d3..03863fb4f5 100644 --- a/pandora_console/godmode/servers/modificar_server.php +++ b/pandora_console/godmode/servers/modificar_server.php @@ -521,7 +521,7 @@ $(document).ready (function () { function (data) { $(".white-box-content").html(data); - $("#submit-add").click(function (e) { + $("#button-add").click(function (e) { add_credential_boxes(); }); @@ -550,7 +550,7 @@ $(document).ready (function () { $(".white-box-content").html(data2); // Insert credential - $("#submit-add").click(function (e) { + $("#button-add").click(function (e) { save_credential_boxes(); }) }, From 87f4a6e15fc66c6840afc1d1867f27df6e1158e7 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Fri, 1 Dec 2023 10:08:25 +0100 Subject: [PATCH 04/48] #12384 Fixed acl --- .../javascript/functions_pandora_networkmap.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandora_console/include/javascript/functions_pandora_networkmap.js b/pandora_console/include/javascript/functions_pandora_networkmap.js index c31216a2fc..44e3ba196c 100644 --- a/pandora_console/include/javascript/functions_pandora_networkmap.js +++ b/pandora_console/include/javascript/functions_pandora_networkmap.js @@ -806,6 +806,10 @@ function edit_node(data_node, dblClick) { var flag_edit_node = true; var edit_node = null; + if (networkmap_write === 0) { + return false; + } + //Only select one node var selection = d3_nm.selectAll(".node_selected"); var id; @@ -1950,6 +1954,10 @@ function init_minimap() { // Context menu //////////////////////////////////////////////////////////////////////// function show_menu(item, data) { + if (networkmap_write === 0) { + return false; + } + mouse = []; mouse[0] = d3_nm.event.pageX; mouse[1] = d3_nm.event.pageY; @@ -2819,6 +2827,10 @@ function cancel_set_parent() { // OWN CODE FOR TO DRAG //////////////////////////////////////////////////////////////////////// function init_drag_and_drop() { + if (networkmap_write === 0) { + return false; + } + window.dragables = svg.selectAll(".dragable_node"); window.drag_start = [0, 0]; From c22525febc900abd3bc54ed291b03ebf6e735a19 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Mon, 4 Dec 2023 16:54:14 +0100 Subject: [PATCH 05/48] #12569 fixed actions credential boxes --- pandora_console/godmode/servers/modificar_server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/servers/modificar_server.php b/pandora_console/godmode/servers/modificar_server.php index 03863fb4f5..8a78de9592 100644 --- a/pandora_console/godmode/servers/modificar_server.php +++ b/pandora_console/godmode/servers/modificar_server.php @@ -609,7 +609,7 @@ $(document).ready (function () { function (data) { $(".white-box-content").html(data); - $("#submit-update").click(function (e) { + $("#button-update").click(function (e) { update_credential_boxes(datas); }); }, From 7b6c14974d1bfee2a230b729f92998b1861a3147 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Wed, 13 Dec 2023 10:34:46 +0100 Subject: [PATCH 06/48] #12573 fixed number of cells in list dashboard --- pandora_console/include/lib/Dashboard/Manager.php | 9 +++++++++ pandora_console/pandoradb_data.sql | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/lib/Dashboard/Manager.php b/pandora_console/include/lib/Dashboard/Manager.php index 4430bfa253..bee64b7ba1 100644 --- a/pandora_console/include/lib/Dashboard/Manager.php +++ b/pandora_console/include/lib/Dashboard/Manager.php @@ -1056,6 +1056,7 @@ class Manager implements PublicLogin 'name' => $name, 'id_user' => $id_user, 'id_group' => $id_group, + 'cells' => 1, 'cells_slideshow' => $slideshow, 'active' => $favourite, 'date_range' => $dateRange, @@ -1367,6 +1368,7 @@ class Manager implements PublicLogin global $config; $items = \get_parameter('items', []); + $totalCells = 0; // Class Dashboard. if (empty($items) === false) { @@ -1398,8 +1400,15 @@ class Manager implements PublicLogin return false; } } + + if (is_array($items) === true) { + $totalCells = count($items); + } } + $values = ['cells' => $totalCells]; + $this->put($values); + echo json_encode($result); } diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 70f9451932..a3f28d816a 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -2704,8 +2704,8 @@ INSERT INTO `treport_content` (`id_rc`,`id_report`,`id_gs`,`id_agent_module`,`ty (2,1,0,0,'top_n',28800,0,2,'Top CPU per agent','',0,'<p>This type of report implies loading a lot of data. Therefore it is recommended for scheduled reports, not real-time view.</p>',NULL,0,'','','','00:00:00','00:00:00',1,1,1,1,1,1,1,0,3,10,0,10,0,1,1,0,'{"show_in_same_row":0,"hide_notinit_agents":0,"priority_mode":"1","dyn_height":"250","text_agent":"Lio=","text_agent_module":"Y3B1Lio="}',0,0,'',0,0,300,0,0,NULL,NULL,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,NULL,NULL,1,0,0,NULL), (3,1,0,0,'event_report_group',21600,0,3,'General event report','This is a sample of not normal events for any agent available in the last 6 hours',0,'<p>This type of report implies loading a lot of data. Therefore it is recommended for scheduled reports, not real-time view.</p>',NULL,0,'','','','00:00:00','00:00:00',1,1,1,1,1,1,1,0,0,10,0,10,0,0,0,0,'{"show_in_same_row":0,"hide_notinit_agents":0,"priority_mode":"1","dyn_height":"250","server_multiple":"\"\"","show_summary_group":0,"filter_event_severity":"[\"20\"]","filter_event_type":"[\"all\"]","filter_event_status":"[\"-1\"]","event_graph_by_agent":"1","event_graph_by_user_validator":"1","event_graph_by_criticity":"1","event_graph_validated_vs_unvalidated":0,"event_filter_search":"","event_filter_exclude":"","custom_data_events":"1","label":""}',0,0,'',0,0,300,0,0,NULL,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,NULL,NULL,1,0,0,NULL); INSERT INTO `tdashboard` (`id`,`name`,`id_user`,`id_group`,`active`,`cells`,`cells_slideshow`) VALUES - (1,'Sample Dashboard #1','',0,0,0,0), - (2,'Sample Dashboard #2','',0,0,0,0); + (1,'Sample Dashboard #1','',0,0,7,0), + (2,'Sample Dashboard #2','',0,0,10,0); INSERT INTO `twidget_dashboard` (`id`,`position`,`options`,`order`,`id_dashboard`,`id_widget`,`prop_width`,`prop_height`) VALUES (1,'{\"x\":\"0\",\"y\":\"0\",\"width\":\"4\",\"height\":\"4\"}','{\"title\":\"Agents hive\",\"background\":\"#ffffff\",\"groups\":[\"12,8,4,9,2,10,13,11\"]}',0,1,1,0.32,0.32), (2,'{\"x\":\"4\",\"y\":\"0\",\"width\":\"3\",\"height\":\"4\"}','{\"title\":\"Clock\",\"background\":\"#ffffff\",\"clockType\":\"analogic\"}',1,1,12,0.32,0.32), From 88784de3ef390d0805bdbb5beed1e01393e533fa Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 13 Dec 2023 13:03:08 +0100 Subject: [PATCH 07/48] #12143 fix datepicker dashboard widget hardening --- .../include/javascript/pandora_dashboards.js | 13 ++++++++++++- pandora_console/include/javascript/pandora_ui.js | 9 +++++++++ .../lib/Dashboard/Widgets/security_hardening.php | 4 ++-- pandora_console/include/styles/pandora.css | 4 ++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/javascript/pandora_dashboards.js b/pandora_console/include/javascript/pandora_dashboards.js index 283acf8005..da969814cc 100644 --- a/pandora_console/include/javascript/pandora_dashboards.js +++ b/pandora_console/include/javascript/pandora_dashboards.js @@ -22,6 +22,9 @@ function show_option_dialog(settings) { method: "updateDashboard", dataType: "json" }, + oncancel: { + reload: true + }, ajax_callback: update_dashboard }); } @@ -458,6 +461,10 @@ function initialiceLayout(data) { }*/ function configurationWidget(cellId, widgetId, size) { + var reload = 0; + if (widgetId == 46) { + reload = 1; + } load_modal({ target: $("#modal-config-widget"), form: "form-config-widget", @@ -483,8 +490,12 @@ function initialiceLayout(data) { method: "saveWidgetIntoCell", dataType: "json" }, + oncancel: { + reload: reload + }, ajax_callback: update_widget_to_cell, - onsubmitClose: 1 + onsubmitClose: 1, + onsubmitReload: reload }); } diff --git a/pandora_console/include/javascript/pandora_ui.js b/pandora_console/include/javascript/pandora_ui.js index 45ca47e92b..de17eae3ea 100644 --- a/pandora_console/include/javascript/pandora_ui.js +++ b/pandora_console/include/javascript/pandora_ui.js @@ -168,6 +168,8 @@ function load_modal(settings) { if (typeof settings.oncancel.confirm == "function") { //receive function settings.oncancel.confirm(cancelModal); + } else if (settings.oncancel.reload == true) { + location.reload(); } else if (settings.oncancel != undefined) { cancelModal(); } @@ -347,6 +349,13 @@ function load_modal(settings) { AJAX_RUNNING = 0; } }); + + if ( + settings.onsubmitReload != undefined && + settings.onsubmitReload == true + ) { + location.reload(); + } } else { AJAX_RUNNING = 0; } diff --git a/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php b/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php index b3c124f039..0e9612cd29 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php +++ b/pandora_console/include/lib/Dashboard/Widgets/security_hardening.php @@ -274,9 +274,9 @@ class SecurityHardening extends Widget 'name' => 'range', 'type' => 'date_range', 'selected' => 'chose_range', - 'date_init' => date('Y-m-d', $values['date_init']), + 'date_init' => date('Y/m/d', $values['date_init']), 'time_init' => date('H:i:s', $values['date_init']), - 'date_end' => date('Y-m-d', $values['date_end']), + 'date_end' => date('Y/m/d', $values['date_end']), 'time_end' => date('H:i:s', $values['date_end']), 'return' => true, ], diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 8f8226320e..2e6cd36149 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -12048,6 +12048,10 @@ div.relative > div > div#ui-datepicker-div { left: 5px !important; } +#ui-datepicker-div .ui-datepicker-header { + background-color: white; +} + .ui-widget-overlay { background: #aaa; opacity: 0.3 !important; From fe9b35ed77b4c6058961fd5a946535b5817b5c80 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 13 Dec 2023 16:51:14 +0100 Subject: [PATCH 08/48] #12622 help only when feedback enable --- pandora_console/general/header.php | 32 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index 102d8e3136..d092722cee 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -397,21 +397,23 @@ echo sprintf('
', $menuTypeClass); $modal_box .= ''.__('Join discord community').''; $modal_box .= '
'; - $modal_help = html_print_div( - [ - 'id' => 'modal-help-content', - 'content' => html_print_image( - 'images/help@header.svg', - true, - [ - 'title' => __('Help'), - 'class' => 'main_menu_icon bot invert_filter', - 'alt' => 'user', - ] - ).$modal_box, - ], - true, - ); + if ($config['activate_feedback'] === '1') { + $modal_help = html_print_div( + [ + 'id' => 'modal-help-content', + 'content' => html_print_image( + 'images/help@header.svg', + true, + [ + 'title' => __('Help'), + 'class' => 'main_menu_icon bot invert_filter', + 'alt' => 'user', + ] + ).$modal_box, + ], + true, + ); + } // User. From 6e150c1bc2ab65dd2cba29aaa5f2919a206b8ad4 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 14 Dec 2023 08:59:13 +0100 Subject: [PATCH 09/48] #12560 alert update manager --- pandora_console/include/class/ConsoleSupervisor.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 83208256fb..ae12f37772 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -928,7 +928,9 @@ class ConsoleSupervisor false ); - if ($prev !== false + if ($data['type'] === 'NOTIF.UPDATEMANAGER.REGISTRATION' && $prev !== false) { + return; + } else if ($prev !== false && (time() - $prev['timestamp']) > $max_age ) { // Clean previous notification. From 9258de7edc976f940ce4383803f23077b51404a6 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 14 Dec 2023 12:25:21 +0100 Subject: [PATCH 10/48] fix multiple selector --- pandora_console/godmode/modules/manage_nc_groups.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandora_console/godmode/modules/manage_nc_groups.php b/pandora_console/godmode/modules/manage_nc_groups.php index d5540d2472..423008db82 100644 --- a/pandora_console/godmode/modules/manage_nc_groups.php +++ b/pandora_console/godmode/modules/manage_nc_groups.php @@ -63,7 +63,7 @@ if (is_metaconsole() === true) { ], [ 'link' => '', - 'label' => __('Component groups'), + 'label' => __('Component groups1221'), ], ] ); @@ -394,11 +394,11 @@ html_print_action_buttons( $('[id^=checkbox-all_delete]').change(function(){ if ($("#checkbox-all_delete").prop("checked")) { $('[id^=checkbox-delete_multiple]').parent().parent().addClass('checkselected'); - $(".check_delete").prop("checked", true); + $(".custom_checkbox_input").prop("checked", true); } else{ $('[id^=checkbox-delete_multiple]').parent().parent().removeClass('checkselected'); - $(".check_delete").prop("checked", false); + $(".custom_checkbox_input").prop("checked", false); } }); }); From 7398982912fac42ac2130ca9fae7bb9a8f4b607a Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 14 Dec 2023 12:27:00 +0100 Subject: [PATCH 11/48] fix multiple selector --- pandora_console/godmode/modules/manage_nc_groups.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/modules/manage_nc_groups.php b/pandora_console/godmode/modules/manage_nc_groups.php index 423008db82..e7ceff1f01 100644 --- a/pandora_console/godmode/modules/manage_nc_groups.php +++ b/pandora_console/godmode/modules/manage_nc_groups.php @@ -63,7 +63,7 @@ if (is_metaconsole() === true) { ], [ 'link' => '', - 'label' => __('Component groups1221'), + 'label' => __('Component groups'), ], ] ); From a008c7486c4b543d1802d0813ba42bcbe86f90d8 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Thu, 14 Dec 2023 17:28:34 +0100 Subject: [PATCH 12/48] #12026 Fixed widget --- .../lib/Dashboard/Widgets/inventory.php | 36 ++++++------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/pandora_console/include/lib/Dashboard/Widgets/inventory.php b/pandora_console/include/lib/Dashboard/Widgets/inventory.php index a8fc01ee1c..8424d6cfbf 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/inventory.php +++ b/pandora_console/include/lib/Dashboard/Widgets/inventory.php @@ -177,6 +177,12 @@ class InventoryWidget extends Widget // Must be configured before using. $this->configurationRequired = false; + if (isset($this->values['inventoryModuleId']) + && $this->values['inventoryModuleId'] === 'basic' + && $this->values['agentId'] === 0 + ) { + $this->configurationRequired = true; + } } @@ -296,9 +302,12 @@ class InventoryWidget extends Widget ]; $fields = []; - array_unshift($fields, __('All')); + if (isset($values['inventoryModuleId']) === false) { + $values['inventoryModuleId'] = 0; + } + $inputs[] = [ 'label' => __('Module'), 'arguments' => [ @@ -316,31 +325,6 @@ class InventoryWidget extends Widget ], ]; - // Agent select. - if ($is_metaconsole === false) { - $agents = []; - $sql = 'SELECT id_agente, nombre FROM tagente'; - if ($inventory_id_group > 0) { - $sql .= ' WHERE id_grupo = '.$inventory_id_group; - } else { - $user_groups = implode(',', array_keys(users_get_groups($config['id_user']))); - - // Avoid errors if there are no groups. - if (empty($user_groups) === true) { - $user_groups = '"0"'; - } - - $sql .= ' WHERE id_grupo IN ('.$user_groups.')'; - } - - $result = db_get_all_rows_sql($sql); - if ($result) { - foreach ($result as $row) { - $agents[$row['id_agente']] = $row['nombre']; - } - } - } - // Date filter. if (is_metaconsole() === false) { $inputs[] = [ From 8df792f11b401ba84d851b73d9b8b03b4d1b3ae2 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Fri, 15 Dec 2023 10:41:21 +0100 Subject: [PATCH 13/48] #12571 custom graphs refactored --- .../reporting/graph_builder.graph_editor.php | 246 +++++++----------- .../godmode/reporting/graph_builder.php | 2 +- pandora_console/include/ajax/graph.ajax.php | 103 ++++++++ pandora_console/include/functions_html.php | 25 +- .../include/styles/custom_graph.css | 16 ++ 5 files changed, 235 insertions(+), 157 deletions(-) create mode 100644 pandora_console/include/styles/custom_graph.css diff --git a/pandora_console/godmode/reporting/graph_builder.graph_editor.php b/pandora_console/godmode/reporting/graph_builder.graph_editor.php index 0256c28f92..c4da379ebd 100644 --- a/pandora_console/godmode/reporting/graph_builder.graph_editor.php +++ b/pandora_console/godmode/reporting/graph_builder.graph_editor.php @@ -30,7 +30,7 @@ if (!$report_w && !$report_m) { require_once $config['homedir'].'/include/functions_agents.php'; require_once $config['homedir'].'/include/functions_modules.php'; require_once $config['homedir'].'/include/functions_groups.php'; - +ui_require_css_file('custom_graph'); $editGraph = (bool) get_parameter('edit_graph', 0); $action = get_parameter('action', ''); @@ -41,113 +41,6 @@ if (isset($_GET['get_agent'])) { } } -switch ($action) { - case 'sort_items': - $resultOperationDB = null; - $position_to_sort = (int) get_parameter('position_to_sort', 1); - $ids_serialize = (string) get_parameter('ids_items_to_sort', ''); - $move_to = (string) get_parameter('move_to', 'after'); - - $countItems = db_get_sql( - ' - SELECT COUNT(id_gs) - FROM tgraph_source - WHERE id_graph = '.$id_graph - ); - - if (($countItems < $position_to_sort) || ($position_to_sort < 1)) { - $resultOperationDB = false; - } else if (!empty($ids_serialize)) { - $ids = explode('|', $ids_serialize); - $items = db_get_all_rows_sql( - 'SELECT id_gs, `field_order` - FROM tgraph_source - WHERE id_graph = '.$id_graph.' - ORDER BY `field_order`' - ); - - if ($items === false) { - $items = []; - } - - - // Clean the repeated order values. - $order_temp = 1; - foreach ($items as $item) { - db_process_sql_update( - 'tgraph_source', - ['`field_order`' => $order_temp], - ['id_gs' => $item['id_rc']] - ); - - $order_temp++; - } - - $items = db_get_all_rows_sql( - 'SELECT id_gs, `field_order` - FROM tgraph_source - WHERE id_graph = '.$id_graph.' - ORDER BY `field_order`' - ); - - if ($items === false) { - $items = []; - } - - - - $temp = []; - - $temp = []; - foreach ($items as $item) { - // Remove the contents from the block to sort. - if (array_search($item['id_gs'], $ids) === false) { - $temp[$item['field_order']] = $item['id_gs']; - } - } - - $items = $temp; - - - - $sorted_items = []; - foreach ($items as $pos => $id_unsort) { - if ($pos == $position_to_sort) { - if ($move_to == 'after') { - $sorted_items[] = $id_unsort; - } - - foreach ($ids as $id) { - $sorted_items[] = $id; - } - - if ($move_to != 'after') { - $sorted_items[] = $id_unsort; - } - } else { - $sorted_items[] = $id_unsort; - } - } - - $items = $sorted_items; - - - - foreach ($items as $order => $id) { - db_process_sql_update( - 'tgraph_source', - ['`field_order`' => ($order + 1)], - ['id_gs' => $id] - ); - } - - $resultOperationDB = true; - } else { - $resultOperationDB = false; - } - break; -} - if ($editGraph) { $graphRows = db_get_all_rows_sql( 'SELECT t1.*, @@ -257,41 +150,6 @@ $table->data[0][1] = html_print_label_input_block( ); -$SortItems = "
"; -$SortItems .= html_print_table($table, true); -$SortItems .= html_print_input_hidden('action', 'sort_items', true); -$SortItems .= html_print_div( - [ - 'class' => 'action-buttons', - 'content' => html_print_submit_button( - __('Sort'), - 'srcbutton', - false, - [ - 'class' => 'mini', - 'icon' => 'search', - 'mode' => 'secondary', - ], - true - ), - ], - true -); -$SortItems .= '
'; - -ui_toggle( - $SortItems, - ''.__('Sort items').'', - '', - '', - false, - false, - '', - 'white-box-content no_border', - 'filter-datatable-main box-flat white_table_graph max_floating_element_size' -); - - // Configuration form. echo ''; echo "
"; @@ -300,10 +158,11 @@ echo "'; echo ''; echo ''; @@ -340,6 +199,7 @@ echo ''; // Modules table. if ($count_module_array > 0) { echo "
'.html_print_input( [ - 'type' => 'select_multiple_modules_filtered', - 'uniqId' => 'modules', - 'class' => 'flex flex-row', - 'searchBar' => true, + 'type' => 'select_multiple_modules_filtered', + 'uniqId' => 'modules', + 'class' => 'flex flex-row', + 'searchBar' => false, + 'placeholderAgents' => __('Search agent name'), ] ).'
"; + echo ''; echo ' @@ -348,6 +208,8 @@ if ($count_module_array > 0) { '; + echo ''; + echo ''; $color = 0; for ($a = 0; $a < $count_module_array; $a++) { // Calculate table line color. @@ -359,7 +221,7 @@ if ($count_module_array > 0) { $color = 1; } - echo ""; + echo ""; echo "'; echo "'; @@ -410,9 +272,30 @@ if ($count_module_array > 0) { echo ''; - echo ''; @@ -420,6 +303,8 @@ if ($count_module_array > 0) { echo ''; } + echo ''; + echo '
'.__('P.').' '.__('Agent').''.__('Weight').' '.__('Delete').' '.__('Sort').'
$position_array[$a]
$position_array[$a]".$agent_array[$a].'"; echo modules_get_agentmodule_name($module_array[$a]).''; + echo ''; - echo html_print_checkbox_extended('sorted_items[]', $idgs_array[$a], false, false, '', 'class="selected_check"', true); + echo html_print_input_image( + 'up', + 'images/arrow-up-white.png', + 'up', + ($config['style'] !== 'pandora_black') ? 'filter: invert(100%)' : '', + true, + [ + 'class' => 'invert_filter main_menu_icon', + 'onclick' => 'reorder(\'up\', \''.$idgs_array[$a].'\', this)', + ], + ); + echo html_print_input_image( + 'down', + 'images/arrow-down-white.png', + 'down', + ($config['style'] !== 'pandora_black') ? 'filter: invert(100%)' : '', + true, + [ + 'class' => 'invert_filter main_menu_icon', + 'onclick' => 'reorder(\'down\', \''.$idgs_array[$a].'\', this)', + ] + ); echo '
'; } @@ -482,4 +367,65 @@ function added_ids_sorted_items_to_hidden_input() { return true; } } + + +function reorder(action, idElement, element) { + var tr = $(element).parent().parent(); + switch (action) { + case "up": + changePosition(action, idElement) + .then((data) => { + if(data.success) { + $(tr).find('.position').html(parseInt($(tr).find('.position').html()) - 1); + $($(tr).prev()).find('.position').html(parseInt($($(tr).prev()).find('.position').html()) + 1); + $(tr).prev().insertAfter(tr); + } + }) + .catch((err) => { + console.log(err); + }) + break; + + case "down": + changePosition(action, idElement) + .then((data) => { + if(data.success) { + $(tr).find('.position').html(parseInt($(tr).find('.position').html()) + 1); + $($(tr).next()).find('.position').html(parseInt(($(tr).next()).find('.position').html()) - 1); + $(tr).next().insertBefore(tr); + } + }) + .catch((err) => { + console.log(err); + }) + break; + + default: + break; + } +} + +function changePosition(order, idElement) { + return new Promise(function(resolve, reject) { + $.ajax({ + method: "POST", + url: "", + dataType: "json", + data: { + page: "include/ajax/graph.ajax", + sort_items: 1, + order, + id_graph: , + id: idElement + }, + success: function(data) { + resolve(data); + }, + error: function(error) { + reject(error); + } + }); + }); +} + diff --git a/pandora_console/godmode/reporting/graph_builder.php b/pandora_console/godmode/reporting/graph_builder.php index 2e7b1f782e..e6aa119e84 100644 --- a/pandora_console/godmode/reporting/graph_builder.php +++ b/pandora_console/godmode/reporting/graph_builder.php @@ -237,7 +237,7 @@ if ($add_module === true) { ); $id_agent_modules = db_get_all_rows_sql( - 'SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente IN ('.implode(',', $id_agents).") AND nombre IN ('".implode("','", $id_modules)."')" + 'SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente IN ('.implode(',', $id_agents).") AND id_agente_modulo IN ('".implode("','", $id_modules)."')" ); if (count($id_agent_modules) > 0 && $id_agent_modules != '') { diff --git a/pandora_console/include/ajax/graph.ajax.php b/pandora_console/include/ajax/graph.ajax.php index 6ea76f373b..2db3a72912 100644 --- a/pandora_console/include/ajax/graph.ajax.php +++ b/pandora_console/include/ajax/graph.ajax.php @@ -17,6 +17,8 @@ $save_custom_graph = (bool) get_parameter('save_custom_graph'); $print_custom_graph = (bool) get_parameter('print_custom_graph', false); $print_sparse_graph = (bool) get_parameter('print_sparse_graph'); $get_graphs = (bool) get_parameter('get_graphs_container'); +$sort_items = (bool) get_parameter('sort_items'); + $width = get_parameter('width', 0); $height = get_parameter('height', 0); @@ -337,3 +339,104 @@ if ($get_graphs) { return; } } + + +if ($sort_items === true) { + $order = (string) get_parameter('order'); + $id = (string) get_parameter('id', ''); + $idGraph = (string) get_parameter('id_graph', ''); + $total = db_get_num_rows('SELECT * FROM tgraph_source WHERE id_graph = '.$idGraph.''); + $item = db_get_row_sql( + 'SELECT id_gs, field_order + FROM tgraph_source + WHERE id_gs = '.$id.' + ORDER BY field_order' + ); + + switch ($order) { + case 'up': + if (($item['field_order'] - 1) < 1) { + echo json_encode(['success' => false]); + return; + } + + $prevItem = db_get_row_sql( + 'SELECT id_gs, field_order + FROM tgraph_source + WHERE id_graph = '.$idGraph.' + AND field_order = '.($item['field_order'] - 1).' + ORDER BY field_order' + ); + + db_process_sql_begin(); + + $resultItem = db_process_sql_update( + 'tgraph_source', + ['field_order' => ($item['field_order'] - 1)], + ['id_gs' => $item['id_gs']], + false + ); + $resultPrevItem = db_process_sql_update( + 'tgraph_source', + ['field_order' => ($prevItem['field_order'] + 1)], + ['id_gs' => $prevItem['id_gs']], + false + ); + + if ($resultItem !== false && $resultPrevItem !== false) { + db_process_sql_commit(); + echo json_encode(['success' => true]); + return; + } else { + db_process_sql_rollback(); + echo json_encode(['success' => false]); + return; + } + break; + + case 'down': + if (($item['field_order'] + 1) > $total) { + echo json_encode(['success' => false]); + return; + } + + $nextItem = db_get_row_sql( + 'SELECT id_gs, field_order + FROM tgraph_source + WHERE id_graph = '.$idGraph.' + AND field_order = '.($item['field_order'] + 1).' + ORDER BY field_order' + ); + + + db_process_sql_begin(); + + $resultItem = db_process_sql_update( + 'tgraph_source', + ['field_order' => ($item['field_order'] + 1)], + ['id_gs' => $item['id_gs']], + false + ); + $resultNextItem = db_process_sql_update( + 'tgraph_source', + ['field_order' => ($nextItem['field_order'] - 1)], + ['id_gs' => $nextItem['id_gs']], + false + ); + + if ($resultItem !== false && $resultNextItem !== false) { + db_process_sql_commit(); + echo json_encode(['success' => true]); + return; + } else { + db_process_sql_rollback(); + echo json_encode(['success' => false]); + return; + } + break; + + default: + echo json_encode(['success' => false]); + break; + } +} diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 5b37dc51d2..eada8c4d90 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -774,7 +774,8 @@ function html_print_select( $select2_multiple_enable_all=false, $form='', $order=false, - $custom_id=null + $custom_id=null, + $placeholder='', ) { $output = "\n"; @@ -1013,7 +1014,8 @@ function html_print_select( $output .= '