diff --git a/pandora_console/godmode/reporting/graph_builder.graph_editor.php b/pandora_console/godmode/reporting/graph_builder.graph_editor.php index a89a9422ba..4daaf0c18d 100644 --- a/pandora_console/godmode/reporting/graph_builder.graph_editor.php +++ b/pandora_console/godmode/reporting/graph_builder.graph_editor.php @@ -32,6 +32,7 @@ require_once($config['homedir'] . "/include/functions_modules.php"); require_once($config['homedir'] . "/include/functions_groups.php"); $editGraph = (bool) get_parameter('edit_graph', 0); +$action = get_parameter('action', ''); if (isset ($_GET["get_agent"])) { $id_agent = $_POST["id_agent"]; @@ -39,6 +40,122 @@ if (isset ($_GET["get_agent"])) { $chunkdata = $_POST["chunk"]; } +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); + + switch ($config["dbtype"]) { + case "mysql": + $items = db_get_all_rows_sql(' + SELECT id_gs, `order` + FROM tgraph_source + WHERE id_graph = ' . $id_graph . ' + ORDER BY `order`'); + break; + } + + if ($items === false) $items = array(); + + + // Clean the repeated order values + $order_temp = 1; + foreach ($items as $item) { + switch ($config["dbtype"]) { + case "mysql": + db_process_sql_update('tgraph_source', + array('`order`' => $order_temp), + array('id_gs' => $item['id_rc'])); + break; + } + + $order_temp++; + } + + + switch ($config["dbtype"]) { + case "mysql": + $items = db_get_all_rows_sql(' + SELECT id_gs, `order` + FROM tgraph_source + WHERE id_graph = ' . $id_graph . ' + ORDER BY `order`'); + break; + } + + if ($items === false) $items = array(); + + + + $temp = array(); + + $temp = array(); + foreach ($items as $item) { + //Remove the contents from the block to sort + if (array_search($item['id_gs'], $ids) === false) { + $temp[$item['order']] = $item['id_gs']; + } + } + $items = $temp; + + + + $sorted_items = array(); + 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) { + switch ($config["dbtype"]) { + case "mysql": + + db_process_sql_update('tgraph_source', + array('`order`' => ($order + 1)), + array('id_gs' => $id)); + break; + } + } + + $resultOperationDB = true; + } + else { + $resultOperationDB = false; + } + break; + } + if ($editGraph) { $graphRows = db_get_all_rows_sql("SELECT t1.*, (SELECT t3.alias @@ -49,7 +166,8 @@ if ($editGraph) { WHERE t2.id_agente_modulo = t1.id_agent_module)) AS agent_name FROM tgraph_source t1 - WHERE t1.id_graph = " . $id_graph); + WHERE t1.id_graph = " . $id_graph . " order by `order`"); + $position_array = array(); $module_array = array(); $weight_array = array(); $agent_array = array(); @@ -65,6 +183,7 @@ if ($editGraph) { $weight_array[] = $graphRow['weight']; $label_array[] = $graphRow['label']; $agent_array[] = $graphRow['agent_name']; + $position_array[] = $graphRow['order']; } $graphInTgraph = db_get_row_sql("SELECT * FROM tgraph WHERE id_graph = " . $id_graph); @@ -81,11 +200,13 @@ if ($editGraph) { if (count($module_array) > 0) { echo "
".__('P.')." | ".__('Agent')." | ".__('Module')." | ".__('Label')." | ".__('Weight')." | -".__('Delete')." | "; +".__('Delete')." | +".__('Sort')." | "; $color = 0; for ($a = 0; $a < count($module_array); $a++) { // Calculate table line color @@ -98,7 +219,8 @@ if (count($module_array) > 0) { $color = 1; } - echo "
---|---|---|---|---|---|---|---|
" . $agent_array[$a] . " | "; + echo "|||||||
$position_array[$a] | "; + echo "" . $agent_array[$a] . " | "; echo ""; echo modules_get_agentmodule_name ($module_array[$a])." | "; @@ -126,11 +248,55 @@ if (count($module_array) > 0) { echo ""; echo "".html_print_image('images/cross.png', true, array ('title' => __('Delete'))).""; - echo " | "; + + echo html_print_checkbox_extended('sorted_items[]', $idgs_array[$a], false, false, '', 'class="selected_check"', true); + + echo " | "; + + + echo ""; } echo "