From 15de773bc0284df78f29b70139dc8f70bb92b181 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 22 Jun 2007 18:51:11 +0000 Subject: [PATCH] =?UTF-8?q?Add:=20d=E9but=20ajout=20autocompletion=20ajax?= =?UTF-8?q?=20sur=20la=20liste=20des=20soci=E9t=E9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/commonobject.class.php | 92 +++++++++++++++++++++----------- htdocs/societe/ajaxcompanies.php | 64 ++++++++++++++++++++++ 2 files changed, 126 insertions(+), 30 deletions(-) create mode 100644 htdocs/societe/ajaxcompanies.php diff --git a/htdocs/commonobject.class.php b/htdocs/commonobject.class.php index 3c3ae0c2bb7..ef3968465d2 100644 --- a/htdocs/commonobject.class.php +++ b/htdocs/commonobject.class.php @@ -382,45 +382,77 @@ class CommonObject */ function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany') { + global $conf, $langs; + // On recherche les societes $sql = "SELECT s.rowid, s.nom FROM"; $sql .= " ".MAIN_DB_PREFIX."societe as s"; - //if ($filter) $sql .= " WHERE $filter"; + if ($conf->use_ajax && $conf->global->CODE_DE_TEST == 1) + { + $sql.= " WHERE rowid = ".$selected; + } $sql .= " ORDER BY nom ASC"; $resql = $object->db->query($sql); if ($resql) { - $javaScript = "window.location='./contact.php?".$var_id."=".$object->id."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;"; - print '\n"; - return $firstCompany; - } - else - { - dolibarr_print_error($object->db); - } - } + $langs->load("companies"); + $obj = $this->db->fetch_object($resql); + $socid = $obj->rowid?$obj->rowid:''; + $javaScript = "window.location=\'./contact.php?".$var_id."=".$object->id."&".$htmlname."=\' + document.getElementById(\'newcompany_id\').value;"; + + // On applique un delai d'execution pour le bon fonctionnement + $htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\')"'; + + print '
'; + if ($obj->rowid == 0) + { + print ''; + } + else + { + print ''; + } + + print ajax_autocompleter($socid,'newcompany','/societe/ajaxcompanies.php','working'); + return $socid; + } + else + { + $javaScript = "window.location='./contact.php?".$var_id."=".$object->id."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;"; + print '\n"; + return $firstCompany; + } + } + else + { + dolibarr_print_error($object->db); + } + } + /** * diff --git a/htdocs/societe/ajaxcompanies.php b/htdocs/societe/ajaxcompanies.php new file mode 100644 index 00000000000..a0a2ec58ba3 --- /dev/null +++ b/htdocs/societe/ajaxcompanies.php @@ -0,0 +1,64 @@ + + * Copyright (C) 2005-2007 Regis Houssin + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/societe/ajaxcountries.php + \brief Fichier de reponse sur evenement Ajax + \version $Revision$ +*/ + +require('../main.inc.php'); + +top_htmlhead("", "", 1, 1); + +print ''; + +// Generation liste des sociétés +if(isset($_POST['newcompany']) && !empty($_POST['newcompany'])) +{ + global $langs; + $langs->load("dict"); + + $sql = "SELECT rowid, nom"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe"; + $sql.= " WHERE nom LIKE '%" . utf8_decode($_POST['newcompany']) . "%'"; + $sql.= " ORDER BY nom ASC;"; + + $resql=$db->query($sql); + + if ($resql) + { + print '
    '; + while($company = $db->fetch_object($resql)) + { + print '
  • '; + print $company->nom; + print ''; + print '
  • '; + } + print '
'; + } +} + +print ""; +print ""; +?>