diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index b67ded65c6e..c48b00050f8 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -589,9 +589,7 @@ 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 = 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->setUpperOrLowerCase(); $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 2034803ecb8..6e0a3a0e195 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -353,9 +353,7 @@ 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 = 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->setUpperOrLowerCase(); 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,10 +462,6 @@ 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 = 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); $this->email = trim($this->email); @@ -478,8 +472,9 @@ class Contact extends CommonObject $this->skype = trim($this->skype); $this->photo = trim($this->photo); $this->fax = trim($this->fax); - $this->zip = (empty($this->zip) ? '' : $this->zip); - $this->town = (empty($this->town) ? '' : $this->town); + $this->zip = (empty($this->zip) ? '' : trim($this->zip)); + $this->town = (empty($this->town) ? '' : trim($this->town)); + $this->setUpperOrLowerCase(); $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id); if (empty($this->statut)) $this->statut = 0; if (empty($this->civility_code) && !is_numeric($this->civility_id)) $this->civility_code = $this->civility_id; // For backward compatibility diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 46208635cd3..5371b8078fa 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -569,6 +569,28 @@ abstract class CommonObject return dol_trunc($ret, $maxlen); } + /** + * Set to upper or ucwords/lower if needed + * + * @return void; + */ + public function setUpperOrLowerCase() + { + global $conf; + if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) { + $this->lastname = dol_ucwords(dol_strtolower($this->lastname)); + $this->firstname = dol_ucwords(dol_strtolower($this->firstname)); + $this->name = dol_ucwords(dol_strtolower($this->name)); + } + if (!empty($conf->global->MAIN_ALL_TO_UPPER)) { + $this->lastname = dol_strtoupper($this->lastname); + $this->name = dol_strtoupper($this->name); + } + if (!empty($conf->global->MAIN_ALL_TOWN_TO_UPPER)) { + $this->town = dol_strtoupper($this->town); + } + } + /** * Return clicable link of object (with eventually picto) * diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 3047e986df8..3fcc7e610ac 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -789,8 +789,7 @@ 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 = dol_ucwords(dol_strtolower($this->name)); - if (!empty($conf->global->MAIN_ALL_TO_UPPER)) $this->name = dol_strtoupper($this->name); + $this->setUpperOrLowerCase(); $this->nom = $this->name; // For backward compatibility if (empty($this->client)) $this->client = 0; if (empty($this->fournisseur)) $this->fournisseur = 0; @@ -1094,8 +1093,6 @@ class Societe extends CommonObject $now = dol_now(); - 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); @@ -1106,6 +1103,7 @@ class Societe extends CommonObject $this->address = $this->address ?trim($this->address) : trim($this->address); $this->zip = $this->zip ?trim($this->zip) : trim($this->zip); $this->town = $this->town ?trim($this->town) : trim($this->town); + $this->setUpperOrLowerCase(); $this->state_id = trim($this->state_id); $this->country_id = ($this->country_id > 0) ? $this->country_id : 0; $this->phone = trim($this->phone); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 87f36cab15a..521a9522ae4 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1122,25 +1122,19 @@ class User extends CommonObject global $mysoc; // Clean parameters - - 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->setUpperOrLowerCase(); $this->login = trim($this->login); if (!isset($this->entity)) $this->entity = $conf->entity; // If not defined, we use default value dol_syslog(get_class($this)."::create login=".$this->login.", user=".(is_object($user) ? $user->id : ''), LOG_DEBUG); // Check parameters - if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) - { + if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) { $langs->load("errors"); $this->error = $langs->trans("ErrorBadEMail", $this->email); return -1; } - if (empty($this->login)) - { + if (empty($this->login)) { $langs->load("errors"); $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login")); return -1; @@ -1467,11 +1461,6 @@ class User extends CommonObject dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncmember=".$nosyncmember.", nosyncmemberpass=".$nosyncmemberpass); // Clean parameters - - 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); $this->employee = $this->employee ? $this->employee : 0; @@ -1479,9 +1468,10 @@ class User extends CommonObject $this->gender = trim($this->gender); $this->pass = trim($this->pass); $this->api_key = trim($this->api_key); - $this->address = $this->address ?trim($this->address) : trim($this->address); - $this->zip = $this->zip ?trim($this->zip) : trim($this->zip); - $this->town = $this->town ?trim($this->town) : trim($this->town); + $this->address = $this->address ? trim($this->address) : trim($this->address); + $this->zip = $this->zip ? trim($this->zip) : trim($this->zip); + $this->town = $this->town ? trim($this->town) : trim($this->town); + $this->setUpperOrLowerCase(); $this->state_id = trim($this->state_id); $this->country_id = ($this->country_id > 0) ? $this->country_id : 0; $this->office_phone = trim($this->office_phone);