diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 3f128ab9c5a..b67ded65c6e 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -589,8 +589,9 @@ class Adherent extends CommonObject $this->town = ($this->town ? $this->town : $this->town); $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id); $this->state_id = ($this->state_id > 0 ? $this->state_id : $this->state_id); - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords(trim($this->lastname)); - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords(trim($this->firstname)); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = dol_ucwords(dol_strtolower($this->lastname)); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = dol_strtoupper($this->lastname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = dol_ucwords(dol_strtolower($this->firstname)); $this->note_public = ($this->note_public ? $this->note_public : $this->note_public); $this->note_private = ($this->note_private ? $this->note_private : $this->note_private); diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index ab6e3c732c9..2034803ecb8 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -353,9 +353,9 @@ class Contact extends CommonObject // Clean parameters $this->lastname = $this->lastname ?trim($this->lastname) : trim($this->name); $this->firstname = trim($this->firstname); - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords(strtolower($this->lastname)); - if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname); - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords(strtolower($this->firstname)); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = dol_ucwords(dol_strtolower($this->lastname)); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = dol_strtoupper($this->lastname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = dol_ucwords(dol_strtolower($this->firstname)); if (empty($this->socid)) $this->socid = 0; if (empty($this->priv)) $this->priv = 0; if (empty($this->statut)) $this->statut = 0; // This is to convert '' into '0' to avoid bad sql request @@ -464,9 +464,9 @@ class Contact extends CommonObject $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); // Clean parameters - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords(strtolower($this->lastname)); - if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname); - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords(strtolower($this->firstname)); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = dol_ucwords(dol_strtolower($this->lastname)); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = dol_strtoupper($this->lastname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = dol_ucwords(dol_strtolower($this->firstname)); $this->lastname = trim($this->lastname) ?trim($this->lastname) : trim($this->lastname); $this->firstname = trim($this->firstname); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 6b76148d350..df2eab61378 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1086,29 +1086,69 @@ function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $keepmoreta } } - /** * Convert a string to lower. Never use strtolower because it does not works with UTF8 strings. * - * @param string $utf8_string String to encode + * @param string $string String to encode + * @param string $encoding Character set encoding * @return string String converted */ -function dol_strtolower($utf8_string) +function dol_strtolower($string, $encoding = "UTF-8") { - return mb_strtolower($utf8_string, "UTF-8"); + if (function_exists('mb_strtolower')) { + return mb_strtolower($string, $encoding); + } else { + return strtolower($string); + } } /** * Convert a string to upper. Never use strtolower because it does not works with UTF8 strings. * - * @param string $utf8_string String to encode + * @param string $string String to encode + * @param string $encoding Character set encoding * @return string String converted */ -function dol_strtoupper($utf8_string) +function dol_strtoupper($string, $encoding = "UTF-8") { - return mb_strtoupper($utf8_string, "UTF-8"); + if (function_exists('mb_strtoupper')) { + return mb_strtoupper($string, $encoding); + } else { + return strtoupper($string); + } } +/** + * Convert first character of the first word of a string to upper. Never use ucfirst because it does not works with UTF8 strings. + * + * @param string $string String to encode + * @param string $encoding Character set encodign + * @return string String converted + */ +function dol_ucfirst($string, $encoding = "UTF-8") +{ + if (function_exists('mb_substr')) { + return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding) . mb_substr($string, 1, null, $encoding); + } else { + return ucfirst($string); + } +} + +/** + * Convert first character of all the words of a string to upper. Never use ucfirst because it does not works with UTF8 strings. + * + * @param string $string String to encode + * @param string $encoding Character set encodign + * @return string String converted + */ +function dol_ucwords($string, $encoding = "UTF-8") +{ + if (function_exists('mb_convert_case')) { + return mb_convert_case($string, MB_CASE_TITLE, $encoding); + } else { + return ucwords($string); + } +} /** * Write log message into outputs. Possible outputs can be: diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 9078b2146d4..3047e986df8 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -789,8 +789,8 @@ class Societe extends CommonObject // Clean parameters if (empty($this->status)) $this->status = 0; $this->name = $this->name ?trim($this->name) : trim($this->nom); - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = ucwords($this->name); - if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name = strtoupper($this->name); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = dol_ucwords(dol_strtolower($this->name)); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name = dol_strtoupper($this->name); $this->nom = $this->name; // For backward compatibility if (empty($this->client)) $this->client = 0; if (empty($this->fournisseur)) $this->fournisseur = 0; @@ -1094,8 +1094,8 @@ class Societe extends CommonObject $now = dol_now(); - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = ucwords($this->name); - if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name = strtoupper($this->name); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = dol_ucwords(dol_strtolower($this->name)); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name = dol_strtoupper($this->name); // Clean parameters $this->id = $id; $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index b6db00d2d16..87f36cab15a 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1123,9 +1123,9 @@ class User extends CommonObject // Clean parameters - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords($this->lastname); - if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname); - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = dol_ucwords(dol_strtolower($this->lastname)); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = dol_strtoupper($this->lastname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = dol_ucwords(dol_strtolower($this->firstname)); $this->login = trim($this->login); if (!isset($this->entity)) $this->entity = $conf->entity; // If not defined, we use default value @@ -1468,9 +1468,9 @@ class User extends CommonObject // Clean parameters - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = ucwords($this->lastname); - if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = strtoupper($this->lastname); - if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = ucwords($this->firstname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname = dol_ucwords(dol_strtolower($this->lastname)); + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->lastname = dol_strtoupper($this->lastname); + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname = dol_ucwords(dol_strtolower($this->firstname)); $this->lastname = trim($this->lastname); $this->firstname = trim($this->firstname);