0, 'tagente_modulo.disabled' => 0, ], [ 'tagente.id_agente', 'tagente.alias', ], $recursion ); echo json_encode(index_array($agents_modules, 'id_agente', 'alias')); return; } return; } function process_manage_delete($module_name, $id_agents, $module_status='all') { global $config; $status_module = (int) get_parameter('status_module'); if (empty($module_name)) { ui_print_error_message(__('No module selected')); return false; } if (empty($id_agents)) { ui_print_error_message(__('No agents selected')); return false; } $module_name = (array) $module_name; // We are selecting "any" agent for the selected modules if (($id_agents[0] == 0) and (is_array($id_agents)) and (count($id_agents) == 1)) { $id_agents = null; } $selection_delete_mode = get_parameter('selection_mode', 'modules'); // Selection mode by Agents if ($selection_delete_mode == 'agents') { // We are selecting "any" module for the selecteds agents if (($module_name[0] == '0') and (is_array($module_name)) and (count($module_name) == 1)) { if ($status_module != -1) { $filter_for_module_deletion = sprintf('tagente_modulo.id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_estado where estado = %s OR utimestamp=0 )', $status_module); } else { $filter_for_module_deletion = false; } } else { $filter_for_module_deletion = sprintf('tagente_modulo.nombre IN ("%s")', implode('","', $module_name)); } $modules = agents_get_modules( $id_agents, 'id_agente_modulo', $filter_for_module_deletion, true ); } else { if ($status_module != -1) { $modules = agents_get_modules( $id_agents, 'id_agente_modulo', sprintf('tagente_modulo.nombre IN ("%s") AND tagente_modulo.id_agente_modulo IN (SELECT id_agente_modulo FROM tagente_estado where estado = %s OR utimestamp=0 )', implode('","', $module_name), $status_module), true ); } else { $modules = agents_get_modules( $id_agents, 'id_agente_modulo', 'tagente_modulo.nombre IN ("'.implode('","', $module_name).'")', true ); } } if (($module_status == 'unknown') && ($module_name[0] == '0') && (is_array($module_name)) && (count($module_name) == 1)) { $modules_to_delete = []; foreach ($modules as $mod_id) { $mod_status = (int) db_get_value_filter('estado', 'tagente_estado', ['id_agente_modulo' => $mod_id]); // Unknown, not init and no data modules if ($mod_status == 3 || $mod_status == 4 || $mod_status == 5) { $modules_to_delete[$mod_id] = $mod_id; } } $modules = $modules_to_delete; } $count_deleted_modules = count($modules); $success = modules_delete_agent_module($modules); if (! $success) { ui_print_error_message( __('There was an error deleting the modules, the operation has been cancelled') ); return false; } else { ui_print_success_message( __('Successfully deleted').' ('.$count_deleted_modules.')' ); return true; } } $module_type = (int) get_parameter('module_type'); $group_select = get_parameter('groups_select'); $delete = (bool) get_parameter_post('delete'); $module_name = get_parameter('module_name'); $agents_select = get_parameter('agents'); $agents_id = get_parameter('id_agents'); $modules_select = get_parameter('module'); $selection_mode = get_parameter('selection_mode', 'modules'); $recursion = get_parameter('recursion'); $modules_selection_mode = get_parameter('modules_selection_mode'); if ($delete) { switch ($selection_mode) { case 'modules': $force = get_parameter('force_type', false); if ($agents_select == false) { $agents_select = []; $agents_ = []; } $agents_ = $agents_select; $modules_ = $module_name; break; case 'agents': $force = get_parameter('force_group', false); $agents_ = $agents_id; $modules_ = $modules_select; break; } $count = 0; $success = 0; // If the option to select all of one group or module type is checked if ($force) { if ($force == 'type') { $condition = ''; if ($module_type != 0) { $condition = ' AND t2.id_tipo_modulo = '.$module_type; } $groups = users_get_groups($config['id_user'], 'AW', false); $group_id_list = ($groups ? join(',', array_keys($groups)) : '0'); $condition = ' AND t1.id_grupo IN ('.$group_id_list.') '; $agents_ = db_get_all_rows_sql( 'SELECT DISTINCT(t1.id_agente) FROM tagente t1, tagente_modulo t2 WHERE t1.id_agente = t2.id_agente AND t2.delete_pending = 0 '.$condition ); foreach ($agents_ as $id_agent) { $module_name = db_get_all_rows_filter('tagente_modulo', ['id_agente' => $id_agent['id_agente'], 'id_tipo_modulo' => $module_type, 'delete_pending' => 0], 'nombre'); if ($module_name == false) { $module_name = []; } foreach ($module_name as $mod_name) { $result = process_manage_delete($mod_name['nombre'], $id_agent['id_agente'], $modules_selection_mode); $count++; $success += (int) $result; } } } else if ($force == 'group') { if ($group_select == 0) { $agents_ = array_keys(agents_get_group_agents(array_keys(users_get_groups($config['id_user'], 'AW', false)), false, 'none')); } else { $agents_ = array_keys(agents_get_group_agents($group_select, false, 'none')); } foreach ($agents_ as $id_agent) { $module_name = db_get_all_rows_filter('tagente_modulo', ['id_agente' => $id_agent], 'nombre'); if ($module_name == false) { $module_name = []; } else { $result = process_manage_delete([0 => 0], $id_agent, $modules_selection_mode); } $success += (int) $result; } } // We empty the agents array to skip the standard procedure $agents_ = []; } if (!$force) { $result = false; $result = process_manage_delete($modules_, $agents_, $modules_selection_mode); } $info = [ 'Agent' => implode(',', $agents_), 'Module' => implode(',', $modules_), ]; $auditMessage = ((bool) $result === true) ? 'Delete module' : 'Fail try to delete module'; db_pandora_audit( AUDIT_LOG_MASSIVE_MANAGEMENT, $auditMessage, false, false, json_encode($info) ); } $groups = users_get_groups(); $agents = agents_get_group_agents( array_keys(users_get_groups()), false, 'none' ); $module_types = db_get_all_rows_filter( 'tagente_modulo,ttipo_modulo', [ 'tagente_modulo.id_tipo_modulo = ttipo_modulo.id_tipo', 'id_agente' => array_keys($agents), 'disabled' => 0, 'order' => 'ttipo_modulo.nombre' ], [ 'DISTINCT(id_tipo)', 'CONCAT(ttipo_modulo.descripcion," (",ttipo_modulo.nombre,")") AS description', ] ); if ($module_types === false) { $module_types = []; } $types = []; foreach ($module_types as $type) { $types[$type['id_tipo']] = $type['description']; } $table = new stdClass(); $table->width = '100%'; $table->class = 'databox filters filter-table-adv'; $table->size[0] = '50%'; $table->size[1] = '50%'; $table->data = []; $table->data[0][0] = html_print_label_input_block( __('Selection mode'), '