diff --git a/htdocs/soc.php b/htdocs/soc.php index 85a36f9422b..679f518f442 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -92,18 +92,17 @@ if ($_POST["action"] == 'add' or $_POST["action"] == 'update') if ($_POST["action"] == 'add') { - $socid = $soc->create($user); + $result = $soc->create($user); - if ($socid > 0) { - Header("Location: soc.php?socid=$socid"); - } - elseif ($socid == -1) { - $mesg="Erreur, cette société existe déjà sous ce nom ou pour ce prefix commercial"; - $_GET["action"]='create'; - } - else { - dolibarr_print_error($db); - } + if ($result == 0) + { + Header("Location: soc.php?socid=".$soc->id); + } + else + { + $_GET["action"]='create'; + //dolibarr_print_error($db); + } } } @@ -128,12 +127,18 @@ if ($_GET["action"] == 'create') print_titre($langs->trans("NewCompany")); print "
\n"; - print $mesg; + if ($soc->error_message) + { + print '
'; + print nl2br($soc->error_message); + print '
'; + } + print '
'; print ''; print ''; - print ''; + print ''; print ''; print ''; diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 72720841869..88c7b0cf521 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -85,20 +85,29 @@ class Societe { function create($user='') { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, datec, datea, fk_user_creat) "; - $sql .= " VALUES ('".trim($this->nom)."', now(), now(), '".$user->id."');"; - if ($this->db->query($sql) ) { - $id = $this->db->last_insert_id(); + $result = $this->verify(); - $result=$this->update($id); - if ($result < 0) { return $result; } + if ($result == 0) + { - return $id; - } else { - dolibarr_print_error($this->db); - } - + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, datec, datea, fk_user_creat) "; + $sql .= " VALUES ('".trim($this->nom)."', now(), now(), '".$user->id."');"; + + if ($this->db->query($sql) ) + { + $this->id = $this->db->last_insert_id(); + } + + $result = $this->update($this->id); + + return $result; + } + else + { + return -1; + } + } /** @@ -109,10 +118,10 @@ class Societe { function verify() { $result = 0; - + $this->error_message = ""; if (strlen(trim($this->nom)) == 0) { - $this->error_message = "Le nom de la société ne peut être vide"; + $this->error_message = "Le nom de la société ne peut être vide.\n"; $result = -2; } @@ -122,17 +131,17 @@ class Societe { { if ($rescode == -1) { - $this->error_message = "La syntaxe du code client est incorrecte."; + $this->error_message .= "La syntaxe du code client est incorrecte.\n"; } if ($rescode == -2) { - $this->error_message = "Vous devez saisir un code client."; + $this->error_message .= "Vous devez saisir un code client.\n"; } if ($rescode == -3) { - $this->error_message = "Ce code client est déjà utilisé."; + $this->error_message .= "Ce code client est déjà utilisé.\n"; } $result = -3; @@ -273,18 +282,10 @@ $this->error_message = "Erreur, le prefix '".$this->prefix_comm."' existe d } } - return $result; } - - - - - - - /** * \brief Recupére l'objet societe * \param socid id de la société à charger en mémoire
'.$langs->trans('Name').'
'.$langs->trans('Name').'
'.$langs->trans('Address').'
'.$langs->trans('Zip').' '; print $langs->trans('Town').'