From f9b2417d894291f08532c0f7efaafad231e118c9 Mon Sep 17 00:00:00 2001 From: Marcos Alconada Date: Thu, 17 Dec 2020 16:55:30 +0100 Subject: [PATCH] error con modulos duplicados en module templates --- .../include/class/ModuleTemplates.class.php | 66 ++++++++++++++++--- 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/class/ModuleTemplates.class.php b/pandora_console/include/class/ModuleTemplates.class.php index 8d89519486..698f75e70d 100644 --- a/pandora_console/include/class/ModuleTemplates.class.php +++ b/pandora_console/include/class/ModuleTemplates.class.php @@ -610,17 +610,67 @@ class ModuleTemplates extends HTML } } else if ($modulesToAdd != '') { $modulesToAddList = explode(',', $modulesToAdd); + + $modulesAddedList = db_get_all_rows_in_table('tnetwork_profile_component'); + + $modulesToAdd = []; + foreach ($modulesToAddList as $module) { - db_process_sql_insert( - 'tnetwork_profile_component', - [ - 'id_nc' => $module, - 'id_np' => $this->id_np, - ] - ); + $is_added = false; + foreach ($modulesAddedList as $item) { + if ($item['id_nc'] === $module + && $item['id_np'] === $this->id_np + ) { + $is_added = true; + } + } + + if ($is_added === false) { + $name = io_safe_output( + db_get_row_filter( + 'tnetwork_component', + ['id_nc' => $module], + 'name' + ) + ); + $modulesToAdd[] = $name; + db_process_sql_insert( + 'tnetwork_profile_component', + [ + 'id_nc' => $module, + 'id_np' => $this->id_np, + ] + ); + } else { + $message = 'Some modules already exists
'; + } } - $this->ajaxMsg('result', __('Components added sucessfully')); + if (empty($modulesToAdd)) { + $this->ajaxMsg( + 'error', + __('The modules is already added') + ); + return false; + } + + if ($message === '') { + $message = 'Following modules will be added:'; + } else { + $message .= 'Following modules will be added:'; + } + + $message .= ''; + + $this->ajaxMsg( + 'result', + __($message) + ); } }