1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 Zabbix SIA 5** 6** This program is free software; you can redistribute it and/or modify 7** it under the terms of the GNU General Public License as published by 8** the Free Software Foundation; either version 2 of the License, or 9** (at your option) any later version. 10** 11** This program is distributed in the hope that it will be useful, 12** but WITHOUT ANY WARRANTY; without even the implied warranty of 13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14** GNU General Public License for more details. 15** 16** You should have received a copy of the GNU General Public License 17** along with this program; if not, write to the Free Software 18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19**/ 20 21 22if ($data['graph']['unavailable_object']) { 23 $item = (new CTableInfo())->setNoDataMessage(_('No permissions to referred object or it does not exist!')); 24 25 $output = [ 26 'header' => $data['name'], 27 'body' => $item->toString() 28 ]; 29} 30else { 31 $flickerfree_item = (new CDiv()) 32 ->addItem((new CLink(null, $data['item_graph_url'])) 33 ->setId($data['graph']['containerid']) 34 ->addClass(ZBX_STYLE_DASHBRD_WIDGET_GRAPH_LINK) 35 ) 36 ->addClass('flickerfreescreen ') 37 ->setAttribute('data-timestamp', $data['graph']['timestamp']) 38 ->setId('flickerfreescreen_'.$data['graph']['dataid']); 39 40 $script = 'timeControl.addObject("'.$data['graph']['dataid'].'", '.CJs::encodeJson($data['timeline']).', '. 41 CJs::encodeJson($data['time_control_data']). 42 ');'. 43 'timeControl.processObjects();'. 44 'window.flickerfreeScreen.add('.zbx_jsvalue($data['fs_data']).');'; 45 46if ($data['widget']['initial_load'] == 1) { 47 $script .= 48 'if (typeof(zbx_graph_widget_resize_end) !== typeof(Function)) {'. 49 'function zbx_graph_widget_resize_end(img_id) {'. 50 'var img = jQuery("#"+img_id),'. 51 'content = img.closest(".dashbrd-grid-widget-content"),'. 52 'property_zone_height = timeControl.objectList[img_id]["objDims"]["graphPropertyZoneHeight"],'. 53 'src = img.attr("src");'. 54 'timeControl.objectList[img_id]["objDims"].width = Math.floor(content.width());'. 55 56 'if (typeof src === "undefined") {'. 57 'return;'. 58 '}'. 59 60 'var img_url = new Curl(src);'. 61 'content.css("overflow", "hidden");'. 62 'img_url.setArgument("width", Math.floor(content.width()));'. 63 'img_url.setArgument("height", Math.floor(content.height()));'. 64 'img_url.setArgument("_", (new Date).getTime().toString(34));'. 65 'content.css("overflow", "");'. 66 'img.attr("src", img_url.getUrl());'. 67 '}'. 68 '}'. 69 70 'if (typeof(zbx_graph_widget_timer_refresh) !== typeof(Function)) {'. 71 'function zbx_graph_widget_timer_refresh(img_id) {'. 72 'timeControl.refreshObject(img_id);'. 73 '}'. 74 '}'. 75 76 'jQuery(".dashbrd-grid-container").dashboardGrid("addAction", "onResizeEnd", '. 77 '"zbx_graph_widget_resize_end", "'.$data['widget']['uniqueid'].'", {'. 78 'parameters: ["'.$data['graph']['dataid'].'"],'. 79 'trigger_name: "graph_widget_resize_end_'.$data['widget']['uniqueid'].'"'. 80 '});'. 81 82 'jQuery(".dashbrd-grid-container").dashboardGrid("addAction", "timer_refresh", '. 83 '"zbx_graph_widget_timer_refresh", "'.$data['widget']['uniqueid'].'", {'. 84 'parameters: ["'.$data['graph']['dataid'].'"],'. 85 'trigger_name: "graph_widget_timer_refresh_'.$data['widget']['uniqueid'].'"'. 86 '});'; 87 } 88 89 $output = [ 90 'header' => $data['name'], 91 'body' => $flickerfree_item->toString(), 92 'script_inline' => $script 93 ]; 94} 95 96if (($messages = getMessages()) !== null) { 97 $output['messages'] = $messages->toString(); 98} 99 100if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) { 101 CProfiler::getInstance()->stop(); 102 $output['debug'] = CProfiler::getInstance()->make()->toString(); 103} 104 105echo (new CJson())->encode($output); 106