Beispiel #1
0
/**
 * 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)));
}
$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);
}
if ($data['server_name'] !== '') {
    $sub_menu_div->addItem((new CDiv($data['server_name']))->addClass(ZBX_STYLE_SERVER_NAME));
}
(new CTag('header', true))->setAttribute('role', 'banner')->addItem((new CDiv())->addItem($top_menu)->addItem($sub_menu_div)->addClass(ZBX_STYLE_NAV)->setAttribute('role', 'navigation'))->show();