/** * @param array $options['objectOptions'] an array of parameters to be added to the request URL * * @see jQuery.multiSelect() */ public function __construct(array $options = []) { parent::__construct('div', true); $this->addClass('multiselect'); $this->setId(zbx_formatDomId($options['name'])); // url $url = new CUrl('jsrpc.php'); $url->setArgument('type', PAGE_TYPE_TEXT_RETURN_JSON); $url->setArgument('method', 'multiselect.get'); $url->setArgument('objectName', $options['objectName']); if (!empty($options['objectOptions'])) { foreach ($options['objectOptions'] as $optionName => $optionvalue) { $url->setArgument($optionName, $optionvalue); } } $params = ['url' => $url->getUrl(), 'name' => $options['name'], 'labels' => ['No matches found' => _('No matches found'), 'More matches found...' => _('More matches found...'), 'type here to search' => _('type here to search'), 'new' => _('new'), 'Select' => _('Select')]]; if (array_key_exists('data', $options)) { $params['data'] = zbx_cleanHashes($options['data']); } foreach (['ignored', 'defaultValue', 'disabled', 'selectedLimit', 'addNew'] as $option) { if (array_key_exists($option, $options)) { $params[$option] = $options[$option]; } } if (array_key_exists('popup', $options)) { foreach (['parameters', 'width', 'height'] as $option) { if (array_key_exists($option, $options['popup'])) { $params['popup'][$option] = $options['popup'][$option]; } } } zbx_add_post_js('jQuery("#' . $this->getAttribute('id') . '").multiSelect(' . CJs::encodeJson($params) . ');'); }
/** * @param array $options['objectOptions'] an array of parameters to be added to the request URL * * @see jQuery.multiSelect() */ public function __construct(array $options = array()) { parent::__construct('div', 'yes'); $this->addClass('multiselect'); $this->attr('id', zbx_formatDomId($options['name'])); // url $url = new CUrl('jsrpc.php'); $url->setArgument('type', PAGE_TYPE_TEXT_RETURN_JSON); $url->setArgument('method', 'multiselect.get'); $url->setArgument('objectName', $options['objectName']); if (!empty($options['objectOptions'])) { foreach ($options['objectOptions'] as $optionName => $optionvalue) { $url->setArgument($optionName, $optionvalue); } } $params = array('url' => $url->getUrl(), 'name' => $options['name'], 'labels' => array('No matches found' => _('No matches found'), 'More matches found...' => _('More matches found...'), 'type here to search' => _('type here to search'), 'new' => _('new'), 'Select' => _('Select')), 'data' => empty($options['data']) ? array() : zbx_cleanHashes($options['data']), 'ignored' => isset($options['ignored']) ? $options['ignored'] : null, 'defaultValue' => isset($options['defaultValue']) ? $options['defaultValue'] : null, 'disabled' => isset($options['disabled']) ? $options['disabled'] : false, 'selectedLimit' => isset($options['selectedLimit']) ? $options['selectedLimit'] : null, 'addNew' => isset($options['addNew']) ? $options['addNew'] : false, 'popup' => array('parameters' => isset($options['popup']['parameters']) ? $options['popup']['parameters'] : null, 'width' => isset($options['popup']['width']) ? $options['popup']['width'] : null, 'height' => isset($options['popup']['height']) ? $options['popup']['height'] : null, 'buttonClass' => isset($options['popup']['buttonClass']) ? $options['popup']['buttonClass'] : null)); zbx_add_post_js('jQuery("#' . $this->getAttribute('id') . '").multiSelect(' . CJs::encodeJson($params) . ');'); }
/** * Creates new CUrl object based on giver URL (or $_REQUEST if null is given), * and adds/removes parameters based on current page context. * * @param string $sourceUrl * * @return CUrl */ public static function getContextUrl($sourceUrl = null) { $config = self::resolveConfig(); $url = new CUrl($sourceUrl); if (isset($config['remove'])) { foreach ($config['remove'] as $key) { $url->removeArgument($key); } } if (isset($config['add'])) { foreach ($config['add'] as $key) { $url->setArgument($key, getRequest($key)); } } return $url; }
function resetGetParams($params, $newURL = null) { zbx_value2array($params); $redirect = false; $url = new CUrl($newURL); foreach ($params as $num => $param) { if (!isset($_GET[$param])) { continue; } $redirect = true; $url->setArgument($param, null); } if ($redirect) { jsRedirect($url->getUrl()); include_once 'include/page_footer.php'; } }
$createForm->cleanItems(); $createForm->addVar('parent_discoveryid', $this->data['parent_discoveryid']); $createForm->addItem(new CSubmit('form', _('Create host prototype'))); $itemsWidget->addPageHeader(_('CONFIGURATION OF HOST PROTOTYPES'), $createForm); // header $itemsWidget->addHeader(array(_('Host prototypes of') . SPACE, new CSpan($this->data['discovery_rule']['name'], 'parent-discovery'))); $itemsWidget->addHeaderRowNumber(); $itemsWidget->addItem(get_header_host_table('hosts', $discoveryRule['hostid'], $this->data['parent_discoveryid'])); // create form $itemForm = new CForm(); $itemForm->setName('hosts'); $itemForm->addVar('parent_discoveryid', $this->data['parent_discoveryid']); // create table $hostTable = new CTableInfo(_('No host prototypes found.')); $sortLink = new CUrl(); $sortLink->setArgument('parent_discoveryid', $this->data['parent_discoveryid']); $sortLink = $sortLink->getUrl(); $hostTable->setHeader(array(new CCheckBox('all_hosts', null, "checkAll('" . $itemForm->getName() . "', 'all_hosts', 'group_hostid');"), make_sorting_header(_('Name'), 'name', $sortLink), _('Templates'), make_sorting_header(_('Status'), 'status', $sortLink))); foreach ($this->data['hostPrototypes'] as $hostPrototype) { // name $name = array(); if ($hostPrototype['templateid']) { $sourceTemplate = $hostPrototype['sourceTemplate']; $name[] = new CLink($sourceTemplate['name'], '?parent_discoveryid=' . $hostPrototype['sourceDiscoveryRuleId'], 'unknown'); $name[] = NAME_DELIMITER; } $name[] = new CLink($hostPrototype['name'], '?form=update&parent_discoveryid=' . $discoveryRule['itemid'] . '&hostid=' . $hostPrototype['hostid']); // template list if (empty($hostPrototype['templates'])) { $hostTemplates = '-'; } else {
/** * Renders an "access denied" message and stops the execution of the script. * * The $mode parameters controls the layout of the message: * - ACCESS_DENY_OBJECT - render the message when denying access to a specific object * - ACCESS_DENY_PAGE - render a complete access denied page * * @param int $mode */ function access_deny($mode = ACCESS_DENY_OBJECT) { // deny access to an object if ($mode == ACCESS_DENY_OBJECT) { require_once dirname(__FILE__) . '/page_header.php'; show_error_message(_('No permissions to referred object or it does not exist!')); require_once dirname(__FILE__) . '/page_footer.php'; } else { // url to redirect the user to after he loggs in $url = new CUrl(!empty($_REQUEST['request']) ? $_REQUEST['request'] : ''); $url->setArgument('sid', null); $url = urlencode($url->toString()); // if the user is logged in - render the access denied message if (CWebUser::isLoggedIn()) { $header = _('Access denied.'); $message = array(_('Your are logged in as'), ' ', bold(CWebUser::$data['alias']), '. ', _('You have no permissions to access this page.'), BR(), _('If you think this message is wrong, please consult your administrators about getting the necessary permissions.')); $buttons = array(); // display the login button only for guest users if (CWebUser::isGuest()) { $buttons[] = new CButton('login', _('Login'), 'javascript: document.location = "index.php?request=' . $url . '";', 'formlist'); } $buttons[] = new CButton('back', _('Go to dashboard'), 'javascript: document.location = "dashboard.php"', 'formlist'); } else { $header = _('You are not logged in.'); $message = array(_('You must login to view this page.'), BR(), _('If you think this message is wrong, please consult your administrators about getting the necessary permissions.')); $buttons = array(new CButton('login', _('Login'), 'javascript: document.location = "index.php?request=' . $url . '";', 'formlist')); } $warning = new CWarning($header, $message); $warning->setButtons($buttons); $warningView = new CView('general.warning', array('warning' => $warning)); $warningView->render(); exit; } }
$req = new CUrl(); $req->setArgument('print', null); $link = new CLink(bold('«' . S_BACK_BIG), $req->getUrl(), 'small_font', null, 'nosid'); $link->setAttribute('style', 'padding-left: 10px;'); $printview = new CDiv($link, 'printless'); $printview->setAttribute('style', 'border: 1px #333 dotted;'); $printview->Show(); } if (!defined('ZBX_PAGE_NO_MENU')) { COpt::compare_files_with_menu($ZBX_MENU); $help = new CLink(S_HELP, 'http://www.zabbix.com/documentation/', 'small_font', null, 'nosid'); $help->setTarget('_blank'); $support = new CLink(S_GET_SUPPORT, 'http://www.zabbix.com/support.php', 'small_font', null, 'nosid'); $support->setTarget('_blank'); $req = new CUrl($_SERVER['REQUEST_URI']); $req->setArgument('print', 1); $printview = new CLink(S_PRINT, $req->getUrl(), 'small_font', null, 'nosid'); $page_header_r_col = array($help, '|', $support, '|', $printview); if ($USER_DETAILS['alias'] != ZBX_GUEST_USER) { $page_header_r_col[] = array('|'); array_push($page_header_r_col, new CLink(S_PROFILE, 'profile.php', 'small_font', null, 'nosid'), '|'); if ($USER_DETAILS['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) { $debug = new CLink(S_DEBUG, '#debug', 'small_font', null, 'nosid'); $d_script = " if(!isset('state', this)) this.state = 'none'; " . " if(this.state == 'none') this.state = 'block'; " . " else this.state = 'none'; " . " showHideByName('zbx_gebug_info', this.state);"; $debug->setAttribute('onclick', 'javascript: ' . $d_script); array_push($page_header_r_col, $debug, '|'); } array_push($page_header_r_col, new CLink(S_LOGOUT, 'index.php?reconnect=1', 'small_font', null, 'nosid')); } else { $page_header_r_col[] = array('|', new CLink(S_LOGIN, 'index.php?reconnect=1', 'small_font', null, 'nosid')); }
/** * Return the URL for the graph. * * @param array $itemIds * * @return string */ protected function getGraphUrl(array $itemIds) { $url = new CUrl('chart.php'); $url->setArgument('period', $this->timeline['period']); $url->setArgument('stime', $this->timeline['stime']); $url->setArgument('itemids', $itemIds); $url->setArgument('type', $this->graphType); if ($this->action == HISTORY_BATCH_GRAPH) { $url->setArgument('batch', 1); } return $url->getUrl() . $this->getProfileUrlParams(); }
$createForm->cleanItems(); $createForm->addVar('hostid', $this->data['hostid']); $createForm->addItem(new CSubmit('form', _('Create discovery rule'))); $discoveryWidget->addPageHeader(_('CONFIGURATION OF DISCOVERY RULES'), $createForm); // header $discoveryWidget->addHeader(_('Discovery rules')); $discoveryWidget->addHeaderRowNumber(); $discoveryWidget->addItem(get_header_host_table('discoveries', $this->data['hostid'])); // create form $discoveryForm = new CForm(); $discoveryForm->setName('discovery'); $discoveryForm->addVar('hostid', $this->data['hostid']); // create table $discoveryTable = new CTableInfo(_('No discovery rules found.')); $sortLink = new CUrl(); $sortLink->setArgument('hostid', $this->data['hostid']); $sortLink = $sortLink->getUrl(); $discoveryTable->setHeader(array(new CCheckBox('all_items', null, "checkAll('" . $discoveryForm->getName() . "', 'all_items', 'g_hostdruleid');"), make_sorting_header(_('Name'), 'name', $sortLink), _('Items'), _('Triggers'), _('Graphs'), $data['host']['flags'] == ZBX_FLAG_DISCOVERY_NORMAL ? _('Hosts') : null, make_sorting_header(_('Key'), 'key_', $sortLink), make_sorting_header(_('Interval'), 'delay', $sortLink), make_sorting_header(_('Type'), 'type', $sortLink), make_sorting_header(_('Status'), 'status', $sortLink), $data['showErrorColumn'] ? _('Error') : null)); foreach ($data['discoveries'] as $discovery) { $description = array(); if ($discovery['templateid']) { $template_host = get_realhost_by_itemid($discovery['templateid']); $description[] = new CLink($template_host['name'], '?hostid=' . $template_host['hostid'], 'unknown'); $description[] = NAME_DELIMITER; } $discovery['name_expanded'] = itemName($discovery); $description[] = new CLink($discovery['name_expanded'], '?form=update&itemid=' . $discovery['itemid']); $status = new CLink(itemIndicator($discovery['status'], $discovery['state']), '?hostid=' . $_REQUEST['hostid'] . '&g_hostdruleid=' . $discovery['itemid'] . '&go=' . ($discovery['status'] ? 'activate' : 'disable'), itemIndicatorStyle($discovery['status'], $discovery['state'])); if ($data['showErrorColumn']) { $error = ''; if ($discovery['status'] == ITEM_STATUS_ACTIVE) {
/** * Returns paging line. * * @param array $items list of items * @param string $sortorder the order in which items are sorted ASC or DESC * @param CUrl $url URL object containing arguments and query * * @return CDiv */ function getPagingLine(&$items, $sortorder, CUrl $url) { global $page; $rowsPerPage = CWebUser::$data['rows_per_page']; $itemsCount = count($items); $pagesCount = $itemsCount > 0 ? ceil($itemsCount / $rowsPerPage) : 1; $currentPage = getPageNumber(); if ($currentPage < 1) { $currentPage = 1; } elseif ($currentPage > $pagesCount) { $currentPage = $pagesCount; } $start = ($currentPage - 1) * $rowsPerPage; $tags = []; if ($pagesCount > 1) { // For MVC pages $page is not set if (isset($page['file'])) { CProfile::update('web.paging.lastpage', $page['file'], PROFILE_TYPE_STR); CProfile::update('web.paging.page', $currentPage, PROFILE_TYPE_INT); } elseif (isset($_REQUEST['action'])) { CProfile::update('web.paging.lastpage', $_REQUEST['action'], PROFILE_TYPE_STR); CProfile::update('web.paging.page', $currentPage, PROFILE_TYPE_INT); } // viewed pages (better to use not odd) $pagingNavRange = 11; $endPage = $currentPage + floor($pagingNavRange / 2); if ($endPage < $pagingNavRange) { $endPage = $pagingNavRange; } if ($endPage > $pagesCount) { $endPage = $pagesCount; } $startPage = $endPage > $pagingNavRange ? $endPage - $pagingNavRange + 1 : 1; if ($startPage > 1) { $url->setArgument('page', 1); $tags[] = new CLink(_('First'), $url->getUrl()); } if ($currentPage > 1) { $url->setArgument('page', $currentPage - 1); $tags[] = new CLink((new CSpan())->addClass(ZBX_STYLE_ARROW_LEFT), $url->getUrl()); } for ($p = $startPage; $p <= $endPage; $p++) { $url->setArgument('page', $p); $link = new CLink($p, $url->getUrl()); if ($p == $currentPage) { $link->addClass(ZBX_STYLE_PAGING_SELECTED); } $tags[] = $link; } if ($currentPage < $pagesCount) { $url->setArgument('page', $currentPage + 1); $tags[] = new CLink((new CSpan())->addClass(ZBX_STYLE_ARROW_RIGHT), $url->getUrl()); } if ($p < $pagesCount) { $url->setArgument('page', $pagesCount); $tags[] = new CLink(_('Last'), $url->getUrl()); } } if ($pagesCount == 1) { $table_stats = _s('Displaying %1$s of %2$s found', $itemsCount, $itemsCount); } else { $config = select_config(); $end = $start + $rowsPerPage; if ($end > $itemsCount) { $end = $itemsCount; } $total = $itemsCount; if ($config['search_limit'] < $itemsCount) { if ($sortorder == ZBX_SORT_UP) { array_pop($items); } else { array_shift($items); } $total .= '+'; } $table_stats = _s('Displaying %1$s to %2$s of %3$s found', $start + 1, $end, $total); } // trim array with items to contain items for current page $items = array_slice($items, $start, $rowsPerPage, true); return (new CDiv())->addClass(ZBX_STYLE_TABLE_PAGING)->addItem((new CDiv())->addClass(ZBX_STYLE_PAGING_BTN_CONTAINER)->addItem($tags)->addItem((new CDiv())->addClass(ZBX_STYLE_TABLE_STATS)->addItem($table_stats))); }
function access_deny() { require_once dirname(__FILE__) . '/page_header.php'; if (CWebUser::$data['alias'] != ZBX_GUEST_USER) { show_error_message(_('No permissions to referred object or it does not exist!')); } else { $url = new CUrl(!empty($_REQUEST['request']) ? $_REQUEST['request'] : ''); $url->setArgument('sid', null); $url = urlencode($url->toString()); $warning = new CWarning(_('You are not logged in.'), array(_('You cannot view this URL as a'), SPACE, bold(ZBX_GUEST_USER), '. ', _('You must login to view this page.'), BR(), _('If you think this message is wrong, please consult your administrators about getting the necessary permissions.'))); $warning->setButtons(array(new CButton('login', _('Login'), 'javascript: document.location = "index.php?request=' . $url . '";', 'formlist'), new CButton('back', _('Cancel'), 'javascript: window.history.back();', 'formlist'))); $warning->show(); } require_once dirname(__FILE__) . '/page_footer.php'; }
**/ $icons = (new CList())->addClass(ZBX_STYLE_TOP_NAV_ICONS)->addItem((new CForm('get', 'search.php'))->addItem([(new CTextBox('search', '', false, 255))->setAttribute('autocomplete', 'off')->addClass(ZBX_STYLE_SEARCH), (new CSubmitButton(SPACE))->addClass(ZBX_STYLE_BTN_SEARCH)]))->addItem((new CLink('Share', 'https://share.zabbix.com/'))->addClass(ZBX_STYLE_TOP_NAV_ZBBSHARE)->setAttribute('target', '_blank')->setAttribute('title', _('Zabbix Share')))->addItem((new CLink(SPACE, 'http://www.zabbix.com/documentation/3.0/'))->addClass(ZBX_STYLE_TOP_NAV_HELP)->setAttribute('target', '_blank')->setAttribute('title', _('Help'))); if (!$data['user']['is_guest']) { $icons->addItem((new CLink(SPACE, 'profile.php'))->addClass(ZBX_STYLE_TOP_NAV_PROFILE)->setAttribute('title', getUserFullname($data['user']))); } $icons->addItem((new CLink(SPACE, 'index.php?reconnect=1'))->addClass(ZBX_STYLE_TOP_NAV_SIGNOUT)->setAttribute('title', _('Sign out'))->addSID()); // 1st level menu $top_menu = (new CDiv())->addItem(new CLink((new CDiv())->addClass(ZBX_STYLE_LOGO), 'zabbix.php?action=dashboard.view'))->addItem((new CList($data['menu']['main_menu']))->addClass(ZBX_STYLE_TOP_NAV))->addItem($icons)->addClass(ZBX_STYLE_TOP_NAV_CONTAINER)->setId('mmenu'); $sub_menu_div = (new CDiv())->addClass(ZBX_STYLE_TOP_SUBNAV_CONTAINER)->onMouseover('javascript: MMenu.submenu_mouseOver();')->onMouseout('javascript: MMenu.mouseOut();'); // 2nd level menu foreach ($data['menu']['sub_menus'] as $label => $sub_menu) { $sub_menu_row = (new CList())->addClass(ZBX_STYLE_TOP_SUBNAV)->setId('sub_' . $label); foreach ($sub_menu as $id => $sub_page) { $url = new CUrl($sub_page['menu_url']); if ($sub_page['menu_action'] !== null) { $url->setArgument('action', $sub_page['menu_action']); } $url->setArgument('ddreset', 1)->removeArgument('sid'); $sub_menu_item = new CLink($sub_page['menu_text'], $url->getUrl()); if ($sub_page['selected']) { $sub_menu_item->addClass(ZBX_STYLE_SELECTED); } $sub_menu_row->addItem($sub_menu_item); } if ($data['menu']['selected'] === $label) { $sub_menu_row->setAttribute('style', 'display: block;'); insert_js('MMenu.def_label = ' . zbx_jsvalue($label)); } else { $sub_menu_row->setAttribute('style', 'display: none;'); } $sub_menu_div->addItem($sub_menu_row);
function get_icon($type, $params = array()) { switch ($type) { case 'favourite': if (CFavorite::exists($params['fav'], $params['elid'], $params['elname'])) { $icon = new CIcon(_('Remove from favourites'), 'iconminus', 'rm4favorites("' . $params['elname'] . '", "' . $params['elid'] . '");'); } else { $icon = new CIcon(_('Add to favourites'), 'iconplus', 'add2favorites("' . $params['elname'] . '", "' . $params['elid'] . '");'); } $icon->setAttribute('id', 'addrm_fav'); return $icon; case 'fullscreen': $url = new CUrl(); $url->setArgument('fullscreen', $params['fullscreen'] ? '0' : '1'); return new CIcon($params['fullscreen'] ? _('Normal view') : _('Fullscreen'), 'fullscreen', "document.location = '" . $url->getUrl() . "';"); case 'reset': return new CIcon(_('Reset'), 'iconreset', 'timeControl.objectReset();'); } return null; }
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; }