Skip to content

Commit d892160

Browse files
committed
Fix error management
1 parent 7ff3076 commit d892160

2 files changed

Lines changed: 42 additions & 23 deletions

File tree

htdocs/don/card.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
exit;
141141
} else {
142142
setEventMessages($object->error, $object->errors, 'errors');
143+
$action = 'create';
143144
}
144145
}
145146

@@ -172,7 +173,7 @@
172173
$object->lastname = (string) GETPOST("lastname", 'alpha');
173174
$object->societe = (string) GETPOST("societe", 'alpha');
174175
$object->address = (string) GETPOST("address", 'alpha');
175-
$object->amount = price2num(GETPOST("amount", 'alpha'));
176+
$object->amount = price2num(GETPOST("amount", 'alpha'), '', 2);
176177
$object->town = (string) GETPOST("town", 'alpha');
177178
$object->zip = (string) GETPOST("zipcode", 'alpha');
178179
$object->country_id = (int) GETPOST('country_id', 'int');
@@ -193,6 +194,9 @@
193194
if ($object->update($user) > 0) {
194195
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
195196
exit;
197+
} else {
198+
setEventMessages($object->error, $object->errors, 'errors');
199+
$action = "create";
196200
}
197201
}
198202
}
@@ -230,7 +234,7 @@
230234
$object->lastname = (string) GETPOST("lastname", 'alpha');
231235
$object->societe = (string) GETPOST("societe", 'alpha');
232236
$object->address = (string) GETPOST("address", 'alpha');
233-
$object->amount = price2num(GETPOST("amount", 'alpha'));
237+
$object->amount = price2num(GETPOST("amount", 'alpha'), '', 2);
234238
$object->zip = (string) GETPOST("zipcode", 'alpha');
235239
$object->town = (string) GETPOST("town", 'alpha');
236240
$object->country_id = (int) GETPOST('country_id', 'int');
@@ -254,6 +258,7 @@
254258
exit;
255259
} else {
256260
setEventMessages($object->error, $object->errors, 'errors');
261+
$action = "create";
257262
}
258263
}
259264
}

htdocs/don/class/don.class.php

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ public function create($user, $notrigger = 0)
353353
$this->town = ($this->town > 0 ? $this->town : $this->town);
354354
$this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
355355
$this->country = ($this->country ? $this->country : $this->country);
356+
$this->amount = price2num($this->amount);
357+
358+
// Check parameters
359+
if ($this->amount < 0) {
360+
$this->error = $langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv("Amount"));
361+
return -1;
362+
}
356363

357364
$this->db->begin();
358365

@@ -382,7 +389,7 @@ public function create($user, $notrigger = 0)
382389
$sql .= ") VALUES (";
383390
$sql .= "'".$this->db->idate($this->date ? $this->date : $now)."'";
384391
$sql .= ", ".((int) $conf->entity);
385-
$sql .= ", ".price2num($this->amount);
392+
$sql .= ", ".((float) $this->amount);
386393
$sql .= ", ".($this->modepaymentid ? $this->modepaymentid : "null");
387394
$sql .= ", ".($this->socid > 0 ? $this->socid : "null");
388395
$sql .= ", '".$this->db->escape($this->firstname)."'";
@@ -464,29 +471,36 @@ public function update($user, $notrigger = 0)
464471
$this->town = ($this->town > 0 ? $this->town : $this->town);
465472
$this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
466473
$this->country = ($this->country ? $this->country : $this->country);
474+
$this->amount = price2num($this->amount);
475+
476+
// Check parameters
477+
if ($this->amount < 0) {
478+
$this->error = $langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv("Amount"));
479+
return -1;
480+
}
467481

468482
$this->db->begin();
469483

470-
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET ";
471-
$sql .= "amount = ".price2num($this->amount);
472-
$sql .= ",fk_payment = ".($this->modepaymentid ? $this->modepaymentid : "null");
473-
$sql .= ",firstname = '".$this->db->escape($this->firstname)."'";
474-
$sql .= ",lastname='".$this->db->escape($this->lastname)."'";
475-
$sql .= ",societe='".$this->db->escape($this->societe)."'";
476-
$sql .= ",address='".$this->db->escape($this->address)."'";
477-
$sql .= ",zip='".$this->db->escape($this->zip)."'";
478-
$sql .= ",town='".$this->db->escape($this->town)."'";
479-
$sql .= ",fk_country = ".($this->country_id > 0 ? ((int) $this->country_id) : '0');
480-
$sql .= ",public=".((int) $this->public);
481-
$sql .= ",fk_projet=".($this->fk_project > 0 ? $this->fk_project : 'null');
482-
$sql .= ",note_private=".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL");
483-
$sql .= ",note_public=".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL");
484-
$sql .= ",datedon='".$this->db->idate($this->date)."'";
485-
$sql .= ",date_valid=".($this->date_valid ? "'".$this->db->idate($this->date)."'" : "null");
486-
$sql .= ",email='".$this->db->escape(trim($this->email))."'";
487-
$sql .= ",phone='".$this->db->escape(trim($this->phone))."'";
488-
$sql .= ",phone_mobile='".$this->db->escape(trim($this->phone_mobile))."'";
489-
$sql .= ",fk_statut=".((int) $this->statut);
484+
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET";
485+
$sql .= " amount = ".((float) $this->amount);
486+
$sql .= ", fk_payment = ".($this->modepaymentid ? $this->modepaymentid : "null");
487+
$sql .= ", firstname = '".$this->db->escape($this->firstname)."'";
488+
$sql .= ", lastname='".$this->db->escape($this->lastname)."'";
489+
$sql .= ", societe='".$this->db->escape($this->societe)."'";
490+
$sql .= ", address='".$this->db->escape($this->address)."'";
491+
$sql .= ", zip='".$this->db->escape($this->zip)."'";
492+
$sql .= ", town='".$this->db->escape($this->town)."'";
493+
$sql .= ", fk_country = ".($this->country_id > 0 ? ((int) $this->country_id) : '0');
494+
$sql .= ", public=".((int) $this->public);
495+
$sql .= ", fk_projet=".($this->fk_project > 0 ? $this->fk_project : 'null');
496+
$sql .= ", note_private=".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL");
497+
$sql .= ", note_public=".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL");
498+
$sql .= ", datedon='".$this->db->idate($this->date)."'";
499+
$sql .= ", date_valid=".($this->date_valid ? "'".$this->db->idate($this->date)."'" : "null");
500+
$sql .= ", email='".$this->db->escape(trim($this->email))."'";
501+
$sql .= ", phone='".$this->db->escape(trim($this->phone))."'";
502+
$sql .= ", phone_mobile='".$this->db->escape(trim($this->phone_mobile))."'";
503+
$sql .= ", fk_statut=".((int) $this->statut);
490504
$sql .= " WHERE rowid = ".((int) $this->id);
491505

492506
dol_syslog(get_class($this)."::Update", LOG_DEBUG);

0 commit comments

Comments
 (0)