natural search in list pages

This commit is contained in:
Cédric Salvador
2013-09-10 16:43:06 +02:00
parent 9826b202e9
commit d9a26d0aa9
422 changed files with 126638 additions and 126593 deletions

View File

@@ -2,6 +2,7 @@
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -115,9 +116,13 @@ if ($catid > 0) $sql.= " AND cs.fk_categorie = ".$catid;
if ($catid == -2) $sql.= " AND cs.fk_categorie IS NULL";
if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$search_categ;
if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL";
if ($search_nom) $sql.= " AND s.nom LIKE '%".$db->escape($search_nom)."%'";
if ($search_nom) {
$sql .= natural_search(array('s.nom'), $search_nom);
}
if ($search_zipcode) $sql.= " AND s.zip LIKE '".$db->escape($search_zipcode)."%'";
if ($search_town) $sql.= " AND s.town LIKE '%".$db->escape($search_town)."%'";
if ($search_town) {
$sql .= natural_search(array('s.town'), $search_town);
}
if ($search_code) $sql.= " AND s.code_client LIKE '%".$db->escape($search_code)."%'";
if ($search_compta) $sql.= " AND s.code_compta LIKE '%".$db->escape($search_compta)."%'";
// Insert sale filter

View File

@@ -8,6 +8,7 @@
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010-2011 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -160,21 +161,17 @@ if (! $user->rights->societe->client->voir && ! $socid) //restriction
{
$sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
}
if ($search_town) //restriction
{
$sql.= " AND s.town LIKE '%".$db->escape(trim($search_town))."%'";
if ($search_town) {//restriction
$sql .= natural_search(array('s.town'), $search_town);
}
if ($search_ref)
{
$sql.= " AND p.ref LIKE '%".$db->escape(trim($search_ref))."%'";
if ($search_ref) {
$sql .= natural_search(array('p.ref'), $search_ref);
}
if ($search_refcustomer)
{
$sql.= " AND p.ref_client LIKE '%".$db->escape(trim($search_refcustomer))."%'";
if ($search_refcustomer) {
$sql .= natural_search(array('p.ref_client'), $search_refcustomer);
}
if ($search_societe)
{
$sql.= " AND s.nom LIKE '%".$db->escape(trim($search_societe))."%'";
if ($search_societe) {
$sql .= natural_search(array('s.nom'), $search_societe);
}
if ($search_author)
{
@@ -184,7 +181,13 @@ if ($search_montant_ht)
{
$sql.= " AND p.total_ht='".$db->escape(price2num(trim($search_montant_ht)))."'";
}
if ($sall) $sql.= " AND (s.nom LIKE '%".$db->escape($sall)."%' OR p.note_private LIKE '%".$db->escape($sall)."%' OR pd.description LIKE '%".$db->escape($sall)."%')";
if ($sall) {
/*$scrit = explode(' ', $sall);
foreach ($scrit as $crit) {
$sql.= " AND (s.nom LIKE '%".$db->escape($crit)."%' OR p.note LIKE '%".$db->escape($crit)."%' OR pd.description LIKE '%".$db->escape($crit)."%')";
}*/
$sql .= natural_search(array('s.nom', 'p.note_private', 'pd.description'), $sall);
}
if ($socid) $sql.= ' AND s.rowid = '.$socid;
if ($viewstatut <> '')
{
@@ -289,7 +292,7 @@ if ($result)
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="16" name="search_societe" value="'.$search_societe.'">';
print '</td>';
print '<td>&nbsp;</td>';
print '<td class="liste_titre"><input class="flat" type="text" size="16" name="search_town" value="'.$search_town.'"></td>';
print '<td class="liste_titre">';
print '<input class="flat" size="10" type="text" name="search_refcustomer" value="'.$search_refcustomer.'">';
print '</td>';

View File

@@ -4,6 +4,7 @@
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -193,10 +194,16 @@ if ($catid > 0) $sql.= " AND cs.fk_categorie = ".$catid;
if ($catid == -2) $sql.= " AND cs.fk_categorie IS NULL";
if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$search_categ;
if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL";
if ($search_nom) $sql .= " AND s.nom LIKE '%".$db->escape(strtolower($search_nom))."%'";
if ($search_nom) {
$sql .= natural_search(array('s.nom'), $search_nom);
}
if ($search_zipcode) $sql .= " AND s.zip LIKE '".$db->escape(strtolower($search_zipcode))."%'";
if ($search_town) $sql .= " AND s.town LIKE '%".$db->escape(strtolower($search_town))."%'";
if ($search_state) $sql .= " AND d.nom LIKE '%".$db->escape(strtolower($search_state))."%'";
if ($search_town) {
$sql .= natural_search(array('s.town'), $search_town);
}
if ($search_state) {
$sql .= natural_search(array('d.nom'), $search_state);
}
if ($search_datec) $sql .= " AND s.datec LIKE '%".$db->escape($search_datec)."%'";
// Insert levels filters
if ($search_levels)
@@ -208,9 +215,8 @@ if ($search_sale)
{
$sql .= " AND sc.fk_user = ".$db->escape($search_sale);
}
if ($socname)
{
$sql .= " AND s.nom LIKE '%".$db->escape($socname)."%'";
if ($socname) {
$sql .= natural_search(array('s.nom'), $search_nom);
$sortfield = "s.nom";
$sortorder = "ASC";
}

View File

@@ -5,6 +5,7 @@
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -125,13 +126,12 @@ $sql.= ' WHERE c.fk_soc = s.rowid';
$sql.= ' AND c.entity = '.$conf->entity;
if ($socid) $sql.= ' AND s.rowid = '.$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($sref)
{
$sql.= " AND c.ref LIKE '%".$db->escape($sref)."%'";
if ($sref) {
$sql .= natural_search(array('c.ref'), $sref);
}
if ($sall)
{
$sql.= " AND (c.ref LIKE '%".$db->escape($sall)."%' OR c.note LIKE '%".$db->escape($sall)."%')";
$sql .= natural_search(array('c.ref', 'c.note_private'), $sall);
}
if ($viewstatut <> '')
{
@@ -187,7 +187,7 @@ else if ($deliveryyear > 0)
}
if (!empty($snom))
{
$sql.= ' AND s.nom LIKE \'%'.$db->escape($snom).'%\'';
$sql .= natural_search(array('s.nom'), $snom);
}
if (!empty($sref_client))
{

View File

@@ -2,6 +2,7 @@
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -75,11 +76,11 @@ if (trim($search_ref) != '')
}
if (trim($search_company) != '')
{
$sql.= ' AND d.societe LIKE \'%'.$db->escape(trim($search_company)) . '%\'';
$sql .= natural_search(array('d.societe'), $search_company);
}
if (trim($search_name) != '')
{
$sql.= ' AND d.lastname LIKE \'%'.$db->escape(trim($search_name)) . '%\' OR d.firstname LIKE \'%'.$db->escape(trim($search_name)) . '%\'';
$sql .= natural_search(array('d.lastname', 'd.firstname'), $search_name);
}
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit+1, $offset);

View File

@@ -8,6 +8,7 @@
* Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -174,11 +175,11 @@ if ($filtre)
}
if ($search_ref)
{
$sql.= ' AND f.facnumber LIKE \'%'.$db->escape(trim($search_ref)).'%\'';
$sql .= natural_search(array('f.facnumber'), $search_ref);
}
if ($search_societe)
{
$sql.= ' AND s.nom LIKE \'%'.$db->escape(trim($search_societe)).'%\'';
$sql .= natural_search(array('s.nom'), $search_societe);
}
if ($search_montant_ht)
{
@@ -219,7 +220,7 @@ if (! $sall)
}
else
{
$sql.= ' AND (s.nom LIKE \'%'.$db->escape($sall).'%\' OR f.facnumber LIKE \'%'.$db->escape($sall).'%\' OR f.note LIKE \'%'.$db->escape($sall).'%\' OR fd.description LIKE \'%'.$db->escape($sall).'%\')';
$sql .= natural_search(array('s.nom', 'f.facnumber', 'f.note_public', 'fd.description'), $sall);
}
$sql.= ' ORDER BY ';
$listfield=explode(',',$sortfield);

View File

@@ -2,6 +2,7 @@
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -112,7 +113,7 @@ else
if (GETPOST("search_account") > 0) $sql .=" AND b.fk_account=".GETPOST("search_account",'int');
if (GETPOST("search_paymenttype") != "") $sql .=" AND c.code='".GETPOST("search_paymenttype")."'";
if (GETPOST("search_amount")) $sql .=" AND p.amount=".price2num(GETPOST("search_amount"));
if (GETPOST("search_company")) $sql .=" AND s.nom LIKE '%".$db->escape(GETPOST("search_company"))."%'";
if (GETPOST("search_company")) $sql .= natural_search(array('s.nom'), GETPOST('search_company'));
}
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit+1, $offset);

View File

@@ -4,6 +4,7 @@
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -148,21 +149,17 @@ else
if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$search_categ;
if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL";
if ($search_lastname) // filter on lastname
{
$sql .= " AND p.lastname LIKE '%".$db->escape($search_lastname)."%'";
if ($search_lastname) { // filter on lastname
$sql .= natural_search(array('p.lastname'), $search_lastname);
}
if ($search_firstname) // filter on firstname
{
$sql .= " AND p.firstname LIKE '%".$db->escape($search_firstname)."%'";
if ($search_firstname) { // filter on firstname
$sql .= natural_search(array('p.firstname'), $search_firstname);
}
if ($search_societe) // filtre sur la societe
{
$sql .= " AND s.nom LIKE '%".$db->escape($search_societe)."%'";
if ($search_societe) { // filtre sur la societe
$sql .= natural_search(array('s.nom'), $search_societe);
}
if (strlen($search_poste)) // filtre sur la societe
{
$sql .= " AND p.poste LIKE '%".$db->escape($search_poste)."%'";
if (strlen($search_poste)) { // filtre sur la societe
$sql .= natural_search(array('p.poste'), $search_poste);
}
if (strlen($search_phone))
{
@@ -206,11 +203,7 @@ else if ($type == "p") // filtre sur type
}
if ($sall)
{
// For natural search
$scrit = explode(' ', $sall);
foreach ($scrit as $crit) {
$sql .= " AND (p.lastname LIKE '%".$db->escape($crit)."%' OR p.firstname LIKE '%".$db->escape($crit)."%' OR p.email LIKE '%".$db->escape($crit)."%')";
}
$sql .= natural_search(array('p.lastname', 'p.firstname', 'p.email'), $sall);
}
if (! empty($socid))
{

View File

@@ -2,6 +2,7 @@
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -79,9 +80,15 @@ $sql.= " WHERE c.fk_soc = s.rowid ";
$sql.= " AND c.entity = ".$conf->entity;
if ($socid) $sql.= " AND s.rowid = ".$socid;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($search_nom) $sql.= " AND s.nom LIKE '%".$db->escape($search_nom)."%'";
if ($search_contract) $sql.= " AND (".(is_numeric($search_contract)?"c.rowid = ".$db->escape($search_contract)." OR ":'')." c.ref LIKE '%".$db->escape($search_contract)."%')";
if ($sall) $sql.= " AND (s.nom LIKE '%".$db->escape($sall)."%' OR cd.label LIKE '%".$db->escape($sall)."%' OR cd.description LIKE '%".$db->escape($sall)."%')";
if ($search_nom) {
$sql .= natural_search(array('s.nom'), $search_nom);
}
if ($search_contract) {
$sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);
}
if ($sall) {
$sql .= natural_search(array('s.nom', 'cd.label', 'cd.description'), $sall);
}
$sql.= " GROUP BY c.rowid, c.ref, c.datec, c.date_contrat, c.statut,";
$sql.= " s.nom, s.rowid";
$sql.= " ORDER BY $sortfield $sortorder";

View File

@@ -8,6 +8,7 @@
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -4436,4 +4437,35 @@ if (! function_exists('getmypid'))
}
}
/**
* Natural search
* @param array[string] $fields array filled with the fields names in the SQL query
* @param string $value the value to look for
* @return string $res the statement to append to the SQL query
* */
function natural_search($fields, $value)
{
global $db;
$crits = explode(' ', $value);
$res = "";
$end = count($fields);
$end2 = count($crits);
$j = 0;
foreach ($crits as $crit) {
$i = 0;
foreach ($fields as $field) {
if ( $i > 0 && $i < $end){
$res .= " OR ";
}
$res .= $field . " LIKE '%" . $db->escape(trim($crit)) . "%'";
$i++;
}
if ($end > 1) $res .= ')';
if ($j < $end2 - 1) $res .= " AND ";
if ($end > 1 && $j < $end2 - 1) $res .= '(';
$j++;
}
return " AND " . ($end > 1? '(' : '') . $res;
}
?>

View File

@@ -3,6 +3,7 @@
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -73,9 +74,15 @@ $sql.= ", ".MAIN_DB_PREFIX."fichinter as f)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."fichinterdet as fd ON fd.fk_fichinter = f.rowid";
$sql.= " WHERE f.fk_soc = s.rowid ";
$sql.= " AND f.entity = ".$conf->entity;
if ($search_ref) $sql .= " AND f.ref LIKE '%".$db->escape($search_ref)."%'";
if ($search_company) $sql .= " AND s.nom LIKE '%".$db->escape($search_company)."%'";
if ($search_desc) $sql .= " AND (f.description LIKE '%".$db->escape($search_desc)."%' OR fd.description LIKE '%".$db->escape($search_desc)."%')";
if ($search_ref) {
$sql .= natural_search(array('f.ref'), $search_ref);
}
if ($search_company) {
$sql .= natural_search(array('s.nom'), $search_company);
}
if ($search_desc) {
$sql .= natural_search(array('f.description', 'fd.description'), $search_desc);
}
if (! $user->rights->societe->client->voir && empty($socid))
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid)

View File

@@ -2,6 +2,7 @@
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -92,11 +93,11 @@ $sql.= " AND cf.entity = ".$conf->entity;
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($sref)
{
$sql.= " AND cf.ref LIKE '%".$db->escape($sref)."%'";
$sql .= natural_search(array('cf.ref'), $sref);
}
if ($snom)
{
$sql.= " AND s.nom LIKE '%".$db->escape($snom)."%'";
$sql .= natural_search(array('s.nom'), $snom);
}
if ($suser)
{
@@ -108,7 +109,7 @@ if ($sttc)
}
if ($sall)
{
$sql.= " AND (cf.ref LIKE '%".$db->escape($sall)."%' OR cf.note LIKE '%".$db->escape($sall)."%')";
$sql .= natural_search(array('cf.ref', 'cf.note_public'), $sall);
}
if ($socid) $sql.= " AND s.rowid = ".$socid;

View File

@@ -4,6 +4,7 @@
* Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -130,12 +131,12 @@ if (GETPOST('filtre'))
if (GETPOST("search_ref"))
{
if (is_numeric(GETPOST("search_ref"))) $sql .= " AND (fac.rowid = ".GETPOST("search_ref",'int')." OR fac.ref = '".$db->escape(GETPOST("search_ref"))."')"; // For backward compatibility
else $sql .= " AND fac.ref LIKE '%".$db->escape(GETPOST("search_ref"))."%'";
if (is_numeric(GETPOST("search_ref"))) $sql .= natural_search(array('fac.rowid', 'fac.ref'), GETPOST('search_ref'));// For backward compatibility
else $sql .= natural_search(array('fac.ref'), GETPOST("search_ref"));
}
if (GETPOST("search_ref_supplier"))
{
$sql .= " AND fac.ref_supplier LIKE '%".$db->escape(GETPOST("search_ref_supplier"))."%'";
$sql .= natural_search(array('fac.ref_supplier'), GETPOST('search_ref_supplier'));
}
if ($month > 0)
{
@@ -150,12 +151,12 @@ else if ($year > 0)
}
if (GETPOST("search_libelle"))
{
$sql .= " AND fac.libelle LIKE '%".$db->escape(GETPOST("search_libelle"))."%'";
$sql .= natural_search(array('fac.libelle'), GETPOST('search_libelle'));
}
if (GETPOST("search_societe"))
{
$sql .= " AND s.nom LIKE '%".$db->escape(GETPOST("search_societe"))."%'";
$sql .= natural_search(array('s.nom'), GETPOST('search_societe'));
}
if (GETPOST("search_montant_ht"))

View File

@@ -3,6 +3,7 @@
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -88,15 +89,18 @@ $sql.= " WHERE s.fk_stcomm = st.id AND s.fournisseur = 1";
$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 ($socname)
{
$sql .= " AND s.nom LIKE '%".$db->escape($socname)."%'";
if ($socname) {
$sql .= natural_search(array('s.nom'), $socname);
$sortfield = "s.nom";
$sortorder = "ASC";
}
if ($search_nom) $sql .= " AND s.nom LIKE '%".$db->escape($search_nom)."%'";
if ($search_nom) {
$sql .= natural_search(array('s.nom'), $search_nom);
}
if ($search_zipcode) $sql .= " AND s.zip LIKE '".$db->escape($search_zipcode)."%'";
if ($search_town) $sql .= " AND s.town LIKE '%".$db->escape($search_town)."%'";
if ($search_town) {
$sql .= natural_search(array('s.town'), $search_town);
}
if ($search_code_fournisseur) $sql .= " AND s.code_fournisseur LIKE '%".$db->escape($search_code_fournisseur)."%'";
if ($search_compta_fournisseur) $sql .= " AND s.code_compta_fournisseur LIKE '%".$db->escape($search_compta_fournisseur)."%'";
if ($search_datec) $sql .= " AND s.datec LIKE '%".$db->escape($search_datec)."%'";

View File

@@ -4,6 +4,7 @@
* Copyright (C) 2005-2007 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -35,35 +36,32 @@ $langs->load("suppliers");
if (!$user->rights->produit->lire && !$user->rights->service->lire) accessforbidden();
$sref=isset($_GET["sref"])?$_GET["sref"]:$_POST["sref"];
$sRefSupplier=isset($_GET["srefsupplier"])?$_GET["srefsupplier"]:$_POST["srefsupplier"];
$snom=isset($_GET["snom"])?$_GET["snom"]:$_POST["snom"];
$sref = GETPOST('sref');
$sRefSupplier = GETPOST('srefsupplier');
$snom = GETPOST('snom');
$type = GETPOST('type');
$type=isset($_GET["type"])?$_GET["type"]:$_POST["type"];
$sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
$sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
$page = $_GET["page"];
$sortfield = GETPOST('sortfield');
$sortorder = GETPOST('sortorder');
$page = GETPOST('page');
if ($page < 0) {
$page = 0 ; }
$page = 0 ;
}
$limit = $conf->liste_limit;
$offset = $limit * $page ;
if (! $sortfield) $sortfield="p.ref";
if (! $sortorder) $sortorder="DESC";
if (! $sortfield) $sortfield = 'p.ref';
if (! $sortorder) $sortorder = 'DESC';
if (! empty($_POST["button_removefilter"]))
if (! empty(GETPOST('button_removefilter')))
{
$sref="";
$sRefSupplier="";
$snom="";
$sref = '';
$sRefSupplier = '';
$snom = '';
}
if ($_GET["fourn_id"] > 0 || $_POST["fourn_id"] > 0)
{
$fourn_id = isset($_GET["fourn_id"])?$_GET["fourn_id"]:$_POST["fourn_id"];
}
$fourn_id = GETPOST('fourn_id', 'int');
if (isset($_REQUEST['catid']))
{
@@ -96,38 +94,33 @@ if ($catid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.f
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as ppf ON p.rowid = ppf.fk_product";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ppf.fk_soc = s.rowid";
$sql.= " WHERE p.entity IN (".getEntity('product', 1).")";
if ($_POST["mode"] == 'search')
if (GETPOST('mode', 'alpha') == 'search')
{
$sql .= " AND (p.ref LIKE '%".$_POST["sall"]."%'";
$sql .= " OR p.label LIKE '%".$_POST["sall"]."%')";
if ($sRefSupplier)
{
$sql .= " AND ppf.ref_fourn LIKE '%".$sRefSupplier."%'";
}
$sql .= natural_search(array('p.ref', 'p.label'), GETPOST('mode', 'alpha'));
}
else
{
if ($_GET["type"] || $_POST["type"])
if (GETPOST('type'))
{
$sql .= " AND p.fk_product_type = ".(isset($_GET["type"])?$_GET["type"]:$_POST["type"]);
$sql .= " AND p.fk_product_type = " . GETPOST('type'));
}
if ($sref)
{
$sql .= " AND p.ref LIKE '%".$sref."%'";
}
if ($sRefSupplier)
{
$sql .= " AND ppf.ref_fourn LIKE '%".$sRefSupplier."%'";
$sql .= natural_search(array('p.ref'), $sref);
}
if ($snom)
{
$sql .= " AND p.label LIKE '%".$snom."%'";
$sql .= natural_search(array('p.label'), $snom);
}
if($catid)
{
$sql .= " AND cp.fk_categorie = ".$catid;
}
}
if ($sRefSupplier)
{
$sql .= natural_search(array('ppf.ref_fourn'), $sRefSupplier);
}
if ($fourn_id > 0)
{
$sql .= " AND ppf.fk_soc = ".$fourn_id;

View File

@@ -137,55 +137,44 @@ else
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
// multilang
if ($conf->global->MAIN_MULTILANGS) // si l'option est active
{
{
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang = '".$langs->getDefaultLang() ."'";
}
$sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')';
if ($sall)
{
// For natural search
$scrit = explode(' ', $sall);
$sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')';
if ($sall) {
// For natural search
$params = array('p.ref', 'p.label', 'p.description', 'p.note');
// multilang
if ($conf->global->MAIN_MULTILANGS) // si l'option est active
{
foreach ($scrit as $crit) {
$sql.= " AND (p.ref LIKE '%".$db->escape($crit)."%' OR p.label LIKE '%".$db->escape($crit)."%' OR p.description LIKE '%".$db->escape($crit)."%' OR p.note LIKE '%".$db->escape($crit)."%' OR pl.description LIKE '%".$db->escape($sall)."%' OR pl.note LIKE '%".$db->escape($sall)."%'";
if (! empty($conf->barcode->enabled))
{
$sql.= " OR p.barcode LIKE '%".$db->escape($crit)."%'";
}
$sql.= ')';
}
}
else
{
foreach ($scrit as $crit) {
$sql.= " AND (p.ref LIKE '%".$db->escape($crit)."%' OR p.label LIKE '%".$db->escape($crit)."%' OR p.description LIKE '%".$db->escape($crit)."%' OR p.note LIKE '%".$db->escape($crit)."%'";
if (! empty($conf->barcode->enabled))
{
$sql.= " OR p.barcode LIKE '%".$db->escape($crit)."%'";
}
$sql.= ')';
}
$params[] = 'pl.description';
$params[] = 'pl.note';
}
}
if (! empty($conf->barcode->enabled)) {
$params[] = 'p.barcode';
}
$sql .= natural_search($params, $sall);
}
// if the type is not 1, we show all products (type = 0,2,3)
if (dol_strlen($type))
{
if ($type == 1) $sql.= " AND p.fk_product_type = '1'";
else $sql.= " AND p.fk_product_type <> '1'";
}
if ($sref) $sql.= " AND p.ref LIKE '%".$sref."%'";
if ($sref) {
$sql .= natural_search(array('p.ref'), $sref);
}
if ($sbarcode) $sql.= " AND p.barcode LIKE '%".$sbarcode."%'";
if ($snom)
{
$params = array('p.label');
// multilang
if ($conf->global->MAIN_MULTILANGS) // si l'option est active
{
$sql.= " AND (p.label LIKE '%".$db->escape($snom)."%' OR (pl.label IS NOT null AND pl.label LIKE '%".$db->escape($snom)."%'))";
{
$params[] = 'pl.label';
}
else $sql.= " AND p.label LIKE '%".$db->escape($snom)."%'";
}
$sql .= natural_search($params, $snom);
}
if (isset($tosell) && dol_strlen($tosell) > 0) $sql.= " AND p.tosell = ".$db->escape($tosell);
if (isset($tobuy) && dol_strlen($tobuy) > 0) $sql.= " AND p.tobuy = ".$db->escape($tobuy);
if (dol_strlen($canvas) > 0) $sql.= " AND p.canvas = '".$db->escape($canvas)."'";

View File

@@ -3,6 +3,7 @@
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Bariley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -84,17 +85,17 @@ if ($mine || ! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$pro
// No need to check company, as filtering of projects must be done by getProjectsAuthorizedForUser
//if ($socid || ! $user->rights->societe->client->voir) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
if ($_GET["search_ref"])
if ($search_ref)
{
$sql.= " AND p.ref LIKE '%".$db->escape($search_ref)."%'";
$sql .= natural_search(array('p.ref'), $search_ref);
}
if ($_GET["search_label"])
if ($search_label)
{
$sql.= " AND p.title LIKE '%".$db->escape($search_label)."%'";
$sql .= natural_search(array('p.title'), $search_label);
}
if ($_GET["search_societe"])
if ($search_societe)
{
$sql.= " AND s.nom LIKE '%".$db->escape($search_societe)."%'";
$sql .= natural_search(array('s.nom'), $search_societe);
}
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($conf->liste_limit+1, $offset);