diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 411fe6d0663ab..ce13099935b22 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1566,7 +1566,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '', $showuserl // Delete if ($user->hasRight('societe', 'contact', 'delete')) { - print ''; + print ''; print img_delete(); print ''; } diff --git a/htdocs/societe/contact.php b/htdocs/societe/contact.php index 21f2105d94a3d..7cbf796fcff04 100644 --- a/htdocs/societe/contact.php +++ b/htdocs/societe/contact.php @@ -138,23 +138,19 @@ if ($action == 'confirm_delete' && $user->hasRight('societe', 'contact', 'delete')) { $id = GETPOST('id', 'int'); if (!empty($id) && $socid > 0) { - $db->begin(); - - $sql = "DELETE t, et FROM ".MAIN_DB_PREFIX."socpeople AS t"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields AS et ON t.rowid = et.fk_object"; - $sql .= " WHERE t.fk_soc = ".((int) $socid); - $sql .= " AND t.rowid = ".((int) $id); - $sql .= " AND ((t.fk_user_creat = ".((int) $user->id)." AND t.priv = 1) OR t.priv = 0)"; - - $result = $db->query($sql); - if (!$result) { - setEventMessages($db->lasterror(), null, 'errors'); - $db->rollback(); - } else { - $db->commit(); + $contact = new Contact($db); + + $result = $contact->fetch($id); + $contact->oldcopy = clone $contact; // @phan-suppress-current-line PhanTypeMismatchProperty + + $result = $contact->delete($user); + + if ($result > 0) { setEventMessages('ContactDeleted', null, 'mesgs'); - header("Location: ".$_SERVER['PHP_SELF']."?id=".$socid); + header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid); exit(); + } else { + setEventMessages($contact->error, $contact->errors, 'errors'); } } }