Modif gestion des erreurs

This commit is contained in:
Rodolphe Quiedeville 2004-12-08 13:34:05 +00:00
parent b7f38eab5f
commit 0730a515e4
2 changed files with 43 additions and 37 deletions

View File

@ -92,18 +92,17 @@ if ($_POST["action"] == 'add' or $_POST["action"] == 'update')
if ($_POST["action"] == 'add') if ($_POST["action"] == 'add')
{ {
$socid = $soc->create($user); $result = $soc->create($user);
if ($socid > 0) { if ($result == 0)
Header("Location: soc.php?socid=$socid"); {
} Header("Location: soc.php?socid=".$soc->id);
elseif ($socid == -1) { }
$mesg="Erreur, cette société existe déjà sous ce nom ou pour ce prefix commercial"; else
$_GET["action"]='create'; {
} $_GET["action"]='create';
else { //dolibarr_print_error($db);
dolibarr_print_error($db); }
}
} }
} }
@ -128,12 +127,18 @@ if ($_GET["action"] == 'create')
print_titre($langs->trans("NewCompany")); print_titre($langs->trans("NewCompany"));
print "<br>\n"; print "<br>\n";
print $mesg; if ($soc->error_message)
{
print '<div class="errormessage">';
print nl2br($soc->error_message);
print '</div>';
}
print '<form action="soc.php" method="post">'; print '<form action="soc.php" method="post">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td>'.$langs->trans('Name').'</td><td colspan="3"><input type="text" name="nom"></td></tr>'; print '<tr><td>'.$langs->trans('Name').'</td><td colspan="3"><input type="text" name="nom" value="'.$soc->nom.'"></td></tr>';
print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3"><textarea name="adresse" cols="30" rows="3" wrap="soft"></textarea></td></tr>'; print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3"><textarea name="adresse" cols="30" rows="3" wrap="soft"></textarea></td></tr>';
print '<tr><td>'.$langs->trans('Zip').'</td><td><input size="6" type="text" name="cp">&nbsp;'; print '<tr><td>'.$langs->trans('Zip').'</td><td><input size="6" type="text" name="cp">&nbsp;';
print $langs->trans('Town').'&nbsp;<input type="text" name="ville"></td>'; print $langs->trans('Town').'&nbsp;<input type="text" name="ville"></td>';

View File

@ -85,20 +85,29 @@ class Societe {
function create($user='') 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) ) { $result = $this->verify();
$id = $this->db->last_insert_id();
$result=$this->update($id); if ($result == 0)
if ($result < 0) { return $result; } {
return $id; $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, datec, datea, fk_user_creat) ";
} else { $sql .= " VALUES ('".trim($this->nom)."', now(), now(), '".$user->id."');";
dolibarr_print_error($this->db);
} 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() function verify()
{ {
$result = 0; $result = 0;
$this->error_message = "";
if (strlen(trim($this->nom)) == 0) 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; $result = -2;
} }
@ -122,17 +131,17 @@ class Societe {
{ {
if ($rescode == -1) 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) 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) 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; $result = -3;
@ -273,18 +282,10 @@ $this->error_message = "Erreur, le prefix '".$this->prefix_comm."' existe d
} }
} }
return $result; return $result;
} }
/** /**
* \brief Recupére l'objet societe * \brief Recupére l'objet societe
* \param socid id de la société à charger en mémoire * \param socid id de la société à charger en mémoire