Fix error management

This commit is contained in:
Laurent Destailleur 2022-01-10 17:55:45 +01:00
parent 7ff30761e1
commit d892160f4f
2 changed files with 42 additions and 23 deletions

View File

@ -140,6 +140,7 @@ if (empty($reshook)) {
exit; exit;
} else { } else {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
$action = 'create';
} }
} }
@ -172,7 +173,7 @@ if (empty($reshook)) {
$object->lastname = (string) GETPOST("lastname", 'alpha'); $object->lastname = (string) GETPOST("lastname", 'alpha');
$object->societe = (string) GETPOST("societe", 'alpha'); $object->societe = (string) GETPOST("societe", 'alpha');
$object->address = (string) GETPOST("address", 'alpha'); $object->address = (string) GETPOST("address", 'alpha');
$object->amount = price2num(GETPOST("amount", 'alpha')); $object->amount = price2num(GETPOST("amount", 'alpha'), '', 2);
$object->town = (string) GETPOST("town", 'alpha'); $object->town = (string) GETPOST("town", 'alpha');
$object->zip = (string) GETPOST("zipcode", 'alpha'); $object->zip = (string) GETPOST("zipcode", 'alpha');
$object->country_id = (int) GETPOST('country_id', 'int'); $object->country_id = (int) GETPOST('country_id', 'int');
@ -193,6 +194,9 @@ if (empty($reshook)) {
if ($object->update($user) > 0) { if ($object->update($user) > 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit; exit;
} else {
setEventMessages($object->error, $object->errors, 'errors');
$action = "create";
} }
} }
} }
@ -230,7 +234,7 @@ if (empty($reshook)) {
$object->lastname = (string) GETPOST("lastname", 'alpha'); $object->lastname = (string) GETPOST("lastname", 'alpha');
$object->societe = (string) GETPOST("societe", 'alpha'); $object->societe = (string) GETPOST("societe", 'alpha');
$object->address = (string) GETPOST("address", 'alpha'); $object->address = (string) GETPOST("address", 'alpha');
$object->amount = price2num(GETPOST("amount", 'alpha')); $object->amount = price2num(GETPOST("amount", 'alpha'), '', 2);
$object->zip = (string) GETPOST("zipcode", 'alpha'); $object->zip = (string) GETPOST("zipcode", 'alpha');
$object->town = (string) GETPOST("town", 'alpha'); $object->town = (string) GETPOST("town", 'alpha');
$object->country_id = (int) GETPOST('country_id', 'int'); $object->country_id = (int) GETPOST('country_id', 'int');
@ -254,6 +258,7 @@ if (empty($reshook)) {
exit; exit;
} else { } else {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
$action = "create";
} }
} }
} }

View File

@ -353,6 +353,13 @@ class Don extends CommonObject
$this->town = ($this->town > 0 ? $this->town : $this->town); $this->town = ($this->town > 0 ? $this->town : $this->town);
$this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id); $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
$this->country = ($this->country ? $this->country : $this->country); $this->country = ($this->country ? $this->country : $this->country);
$this->amount = price2num($this->amount);
// Check parameters
if ($this->amount < 0) {
$this->error = $langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv("Amount"));
return -1;
}
$this->db->begin(); $this->db->begin();
@ -382,7 +389,7 @@ class Don extends CommonObject
$sql .= ") VALUES ("; $sql .= ") VALUES (";
$sql .= "'".$this->db->idate($this->date ? $this->date : $now)."'"; $sql .= "'".$this->db->idate($this->date ? $this->date : $now)."'";
$sql .= ", ".((int) $conf->entity); $sql .= ", ".((int) $conf->entity);
$sql .= ", ".price2num($this->amount); $sql .= ", ".((float) $this->amount);
$sql .= ", ".($this->modepaymentid ? $this->modepaymentid : "null"); $sql .= ", ".($this->modepaymentid ? $this->modepaymentid : "null");
$sql .= ", ".($this->socid > 0 ? $this->socid : "null"); $sql .= ", ".($this->socid > 0 ? $this->socid : "null");
$sql .= ", '".$this->db->escape($this->firstname)."'"; $sql .= ", '".$this->db->escape($this->firstname)."'";
@ -464,11 +471,18 @@ class Don extends CommonObject
$this->town = ($this->town > 0 ? $this->town : $this->town); $this->town = ($this->town > 0 ? $this->town : $this->town);
$this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id); $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
$this->country = ($this->country ? $this->country : $this->country); $this->country = ($this->country ? $this->country : $this->country);
$this->amount = price2num($this->amount);
// Check parameters
if ($this->amount < 0) {
$this->error = $langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv("Amount"));
return -1;
}
$this->db->begin(); $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."don SET";
$sql .= "amount = ".price2num($this->amount); $sql .= " amount = ".((float) $this->amount);
$sql .= ", fk_payment = ".($this->modepaymentid ? $this->modepaymentid : "null"); $sql .= ", fk_payment = ".($this->modepaymentid ? $this->modepaymentid : "null");
$sql .= ", firstname = '".$this->db->escape($this->firstname)."'"; $sql .= ", firstname = '".$this->db->escape($this->firstname)."'";
$sql .= ", lastname='".$this->db->escape($this->lastname)."'"; $sql .= ", lastname='".$this->db->escape($this->lastname)."'";