From 592a041bc5aee9371679cfe46b40b46a6799454d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 4 Apr 2016 16:02:29 +0200 Subject: [PATCH] FIX Filter/search on extrafields on lists --- dev/skeletons/skeleton_list.php | 17 +++++++----- htdocs/contact/list.php | 2 +- htdocs/product/list.php | 2 +- htdocs/projet/list.php | 47 ++++++++++++++++++++++++++------- htdocs/projet/tasks/list.php | 43 +++++++++++++++++++++++++----- htdocs/societe/list.php | 37 ++++++++++++++------------ htdocs/user/index.php | 19 +++++++++++-- 7 files changed, 122 insertions(+), 45 deletions(-) diff --git a/dev/skeletons/skeleton_list.php b/dev/skeletons/skeleton_list.php index 2321b76aac8..bbe67d68df5 100644 --- a/dev/skeletons/skeleton_list.php +++ b/dev/skeletons/skeleton_list.php @@ -217,7 +217,7 @@ foreach ($search_array_options as $key => $val) $tmpkey=preg_replace('/search_options_/','',$key); $typ=$extrafields->attribute_type[$tmpkey]; $mode=0; - if (in_array($typ, array('int'))) $mode=1; // Search on a numeric + if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit))) { $sql .= natural_search('ef.'.$tmpkey, $crit, $mode); @@ -335,12 +335,15 @@ if ($resql) $align=$extrafields->getAlignFlag($key); $typeofextrafield=$extrafields->attribute_type[$key]; print ''; - if (in_array($typeofextrafield, array('varchar', 'int', 'select'))) - { - $crit=$val; - $tmpkey=preg_replace('/search_options_/','',$key); - print ''; - } + if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select'))) + { + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + $searchclass=''; + if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring'; + if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum'; + print ''; + } print ''; } } diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index cee89d0970f..702ecb2042f 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -321,7 +321,7 @@ foreach ($search_array_options as $key => $val) $tmpkey=preg_replace('/search_options_/','',$key); $typ=$extrafields->attribute_type[$tmpkey]; $mode=0; - if (in_array($typ, array('int'))) $mode=1; // Search on a numeric + if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit))) { $sql .= natural_search('ef.'.$tmpkey, $crit, $mode); diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 55413f7ed1d..51e453393a0 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -260,7 +260,7 @@ else $tmpkey=preg_replace('/search_options_/','',$key); $typ=$extrafields->attribute_type[$tmpkey]; $mode=0; - if (in_array($typ, array('int'))) $mode=1; // Search on a numeric + if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit))) { $sql .= natural_search('ef.'.$tmpkey, $crit, $mode); diff --git a/htdocs/projet/list.php b/htdocs/projet/list.php index 9f1cc038cc5..6503ac5ca41 100644 --- a/htdocs/projet/list.php +++ b/htdocs/projet/list.php @@ -98,7 +98,7 @@ $hookmanager->initHooks(array($contextpage)); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('project'); +$extralabels = $extrafields->fetch_name_optionals_label('projet'); $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); // List of fields to search into when doing a "search in all" @@ -213,16 +213,15 @@ $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager->resPrint; $sql.= " FROM ".MAIN_DB_PREFIX."projet as p"; +if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_extrafields as ef on (p.rowid = ef.fk_object)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid"; - // We'll need this table joined to the select in order to filter by sale if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid"; if ($search_user > 0) { $sql.=", ".MAIN_DB_PREFIX."element_contact as ecp"; } - $sql.= " WHERE p.entity IN (".getEntity('project',1).')'; if (! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")"; // public and assigned to, or restricted to company for external users // No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser @@ -271,6 +270,19 @@ if ($search_public!='') $sql .= " AND p.public = ".$db->escape($search_public); if ($search_sale > 0) $sql.= " AND sc.fk_user = " .$search_sale; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))"; if ($search_user > 0) $sql.= " AND ecp.fk_c_type_contact IN (".join(',',array_keys($listofprojectcontacttype)).") AND ecp.element_id = p.rowid AND ecp.fk_socpeople = ".$search_user; +// Add where from extra fields +foreach ($search_array_options as $key => $val) +{ + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + $typ=$extrafields->attribute_type[$tmpkey]; + $mode=0; + if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric + if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit))) + { + $sql .= natural_search('ef.'.$tmpkey, $crit, $mode); + } +} // Add where from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook @@ -484,15 +496,30 @@ if ($resql) print ''; print ''; } - // Extra fields - if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) - { - foreach($extrafields->attribute_label as $key => $val) + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) { - if (! empty($arrayfields["ef.".$key]['checked'])) print ''; + if (! empty($arrayfields["ef.".$key]['checked'])) + { + $align=$extrafields->getAlignFlag($key); + $typeofextrafield=$extrafields->attribute_type[$key]; + print ''; + if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select'))) + { + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + $searchclass=''; + if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring'; + if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum'; + print ''; + } + print ''; + } } - } - // Fields from hook + } + // Fields from hook $parameters=array('arrayfields'=>$arrayfields); $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; diff --git a/htdocs/projet/tasks/list.php b/htdocs/projet/tasks/list.php index 8caf413c8ee..8ec4eeffedb 100644 --- a/htdocs/projet/tasks/list.php +++ b/htdocs/projet/tasks/list.php @@ -66,7 +66,7 @@ $hookmanager->initHooks(array($contextpage)); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('project'); +$extralabels = $extrafields->fetch_name_optionals_label('projet_task'); $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); // Security check @@ -226,6 +226,7 @@ $sql.=$hookmanager->resPrint; $sql.= " FROM ".MAIN_DB_PREFIX."projet as p"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid,"; $sql.= " ".MAIN_DB_PREFIX."projet_task as t"; +if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task_extrafields as ef on (t.rowid = ef.fk_object)"; if ($search_project_user > 0) { $sql.=", ".MAIN_DB_PREFIX."element_contact as ecp"; @@ -275,6 +276,19 @@ if ($search_projectstatus >= 0) $sql .= " AND p.fk_statut = ".$db->escape($searc if ($search_public!='') $sql .= " AND p.public = ".$db->escape($search_public); if ($search_project_user > 0) $sql.= " AND ecp.fk_c_type_contact IN (".join(',',array_keys($listofprojectcontacttype)).") AND ecp.element_id = p.rowid AND ecp.fk_socpeople = ".$search_project_user; if ($search_task_user > 0) $sql.= " AND ect.fk_c_type_contact IN (".join(',',array_keys($listoftaskcontacttype)).") AND ect.element_id = t.rowid AND ect.fk_socpeople = ".$search_task_user; +// Add where from extra fields +foreach ($search_array_options as $key => $val) +{ + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + $typ=$extrafields->attribute_type[$tmpkey]; + $mode=0; + if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric + if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit))) + { + $sql .= natural_search('ef.'.$tmpkey, $crit, $mode); + } +} // Add where from hooks $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook @@ -479,14 +493,29 @@ if ($resql) if (! empty($arrayfields['t.duration_effective']['checked'])) print ''; if (! empty($arrayfields['t.progress_calculated']['checked'])) print ''; if (! empty($arrayfields['t.progress']['checked'])) print ''; - // Extra fields - if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) - { - foreach($extrafields->attribute_label as $key => $val) + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) { - if (! empty($arrayfields["ef.".$key]['checked'])) print ''; + if (! empty($arrayfields["ef.".$key]['checked'])) + { + $align=$extrafields->getAlignFlag($key); + $typeofextrafield=$extrafields->attribute_type[$key]; + print ''; + if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select'))) + { + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + $searchclass=''; + if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring'; + if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum'; + print ''; + } + print ''; + } } - } + } // Fields from hook $parameters=array('arrayfields'=>$arrayfields); $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index d32032ef52d..3e49c5954b9 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -408,7 +408,7 @@ foreach ($search_array_options as $key => $val) $tmpkey=preg_replace('/search_options_/','',$key); $typ=$extrafields->attribute_type[$tmpkey]; $mode=0; - if (in_array($typ, array('int'))) $mode=1; // Search on a numeric + if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit))) { $sql .= natural_search('ef.'.$tmpkey, $crit, $mode); @@ -604,35 +604,35 @@ if ($resql) { print ''; if (! empty($search_nom_only) && empty($search_nom)) $search_nom=$search_nom_only; - print ''; + print ''; print ''; } // Barcode if (! empty($arrayfields['s.barcode']['checked'])) { print ''; - print ''; + print ''; print ''; } // Customer code if (! empty($arrayfields['s.code_client']['checked'])) { print ''; - print ''; + print ''; print ''; } // Supplier code if (! empty($arrayfields['s.code_fournisseur']['checked'])) { print ''; - print ''; + print ''; print ''; } // Account Customer code if (! empty($arrayfields['s.code_compta']['checked'])) { print ''; - print ''; + print ''; print ''; } // Account Supplier code @@ -646,21 +646,21 @@ if ($resql) if (! empty($arrayfields['s.town']['checked'])) { print ''; - print ''; + print ''; print ''; } // Zip if (! empty($arrayfields['s.zip']['checked'])) { print ''; - print ''; + print ''; print ''; } // State if (! empty($arrayfields['state.nom']['checked'])) { print ''; - print ''; + print ''; print ''; } // Country @@ -681,42 +681,42 @@ if ($resql) { // IdProf1 print ''; - print ''; + print ''; print ''; } if (! empty($arrayfields['s.siret']['checked'])) { // IdProf2 print ''; - print ''; + print ''; print ''; } if (! empty($arrayfields['s.ape']['checked'])) { // IdProf3 print ''; - print ''; + print ''; print ''; } if (! empty($arrayfields['s.idprof4']['checked'])) { // IdProf4 print ''; - print ''; + print ''; print ''; } if (! empty($arrayfields['s.idprof5']['checked'])) { // IdProf5 print ''; - print ''; + print ''; print ''; } if (! empty($arrayfields['s.idprof6']['checked'])) { // IdProf6 print ''; - print ''; + print ''; print ''; } @@ -782,11 +782,14 @@ if ($resql) $align=$extrafields->getAlignFlag($key); $typeofextrafield=$extrafields->attribute_type[$key]; print ''; - if (in_array($typeofextrafield, array('varchar', 'int', 'select'))) + if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select'))) { $crit=$val; $tmpkey=preg_replace('/search_options_/','',$key); - print ''; + $searchclass=''; + if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring'; + if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum'; + print ''; } print ''; } diff --git a/htdocs/user/index.php b/htdocs/user/index.php index 161e39a89a8..f4c77644f1f 100644 --- a/htdocs/user/index.php +++ b/htdocs/user/index.php @@ -213,7 +213,7 @@ foreach ($search_array_options as $key => $val) $tmpkey=preg_replace('/search_options_/','',$key); $typ=$extrafields->attribute_type[$tmpkey]; $mode=0; - if (in_array($typ, array('int'))) $mode=1; // Search on a numeric + if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit))) { $sql .= natural_search('ef.'.$tmpkey, $crit, $mode); @@ -368,7 +368,22 @@ if ($result) { foreach($extrafields->attribute_label as $key => $val) { - if (! empty($arrayfields["ef.".$key]['checked'])) print ''; + if (! empty($arrayfields["ef.".$key]['checked'])) + { + $align=$extrafields->getAlignFlag($key); + $typeofextrafield=$extrafields->attribute_type[$key]; + print ''; + if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select'))) + { + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + $searchclass=''; + if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring'; + if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum'; + print ''; + } + print ''; + } } } // Fields from hook