diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 6abfd2312e3..c99683601d8 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1888,8 +1888,7 @@ function dol_format_address($object, $withcountry = 0, $sep = "\n", $outputlangs $ret .= ($extralangcode ? $object->array_languages['address'][$extralangcode] : $object->address); } // Zip/Town/State - if (in_array($object->country_code, array('AU', 'CA', 'US')) || !empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS)) // US: title firstname name \n address lines \n town, state, zip \n country - { + if (isset($object->country_code) && in_array($object->country_code, array('AU', 'CA', 'US')) || !empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS)) { // US: title firstname name \n address lines \n town, state, zip \n country $town = ($extralangcode ? $object->array_languages['town'][$extralangcode] : $object->town); $ret .= ($ret ? $sep : '').$town; if ($object->state) @@ -1897,8 +1896,7 @@ function dol_format_address($object, $withcountry = 0, $sep = "\n", $outputlangs $ret .= ($ret ? ", " : '').$object->state; } if ($object->zip) $ret .= ($ret ? ", " : '').$object->zip; - } elseif (in_array($object->country_code, array('GB', 'UK'))) // UK: title firstname name \n address lines \n town state \n zip \n country - { + } elseif (isset($object->country_code) && in_array($object->country_code, array('GB', 'UK'))) { // UK: title firstname name \n address lines \n town state \n zip \n country $town = ($extralangcode ? $object->array_languages['town'][$extralangcode] : $object->town); $ret .= ($ret ? $sep : '').$town; if ($object->state) @@ -1906,8 +1904,7 @@ function dol_format_address($object, $withcountry = 0, $sep = "\n", $outputlangs $ret .= ($ret ? ", " : '').$object->state; } if ($object->zip) $ret .= ($ret ? $sep : '').$object->zip; - } elseif (in_array($object->country_code, array('ES', 'TR'))) // ES: title firstname name \n address lines \n zip town \n state \n country - { + } elseif (isset($object->country_code) && in_array($object->country_code, array('ES', 'TR'))) { // ES: title firstname name \n address lines \n zip town \n state \n country $ret .= ($ret ? $sep : '').$object->zip; $town = ($extralangcode ? $object->array_languages['town'][$extralangcode] : $object->town); $ret .= ($town ? (($object->zip ? ' ' : '').$town) : ''); @@ -1915,14 +1912,12 @@ function dol_format_address($object, $withcountry = 0, $sep = "\n", $outputlangs { $ret .= "\n".$object->state; } - } elseif (in_array($object->country_code, array('IT'))) // IT: tile firstname name\n address lines \n zip (Code Departement) \n country - { + } elseif (isset($object->country_code) && in_array($object->country_code, array('IT'))) { // IT: tile firstname name\n address lines \n zip (Code Departement) \n country $ret .= ($ret ? $sep : '').$object->zip; $town = ($extralangcode ? $object->array_languages['town'][$extralangcode] : $object->town); $ret .= ($town ? (($object->zip ? ' ' : '').$town) : ''); $ret .= ($object->state_code ? (' '.($object->state_code)) : ''); - } else // Other: title firstname name \n address lines \n zip town \n country - { + } else { // Other: title firstname name \n address lines \n zip town \n country $town = ($extralangcode ? $object->array_languages['town'][$extralangcode] : $object->town); $ret .= $object->zip ? (($ret ? $sep : '').$object->zip) : ''; $ret .= ($town ? (($object->zip ? ' ' : ($ret ? $sep : '')).$town) : ''); @@ -1932,10 +1927,9 @@ function dol_format_address($object, $withcountry = 0, $sep = "\n", $outputlangs } } if (!is_object($outputlangs)) $outputlangs = $langs; - if ($withcountry) - { + if ($withcountry) { $langs->load("dict"); - $ret .= ($object->country_code ? ($ret ? $sep : '').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$object->country_code)) : ''); + $ret .= (empty($object->country_code) ? '' : ($ret ? $sep : '').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv("Country".$object->country_code))); } return $ret;