From d5fb9f1051818a6a3edc389b2593f852882d60f7 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Thu, 7 Feb 2019 12:22:50 +0100 Subject: [PATCH] Added AJAX to user notification config window Former-commit-id: 9ca09ae777d699588a76dfb619156d800a95895b --- .../include/functions_notifications.php | 27 +++++- .../users/user_edit_notifications.php | 92 ++++++++++++++++--- 2 files changed, 106 insertions(+), 13 deletions(-) diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index 0f26ed977c..9037e9790f 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -168,9 +168,9 @@ function check_notification_readable(int $id_message) * * @return array with sources info */ -function notifications_get_all_sources() +function notifications_get_all_sources($filter=[]) { - return db_get_all_rows_in_table('tnotification_source'); + return db_get_all_rows_filter('tnotification_source', $filter); } @@ -478,6 +478,27 @@ function notifications_get_user_label_status($source, $user, $label) return notifications_build_user_enable_return($value, false); } +function notifications_set_user_label_status($source, $user, $label, $value) { + $source_info = notifications_get_all_sources(['id' => $source]); + if (!isset($source_info[0]) + || !$source_info[0]['enabled'] + || !$source_info[0][$label] + || !$source_info[0]['user_editable'] + ) { + return false; + } + + return (bool) db_process_sql_update( + 'tnotification_source_user', + [$label => $value], + [ + 'id_user' => $user, + 'id_source' => $source, + ] + ); + +} + /** * Print the notification ball to see unread messages @@ -634,6 +655,8 @@ function notifications_print_user_switch($source, $user, $label) 'name' => $label, 'value' => $status['status'], 'disabled' => !$status['enabled'], + 'class' => 'notifications-user-label_individual', + 'id' => 'notifications-user-'.$source['id'].'-label-'.$label, ] ); } diff --git a/pandora_console/operation/users/user_edit_notifications.php b/pandora_console/operation/users/user_edit_notifications.php index d7a4f71194..6ffbf87976 100644 --- a/pandora_console/operation/users/user_edit_notifications.php +++ b/pandora_console/operation/users/user_edit_notifications.php @@ -4,7 +4,6 @@ // ================================================== // Copyright (c) 2005-2010 Artica Soluciones Tecnologicas // Please see http://pandorafms.org for full contribution list - // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation for version 2. @@ -12,19 +11,39 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. - // Load global vars global $config; // Includes. -include_once ($config['homedir'] . '/include/functions_notifications.php'); +require_once $config['homedir'].'/include/functions_notifications.php'; // Load the header -require($config['homedir'] . "/operation/users/user_edit_header.php"); +require $config['homedir'].'/operation/users/user_edit_header.php'; + +if (get_parameter('change_label', 0)) { + $label = get_parameter('label', ''); + $source = get_parameter('source', 0); + $user = get_parameter('user', ''); + $value = get_parameter('value', 0) ? 1 : 0; + + // Update the label value. + ob_clean(); + echo json_encode( + [ + 'result' => notifications_set_user_label_status( + $source, + $user, + $label, + $value + ), + ] + ); + return; +} // User notification table. It is just a wrapper. $table_content = new StdClass(); -$table_content->data = array(); +$table_content->data = []; $table_content->width = '100%'; $table_content->id = 'user-notifications-wrapper'; $table_content->class = 'databox filters'; @@ -33,20 +52,71 @@ $table_content->size[1] = '33%'; $table_content->size[2] = '33%'; // Print the header. -$table_content->data[] = array ( +$table_content->data[] = [ '', __('Enable'), - __('Also receive an email') -); + __('Also receive an email'), +]; $sources = notifications_get_all_sources(); foreach ($sources as $source) { - $table_content->data[] = array( + $table_content->data[] = [ $source['description'], notifications_print_user_switch($source, $id, 'enabled'), notifications_print_user_switch($source, $id, 'also_mail'), - ); + ]; } + html_print_table($table_content); -?> \ No newline at end of file +// Print id user to handle it on js. +html_print_input_hidden('id_user', $id); + +?> +