From 5194bd165c24c350e03b1206692bb6522ee0c19b Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 20 Dec 2023 15:14:16 +0100 Subject: [PATCH 1/4] #12156 fix notification group --- .../include/functions_notifications.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index c65c475550..9e7db33bae 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -636,13 +636,15 @@ function notifications_get_user_label_status($source, $user, $label) ); // Clean default common groups error for mesagges. + $group_enable = true; if ($common_groups[0] === 0) { unset($common_groups[0]); + $group_enable = false; } // No group found, return no permissions. $value = empty($common_groups) ? false : $source[$label]; - return notifications_build_user_enable_return($value, false); + return notifications_build_user_enable_return($value, $group_enable); } @@ -674,6 +676,18 @@ function notifications_set_user_label_status($source, $user, $label, $value) return false; } + $eixsts = db_get_row('tnotification_source_user', 'id_user', $user); + if ($eixsts === false) { + db_process_sql_insert( + 'tnotification_source_user', + [ + 'id_user' => $user, + 'id_source' => $source, + 'enabled' => '1', + ] + ); + } + return (bool) db_process_sql_update( 'tnotification_source_user', [$label => $value], From 43b8db9c8419ec6e6fa9dac94a03ffddde0fe270 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 15 Jan 2024 10:15:46 +0100 Subject: [PATCH 2/4] #12156 also mail added notification on create --- .../include/functions_notifications.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index 9e7db33bae..78b5facde4 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -684,18 +684,20 @@ function notifications_set_user_label_status($source, $user, $label, $value) 'id_user' => $user, 'id_source' => $source, 'enabled' => '1', + 'also_mail' => '1', + ] + ); + return true; + } else { + return (bool) db_process_sql_update( + 'tnotification_source_user', + [$label => $value], + [ + 'id_user' => $user, + 'id_source' => $source, ] ); } - - return (bool) db_process_sql_update( - 'tnotification_source_user', - [$label => $value], - [ - 'id_user' => $user, - 'id_source' => $source, - ] - ); } From 87e17be08484bfaa1fd74a28bd6232ee9243c5ee Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 15 Jan 2024 12:38:42 +0100 Subject: [PATCH 3/4] #12156 fix error on update when empty db values --- pandora_console/include/functions_notifications.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index 78b5facde4..89027fbf81 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -677,6 +677,12 @@ function notifications_set_user_label_status($source, $user, $label, $value) } $eixsts = db_get_row('tnotification_source_user', 'id_user', $user); + if (empty($eixsts['enabled']) && empty($eixsts['also_mail'])) { + $sql = sprintf('DELETE FROM tnotification_source_user WHERE id_user = "%s" AND id_source = "%s"', $user, $source); + db_process_sql($sql); + $eixsts = false; + } + if ($eixsts === false) { db_process_sql_insert( 'tnotification_source_user', From d34bd3f22334d7bd761555b63f769a3edeb11534 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 15 Jan 2024 13:26:28 +0100 Subject: [PATCH 4/4] #12156 fix sql error check exists --- pandora_console/include/functions_notifications.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index 89027fbf81..e59208f8ef 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -676,14 +676,14 @@ function notifications_set_user_label_status($source, $user, $label, $value) return false; } - $eixsts = db_get_row('tnotification_source_user', 'id_user', $user); - if (empty($eixsts['enabled']) && empty($eixsts['also_mail'])) { + $exists = db_process_sql(sprintf('SELECT * FROM tnotification_source_user WHERE id_user = "%s" AND id_source = "%s"', $user, $source)); + if (empty($exists['enabled']) && empty($exists['also_mail'])) { $sql = sprintf('DELETE FROM tnotification_source_user WHERE id_user = "%s" AND id_source = "%s"', $user, $source); db_process_sql($sql); - $eixsts = false; + $exists = false; } - if ($eixsts === false) { + if ($exists === false) { db_process_sql_insert( 'tnotification_source_user', [