added Search in custom fields

This commit is contained in:
Daniel Maya 2017-10-25 12:04:14 +02:00
parent 8fa33a2401
commit 3bafe27361
2 changed files with 44 additions and 4 deletions

View File

@ -314,6 +314,13 @@ function agents_get_agents ($filter = false, $fields = false,
$search = ''; $search = '';
} }
if (isset($filter['search_custom'])) {
$search_custom = $filter['search_custom'];
unset($filter['search_custom']);
} else {
$search_custom = '';
}
if (isset($filter['offset'])) { if (isset($filter['offset'])) {
$offset = $filter['offset']; $offset = $filter['offset'];
unset($filter['offset']); unset($filter['offset']);
@ -450,8 +457,8 @@ function agents_get_agents ($filter = false, $fields = false,
$sql_extra, $where, $where_nogroup, $status_sql, $search, $disabled); $sql_extra, $where, $where_nogroup, $status_sql, $search, $disabled);
} }
else { else {
$where = sprintf('%s AND %s AND (%s) %s AND %s', $where = sprintf('%s AND %s AND (%s) %s AND %s %s',
$where, $where_nogroup, $status_sql, $search, $disabled); $where, $where_nogroup, $status_sql, $search, $disabled, $search_custom);
} }
$sql = sprintf('SELECT %s $sql = sprintf('SELECT %s
FROM tagente FROM tagente
@ -1299,6 +1306,24 @@ function agents_get_agent_id ($agent_name, $io_safe_input = false) {
return (int) db_get_value ('id_agente', 'tagente', 'nombre', $agent_name); return (int) db_get_value ('id_agente', 'tagente', 'nombre', $agent_name);
} }
/**
* Get agents id from an agent alias.
*
* @param string $agent_alias Agent alias to get its id.
* @param boolean $io_safe_input If it is true transform to safe string, by default false.
*
* @return int Id from the agent of the given alias.
*/
function agents_get_agent_id_by_alias ($alias, $io_safe_input = false) {
if ($io_safe_input) {
$alias = io_safe_input($alias);
}
$sql = sprintf("SELECT tagente.id_agente FROM tagente WHERE alias LIKE '%s' ",$alias);
$agent_id = db_get_all_rows_sql($sql);
return $agent_id;
}
/** /**
* Get name of an agent. * Get name of an agent.
* *

View File

@ -141,6 +141,7 @@ ob_end_clean();
// Take some parameters (GET) // Take some parameters (GET)
$group_id = (int) get_parameter ("group_id", 0); $group_id = (int) get_parameter ("group_id", 0);
$search = trim(get_parameter ("search", "")); $search = trim(get_parameter ("search", ""));
$search_custom = trim(get_parameter ("search_custom", ""));
$offset = (int)get_parameter('offset', 0); $offset = (int)get_parameter('offset', 0);
$refr = get_parameter('refr', 0); $refr = get_parameter('refr', 0);
$recursion = get_parameter('recursion', 0); $recursion = get_parameter('recursion', 0);
@ -205,7 +206,7 @@ html_print_checkbox ("recursion", 1, $recursion, false, false, 'this.form.submit
echo '</td><td style="white-space:nowrap;">'; echo '</td><td style="white-space:nowrap;">';
echo __('Search') . '&nbsp;'; echo __('Search') . '&nbsp;';
html_print_input_text ("search", $search, '', 12); html_print_input_text ("search", $search, '', 15);
echo '</td><td style="white-space:nowrap;">'; echo '</td><td style="white-space:nowrap;">';
@ -222,6 +223,11 @@ html_print_select ($fields, "status", $status, 'this.form.submit()', __('All'),
echo '</td><td style="white-space:nowrap;">'; echo '</td><td style="white-space:nowrap;">';
echo __('Search in custom fields') . '&nbsp;';
html_print_input_text ("search_custom", $search_custom, '', 15);
echo '</td><td style="white-space:nowrap;">';
html_print_submit_button (__('Search'), "srcbutton", '', html_print_submit_button (__('Search'), "srcbutton", '',
array ("class" => "sub search")); array ("class" => "sub search"));
@ -384,7 +390,6 @@ switch ($sortField) {
$search_sql = ''; $search_sql = '';
if ($search != "") { if ($search != "") {
//$search_sql = " AND ( nombre " . $order_collation . " LIKE '%$search%' OR direccion LIKE '%$search%' OR comentarios LIKE '%$search%') ";
$sql = "SELECT DISTINCT taddress_agent.id_agent FROM taddress $sql = "SELECT DISTINCT taddress_agent.id_agent FROM taddress
INNER JOIN taddress_agent ON INNER JOIN taddress_agent ON
taddress.id_a = taddress_agent.id_a taddress.id_a = taddress_agent.id_a
@ -409,6 +414,14 @@ if ($search != "") {
} }
} }
if(!empty($search_custom)){
$search_sql_custom = " AND EXISTS (SELECT * FROM tagent_custom_data
WHERE id_agent = id_agente AND description LIKE '%$search_custom%')";
} else {
$search_sql_custom = "";
}
// Show only selected groups // Show only selected groups
if ($group_id > 0) { if ($group_id > 0) {
$groups = array($group_id); $groups = array($group_id);
@ -464,6 +477,7 @@ else {
'disabled' => 0, 'disabled' => 0,
'id_grupo' => $groups, 'id_grupo' => $groups,
'search' => $search_sql, 'search' => $search_sql,
'search_custom' => $search_sql_custom,
'status' => $status), 'status' => $status),
array ('COUNT(*) as total'), $access, false); array ('COUNT(*) as total'), $access, false);
$total_agents = isset ($total_agents[0]['total']) ? $total_agents = isset ($total_agents[0]['total']) ?
@ -474,6 +488,7 @@ else {
'id_grupo' => $groups, 'id_grupo' => $groups,
'disabled' => 0, 'disabled' => 0,
'status' => $status, 'status' => $status,
'search_custom' => $search_sql_custom,
'search' => $search_sql, 'search' => $search_sql,
'offset' => (int) get_parameter ('offset'), 'offset' => (int) get_parameter ('offset'),
'limit' => (int) $config['block_size']), 'limit' => (int) $config['block_size']),