diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index ec8ff84b763..1cf2a8e5e09 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -73,6 +73,10 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both $sall=""; } +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +$hookmanager->initHooks(array('memberlist')); +$extrafields = new ExtraFields($db); + /* * View @@ -91,6 +95,12 @@ $sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, $sql.= " d.datefin,"; $sql.= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,"; $sql.= " t.libelle as type, t.cotisation"; +// Add fields for extrafields +foreach ($extrafields->attribute_list as $key => $val) $sql.=",ef.".$key.' as options_'.$key; +// Add fields from hooks +$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."adherent as d"; if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_member as cm ON d.rowid = cm.fk_member"; // We need this table joined to the select in order to filter by categ $sql.= ", ".MAIN_DB_PREFIX."adherent_type as t"; @@ -100,52 +110,23 @@ if ($catid == -2) $sql.= " AND cm.fk_categorie IS NULL"; if ($search_categ > 0) $sql.= " AND cm.fk_categorie = ".$db->escape($search_categ); if ($search_categ == -2) $sql.= " AND cm.fk_categorie IS NULL"; $sql.= " AND d.entity IN (".getEntity('adherent', 1).")"; -if ($sall) -{ - // For natural search - $scrit = explode(' ', $sall); - foreach ($scrit as $crit) - { - $sql.=" AND ("; - if (is_numeric($sall)) $sql.= "d.rowid = ".$db->escape($sall)." OR "; - $sql.=" d.firstname LIKE '%".$db->escape($sall)."%' OR d.lastname LIKE '%".$db->escape($sall)."%' OR d.societe LIKE '%".$db->escape($sall)."%'"; - $sql.=" OR d.email LIKE '%".$db->escape($sall)."%' OR d.login LIKE '%".$db->escape($sall)."%' OR d.address LIKE '%".$db->escape($sall)."%'"; - $sql.=" OR d.town LIKE '%".$db->escape($sall)."%' OR d.note_public LIKE '%".$db->escape($sall)."%' OR d.note_private LIKE '%".$db->escape($sall)."%')"; - } -} -if ($type > 0) -{ - $sql.=" AND t.rowid=".$db->escape($type); -} -if (isset($_GET["statut"]) || isset($_POST["statut"])) -{ - $sql.=" AND d.statut in (".$db->escape($statut).")"; // Peut valoir un nombre ou liste de nombre separes par virgules -} +if ($sall) $sql.=natural_search(array("d.rowid", "d.firstname", "d.lastname", "d.societe", "d.email", "d.login", "d.address", "d.town", "d.note_public", "d.note_private"), $sall); +if ($type > 0) $sql.=" AND t.rowid=".$db->escape($type); +if (isset($_GET["statut"]) || isset($_POST["statut"])) $sql.=" AND d.statut in (".$db->escape($statut).")"; // Peut valoir un nombre ou liste de nombre separes par virgules if ($search_ref) { if (is_numeric($search_ref)) $sql.= " AND (d.rowid = ".$db->escape($search_ref).")"; else $sql.=" AND 1 = 2"; // Always wrong } -if ($search_lastname) -{ - $sql.= " AND (d.firstname LIKE '%".$db->escape($search_lastname)."%' OR d.lastname LIKE '%".$db->escape($search_lastname)."%' OR d.societe LIKE '%".$db->escape($search_lastname)."%')"; -} -if ($search_login) -{ - $sql.= " AND d.login LIKE '%".$db->escape($search_login)."%'"; -} -if ($search_email) -{ - $sql.= " AND (d.email LIKE '%".$db->escape($search_email)."%')"; -} -if ($filter == 'uptodate') -{ - $sql.=" AND datefin >= '".$db->idate($now)."'"; -} -if ($filter == 'outofdate') -{ - $sql.=" AND (datefin IS NULL OR datefin < '".$db->idate($now)."')"; -} +if ($search_lastname) $sql.= natural_search(array("d.firstname", "d.lastname", "d.societe"), $search_lastname); +if ($search_login) $sql.= natural_search("d.login", $search_login); +if ($search_email) $sql.= natural_search("d.email", $search_email); +if ($filter == 'uptodate') $sql.=" AND datefin >= '".$db->idate($now)."'"; +if ($filter == 'outofdate') $sql.=" AND (datefin IS NULL OR datefin < '".$db->idate($now)."')"; +// Add where from hooks +$parameters=array(); +$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook +$sql.=$hookmanager->resPrint; // Count total nb of records with no order and no limits $nbtotalofrecords = 0; @@ -204,7 +185,7 @@ if ($resql) } print '