'nombre', 'order' => 'ASC');
break;
case 'down':
$selectNameDown = $selected;
$order = array('field' => 'nombre', 'order' => 'DESC');
break;
}
break;
case 'os':
switch ($sort) {
case 'up':
$selectOsUp = $selected;
$order = array('field' => 'id_os', 'order' => 'ASC');
break;
case 'down':
$selectOsDown = $selected;
$order = array('field' => 'id_os', 'order' => 'DESC');
break;
}
break;
case 'interval':
switch ($sort) {
case 'up':
$selectIntervalUp = $selected;
$order = array('field' => 'intervalo', 'order' => 'ASC');
break;
case 'down':
$selectIntervalDown = $selected;
$order = array('field' => 'intervalo', 'order' => 'DESC');
break;
}
break;
case 'group':
switch ($sort) {
case 'up':
$selectGroupUp = $selected;
$order = array('field' => 'id_grupo', 'order' => 'ASC');
break;
case 'down':
$selectGroupDown = $selected;
$order = array('field' => 'id_grupo', 'order' => 'DESC');
break;
}
break;
case 'last_contact':
switch ($sort) {
case 'up':
$selectLastContactUp = $selected;
$order = array('field' => 'ultimo_contacto', 'order' => 'ASC');
break;
case 'down':
$selectLastContactDown = $selected;
$order = array('field' => 'ultimo_contacto', 'order' => 'DESC');
break;
}
break;
default:
$selectNameUp = $selected;
$selectNameDown = '';
$selectOsUp = '';
$selectOsDown = '';
$selectIntervalUp = '';
$selectIntervalDown = '';
$selectGroupUp = '';
$selectGroupDown = '';
$selectLastContactUp = '';
$selectLastContactDown = '';
$order = array('field' => 'nombre', 'order' => 'ASC');
break;
}
$agents = false;
if ($searchAgents) {
$sql = "SELECT id_agente, tagente.ultimo_contacto, tagente.nombre, tagente.id_os, tagente.intervalo, tagente.id_grupo, tagente.disabled
FROM tagente
INNER JOIN tgrupo
ON tgrupo.id_grupo = tagente.id_grupo
WHERE tagente.nombre COLLATE utf8_general_ci LIKE '%" . $stringSearchSQL . "%' OR
tgrupo.nombre LIKE '%" . $stringSearchSQL . "%'
ORDER BY " . $order['field'] . " " . $order['order'] . "
LIMIT " . $config['block_size'] . " OFFSET " . get_parameter ('offset',0);
$agents = process_sql($sql);
if($agents !== false) {
// ACLs check
$agents_id = array();
foreach($agents as $key => $agent){
if (!give_acl ($config["id_user"], $agent["id_grupo"], "AR")) {
unset($agents[$key]);
} else {
$agents_id[] = $agent["id_agente"];
}
}
if(!$agents_id) {
$agent_condition = "";
}else {
// Condition with the visible agents
$agent_condition = " AND id_agente IN (".implode(',',$agents_id).")";
}
$sql = "SELECT count(id_agente) AS count
FROM tagente
INNER JOIN tgrupo
ON tgrupo.id_grupo = tagente.id_grupo
WHERE (tagente.nombre COLLATE utf8_general_ci LIKE '%" . $stringSearchSQL . "%' OR
tgrupo.nombre LIKE '%" . $stringSearchSQL . "%')".$agent_condition;
$totalAgents = get_db_row_sql($sql);
$totalAgents = $totalAgents['count'];
}
}
if (!$agents) {
echo "