$agent['id_agente'], 'name' => io_safe_output($agent['nombre']), 'ip' => io_safe_output($agent['direccion'])); } echo json_encode($data); return; } elseif ($search_agents && ($config['metaconsole'] == 1) && defined('METACONSOLE')) { $servers = db_get_all_rows_sql ("SELECT * FROM tmetaconsole_setup WHERE disabled = 0"); if (!isset($servers)) { return; } $id_agent = (int) get_parameter ('id_agent'); $string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */ $id_group = (int) get_parameter('id_group', -1); $addedItems = html_entity_decode((string) get_parameter('add')); $addedItems = json_decode($addedItems); if ($addedItems != null) { foreach ($addedItems as $item) { echo $item . "|\n"; } } $filter = array (); switch ($config["dbtype"]) { case "mysql": case "postgresql": $filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%")'; break; case "oracle": $filter[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\') OR UPPER(direccion) LIKE UPPER(\'%'.$string.'%\'))'; break; } if ($id_group != -1) { if($id_group == 0) { $user_groups = users_get_groups ($config['id_user'], "AR", true); $filter['id_grupo'] = array_keys ($user_groups); } else { $filter['id_grupo'] = $id_group; } } $data = array(); foreach ($servers as $server) { if (metaconsole_load_external_db ($server) != NOERR) { continue; } $agents = agents_get_agents ($filter, array ('id_agente','nombre', 'direccion')); if ($agents === false) continue; foreach ($agents as $agent) { $data[] = array('id' => $agent['id_agente'], 'name' => io_safe_output($agent['nombre']) . " (" . io_safe_output($server['server_name']) . ") ", 'ip' => io_safe_output($agent['direccion']), 'server' => io_safe_output($server['server_name'])); } //Restore db connection metaconsole_restore_db(); } echo json_encode($data); return; } ?>