diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php
index c05305b6393..588383021a0 100644
--- a/htdocs/admin/company.php
+++ b/htdocs/admin/company.php
@@ -83,7 +83,11 @@ if ( ($action == 'update' && ! GETPOST("cancel", 'alpha'))
$mysoc->state_label=$tmparray['label'];
$s=$mysoc->state_id.':'.$mysoc->state_code.':'.$mysoc->state_label;
- dolibarr_set_const($db, "MAIN_INFO_SOCIETE_STATE", $s,'chaine', 0, '', $conf->entity);
+ dolibarr_set_const($db, "MAIN_INFO_SOCIETE_STATE", $s, 'chaine', 0, '', $conf->entity);
+ }
+ else
+ {
+ dolibarr_del_const($db, "MAIN_INFO_SOCIETE_STATE", $conf->entity);
}
$db->begin();
@@ -385,7 +389,13 @@ if ($action == 'edit' || $action == 'updateedit')
print '
'.$langs->trans("State").' ';
- $formcompany->select_departement($conf->global->MAIN_INFO_SOCIETE_STATE, $mysoc->country_code, 'state_id');
+ $state_id=0;
+ if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE))
+ {
+ $tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_STATE);
+ $state_id=$tmp[0];
+ }
+ $formcompany->select_departement($state_id, $mysoc->country_code, 'state_id');
print ' '."\n";
@@ -774,8 +784,12 @@ else
if (! empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT)) print ''.$langs->trans("Region-State").' ';
else print ' '.$langs->trans("State").' ';
- if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE)) print getState($conf->global->MAIN_INFO_SOCIETE_STATE, $conf->global->MAIN_SHOW_STATE_CODE, 0, $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT);
- else print ' ';
+ if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE))
+ {
+ $tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_STATE);
+ $state_id=$tmp[0];
+ print getState($state_id, $conf->global->MAIN_SHOW_STATE_CODE, 0, $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT);
+ }
print ' ';
diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php
index d1366cb8511..17643e2d69a 100644
--- a/htdocs/core/class/html.formcompany.class.php
+++ b/htdocs/core/class/html.formcompany.class.php
@@ -211,13 +211,13 @@ class FormCompany
* The key of the list is the code (there can be several entries for a given code but in this case, the country field differs).
* Thus the links with the departments are done on a department independently of its name.
*
- * @param string $selected Code state preselected (mus be state id)
+ * @param int $selected Code state preselected (mus be state id)
* @param integer $country_codeid Country code or id: 0=list for all countries, otherwise country code or country rowid to show
* @param string $htmlname Id of department. If '', we want only the string with
* @return string String with HTML select
* @see select_country()
*/
- public function select_state($selected = '', $country_codeid = 0, $htmlname = 'state_id')
+ public function select_state($selected = 0, $country_codeid = 0, $htmlname = 'state_id')
{
// phpcs:enable
global $conf,$langs,$user;
diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php
index 6ccf5eb4fed..5ded310683b 100644
--- a/htdocs/societe/class/societe.class.php
+++ b/htdocs/societe/class/societe.class.php
@@ -3438,7 +3438,6 @@ class Societe extends CommonObject
$this->address=empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS)?'':$conf->global->MAIN_INFO_SOCIETE_ADDRESS;
$this->zip=empty($conf->global->MAIN_INFO_SOCIETE_ZIP)?'':$conf->global->MAIN_INFO_SOCIETE_ZIP;
$this->town=empty($conf->global->MAIN_INFO_SOCIETE_TOWN)?'':$conf->global->MAIN_INFO_SOCIETE_TOWN;
- $this->state_id=empty($conf->global->MAIN_INFO_SOCIETE_STATE)?'':$conf->global->MAIN_INFO_SOCIETE_STATE;
$this->region_code=empty($conf->global->MAIN_INFO_SOCIETE_REGION)?'':$conf->global->MAIN_INFO_SOCIETE_REGION;
$this->object=empty($conf->global->MAIN_INFO_SOCIETE_OBJECT)?'':$conf->global->MAIN_INFO_SOCIETE_OBJECT;
@@ -3472,7 +3471,7 @@ class Societe extends CommonObject
//TODO This could be replicated for region but function `getRegion` didn't exist, so I didn't added it.
// We define state_id, state_code and state
- $state_id=$state_code=$state_label='';
+ $state_id=0;$state_code=$state_label='';
if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE))
{
$tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_STATE);