From 12d929be76d99e1c8205c011c268c65f017f1488 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 11 Oct 2024 11:53:31 +0200 Subject: [PATCH 1/3] FIX avoid pgsql error --- htdocs/core/lib/company.lib.php | 2 +- htdocs/societe/contact.php | 26 +++++++++++--------------- 2 files changed, 12 insertions(+), 16 deletions(-) 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..aef9f81df6452 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; + + $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'); } } } From 5613b9be6768347ebfc95e2f90fb7b25b2e41bf3 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 11 Oct 2024 14:10:49 +0200 Subject: [PATCH 2/3] FIX remove phan error --- htdocs/societe/contact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/contact.php b/htdocs/societe/contact.php index aef9f81df6452..fd56f6156277b 100644 --- a/htdocs/societe/contact.php +++ b/htdocs/societe/contact.php @@ -141,7 +141,7 @@ $contact = new Contact($db); $result = $contact->fetch($id); - $contact->oldcopy = clone $contact; + $contact->oldcopy = clone $contact; // @phan-suppress-currentline PhanTypeMismatchProperty $result = $contact->delete($user); From 766afe505f88fe7e3fa73610604f234234fcef9c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 11 Oct 2024 14:17:54 +0200 Subject: [PATCH 3/3] FIX syntax error --- htdocs/societe/contact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/contact.php b/htdocs/societe/contact.php index fd56f6156277b..7cbf796fcff04 100644 --- a/htdocs/societe/contact.php +++ b/htdocs/societe/contact.php @@ -141,7 +141,7 @@ $contact = new Contact($db); $result = $contact->fetch($id); - $contact->oldcopy = clone $contact; // @phan-suppress-currentline PhanTypeMismatchProperty + $contact->oldcopy = clone $contact; // @phan-suppress-current-line PhanTypeMismatchProperty $result = $contact->delete($user);