diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index c4855fa5416..41528814026 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -610,19 +610,19 @@ class FormCompany /** * Retourne la liste deroulante des codes postaux et des villes associƩes */ - function select_zipcode($selected='',$htmlname='zipcode') + function select_zipcode($selected='',$field1='zipcode',$field2='town',$field3='fk_pays') { - print ajax_autocompleter('',$htmlname,DOL_URL_ROOT.'/societe/ajaxziptown.php')."\n"; - print ''."\n"; + print ajax_autocompleter_ziptown($field1,$field2,$field3,DOL_URL_ROOT.'/societe/ajaxziptown.php')."\n"; + print ''."\n"; } /** * Retourne la liste deroulante des villes et des codes postaux associƩs */ - function select_town($selected='',$htmlname='town') + function select_town($selected='',$field1='town',$field2='zipcode',$field3='fk_pays') { - print ajax_autocompleter('',$htmlname,DOL_URL_ROOT.'/societe/ajaxziptown.php')."\n"; - print ''."\n"; + print ajax_autocompleter_ziptown($field1,$field2,$field3,DOL_URL_ROOT.'/societe/ajaxziptown.php')."\n"; + print ''."\n"; } } diff --git a/htdocs/lib/ajax.lib.php b/htdocs/lib/ajax.lib.php index dc3c857e4c6..331cd90b897 100644 --- a/htdocs/lib/ajax.lib.php +++ b/htdocs/lib/ajax.lib.php @@ -128,6 +128,61 @@ function ajax_autocompleter($selected='',$htmlname,$url,$option='') return $script; } +/** + * \brief Get value of field, do Ajax process and return result + * \param htmlname nom et id du champ + * \param url chemin du fichier de reponse : /chemin/fichier.php + * \return string script complet + */ +function ajax_autocompleter_ziptown($field1,$field2,$field3,$url,$option='') +{ + $script=''; + + $script.= ''; + + return $script; +} + /** * Show an ajax dialog * @param title Title of dialog box diff --git a/htdocs/societe/ajaxziptown.php b/htdocs/societe/ajaxziptown.php index cffdc426b1a..b582c27ab0d 100644 --- a/htdocs/societe/ajaxziptown.php +++ b/htdocs/societe/ajaxziptown.php @@ -95,10 +95,18 @@ if (! empty($_GET['zipcode']) || ! empty($_GET['town'])) { $country = $row['fk_country']?($langs->trans('Country'.$row['country_code'])!='Country'.$row['country_code']?$langs->trans('Country'.$row['country_code']):$row['country']):''; - $row_array['label'] = $row['zip'].' '.$row['town'].' ('.$country.')'; - $row_array['zip'] = $row['zip']; - $row_array['town'] = $row['town']; - $row_array['fk_country'] = $row['fk_country']; + $row_array['label'] = $row['zip'].' '.$row['town'].' ('.$country.')'; + if ($zipcode) + { + $row_array['value'] = $row['zip']; + $row_array['field2'] = $row['town']; + } + if ($town) + { + $row_array['value'] = $row['town']; + $row_array['field2'] = $row['zip']; + } + $row_array['field3'] = $row['fk_country']; array_push($return_arr,$row_array); } diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 0b17186f0fb..26bb6f95ea1 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -3,7 +3,7 @@ * Copyright (C) 2003 Brian Fraval * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005 Eric Seigne - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2008 Patrick Raguin * Copyright (C) 2010 Juanjo Menent * @@ -767,10 +767,14 @@ else print ''; // Zip / Town - print ''.$langs->trans('Zip').''; - if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; - print ''; - print ''.$langs->trans('Town').''; + print ''.$langs->trans('Zip').''; + $formcompany->select_zipcode($soc->cp,'zipcode','town','selectpays_id'); + //print ''; + //if ($conf->use_javascript_ajax && $conf->global->MAIN_AUTOFILL_TOWNFROMZIP) print ' '; + print ''.$langs->trans('Town').''; + $formcompany->select_zipcode($soc->ville,'town','zipcode','selectpays_id'); + //print ''; + print ''; // Country print ''.$langs->trans('Country').'';