From 539802276b0dbd1e34cc85aa38361dc9287f6746 Mon Sep 17 00:00:00 2001 From: erics Date: Sat, 11 Sep 2004 10:02:40 +0000 Subject: [PATCH] =?UTF-8?q?genprefix=20ajout=E9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/societe.class.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 85a823cee46..a5f0669638b 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -378,7 +378,7 @@ class Societe { $nom = preg_replace("/[[:punct:]]/","",$this->db->result(0,0)); $this->db->free(); - $prefix = strtoupper(substr($nom, 0, 4)); + $prefix = $this->genprefix($nom,4); $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."societe WHERE prefix_comm = '$prefix'"; if ( $this->db->query( $sql) ) @@ -416,6 +416,37 @@ class Societe { return $prefix; } + /** + * \brief Génère le préfix de la société + * \param nom nom de la société + * \param taille taille du prefix à retourner + * \param mot l'indice du mot à utiliser + * + */ + function genprefix($nom, $taille=4,$mot=0) + { + $retour = ""; + $tab = explode(" ",$nom); + if($mot < count($tab)) { + $prefix = substr($tab[$mot],0,$taille); + //On vérifie que ce prefix n'a pas déjà été pris ... + $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."societe WHERE prefix_comm = '$prefix'"; + if ( $this->db->query( $sql) ) + { + if ( $this->db->result(0, 0) ) + { + $this->db->free(); + $retour = $this->genprefix($nom,$taille,$mot+1); + } + else + { + $retour = $prefix; + } + } + } + return $retour; + } + /** * \brief Définit la société comme un client *