From c787e7f2a15d8ef5c4679d16724dd50cb00b0080 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 13 Jul 2016 12:02:45 +0200 Subject: [PATCH] FIX Clear of filter should also reset categories and extrafields filter FIX Filter on categories should depends on context --- htdocs/contact/list.php | 48 +++++++++++++++++++++++++++----------- htdocs/contrat/list.php | 51 +++++++++++++++++++++++++++++++---------- 2 files changed, 74 insertions(+), 25 deletions(-) diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index a66c1dab94658..5504d43671cab 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -57,6 +57,8 @@ $search_skype=GETPOST("search_skype"); $search_priv=GETPOST("search_priv"); $search_categ=GETPOST("search_categ",'int'); +$search_categ_thirdparty=GETPOST("search_categ_thirdparty",'int'); +$search_categ_supplier=GETPOST("search_categ_supplier",'int'); $search_status=GETPOST("search_status",'int'); $search_type=GETPOST('search_type','alpha'); if ($search_status=='') $search_status=1; // always display activ customer first @@ -191,6 +193,10 @@ $search_skype=""; $search_priv=""; $search_status=-1; + $search_categ=''; + $search_categ_thirdparty=''; + $search_categ_supplier=''; + $search_array_options=array(); } if ($search_priv < 0) $search_priv=''; @@ -220,7 +226,9 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (p.rowid = ef.fk_object)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = p.fk_pays"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc"; -if (! empty($search_categ)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_contact as cs ON p.rowid = cs.fk_socpeople"; // We need this table joined to the select in order to filter by categ +if (! empty($search_categ)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_contact as cc ON p.rowid = cc.fk_socpeople"; // We need this table joined to the select in order to filter by categ +if (! empty($search_categ_thirdparty)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; // We need this table joined to the select in order to filter by categ +if (! empty($search_categ_supplier)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cs2 ON s.rowid = cs2.fk_soc"; // We need this table joined to the select in order to filter by categ if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; $sql.= ' WHERE p.entity IN ('.getEntity('societe', 1).')'; if (!$user->rights->societe->client->voir && !$socid) //restriction @@ -243,8 +251,12 @@ if ($search_priv == '1') $sql .= " AND (p.priv='1' AND p.fk_user_creat=".$user->id.")"; } -if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$db->escape($search_categ); -if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL"; +if ($search_categ > 0) $sql.= " AND cc.fk_categorie = ".$db->escape($search_categ); +if ($search_categ == -2) $sql.= " AND cc.fk_categorie IS NULL"; +if ($search_categ_thirdparty > 0) $sql.= " AND cs.fk_categorie = ".$db->escape($search_categ_thirdparty); +if ($search_categ_thirdparty == -2) $sql.= " AND cs.fk_categorie IS NULL"; +if ($search_categ_supplier > 0) $sql.= " AND cs2.fk_categorie = ".$db->escape($search_categ_supplier); +if ($search_categ_supplier == -2) $sql.= " AND cs2.fk_categorie IS NULL"; if ($search_firstlast_only) { $sql .= natural_search(array('p.lastname','p.firstname'), $search_firstlast_only); @@ -333,7 +345,7 @@ $sql.=$hookmanager->resPrint; // Add order -if($view == "recent") +if ($view == "recent") { $sql.= $db->order("p.datec","DESC"); } @@ -350,15 +362,7 @@ $nbtotalofrecords = $db->num_rows($result); } -// Add limit -if($view == "recent") -{ - $sql.= $db->plimit($limit+1, $offset); -} -else -{ - $sql.= $db->plimit($limit+1, $offset); -} +$sql.= $db->plimit($limit+1, $offset); //print $sql; dol_syslog("contact/list.php", LOG_DEBUG); @@ -374,6 +378,8 @@ $param.='&begin='.urlencode($begin).'&view='.urlencode($view).'&userid='.urlencode($userid).'&contactname='.urlencode($sall); $param.='&type='.urlencode($type).'&view='.urlencode($view); if (!empty($search_categ)) $param.='&search_categ='.urlencode($search_categ); + if (!empty($search_categ_thirdparty)) $param.='&search_categ_thirdparty='.urlencode($search_categ_thirdparty); + if (!empty($search_categ_supplier)) $param.='&search_categ_supplier='.urlencode($search_categ_supplier); if ($search_lastname != '') $param.='&search_lastname='.urlencode($search_lastname); if ($search_firstname != '') $param.='&search_firstname='.urlencode($search_firstname); if ($search_societe != '') $param.='&search_societe='.urlencode($search_societe); @@ -423,6 +429,22 @@ $moreforfilter.=$langs->trans('Categories'). ': '; $moreforfilter.=$formother->select_categories(Categorie::TYPE_CONTACT,$search_categ,'search_categ',1); $moreforfilter.=''; + if (empty($type) || $type == 'c' || $type == 'p') + { + $moreforfilter.='
'; + if ($type == 'c') $moreforfilter.=$langs->trans('CustomersCategoriesShort'). ': '; + else if ($type == 'p') $moreforfilter.=$langs->trans('ProspectsCategoriesShort'). ': '; + else $moreforfilter.=$langs->trans('CustomersProspectsCategoriesShort'). ': '; + $moreforfilter.=$formother->select_categories(Categorie::TYPE_CUSTOMER,$search_categ_thirdparty,'search_categ_thirdparty',1); + $moreforfilter.='
'; + } + if (empty($type) || $type == 'f') + { + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('SuppliersCategoriesShort'). ': '; + $moreforfilter.=$formother->select_categories(Categorie::TYPE_SUPPLIER,$search_categ_supplier,'search_categ_supplier',1); + $moreforfilter.='
'; + } } if ($moreforfilter) { diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 350a0435d38e3..8e81c63c0ee36 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -67,20 +67,18 @@ $staticcontrat=new Contrat($db); $staticcontratligne=new ContratLigne($db); -if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers -{ - $search_name=""; - $search_contract=""; - $search_ref_supplier=""; - $search_user=''; - $search_sale=''; - $search_product_category=''; - $sall=""; - $search_status=""; -} - if ($search_status == '') $search_status=1; +$contextpage='contractlist'; + +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +$hookmanager->initHooks(array($contextpage)); +$extrafields = new ExtraFields($db); + +// fetch optionals attributes and labels +$extralabels = $extrafields->fetch_name_optionals_label('contract'); +$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); + // List of fields to search into when doing a "search in all" $fieldstosearchall = array( 'c.ref'=>'Ref', @@ -93,6 +91,35 @@ if (empty($user->socid)) $fieldstosearchall["c.note_private"]="NotePrivate"; +/* + * Action + */ + +$parameters=array(); +$reshook=$hookmanager->executeHooks('doActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + +if (empty($reshook)) +{ + +} + +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers +{ + $search_name=""; + $search_contract=""; + $search_ref_supplier=""; + $search_user=''; + $search_sale=''; + $search_product_category=''; + $sall=""; + $search_status=""; + $search_array_options=array(); +} + + /* * View */