diff --git a/modules/porti/actions.php b/modules/porti/actions.php index c59fb3185..9f80727d3 100644 --- a/modules/porti/actions.php +++ b/modules/porti/actions.php @@ -44,17 +44,20 @@ switch (filter('op')) { break; case 'delete': - $documenti = $dbo->fetchArray('SELECT id FROM dt_ddt WHERE idporto='.prepare($id_record).' -UNION SELECT id FROM co_documenti WHERE idporto='.prepare($id_record).' -UNION SELECT id FROM co_preventivi WHERE idporto='.prepare($id_record)); + + $documenti = $dbo->fetchNum('SELECT id FROM dt_ddt WHERE idporto='.prepare($id_record).' + UNION SELECT id FROM co_documenti WHERE idporto='.prepare($id_record).' + UNION SELECT id FROM co_preventivi WHERE idporto='.prepare($id_record)); - if (isset($id_record) && !empty($documenti)) { + if (isset($id_record) && empty($documenti)) { $dbo->query('DELETE FROM `dt_porto` WHERE `id`='.prepare($id_record)); $_SESSION['infos'][] = tr('Tipologia di _TYPE_ eliminata con successo!', [ '_TYPE_' => 'porto', ]); } else { + $_SESSION['errors'][] = tr('Sono presenti dei documenti collegati a questo porto!'); + } break; diff --git a/modules/porti/edit.php b/modules/porti/edit.php index 4faf91daf..d14d17a21 100644 --- a/modules/porti/edit.php +++ b/modules/porti/edit.php @@ -23,17 +23,18 @@ include_once __DIR__.'/../../core.php'; fetchArray('SELECT id FROM dt_ddt WHERE idporto='.prepare($id_record).' -UNION SELECT id FROM co_documenti WHERE idporto='.prepare($id_record).' -UNION SELECT id FROM co_preventivi WHERE idporto='.prepare($id_record)); +$documenti = $dbo->fetchNum('SELECT id FROM dt_ddt WHERE idporto='.prepare($id_record).' + UNION SELECT id FROM co_documenti WHERE idporto='.prepare($id_record).' + UNION SELECT id FROM co_preventivi WHERE idporto='.prepare($id_record)); +if (!empty($documenti)){ echo '
'.tr('Ci sono _NUM_ documenti collegati', [ '_NUM_' => count($documenti), ]).'.
'; - +} ?>