Skip to content

Commit

Permalink
FIX Clear of filter should also reset categories and extrafields filter
Browse files Browse the repository at this point in the history
FIX Filter on categories should depends on context
  • Loading branch information
eldy committed Jul 13, 2016
1 parent 490336b commit c787e7f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 25 deletions.
48 changes: 35 additions & 13 deletions htdocs/contact/list.php
Expand Up @@ -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
Expand Down Expand Up @@ -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='';

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -333,7 +345,7 @@
$sql.=$hookmanager->resPrint;

// Add order
if($view == "recent")
if ($view == "recent")
{
$sql.= $db->order("p.datec","DESC");
}
Expand All @@ -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);
Expand All @@ -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.='&amp;search_lastname='.urlencode($search_lastname);
if ($search_firstname != '') $param.='&amp;search_firstname='.urlencode($search_firstname);
if ($search_societe != '') $param.='&amp;search_societe='.urlencode($search_societe);
Expand Down Expand Up @@ -423,6 +429,22 @@
$moreforfilter.=$langs->trans('Categories'). ': ';
$moreforfilter.=$formother->select_categories(Categorie::TYPE_CONTACT,$search_categ,'search_categ',1);
$moreforfilter.='</div>';
if (empty($type) || $type == 'c' || $type == 'p')
{
$moreforfilter.='<div class="divsearchfield">';
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.='</div>';
}
if (empty($type) || $type == 'f')
{
$moreforfilter.='<div class="divsearchfield">';
$moreforfilter.=$langs->trans('SuppliersCategoriesShort'). ': ';
$moreforfilter.=$formother->select_categories(Categorie::TYPE_SUPPLIER,$search_categ_supplier,'search_categ_supplier',1);
$moreforfilter.='</div>';
}
}
if ($moreforfilter)
{
Expand Down
51 changes: 39 additions & 12 deletions htdocs/contrat/list.php
Expand Up @@ -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',
Expand All @@ -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
*/
Expand Down

0 comments on commit c787e7f

Please sign in to comment.