From cac7b1f49fc58eff38d1264adae4368a1331e590 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 22 Jun 2015 16:34:25 +0200 Subject: [PATCH] NEW Add hooks on list of members to allow an external module to add more fields into list view. --- htdocs/adherents/list.php | 102 +++++++++++++++++--------------- htdocs/langs/en_US/members.lang | 3 +- htdocs/societe/list.php | 28 ++++----- 3 files changed, 69 insertions(+), 64 deletions(-) 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 '
'; - print ""; + print ''; // Filter on categories $moreforfilter=''; @@ -215,14 +196,17 @@ if ($resql) $moreforfilter.=$formother->select_categories(Categorie::TYPE_MEMBER,$search_categ,'search_categ',1); $moreforfilter.='       '; } - if ($moreforfilter) + if (! empty($moreforfilter)) { - print ''; - print ''; + $parameters=array(); + $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + print ''; } + print "
'; + print '
'; print $moreforfilter; - print '
"; print ''; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"d.rowid",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Name")." / ".$langs->trans("Company"),$_SERVER["PHP_SELF"],"d.lastname",$param,"","",$sortfield,$sortorder); @@ -230,7 +214,12 @@ if ($resql) print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"t.libelle",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Person"),$_SERVER["PHP_SELF"],"d.morphy",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("EMail"),$_SERVER["PHP_SELF"],"d.email",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"d.statut,d.datefin",$param,"","",$sortfield,$sortorder); + + $parameters=array(); + $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"d.statut,d.datefin",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("EndSubscription"),$_SERVER["PHP_SELF"],"d.datefin",$param,"",'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"",$param,"",'width="60" align="center"',$sortfield,$sortorder); print "\n"; @@ -257,7 +246,12 @@ if ($resql) print ''; - print ''; + $parameters=array(); + $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + // Status + print ''; print '\n"; - // Statut + $parameters=array('obj' => $obj); + $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + // Statut print '"; @@ -366,6 +364,12 @@ if ($resql) $i++; } + $db->free($resql); + + $parameters=array('sql' => $sql); + $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + print "
'; print '  '; print ''; @@ -317,7 +311,11 @@ if ($resql) // EMail print "".dol_print_email($objp->email,0,0,1)."'; print $memberstatic->LibStatut($objp->statut,$objp->cotisation,$datefin,2); print "
\n"; print '
'; diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index 3593e4c879f..daab8dcc3e5 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -199,7 +199,8 @@ Entreprises=Companies DOLIBARRFOUNDATION_PAYMENT_FORM=To make your subscription payment using a bank transfer, see page http://wiki.dolibarr.org/index.php/Subscribe.
To pay using a Credit Card or Paypal, click on button at bottom of this page.
ByProperties=By characteristics MembersStatisticsByProperties=Members statistics by characteristics -MembersByNature=Members by nature +MembersByNature=This screen show you statistics on members by nature. +MembersByRegion=This screen show you statistics on members by region. VATToUseForSubscriptions=VAT rate to use for subscriptions NoVatOnSubscription=No TVA for subscriptions MEMBER_PAYONLINE_SENDEMAIL=Email to warn when Dolibarr receive a confirmation of a validated payment for subscription diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index 6f96729155d..1019e7ee167 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -214,22 +214,22 @@ if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs"; $sql.= " WHERE s.fk_stcomm = st.id"; $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; -if ($socid) $sql.= " AND s.rowid = ".$socid; -if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale -if ($search_categ) $sql.= " AND s.rowid = cs.fk_soc"; // Join for the needed table to filter by categ +if ($socid) $sql.= " AND s.rowid = ".$socid; +if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale +if ($search_categ) $sql.= " AND s.rowid = cs.fk_soc"; // Join for the needed table to filter by categ if (! $user->rights->fournisseur->lire) $sql.=" AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible -if ($search_sale) $sql .= " AND sc.fk_user = ".$db->escape($search_sale); -if ($search_categ) $sql .= " AND cs.fk_categorie = ".$db->escape($search_categ); +if ($search_sale) $sql .= " AND sc.fk_user = ".$db->escape($search_sale); +if ($search_categ) $sql .= " AND cs.fk_categorie = ".$db->escape($search_categ); if ($search_nom_only) $sql.= natural_search("s.nom",$search_nom_only); -if ($search_all) $sql.= natural_search(array("s.nom", "s.name_alias", "s.code_client", "s.code_fournisseur", "s.email", "s.url","s.siren","s.siret","s.ape","s.idprof4","s.idprof5","s.idprof6"), $search_all); -if ($search_nom) $sql.= natural_search(array("s.nom", "s.name_alias", "s.code_client", "s.code_fournisseur", "s.email", "s.url","s.siren","s.siret","s.ape","s.idprof4","s.idprof5","s.idprof6"), $search_nom); -if ($search_town) $sql .= " AND s.town LIKE '%".$db->escape($search_town)."%'"; -if ($search_idprof1) $sql .= " AND s.siren LIKE '%".$db->escape($search_idprof1)."%'"; -if ($search_idprof2) $sql .= " AND s.siret LIKE '%".$db->escape($search_idprof2)."%'"; -if ($search_idprof3) $sql .= " AND s.ape LIKE '%".$db->escape($search_idprof3)."%'"; -if ($search_idprof4) $sql .= " AND s.idprof4 LIKE '%".$db->escape($search_idprof4)."%'"; -if ($search_idprof5) $sql .= " AND s.idprof5 LIKE '%".$db->escape($search_idprof5)."%'"; -if ($search_idprof6) $sql .= " AND s.idprof6 LIKE '%".$db->escape($search_idprof6)."%'"; +if ($search_all) $sql.= natural_search(array("s.nom", "s.name_alias", "s.code_client", "s.code_fournisseur", "s.email", "s.url","s.siren","s.siret","s.ape","s.idprof4","s.idprof5","s.idprof6"), $search_all); +if ($search_nom) $sql.= natural_search(array("s.nom", "s.name_alias", "s.code_client", "s.code_fournisseur", "s.email", "s.url","s.siren","s.siret","s.ape","s.idprof4","s.idprof5","s.idprof6"), $search_nom); +if ($search_town) $sql .= " AND s.town LIKE '%".$db->escape($search_town)."%'"; +if ($search_idprof1) $sql .= " AND s.siren LIKE '%".$db->escape($search_idprof1)."%'"; +if ($search_idprof2) $sql .= " AND s.siret LIKE '%".$db->escape($search_idprof2)."%'"; +if ($search_idprof3) $sql .= " AND s.ape LIKE '%".$db->escape($search_idprof3)."%'"; +if ($search_idprof4) $sql .= " AND s.idprof4 LIKE '%".$db->escape($search_idprof4)."%'"; +if ($search_idprof5) $sql .= " AND s.idprof5 LIKE '%".$db->escape($search_idprof5)."%'"; +if ($search_idprof6) $sql .= " AND s.idprof6 LIKE '%".$db->escape($search_idprof6)."%'"; // Filter on type of thirdparty if ($search_type > 0 && in_array($search_type,array('1,3','2,3'))) $sql .= " AND s.client IN (".$db->escape($search_type).")"; if ($search_type > 0 && in_array($search_type,array('4'))) $sql .= " AND s.fournisseur = 1";