Merge branch '1490-Añadir-un-nuevo-campo-de-búsqueda-en-vista-de-agentes-dev' into 'develop'

added Search in custom fields

See merge request artica/pandorafms!969
This commit is contained in:
vgilc 2017-11-29 16:57:32 +01:00
commit 43308596c1
2 changed files with 44 additions and 4 deletions

View File

@ -325,6 +325,13 @@ function agents_get_agents ($filter = false, $fields = false,
$search = '';
}
if (isset($filter['search_custom'])) {
$search_custom = $filter['search_custom'];
unset($filter['search_custom']);
} else {
$search_custom = '';
}
if (isset($filter['offset'])) {
$offset = $filter['offset'];
unset($filter['offset']);
@ -461,8 +468,8 @@ function agents_get_agents ($filter = false, $fields = false,
$sql_extra, $where, $where_nogroup, $status_sql, $search, $disabled);
}
else {
$where = sprintf('%s AND %s AND (%s) %s AND %s',
$where, $where_nogroup, $status_sql, $search, $disabled);
$where = sprintf('%s AND %s AND (%s) %s AND %s %s',
$where, $where_nogroup, $status_sql, $search, $disabled, $search_custom);
}
$sql = sprintf('SELECT %s
FROM tagente
@ -1310,6 +1317,24 @@ function agents_get_agent_id ($agent_name, $io_safe_input = false) {
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.
*

View File

@ -141,6 +141,7 @@ ob_end_clean();
// Take some parameters (GET)
$group_id = (int) get_parameter ("group_id", 0);
$search = trim(get_parameter ("search", ""));
$search_custom = trim(get_parameter ("search_custom", ""));
$offset = (int)get_parameter('offset', 0);
$refr = get_parameter('refr', 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 __('Search') . '&nbsp;';
html_print_input_text ("search", $search, '', 12);
html_print_input_text ("search", $search, '', 15);
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 __('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", '',
array ("class" => "sub search"));
@ -384,7 +390,6 @@ switch ($sortField) {
$search_sql = '';
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
INNER JOIN taddress_agent ON
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
if ($group_id > 0) {
$groups = array($group_id);
@ -464,6 +477,7 @@ else {
'disabled' => 0,
'id_grupo' => $groups,
'search' => $search_sql,
'search_custom' => $search_sql_custom,
'status' => $status),
array ('COUNT(*) as total'), $access, false);
$total_agents = isset ($total_agents[0]['total']) ?
@ -474,6 +488,7 @@ else {
'id_grupo' => $groups,
'disabled' => 0,
'status' => $status,
'search_custom' => $search_sql_custom,
'search' => $search_sql,
'offset' => (int) get_parameter ('offset'),
'limit' => (int) $config['block_size']),