From 703fddb94ea8739b36d805fd09ada0c16c64e9e3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 2 May 2011 18:21:57 +0000 Subject: [PATCH] New: Add option MAIN_FIRST_TO_UPPER --- ChangeLog | 2 + htdocs/adherents/class/adherent.class.php | 10 ++- htdocs/contact/class/contact.class.php | 23 ++++--- htdocs/societe/class/societe.class.php | 80 ++++++++++++----------- 4 files changed, 65 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0aca5b9581f..58f42d3c0b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ $Id$ ***** ChangeLog for 3.1 compared to 3.0 ***** For users: +- New: Add option MAIN_FIRST_TO_UPPER to force upper case of first + letters for names and firstname. - New: Can filter of payment type in bank transaction list. - New: Status is visible into user list. - New: Support BSB code for bank account in australia. diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 6fb36a7a16b..f63be99ff32 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -383,6 +383,10 @@ class Adherent extends CommonObject dol_syslog("Adherent::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass.", email=".$this->email); + // Clean parameters + if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->nom=ucwords(trim($this->nom)); + if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->prenom=ucwords(trim($this->prenom)); + // Check parameters if (! empty($conf->global->ADHERENT_MAIL_REQUIRED) && ! isValidEMail($this->email)) { @@ -979,7 +983,7 @@ class Adherent extends CommonObject $this->address = $obj->adresse; $this->zip = $obj->cp; $this->town = $obj->ville; - + $this->fk_departement = $obj->fk_departement; $this->departement_code = $obj->fk_departement?$obj->departement_code:''; $this->departement = $obj->fk_departement?$obj->departement:''; @@ -990,7 +994,7 @@ class Adherent extends CommonObject elseif ($obj->pays_lib) $this->pays=$obj->pays_lib; else $this->pays=$obj->pays; $this->country = $this->pays; - + $this->phone = $obj->phone; $this->phone_perso = $obj->phone_perso; $this->phone_mobile = $obj->phone_mobile; @@ -1772,7 +1776,7 @@ class Adherent extends CommonObject } return trim($ret); } - + /** * Retourne le libelle du statut d'un adherent (brouillon, valide, resilie) diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 43560fd3fe3..a2ab2919d94 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -109,14 +109,18 @@ class Contact extends CommonObject // Clean parameters $this->name=trim($this->name); - if (! $this->socid) $this->socid = 0; + $this->firstname=trim($this->firstname); + if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name); + if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname=ucwords($this->firstname); + if (! $this->socid) $this->socid = 0; if (! $this->priv) $this->priv = 0; $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople ("; $sql.= " datec"; $sql.= ", fk_soc"; - $sql.= ", name"; - $sql.= ", fk_user_creat"; + $sql.= ", name"; + $sql.= ", firstname"; + $sql.= ", fk_user_creat"; $sql.= ", priv"; $sql.= ", canvas"; $sql.= ", entity"; @@ -125,6 +129,7 @@ class Contact extends CommonObject if ($this->socid > 0) $sql.= " ".$this->socid.","; else $sql.= "null,"; $sql.= "'".$this->db->escape($this->name)."',"; + $sql.= "'".$this->db->escape($this->firstname)."',"; $sql.= " ".($user->id > 0 ? "'".$user->id."'":"null").","; $sql.= " ".$this->priv.","; $sql.= " ".($this->canvas?"'".$this->canvas."'":"null").","; @@ -438,9 +443,9 @@ class Contact extends CommonObject function fetch($id, $user=0) { global $langs; - + $langs->load("companies"); - + $sql = "SELECT c.rowid, c.fk_soc, c.civilite as civilite_id, c.name, c.firstname,"; $sql.= " c.address, c.cp, c.ville,"; $sql.= " c.fk_pays,"; @@ -491,7 +496,7 @@ class Contact extends CommonObject $this->pays_code = $obj->fk_pays?$obj->pays_code:''; $this->pays = ($obj->fk_pays > 0)?$langs->transnoentities("Country".$obj->pays_code):$langs->transnoentities("SelectCountry"); $this->country = ($obj->fk_pays > 0)?$langs->transnoentities("Country".$obj->pays_code):$langs->transnoentities("SelectCountry"); - + $this->socid = $obj->fk_soc; $this->socname = $obj->socname; $this->poste = $obj->poste; @@ -793,7 +798,7 @@ class Contact extends CommonObject * Use $this->id, $this->name, $this->firstname, this->civilite_id * @param withpicto Include picto with link * @param option Where the link point to - * @param maxlen Max length of + * @param maxlen Max length of * @return string String with URL */ function getNomUrl($withpicto=0,$option='',$maxlen=0) @@ -840,8 +845,8 @@ class Contact extends CommonObject } return trim($ret); } - - + + /** * Return label of a civility contact * @return string Translated name of civility diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index f312bafe9d9..4c97a0d509f 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -170,8 +170,9 @@ class Societe extends CommonObject global $langs,$conf; // Clean parameters - $this->name=trim($this->name); - $this->nom=trim($this->nom); + $this->name=$this->name?trim($this->name):trim($this->nom); + if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name); + $this->nom=$this->name; // For backward compatibility dol_syslog("Societe::create ".$this->name); @@ -199,7 +200,7 @@ class Societe extends CommonObject if ($result >= 0) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, entity, datec, datea, fk_user_creat, canvas)"; - $sql.= " VALUES ('".$this->db->escape($this->nom)."', ".$conf->entity.", '".$this->db->idate($now)."', '".$this->db->idate($now)."'"; + $sql.= " VALUES ('".$this->db->escape($this->name)."', ".$conf->entity.", '".$this->db->idate($now)."', '".$this->db->idate($now)."'"; $sql.= ", ".($user->id > 0 ? "'".$user->id."'":"null"); $sql.= ", ".($this->canvas ? "'".$this->canvas."'":"null"); $sql.= ")"; @@ -253,7 +254,7 @@ class Societe extends CommonObject if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { - $this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->nom); + $this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name); } else { @@ -282,10 +283,10 @@ class Societe extends CommonObject $this->errors=array(); $result = 0; - $this->name=trim($this->name); - $this->nom=trim($this->nom); + $this->name=$this->name?trim($this->name):trim($this->nom); + $this->nom=$this->name; // For backward compatibility - if (! $this->nom) + if (! $this->name) { $this->errors[] = 'ErrorBadThirdPartyName'; $result = -2; @@ -365,14 +366,18 @@ class Societe extends CommonObject dol_syslog("Societe::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur); + $now=dol_now(); + // Clean parameters $this->id=$id; - $this->nom=trim($this->nom); // TODO obsolete - $this->name=trim($this->name); - $this->adresse=trim($this->adresse); // TODO obsolete - $this->address=trim($this->address); - $this->cp=trim($this->cp); - $this->ville=trim($this->ville); + $this->name=$this->name?trim($this->name):trim($this->nom); + $this->nom=trim($this->nom); // TODO obsolete + $this->address=$this->address?trim($this->address):trim($this->adresse); + $this->adresse=$this->address; // TODO obsolete + $this->zip=$this->zip?trim($this->zip):trim($this->cp); + $this->cp=$this->zip; // TODO obsolete + $this->town=$this->town?trim($this->town):trim($this->ville); + $this->ville=$this->town; // TODO obsolete $this->departement_id=trim($this->departement_id); $this->pays_id=trim($this->pays_id); $this->tel=trim($this->tel); @@ -429,12 +434,12 @@ class Societe extends CommonObject dol_syslog("Societe::Update verify ok"); $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; - $sql.= " SET nom = '" . $this->db->escape($this->nom) ."'"; // Champ obligatoire - $sql.= ",datea = '".$this->db->idate(mktime())."'"; + $sql.= " SET nom = '" . $this->db->escape($this->name) ."'"; // Champ obligatoire + $sql.= ",datea = '".$this->db->idate($now)."'"; $sql.= ",address = '" . $this->db->escape($this->address) ."'"; - $sql.= ",cp = ".($this->cp?"'".$this->cp."'":"null"); - $sql.= ",ville = ".($this->ville?"'".$this->db->escape($this->ville)."'":"null"); + $sql.= ",cp = ".($this->zip?"'".$this->zip."'":"null"); + $sql.= ",ville = ".($this->town?"'".$this->db->escape($this->town)."'":"null"); $sql .= ",fk_departement = '" . ($this->departement_id?$this->departement_id:'0') ."'"; $sql .= ",fk_pays = '" . ($this->pays_id?$this->pays_id:'0') ."'"; @@ -611,19 +616,19 @@ class Societe extends CommonObject $this->entity = $obj->entity; $this->ref = $obj->rowid; - $this->nom = $obj->name; // TODO obsolete $this->name = $obj->name; + $this->nom = $obj->name; // TODO obsolete $this->ref_ext = $obj->ref_ext; $this->datec = $this->db->jdate($obj->datec); $this->date_update = $this->db->jdate($obj->date_update); - $this->adresse = $obj->address; // TODO obsolete $this->address = $obj->address; - $this->cp = $obj->zip; // TODO obsolete + $this->adresse = $obj->address; // TODO obsolete $this->zip = $obj->zip; - $this->ville = $obj->town;// TODO obsolete + $this->cp = $obj->zip; // TODO obsolete $this->town = $obj->town; + $this->ville = $obj->town;// TODO obsolete $this->pays_id = $obj->fk_pays; // TODO obsolete $this->country_id = $obj->fk_pays; @@ -977,21 +982,20 @@ class Societe extends CommonObject } /** - * \brief Attribut le prefix de la societe en base - * + * Update record to set prefix */ function attribute_prefix() { global $conf; - $sql = "SELECT nom FROM ".MAIN_DB_PREFIX."societe WHERE rowid = '".$this->id."'"; + $sql = "SELECT nom as name FROM ".MAIN_DB_PREFIX."societe WHERE rowid = '".$this->id."'"; $resql=$this->db->query( $sql); if ($resql) { if ($this->db->num_rows($resql)) { $obj=$this->db->fetch_object($resql); - $nom = preg_replace("/[[:punct:]]/","",$obj->nom); + $nom = preg_replace("/[[:punct:]]/","",$obj->name); $this->db->free(); $prefix = $this->genprefix($nom,4); @@ -1385,8 +1389,7 @@ class Societe extends CommonObject $lien.=(!empty($this->canvas)?'&canvas='.$this->canvas:'').'">'; $lienfin=''; - $name=$this->name; - if (empty($name)) $name=$this->nom; + $name=$this->name?$this->name:$this->nom; if ($withpicto) $result.=($lien.img_object($langs->trans("ShowCompany").': '.$name,'company').$lienfin); if ($withpicto && $withpicto != 2) $result.=' '; @@ -1434,7 +1437,7 @@ class Societe extends CommonObject { if (empty($this->name)) $this->name=$this->nom; // TODO: Tester si email non deja present dans tableau contact - $contact_email[-1]=$langs->trans("ThirdParty").': '.dol_trunc($this->nom,16)." <".$this->email.">"; + $contact_email[-1]=$langs->trans("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">"; } return $contact_email; } @@ -1452,7 +1455,7 @@ class Societe extends CommonObject { if (empty($this->name)) $this->name=$this->nom; // TODO: Tester si tel non deja present dans tableau contact - $contact_phone[-1]=$langs->trans("ThirdParty").': '.dol_trunc($this->nom,16)." <".$this->tel.">"; + $contact_phone[-1]=$langs->trans("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->tel.">"; } return $contact_phone; } @@ -2027,7 +2030,7 @@ class Societe extends CommonObject */ function info($id) { - $sql = "SELECT s.rowid, s.nom, s.datec, s.datea,"; + $sql = "SELECT s.rowid, s.nom as name, s.datec, s.datea,"; $sql.= " fk_user_creat, fk_user_modif"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE s.rowid = ".$id; @@ -2052,7 +2055,7 @@ class Societe extends CommonObject $muser->fetch($obj->fk_user_modif); $this->user_modification = $muser; } - $this->ref = $obj->nom; + $this->ref = $obj->name; $this->date_creation = $this->db->jdate($obj->datec); $this->date_modification = $this->db->jdate($obj->datea); } @@ -2202,17 +2205,17 @@ class Societe extends CommonObject /** - * Cree en base un tiers depuis l'objet adherent - * @param member Objet adherent source - * @param socname Name of third to force - * @return int Si erreur <0, si ok renvoie id compte cree + * Create a third party into database from a member object + * @param member Object member + * @param socname Name of third party to force + * @return int <0 if KO, id of created account if OK */ function create_from_member($member,$socname='') { global $conf,$user,$langs; - $name = !empty($socname)?$socname:$member->societe; - if (empty($name)) $name=trim($member->nom.' '.$member->prenom); + $name = $socname?$socname:$member->societe; + if (empty($name)) $name=$member->getFullName($langs); // Positionne parametres $this->nom=$name; // TODO obsolete @@ -2283,7 +2286,8 @@ class Societe extends CommonObject // Initialize parameters $this->id=0; - $this->nom = 'THIRDPARTY SPECIMEN '.dol_print_date($now,'dayhourlog'); + $this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now,'dayhourlog'); + $this->nom = $this->name; // For backward compatibility $this->specimen=1; $this->cp='99999'; $this->ville='MyTown';