protected function doAction() { $profile = ['graphid' => 'web.favorite.graphids', 'itemid' => 'web.favorite.graphids', 'screenid' => 'web.favorite.screenids', 'slideshowid' => 'web.favorite.screenids', 'sysmapid' => 'web.favorite.sysmapids']; $object = $this->getInput('object'); $objectid = $this->getInput('objectid'); $data = []; DBstart(); $result = CFavorite::remove($profile[$object], $objectid, $object); $result = DBend($result); if ($result) { $data['main_block'] = '$("addrm_fav").title = "' . _('Add to favourites') . '";' . "\n" . '$("addrm_fav").onclick = function() { add2favorites("' . $object . '", "' . $objectid . '"); }' . "\n" . 'switchElementClass("addrm_fav", "btn-remove-fav", "btn-add-fav");'; } else { $data['main_block'] = ''; } $this->setResponse(new CControllerResponseData($data)); }
protected function doAction() { $filter = ['groupids' => null, 'maintenance' => null, 'severity' => null, 'trigger_name' => '', 'extAck' => 0]; if (CProfile::get('web.dashconf.filter.enable', 0) == 1) { // groups if (CProfile::get('web.dashconf.groups.grpswitch', 0) == 0) { // null mean all groups $filter['groupids'] = null; } else { $filter['groupids'] = zbx_objectValues(CFavorite::get('web.dashconf.groups.groupids'), 'value'); $hideHostGroupIds = zbx_objectValues(CFavorite::get('web.dashconf.groups.hide.groupids'), 'value'); if ($hideHostGroupIds) { // get all groups if no selected groups defined if (!$filter['groupids']) { $dbHostGroups = API::HostGroup()->get(['output' => ['groupid']]); $filter['groupids'] = zbx_objectValues($dbHostGroups, 'groupid'); } $filter['groupids'] = array_diff($filter['groupids'], $hideHostGroupIds); // get available hosts $dbAvailableHosts = API::Host()->get(['groupids' => $filter['groupids'], 'output' => ['hostid']]); $availableHostIds = zbx_objectValues($dbAvailableHosts, 'hostid'); $dbDisabledHosts = API::Host()->get(['groupids' => $hideHostGroupIds, 'output' => ['hostid']]); $disabledHostIds = zbx_objectValues($dbDisabledHosts, 'hostid'); $filter['hostids'] = array_diff($availableHostIds, $disabledHostIds); } else { if (!$filter['groupids']) { // null mean all groups $filter['groupids'] = null; } } } // hosts $maintenance = CProfile::get('web.dashconf.hosts.maintenance', 1); $filter['maintenance'] = $maintenance == 0 ? 0 : null; // triggers $severity = CProfile::get('web.dashconf.triggers.severity', null); $filter['severity'] = zbx_empty($severity) ? null : explode(';', $severity); $filter['severity'] = zbx_toHash($filter['severity']); $filter['trigger_name'] = CProfile::get('web.dashconf.triggers.name', ''); $config = select_config(); $filter['extAck'] = $config['event_ack_enable'] ? CProfile::get('web.dashconf.events.extAck', 0) : 0; } $this->setResponse(new CControllerResponseData(['filter' => $filter, 'user' => ['debug_mode' => $this->getDebugMode()]])); }
protected function doAction() { $filter = ['groupids' => null, 'maintenance' => null]; if (CProfile::get('web.dashconf.filter.enable', 0) == 1) { // groups if (CProfile::get('web.dashconf.groups.grpswitch', 0) == 0) { // null mean all groups $filter['groupids'] = null; } else { $filter['groupids'] = zbx_objectValues(CFavorite::get('web.dashconf.groups.groupids'), 'value'); $hideHostGroupIds = zbx_objectValues(CFavorite::get('web.dashconf.groups.hide.groupids'), 'value'); if ($hideHostGroupIds) { // get all groups if no selected groups defined if (!$filter['groupids']) { $dbHostGroups = API::HostGroup()->get(['output' => ['groupid']]); $filter['groupids'] = zbx_objectValues($dbHostGroups, 'groupid'); } $filter['groupids'] = array_diff($filter['groupids'], $hideHostGroupIds); // get available hosts $dbAvailableHosts = API::Host()->get(['groupids' => $filter['groupids'], 'output' => ['hostid']]); $availableHostIds = zbx_objectValues($dbAvailableHosts, 'hostid'); $dbDisabledHosts = API::Host()->get(['groupids' => $hideHostGroupIds, 'output' => ['hostid']]); $disabledHostIds = zbx_objectValues($dbDisabledHosts, 'hostid'); $filter['hostids'] = array_diff($availableHostIds, $disabledHostIds); } else { if (!$filter['groupids']) { // null mean all groups $filter['groupids'] = null; } } } // hosts $maintenance = CProfile::get('web.dashconf.hosts.maintenance', 1); $filter['maintenance'] = $maintenance == 0 ? 0 : null; } $this->setResponse(new CControllerResponseData(['filter' => $filter, 'user' => ['debug_mode' => $this->getDebugMode()]])); }
} if (isset($_REQUEST['favobj'])) { if (getRequest('favobj') === 'timelinefixedperiod' && hasRequest('favid')) { CProfile::update('web.screens.timelinefixed', getRequest('favid'), PROFILE_TYPE_INT); } if (str_in_array($_REQUEST['favobj'], array('itemid', 'graphid'))) { $result = false; DBstart(); if ($_REQUEST['favaction'] == 'add') { $result = CFavorite::add('web.favorite.graphids', $_REQUEST['favid'], $_REQUEST['favobj']); if ($result) { echo '$("addrm_fav").title = "' . _('Remove from favourites') . '";' . "\n"; echo '$("addrm_fav").onclick = function() { rm4favorites("graphid", "' . $_REQUEST['favid'] . '"); }' . "\n"; } } elseif ($_REQUEST['favaction'] == 'remove') { $result = CFavorite::remove('web.favorite.graphids', $_REQUEST['favid'], $_REQUEST['favobj']); if ($result) { echo '$("addrm_fav").title = "' . _('Add to favourites') . '";' . "\n"; echo '$("addrm_fav").onclick = function() { add2favorites("graphid", "' . $_REQUEST['favid'] . '"); }' . "\n"; } } $result = DBend($result); if ($page['type'] == PAGE_TYPE_JS && $result) { echo 'switchElementClass("addrm_fav", "iconminus", "iconplus");'; } } } if (!empty($_REQUEST['period']) || !empty($_REQUEST['stime'])) { CScreenBase::calculateTime(array('profileIdx' => 'web.screens', 'profileIdx2' => $pageFilter->graphid, 'updateProfile' => true, 'period' => getRequest('period'), 'stime' => getRequest('stime'))); $curl = new CUrl(); $curl->removeArgument('period');
function make_screen_submenu() { $favScreens = array(); $fav_screens = CFavorite::get('web.favorite.screenids'); if (!$fav_screens) { return $favScreens; } $screenids = array(); foreach ($fav_screens as $favorite) { if ('screenid' == $favorite['source']) { $screenids[$favorite['value']] = $favorite['value']; } } $options = array('screenids' => $screenids, 'output' => array('screenid', 'name')); $screens = API::Screen()->get($options); $screens = zbx_toHash($screens, 'screenid'); foreach ($fav_screens as $favorite) { $source = $favorite['source']; $sourceid = $favorite['value']; if ('slideshowid' == $source) { if (!slideshow_accessible($sourceid, PERM_READ)) { continue; } if (!($slide = get_slideshow_by_slideshowid($sourceid))) { continue; } $slide_added = true; $favScreens[] = array('name' => $slide['name'], 'favobj' => 'slideshowid', 'favid' => $slide['slideshowid'], 'favaction' => 'remove'); } else { if (!isset($screens[$sourceid])) { continue; } $screen = $screens[$sourceid]; $screen_added = true; $favScreens[] = array('name' => $screen['name'], 'favobj' => 'screenid', 'favid' => $screen['screenid'], 'favaction' => 'remove'); } } if (isset($screen_added)) { $favScreens[] = array('name' => _('Remove') . ' ' . _('All') . ' ' . _('Screens'), 'favobj' => 'screenid', 'favid' => 0, 'favaction' => 'remove'); } if (isset($slide_added)) { $favScreens[] = array('name' => _('Remove') . ' ' . _('All') . ' ' . _('Slides'), 'favobj' => 'slideshowid', 'favid' => 0, 'favaction' => 'remove'); } return $favScreens; }
/** * Prepare data for favourite screens menu popup. * * @return array */ public static function getFavouriteScreens() { $screens = $slideshows = array(); $favourites = CFavorite::get('web.favorite.screenids'); if ($favourites) { $screenIds = $slideshowIds = array(); foreach ($favourites as $favourite) { if ($favourite['source'] === 'screenid') { $screenIds[$favourite['value']] = $favourite['value']; } } $dbScreens = API::Screen()->get(array('output' => array('screenid', 'name'), 'screenids' => $screenIds, 'preservekeys' => true)); foreach ($favourites as $favourite) { $sourceId = $favourite['value']; if ($favourite['source'] === 'slideshowid') { if (slideshow_accessible($sourceId, PERM_READ)) { $dbSlideshow = get_slideshow_by_slideshowid($sourceId); if ($dbSlideshow) { $slideshows[] = array('id' => $dbSlideshow['slideshowid'], 'label' => $dbSlideshow['name']); } } } else { if (isset($dbScreens[$sourceId])) { $dbScreen = $dbScreens[$sourceId]; $screens[] = array('id' => $dbScreen['screenid'], 'label' => $dbScreen['name']); } } } } return array('type' => 'favouriteScreens', 'screens' => $screens, 'slideshows' => $slideshows); }
/** * Get favourite screens and slide shows data. * * @return array['screens'] * @return array['slideshows'] */ function getFavouriteScreensData() { $screens = $slideshows = []; $favourites = CFavorite::get('web.favorite.screenids'); if ($favourites) { $screenIds = $slideshowIds = []; foreach ($favourites as $favourite) { if ($favourite['source'] === 'screenid') { $screenIds[$favourite['value']] = $favourite['value']; } } $dbScreens = API::Screen()->get(['output' => ['screenid', 'name'], 'screenids' => $screenIds, 'preservekeys' => true]); foreach ($favourites as $favourite) { $sourceId = $favourite['value']; if ($favourite['source'] === 'slideshowid') { if (slideshow_accessible($sourceId, PERM_READ)) { $dbSlideshow = get_slideshow_by_slideshowid($sourceId, PERM_READ); if ($dbSlideshow) { $slideshows[] = ['id' => $dbSlideshow['slideshowid'], 'label' => $dbSlideshow['name']]; } } } else { if (isset($dbScreens[$sourceId])) { $dbScreen = $dbScreens[$sourceId]; $screens[] = ['id' => $dbScreen['screenid'], 'label' => $dbScreen['name']]; } } } } return ['screens' => $screens, 'slideshows' => $slideshows]; }
$data['groupIds'] = getRequest('groupids', array()); $data['groupIds'] = zbx_toHash($data['groupIds']); $data['hideGroupIds'] = getRequest('hidegroupids', array()); $data['hideGroupIds'] = zbx_toHash($data['hideGroupIds']); } else { $data['isFilterEnable'] = CProfile::get('web.dashconf.filter.enable', 0); $data['maintenance'] = CProfile::get('web.dashconf.hosts.maintenance', 1); $data['extAck'] = CProfile::get('web.dashconf.events.extAck', 0); $data['severity'] = CProfile::get('web.dashconf.triggers.severity', '0;1;2;3;4;5'); $data['severity'] = zbx_empty($data['severity']) ? array() : explode(';', $data['severity']); // groups $data['grpswitch'] = CProfile::get('web.dashconf.groups.grpswitch', 0); $data['groupIds'] = CFavorite::get('web.dashconf.groups.groupids'); $data['groupIds'] = zbx_objectValues($data['groupIds'], 'value'); $data['groupIds'] = zbx_toHash($data['groupIds']); $data['hideGroupIds'] = CFavorite::get('web.dashconf.groups.hide.groupids'); $data['hideGroupIds'] = zbx_objectValues($data['hideGroupIds'], 'value'); $data['hideGroupIds'] = zbx_toHash($data['hideGroupIds']); } $data['severity'] = zbx_toHash($data['severity']); $data['severities'] = array(TRIGGER_SEVERITY_NOT_CLASSIFIED, TRIGGER_SEVERITY_INFORMATION, TRIGGER_SEVERITY_WARNING, TRIGGER_SEVERITY_AVERAGE, TRIGGER_SEVERITY_HIGH, TRIGGER_SEVERITY_DISASTER); if ($data['grpswitch']) { // show groups $data['groups'] = API::HostGroup()->get(array('groupids' => $data['groupIds'], 'output' => array('groupid', 'name'))); CArrayHelper::sort($data['groups'], array(array('field' => 'name', 'order' => ZBX_SORT_UP))); foreach ($data['groups'] as &$group) { $group['id'] = $group['groupid']; unset($group['groupid']); } unset($group); // hide groups
function get_icon($name, $params = array()) { switch ($name) { case 'favourite': if (CFavorite::exists($params['fav'], $params['elid'], $params['elname'])) { $icon = new CIcon(_('Remove from favourites'), 'iconminus', 'rm4favorites("' . $params['elname'] . '", "' . $params['elid'] . '", 0);'); } else { $icon = new CIcon(_('Add to favourites'), 'iconplus', 'add2favorites("' . $params['elname'] . '", "' . $params['elid'] . '");'); } $icon->setAttribute('id', 'addrm_fav'); break; case 'fullscreen': $url = new Curl(); $url->setArgument('fullscreen', $params['fullscreen'] ? '0' : '1'); $icon = new CIcon($_REQUEST['fullscreen'] ? _('Normal view') : _('Fullscreen'), 'fullscreen', "document.location = '" . $url->getUrl() . "';"); break; case 'menu': $icon = new CIcon(_('Menu'), 'iconmenu', 'create_page_menu(event, "' . $params['menu'] . '");'); break; case 'reset': $icon = new CIcon(_('Reset'), 'iconreset', 'timeControl.objectReset();'); break; } return $icon; }
echo ' jQuery("#' . WIDGET_FAVOURITE_MAPS . '").html(' . CJs::encodeJson($data) . '); jQuery(".menuPopup").remove(); jQuery("#favouriteMaps").data("menu-popup", ' . CJs::encodeJson(CMenuPopupHelper::getFavouriteMaps()) . ');'; break; // favourite screens, slideshows // favourite screens, slideshows case 'screenid': case 'slideshowid': if ($favouriteAction == 'add') { zbx_value2array($favouriteId); foreach ($favouriteId as $id) { $result &= CFavorite::add('web.favorite.screenids', $id, $favouriteObject); } } elseif ($favouriteAction == 'remove') { $result &= CFavorite::remove('web.favorite.screenids', $favouriteId, $favouriteObject); } $data = getFavouriteScreens(); $data = $data->toString(); echo ' jQuery("#' . WIDGET_FAVOURITE_SCREENS . '").html(' . CJs::encodeJson($data) . '); jQuery(".menuPopup").remove(); jQuery("#favouriteScreens").data("menu-popup", ' . CJs::encodeJson(CMenuPopupHelper::getFavouriteScreens()) . ');'; break; } DBend($result); } if ($page['type'] == PAGE_TYPE_JS || $page['type'] == PAGE_TYPE_HTML_BLOCK) { require_once dirname(__FILE__) . '/include/page_footer.php'; exit; }
function get_icon($type, $params = []) { switch ($type) { case 'favourite': if (CFavorite::exists($params['fav'], $params['elid'], $params['elname'])) { $icon = (new CRedirectButton(SPACE, null))->addClass(ZBX_STYLE_BTN_REMOVE_FAV)->setTitle(_('Remove from favourites'))->onClick('rm4favorites("' . $params['elname'] . '", "' . $params['elid'] . '");'); } else { $icon = (new CRedirectButton(SPACE, null))->addClass(ZBX_STYLE_BTN_ADD_FAV)->setTitle(_('Add to favourites'))->onClick('add2favorites("' . $params['elname'] . '", "' . $params['elid'] . '");'); } $icon->setId('addrm_fav'); return $icon; case 'fullscreen': $url = new CUrl(); if ($params['fullscreen'] == 0) { $url->setArgument('fullscreen', '1'); $icon = (new CRedirectButton(SPACE, $url->getUrl()))->setTitle(_('Fullscreen'))->addClass(ZBX_STYLE_BTN_MAX); } else { $url->setArgument('fullscreen', '0'); $icon = (new CRedirectButton(SPACE, $url->getUrl()))->setTitle(_('Normal view'))->addClass(ZBX_STYLE_BTN_MIN); } return $icon; case 'dashconf': $icon = (new CRedirectButton(SPACE, 'dashconf.php'))->addClass(ZBX_STYLE_BTN_CONF)->setTitle(_('Configure')); if ($params['enabled']) { $icon = [$icon, (new CDiv())->addClass(ZBX_STYLE_ACTIVE_INDIC)]; } return $icon; case 'screenconf': return (new CRedirectButton(SPACE, null))->addClass(ZBX_STYLE_BTN_CONF)->setTitle(_('Refresh time')); case 'overviewhelp': return (new CRedirectButton(SPACE, null))->addClass(ZBX_STYLE_BTN_INFO); case 'reset': return (new CRedirectButton(SPACE, null))->addClass(ZBX_STYLE_BTN_RESET)->setTitle(_('Reset'))->onClick('timeControl.objectReset();'); } return null; }
protected function doAction() { $object = $this->getInput('object'); $operation = $this->getInput('operation'); $objectids = $this->getInput('objectids'); $data = []; $result = true; DBstart(); switch ($object) { // favourite graphs case 'itemid': case 'graphid': zbx_value2array($objectids); foreach ($objectids as $id) { if ($operation == 'create') { $result &= CFavorite::add('web.favorite.graphids', $id, $object); } elseif ($operation == 'delete') { $result &= CFavorite::remove('web.favorite.graphids', $id, $object); } } $graphs = getFavouriteGraphs(); $graphs = $graphs->toString(); $data['main_block'] = 'jQuery("#' . WIDGET_FAVOURITE_GRAPHS . '").html(' . CJs::encodeJson($graphs) . ');' . 'jQuery(".action-menu").remove();' . 'jQuery("#favouriteGraphs").data(' . '"menu-popup", ' . CJs::encodeJson(CMenuPopupHelper::getFavouriteGraphs()) . ');'; break; // favourite maps // favourite maps case 'sysmapid': zbx_value2array($objectids); foreach ($objectids as $id) { if ($operation == 'create') { $result &= CFavorite::add('web.favorite.sysmapids', $id, $object); } elseif ($operation == 'delete') { $result &= CFavorite::remove('web.favorite.sysmapids', $id, $object); } } $maps = getFavouriteMaps(); $maps = $maps->toString(); $data['main_block'] = 'jQuery("#' . WIDGET_FAVOURITE_MAPS . '").html(' . CJs::encodeJson($maps) . ');' . 'jQuery(".action-menu").remove();' . 'jQuery("#favouriteMaps").data(' . '"menu-popup", ' . CJs::encodeJson(CMenuPopupHelper::getFavouriteMaps()) . ');'; break; // favourite screens, slideshows // favourite screens, slideshows case 'screenid': case 'slideshowid': zbx_value2array($objectids); foreach ($objectids as $id) { if ($operation == 'create') { $result &= CFavorite::add('web.favorite.screenids', $id, $object); } elseif ($operation == 'delete') { $result &= CFavorite::remove('web.favorite.screenids', $id, $object); } } $screens = getFavouriteScreens(); $screens = $screens->toString(); $data['main_block'] = 'jQuery("#' . WIDGET_FAVOURITE_SCREENS . '").html(' . CJs::encodeJson($screens) . ');' . 'jQuery(".action-menu").remove();' . 'jQuery("#favouriteScreens").data(' . '"menu-popup", ' . CJs::encodeJson(CMenuPopupHelper::getFavouriteScreens()) . ');'; break; default: $data['main_block'] = ''; } DBend($result); $this->setResponse(new CControllerResponseData($data)); }