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 '