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 22class CScreenSimpleGraph extends CScreenBase { 23 24 /** 25 * Process screen. 26 * 27 * @return CDiv (screen inside container) 28 */ 29 public function get() { 30 $this->dataId = 'graph_'.$this->screenitem['screenitemid'].'_'.$this->screenitem['screenid']; 31 $resourceid = !empty($this->screenitem['real_resourceid']) ? $this->screenitem['real_resourceid'] : $this->screenitem['resourceid']; 32 $containerid = 'graph_container_'.$this->screenitem['screenitemid'].'_'.$this->screenitem['screenid']; 33 $graphDims = getGraphDims(); 34 $graphDims['graphHeight'] = (int) $this->screenitem['height']; 35 $graphDims['width'] = (int) $this->screenitem['width']; 36 37 // get time control 38 $timeControlData = [ 39 'id' => $this->getDataId(), 40 'containerid' => $containerid, 41 'objDims' => $graphDims, 42 'loadImage' => 1 43 ]; 44 45 // host feature 46 if ($this->screenitem['dynamic'] == SCREEN_DYNAMIC_ITEM && !empty($this->hostid)) { 47 $newitemid = get_same_item_for_host($resourceid, $this->hostid); 48 $resourceid = !empty($newitemid) ? $newitemid : ''; 49 } 50 51 if ($this->mode == SCREEN_MODE_PREVIEW && !empty($resourceid)) { 52 $this->action = (new CUrl('history.php')) 53 ->setArgument('action', HISTORY_GRAPH) 54 ->setArgument('itemids', [$resourceid]) 55 ->setArgument('from', $this->timeline['from']) 56 ->setArgument('to', $this->timeline['to']) 57 ->setArgument('profileIdx', $this->profileIdx) 58 ->setArgument('profileIdx2', $this->profileIdx2) 59 ->getUrl(); 60 } 61 62 if ($resourceid && $this->mode != SCREEN_MODE_EDIT) { 63 if ($this->mode == SCREEN_MODE_PREVIEW) { 64 $timeControlData['loadSBox'] = 1; 65 } 66 } 67 68 if ($resourceid) { 69 $src = (new CUrl('chart.php')) 70 ->setArgument('itemids', [$resourceid]) 71 ->setArgument('width', $this->screenitem['width']) 72 ->setArgument('height', $this->screenitem['height']); 73 } 74 else { 75 $src = new CUrl('chart3.php'); 76 } 77 78 if ($this->mode == SCREEN_MODE_EDIT) { 79 $src 80 ->setArgument('from', ZBX_PERIOD_DEFAULT_FROM) 81 ->setArgument('to', ZBX_PERIOD_DEFAULT_TO); 82 } 83 else { 84 $src 85 ->setArgument('from', $this->timeline['from']) 86 ->setArgument('to', $this->timeline['to']); 87 } 88 89 $src 90 ->setArgument('profileIdx', $this->profileIdx) 91 ->setArgument('profileIdx2', $this->profileIdx2); 92 93 $timeControlData['src'] = $src->getUrl(); 94 95 // output 96 if ($this->mode == SCREEN_MODE_JS) { 97 return 'timeControl.addObject("'.$this->getDataId().'", '.json_encode($this->timeline).', '. 98 json_encode($timeControlData).')'; 99 } 100 101 if ($this->mode == SCREEN_MODE_SLIDESHOW) { 102 insert_js('timeControl.addObject("'.$this->getDataId().'", '.json_encode($this->timeline).', '. 103 json_encode($timeControlData).');' 104 ); 105 } 106 else { 107 zbx_add_post_js('timeControl.addObject("'.$this->getDataId().'", '.json_encode($this->timeline).', '. 108 json_encode($timeControlData).');' 109 ); 110 } 111 112 if ($this->mode == SCREEN_MODE_EDIT || $this->mode == SCREEN_MODE_SLIDESHOW || !$resourceid) { 113 $item = new CDiv(); 114 } 115 elseif ($this->mode == SCREEN_MODE_PREVIEW) { 116 $item = new CLink(null, (new CUrl('history.php')) 117 ->setArgument('action', HISTORY_GRAPH) 118 ->setArgument('itemids', [$resourceid]) 119 ->setArgument('from', $this->timeline['from']) 120 ->setArgument('to', $this->timeline['to']) 121 ->getUrl() 122 ); 123 } 124 $item->setId($containerid); 125 126 return $this->getOutput($item); 127 } 128} 129