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 ""; echo " + - "; + + "; $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 ""; + echo ""; + echo ""; echo ""; @@ -126,11 +248,55 @@ if (count($module_array) > 0) { echo ""; + echo ""; + + echo ""; + + + echo ""; } echo "
".__('P.')." ".__('Agent')." ".__('Module')." ".__('Label')." ".__('Weight')."".__('Delete')."".__('Delete')."".__('Sort')."
" . $agent_array[$a] . "
$position_array[$a]" . $agent_array[$a] . ""; echo modules_get_agentmodule_name ($module_array[$a]).""; 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 "
"; } + +$table = new stdClass(); +$table->width = '100%'; +$table->colspan[0][0] = 3; +$table->size = array(); +$table->size[0] = '25%'; +$table->size[1] = '25%'; +$table->size[2] = '25%'; +$table->size[3] = '25%'; +if (defined("METACONSOLE")) { + $table->class = "databox data"; + $table->head[0] = __("Sort items"); + $table->head_colspan[0] = 4; + $table->headstyle[0] = 'text-align: center'; +} +else { + $table->data[0][0] = "". __("Sort items") . ""; +} +$table->data[1][0] = __('Sort selected items from position: '); +$table->data[1][1] = html_print_select_style( + array('before' => __('Move before to'), 'after' => __('Move after to')), 'move_to', + '', '', '', '', 0, true); +$table->data[1][2] = html_print_input_text_extended('position_to_sort', 1, + 'text-position_to_sort', '', 3, 10, false, "only_numbers('position_to_sort');", '', true); +$table->data[1][2] .= html_print_input_hidden('ids_items_to_sort', '', true); +$table->data[1][3] = html_print_submit_button(__('Sort'), 'sort_submit', false, 'class="sub upd"', true); +$table->data[1][4] = html_print_input_hidden('action', 'sort_items', true); + +echo "
"; +html_print_table($table); +echo "
"; + +echo "
"; + + //Configuration form echo ''; echo "
"; @@ -217,4 +383,28 @@ function filterByGroup(idGroup) { "json" ); } + +function added_ids_sorted_items_to_hidden_input() { + var ids = ''; + var first = true; + + $("input.selected_check:checked").each(function(i, val) { + if (!first) + ids = ids + '|'; + first = false; + + ids = ids + $(val).val(); + }); + + $("input[name='ids_items_to_sort']").val(ids); + + if (ids == '') { + alert(""); + + return false; + } + else { + return true; + } +}