From ea112824395e80285e50287add5def4b58c0c671 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 13 Jan 2016 13:02:35 +0100 Subject: [PATCH] Cleaned duplicated order values in the reports. TICKET: #3156 (cherry picked from commit 51c5b6214ab6282979599f2b78c4ce40dc4a5a56) --- .../godmode/reporting/reporting_builder.php | 65 +++++++++++++++++-- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 844d5c571f..69d5dd058c 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -126,8 +126,10 @@ switch ($action) { $ids_serialize = (string)get_parameter('ids_items_to_sort', ''); $move_to = (string)get_parameter('move_to', 'after'); - $countItems = db_get_sql('SELECT COUNT(id_rc) - FROM treport_content WHERE id_report = ' . $idReport); + $countItems = db_get_sql(' + SELECT COUNT(id_rc) + FROM treport_content + WHERE id_report = ' . $idReport); if (($countItems < $position_to_sort) || ($position_to_sort < 1)) { $resultOperationDB = false; @@ -137,14 +139,16 @@ switch ($action) { switch ($config["dbtype"]) { case "mysql": - $items = db_get_all_rows_sql('SELECT id_rc, `order` + $items = db_get_all_rows_sql(' + SELECT id_rc, `order` FROM treport_content WHERE id_report = ' . $idReport . ' ORDER BY `order`'); break; case "oracle": case "postgresql": - $items = db_get_all_rows_sql('SELECT id_rc, "order" + $items = db_get_all_rows_sql(' + SELECT id_rc, "order" FROM treport_content WHERE id_report = ' . $idReport . ' ORDER BY "order"'); @@ -154,6 +158,49 @@ switch ($action) { 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('treport_content', + array('`order`' => $order_temp), + array('id_rc' => $item['id_rc'])); + break; + case "postgresql": + case "oracle": + db_process_sql_update('treport_content', + array('"order"' => $order_temp), + array('id_rc' => $item['id_rc'])); + break; + } + + $order_temp++; + } + + + switch ($config["dbtype"]) { + case "mysql": + $items = db_get_all_rows_sql(' + SELECT id_rc, `order` + FROM treport_content + WHERE id_report = ' . $idReport . ' + ORDER BY `order`'); + break; + case "oracle": + case "postgresql": + $items = db_get_all_rows_sql(' + SELECT id_rc, "order" + FROM treport_content + WHERE id_report = ' . $idReport . ' + ORDER BY "order"'); + break; + } + + if ($items === false) $items = array(); + + + $temp = array(); $temp = array(); @@ -165,6 +212,8 @@ switch ($action) { } $items = $temp; + + $sorted_items = array(); foreach ($items as $pos => $id_unsort) { if ($pos == $position_to_sort) { @@ -187,16 +236,20 @@ switch ($action) { $items = $sorted_items; + + foreach ($items as $order => $id) { switch ($config["dbtype"]) { case "mysql": db_process_sql_update('treport_content', - array('`order`' => ($order + 1)), array('id_rc' => $id)); + array('`order`' => ($order + 1)), + array('id_rc' => $id)); break; case "postgresql": case "oracle": db_process_sql_update('treport_content', - array('"order"' => ($order + 1)), array('id_rc' => $id)); + array('"order"' => ($order + 1)), + array('id_rc' => $id)); break; } }