= 2) {
for ($i = 1; $i < $idCount; $i++) {
$aux = $id[$i]['id_agent'];
$search_sql .= " OR t1.id_agente = $aux";
}
}
} else {
$search_sql = " t1.nombre LIKE '%%".$stringSearchSQL."%%' OR
t2.nombre LIKE '%%".$stringSearchSQL."%%' OR
t1.direccion LIKE '%%".$stringSearchSQL."%%' OR
t1.comentarios LIKE '%%".$stringSearchSQL."%%' OR
t1.alias LIKE '%%".$stringSearchSQL."%%'";
}
if ($has_secondary === true) {
$search_sql .= " OR (tasg.id_group IS NOT NULL AND
tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE nombre LIKE '%%".$stringSearchSQL."%%'))";
}
$sql = "
FROM tagente t1 LEFT JOIN tagent_secondary_group tasg
ON t1.id_agente = tasg.id_agent
INNER JOIN tgrupo t2
ON t2.id_grupo = t1.id_grupo
WHERE (
1 = (
SELECT is_admin
FROM tusuario
WHERE id_user = '".$config['id_user']."'
)
OR (
t1.id_grupo IN (".implode(',', $id_userGroups).')
OR tasg.id_group IN ('.implode(',', $id_userGroups).")
)
OR 0 IN (
SELECT id_grupo
FROM tusuario_perfil
WHERE id_usuario = '".$config['id_user']."'
AND id_perfil IN (
SELECT id_perfil
FROM tperfil WHERE agent_view = 1
)
)
)
AND (
".$search_sql.'
)
';
$select = 'SELECT DISTINCT(t1.id_agente), t1.ultimo_contacto, t1.nombre, t1.comentarios, t1.id_os, t1.intervalo, t1.id_grupo, t1.disabled, t1.alias, t1.quiet';
if (is_array($order)) {
// Datatables offset, limit.
$start = get_parameter('start', 0);
$length = get_parameter(
'length',
$config['block_size']
);
$limit = ' ORDER BY '.$order['field'].' '.$order['direction'].' LIMIT '.$length.' OFFSET '.$start;
}
$query = $select.$sql;
$query .= $limit;
$agents = db_process_sql($query);
if (empty($agents)) {
$agents = [];
}
$count_agents_main = 0;
if ($only_count) {
$count_agents_main = count($agents);
}
if ($agents !== false) {
$totalAgents = db_get_value_sql(
'SELECT COUNT(DISTINCT id_agente) AS agent_count '.$sql
);
$_SESSION['totalAgents'] = $totalAgents;
}
foreach ($agents as $key => $agent) {
if ($agent['disabled']) {
$agents[$key]['agent'] = ''.ucfirst(strtolower($agent['alias'])).''.ui_print_help_tip(__('Disabled'), true).'';
} else {
$agents[$key]['agent'] = ''.ucfirst(strtolower($agent['alias'])).'';
}
$agents[$key]['os'] = ui_print_os_icon($agent['id_os'], false, true);
$agents[$key]['interval'] = human_time_description_raw($agent['intervalo'], false, 'tiny');
$agents[$key]['group_icon'] = ui_print_group_icon($agent['id_grupo'], true);
$agent_info = reporting_get_agent_module_info($agent['id_agente']);
$modulesCell = reporting_tiny_stats($agent_info, true);
$agents[$key]['module'] = $modulesCell;
$agents[$key]['status'] = $agent_info['status_img'];
$agents[$key]['alert'] = $agent_info['alert_img'];
$last_time = time_w_fixed_tz($agent['ultimo_contacto']);
$now = get_system_time();
$diferencia = ($now - $last_time);
$time = ui_print_timestamp($last_time, true);
$time_style = $time;
if ($diferencia > ($agent['intervalo'] * 2)) {
$time_style = ''.$time.'';
}
$agents[$key]['last_contact'] = $time_style;
}
// RecordsTotal && recordsfiltered resultados totales.
echo json_encode(
[
'data' => ($agents ?? []),
'recordsTotal' => $totalAgents,
'recordsFiltered' => $totalAgents,
]
);
}