Fix: register_globals=off

Fix: Meilleure gestion erreur.
This commit is contained in:
Laurent Destailleur 2004-08-07 00:24:39 +00:00
parent c5fa921e27
commit 8d30262717
2 changed files with 27 additions and 12 deletions

View File

@ -76,7 +76,14 @@ if ($_POST["action"] == 'add' or $_POST["action"] == 'update')
if ($_POST["action"] == 'add')
{
$socid = $soc->create();
Header("Location: soc.php?socid=$socid");
if ($socid > 0) {
Header("Location: soc.php?socid=$socid");
}
else {
$mesg="Erreur, cette société existe déjà";
$_GET["actions"]='create';
}
}
}
@ -99,7 +106,10 @@ if ($_GET["action"] == 'create')
if ($_GET["type"]=='c') { $soc->client=1; }
if ($_GET["type"]=='p') { $soc->client=2; }
print '<div class="titre">'.$langs->trans("NewCompany").'</div><br>';
print_titre($langs->trans("NewCompany"));
print "<br>\n";
print $mesg;
print '<form action="soc.php" method="post">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="fournisseur" value="0">';

View File

@ -70,10 +70,14 @@ class Societe {
if ($this->db->query($sql) ) {
$id = $this->db->last_insert_id();
$this->update($id);
$result=$this->update($id);
if ($result < 0) { return $result; }
return $id;
}
} else {
dolibarr_print_error($this->db);
}
}
/*
*
@ -102,7 +106,6 @@ class Societe {
* TODO simpliste pour l'instant mais remplit 95% des cas
* à améliorer
*/
if ($this->departement_id == -1 && $this->pays_id == 1)
{
if (strlen(trim($this->cp)) == 5)
@ -139,18 +142,20 @@ class Societe {
$sql .= ",client = '" . $this->client ."'";
$sql .= ",fournisseur = '" . $this->fournisseur ."'";
$sql .= " WHERE idp = '" . $id ."';";
if ($this->db->query($sql))
{
return 0;
return 0;
}
else
{
if ($this->db->errno() == 1062)
{
// Doublons sur le prefix commercial
return -1;
}
print $this->db->error();
if ($this->db->errno() == $this->db->ERROR_DUPLICATE)
{
// Doublon
return -1;
}
dolibarr_print_error($this->db);
}
}