diff --git a/pandora_console/godmode/setup/setup_notifications.php b/pandora_console/godmode/setup/setup_notifications.php index c105b89e62..d3c846aebf 100644 --- a/pandora_console/godmode/setup/setup_notifications.php +++ b/pandora_console/godmode/setup/setup_notifications.php @@ -35,7 +35,8 @@ if (get_parameter('update_config', 0)) { $mail_value = (int)get_parameter("mail-{$id}", 0); $user_value = (int)get_parameter("user-{$id}", 0); $postpone_value = (int)get_parameter("postpone-{$id}", 0); - $res = mysql_db_process_sql_update( + $all_users = (int)get_parameter("all-{$id}", 0); + $res = db_process_sql_update( 'tnotification_source', array( 'enabled' => $enable_value, @@ -45,7 +46,10 @@ if (get_parameter('update_config', 0)) { ), array('id' => $source['id']) ); - return $res && $carry; + $all_users_res = $all_users + ? notifications_add_group_to_source($source['id'], array(0)) + : notifications_remove_group_from_source($source['id'], array(0)); + return $all_users_res && $res && $carry; }, true); } diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index 3d62dc0429..921b5c55e1 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -207,6 +207,53 @@ function notifications_get_group_sources_for_select($source_id) { return index_array($groups, 'id_group', 'name'); } +/** + * Delete a set of groups from notification source + * + * @param int Source id + * @param array Id of groups to be deleted + * + * @return bool True if success. False otherwise. + */ +function notifications_remove_group_from_source ($source_id, $groups) { + // Source id is mandatory + if (!isset($source_id)) return false; + + // Delete from database + return db_process_sql_delete ( + 'tnotification_source_group', + array( + 'id_group' => $groups, + 'id_source' => $source_id + ) + ) !== false; +} + +/** + * Insert a set of groups to notification source + * + * @param int Source id + * @param array Id of groups to be deleted + * + * @return bool True if success. False otherwise. + */ +function notifications_add_group_to_source ($source_id, $groups) { + // Source id is mandatory + if (!isset($source_id)) return false; + + // Insert into database all groups passed + $res = true; + foreach ($groups as $group) { + $res = db_process_sql_insert( + 'tnotification_source_group', + array( + 'id_group' => $group, + 'id_source' => $source_id) + ) !== false; + } + return $res; +} + /** * Print the notification ball to see unread messages *