diff options
Diffstat (limited to 'frontends/php/include/classes/screens/CScreenBuilder.php')
-rw-r--r-- | frontends/php/include/classes/screens/CScreenBuilder.php | 77 |
1 files changed, 71 insertions, 6 deletions
diff --git a/frontends/php/include/classes/screens/CScreenBuilder.php b/frontends/php/include/classes/screens/CScreenBuilder.php index f5d3c1587b7..ba00ae06712 100644 --- a/frontends/php/include/classes/screens/CScreenBuilder.php +++ b/frontends/php/include/classes/screens/CScreenBuilder.php @@ -163,6 +163,8 @@ class CScreenBuilder { * @param int $options['resourcetype'] * @param int $options['screenitemid'] * @param int $options['hostid'] + * @param array $options['screen'] + * @param int $options['screenid'] * * @return CScreenBase */ @@ -229,6 +231,7 @@ class CScreenBuilder { return new CScreenDataOverview($options); case SCREEN_RESOURCE_URL: + $options = self::appendTemplatedScreenOption($options); return new CScreenUrl($options); case SCREEN_RESOURCE_ACTIONS: @@ -247,17 +250,62 @@ class CScreenBuilder { return new CScreenHostTriggers($options); case SCREEN_RESOURCE_HISTORY: + // TODO: pass the items from the outside instead of retrieving them by ids + if (isset($options['itemids'])) { + $items = API::Item()->get(array( + 'itemids' => $options['itemids'], + 'webitems' => true, + 'selectHosts' => array('name'), + 'output' => array('itemid', 'hostid', 'name', 'key_', 'value_type', 'valuemapid'), + 'preservekeys' => true + )); + + $items = CMacrosResolverHelper::resolveItemNames($items); + + $options['items'] = $items; + unset($options['itemids']); + } + return new CScreenHistory($options); case SCREEN_RESOURCE_CHART: return new CScreenChart($options); + case SCREEN_RESOURCE_LLD_GRAPH: + $options = self::appendTemplatedScreenOption($options); + return new CScreenLldGraph($options); + + case SCREEN_RESOURCE_LLD_SIMPLE_GRAPH: + $options = self::appendTemplatedScreenOption($options); + return new CScreenLldSimpleGraph($options); + default: return null; } } /** + * Appends boolean option 'isTemplatedScreen' to ouput options. + * + * @param array $options + * + * @return array + */ + protected static function appendTemplatedScreenOption(array $options) { + if (isset($options['screen'])) { + $options['isTemplatedScreen'] = (bool) $options['screen']['templateid']; + } + elseif (isset($options['screenid'])) { + $options['isTemplatedScreen'] = (bool) API::TemplateScreen()->get(array( + 'screenids' => array($options['screenid']), + 'output' => array() + )); + } + + return $options; + } + + /** * Process screen with particular screen objects. * * @return CTable @@ -292,7 +340,7 @@ class CScreenBuilder { $screenTable->setAttribute('class', in_array($this->mode, array(SCREEN_MODE_PREVIEW, SCREEN_MODE_SLIDESHOW)) ? 'screen_view' : 'screen_edit' ); - $screenTable->setAttribute('id', 'iframe'); + $screenTable->setAttribute('id', self::makeScreenTableId($this->screen['screenid'])); // action top row if ($this->mode == SCREEN_MODE_EDIT) { @@ -383,6 +431,8 @@ class CScreenBuilder { // screen cell elseif (!empty($screenitem['screenitemid']) && isset($screenitem['resourcetype'])) { $screenBase = CScreenBuilder::getScreen(array( + 'screen' => $this->screen, + 'screenid' => $this->screen['screenid'], 'isFlickerfree' => $this->isFlickerfree, 'pageFile' => $this->pageFile, 'mode' => $this->mode, @@ -466,8 +516,10 @@ class CScreenBuilder { $removeRowLink = 'javascript: location.href = "screenedit.php?screenid='.$this->screen['screenid'].'&rmv_row='.$r.'";'; } else { - $removeRowLink = 'javascript: if (Confirm("'._('This screen-row is not empty. Delete it?').'")) {'. - ' location.href = "screenedit.php?screenid='.$this->screen['screenid'].'&rmv_row='.$r.'"; }'; + $removeRowLink = 'javascript:'. + ' if (confirm('.CJs::encodeJson(_('This screen-row is not empty. Delete it?')).')) {'. + ' location.href = "screenedit.php?screenid='.$this->screen['screenid'].'&rmv_row='.$r.'";'. + ' }'; } $icon->addAction('onclick', $removeRowLink); array_push($newColumns, new CCol($icon)); @@ -484,8 +536,10 @@ class CScreenBuilder { for ($i = 0; $i < $this->screen['hsize']; $i++) { $icon = new CImg('images/general/minus.png', null, null, null, 'pointer'); if (isset($emptyScreenColumns[$i])) { - $removeColumnLink = 'javascript: if (Confirm("'._('This screen-column is not empty. Delete it?').'")) {'. - ' location.href = "screenedit.php?screenid='.$this->screen['screenid'].'&rmv_col='.$i.'"; }'; + $removeColumnLink = 'javascript:'. + ' if (confirm('.CJs::encodeJson(_('This screen-column is not empty. Delete it?')).')) {'. + ' location.href = "screenedit.php?screenid='.$this->screen['screenid'].'&rmv_col='.$i.'";'. + ' }'; } else { $removeColumnLink = 'javascript: location.href = "screenedit.php?config=1&screenid='.$this->screen['screenid'].'&rmv_col='.$i.'";'; @@ -543,7 +597,7 @@ class CScreenBuilder { * @param string $screenid */ public static function insertInitScreenJs($screenid) { - zbx_add_post_js('init_screen("'.$screenid.'", "iframe", "'.$screenid.'");'); + zbx_add_post_js('init_screen("'.$screenid.'", "'.self::makeScreenTableId($screenid).'", "'.$screenid.'");'); } /** @@ -578,4 +632,15 @@ class CScreenBuilder { CScreenBuilder::insertScreenRefreshTimeJs(); CScreenBuilder::insertProcessObjectsJs(); } + + /** + * Creates a string for screen table ID attribute. + * + * @param string $screenId + * + * @return string + */ + protected static function makeScreenTableId($screenId) { + return 'screentable_'.$screenId; + } } |