$res]; echo json_encode($result); return; } if (get_parameter('remove_source_on_database', 0)) { $res = ($is_users) ? notifications_remove_users_from_source($source, $elements) : notifications_remove_group_from_source($source, $elements); $result = ['result' => $res]; echo json_encode($result); return; } if (get_parameter('update_config', 0)) { $element = (string) get_parameter('element', ''); $value = (int) get_parameter('value', 0); $source = (string) get_parameter('source'); // Update the label value. ob_clean(); $res = false; switch ($element) { // All users has other action. case 'all_users': $res = ($value) ? notifications_add_group_to_source($source, [0]) : notifications_remove_group_from_source($source, [0]); break; case 'subtype': $data = explode('.', $source, 2); $source_id = $data[0]; $subtype = $data[1]; $source = notifications_get_all_sources( [ 'id' => $source_id ] ); if ($source !== false && is_array($source[0]) === true) { $source = $source[0]; $blacklist = json_decode($source['subtype_blacklist'], 1); if (json_last_error() !== JSON_ERROR_NONE) { $blacklist = []; } if ((bool) $value === true) { unset($blacklist[$subtype]); } else { $blacklist[$subtype] = 1; } $source['subtype_blacklist'] = json_encode($blacklist, 1); $res = (bool) db_process_sql_update( 'tnotification_source', ['subtype_blacklist' => $source['subtype_blacklist']], ['id' => $source['id']] ); } break; default: $res = (bool) db_process_sql_update( 'tnotification_source', [$element => $value], ['id' => $source] ); break; } echo json_encode(['result' => $res]); return; } if (get_parameter('check_new_notifications', 0)) { $last_id_ui = (int) get_parameter('last_id', 0); $counters = notifications_get_counters(); if ((int) $last_id_ui === (int) $counters['last_id']) { echo json_encode(['has_new_notifications' => false]); return; } if (messages_get_count() == 0) { return; } $messages = messages_get_overview( 'timestamp', 'ASC', false, true, 0, ['id_mensaje' => '>'.$last_id_ui] ); if ($messages === false) { $messages = []; } // If there is new messages, get the info. echo json_encode( [ 'has_new_notifications' => true, 'new_ball' => base64_encode( notifications_print_ball( $counters['notifications'], $counters['last_id'] ) ), 'new_notifications' => array_map( function ($elem) { $elem['full_url'] = messages_get_url($elem['id_mensaje']); return $elem; }, $messages ), ] ); return; } if (get_parameter('mark_notification_as_read', 0)) { $message = (int) get_parameter('message', 0); messages_process_read($message); // TODO check read. $url = messages_get_url($message); // Return false if cannot get the URL. if ($url === false) { echo json_encode(['result' => false]); return; } // If there is new messages, get the info. echo json_encode( [ 'result' => true, 'url' => $url, ] ); return; } if (get_parameter('mark_all_notification_as_read', 0)) { $unread_messages = db_get_all_rows_sql('SELECT id_mensaje FROM tnotification_user WHERE utimestamp_read is NULL'); if ($unread_messages !== false) { foreach ($unread_messages as $messages) { messages_process_read($messages['id_mensaje']); } $result = true; } else { $result = false; } // If there is new messages, get the info. echo json_encode( ['result' => $result] ); return; } if (get_parameter('get_notifications_dropdown', 0)) { echo notifications_print_dropdown(); return; } if (get_parameter('get_notification', 0)) { $msg_id = get_parameter('id', 0); if ($msg_id > 0) { $msg = messages_get_message($msg_id); $msg['mensaje'] = io_safe_output($msg['mensaje']); $msg['subject'] = io_safe_output($msg['subject']); echo json_encode($msg); } return; } // Notification table. It is just a wrapper. $table_content = new StdClass(); $table_content->data = []; $table_content->width = '100%'; $table_content->id = 'notifications-wrapper'; $table_content->class = 'databox filters'; $table_content->size['name'] = '30%'; // Print each source configuration. $table_content->data = array_map( function ($source) { return notifications_print_global_source_configuration($source); }, notifications_get_all_sources() ); html_print_table($table_content); ?>