function viewPlugins($option)
{
    global $_CB_database, $_CB_framework;
    $limit = (int) $_CB_framework->getCfg('list_limit');
    if ($limit == 0) {
        $limit = 10;
    }
    $limit = $_CB_framework->getUserStateFromRequest("viewlistlimit", 'limit', $limit);
    $lastCBlist = $_CB_framework->getUserState("view{$option}lastCBlist", null);
    if ($lastCBlist == 'showplugins') {
        $limitstart = $_CB_framework->getUserStateFromRequest("view{$option}limitstart", 'limitstart', 0);
        $lastSearch = $_CB_framework->getUserState("search{$option}", null);
        $search = $_CB_framework->getUserStateFromRequest("search{$option}", 'search', '');
        if ($lastSearch != $search) {
            $limitstart = 0;
            $_CB_framework->setUserState("view{$option}limitstart", $limitstart);
        }
        $search = trim(strtolower($search));
        $filter_type = $_CB_framework->getUserStateFromRequest("filter_type{$option}", 'filter_type', "0");
    } else {
        clearSearchBox();
        $search = "";
        $limitstart = 0;
        $_CB_framework->setUserState("view{$option}limitstart", $limitstart);
        $_CB_framework->setUserState("view{$option}lastCBlist", "showplugins");
        $filter_type = "0";
        $_CB_framework->setUserState("filter_type{$option}", $filter_type);
    }
    $where = array();
    // used by filter
    if ($filter_type) {
        $where[] = "m.type = '{$filter_type}'";
    }
    if ($search) {
        $search = cbEscapeSQLsearch(trim(strtolower(cbGetEscaped($search))));
        $where[] = "LOWER( m.name ) LIKE '%{$search}%'";
    }
    if (!$_CB_framework->acl->amIaSuperAdmin()) {
        $viewAccessLevels = CBuser::getMyInstance()->getAuthorisedViewLevelsIds(true);
        $viewAccessLevelsCleaned = implode(',', cbArrayToInts($viewAccessLevels));
        $where[] = 'm.access IN (' . $viewAccessLevelsCleaned . ')';
    }
    // get the total number of records
    $query = "SELECT COUNT(*) FROM #__comprofiler_plugin AS m " . (count($where) ? "\n WHERE " . implode(' AND ', $where) : '');
    $_CB_database->setQuery($query);
    $total = $_CB_database->loadResult();
    if ($total <= $limitstart) {
        $limitstart = 0;
    }
    cbimport('cb.pagination');
    $pageNav = new cbPageNav($total, $limitstart, $limit);
    if (checkJversion() == 2) {
        $title = 'title';
    } else {
        $title = 'name';
    }
    $query = "SELECT m.*, u.name AS editor, g.{$title} AS groupname" . "\n FROM #__comprofiler_plugin AS m" . "\n LEFT JOIN #__users AS u ON u.id = m.checked_out";
    if (checkJversion() == 2) {
        $query .= "\n LEFT JOIN #__viewlevels AS g ON g.id = m.access + IF(m.access <= 2, 1, 0)";
        // fix J1.6's wrong access levels, same as g.id = IF( m.access = 0, 1, IF( m.access = 1, 2, IF( m.access = 2, 3, m.access ) ) )
    } else {
        $query .= "\n LEFT JOIN #__groups AS g ON g.id = m.access";
    }
    $query .= (count($where) ? "\n WHERE " . implode(' AND ', $where) : '') . "\n GROUP BY m.id" . "\n ORDER BY m.type ASC, m.ordering ASC, m.name ASC";
    $_CB_database->setQuery($query, (int) $pageNav->limitstart, (int) $pageNav->limit);
    $rows = $_CB_database->loadObjectList();
    if ($_CB_database->getErrorNum()) {
        echo $_CB_database->stderr();
        return false;
    }
    // get list of Positions for dropdown filter
    $query = "SELECT type AS value, type AS text" . "\n FROM #__comprofiler_plugin" . "\n GROUP BY type" . "\n ORDER BY type";
    $types[] = moscomprofilerHTML::makeOption('0', !defined('_SEL_TYPE') ? '- ' . CBTxt::T('Select Type') . ' -' : _SEL_TYPE);
    // Mambo 4.5.1 Compatibility
    $_CB_database->setQuery($query);
    $types = array_merge($types, $_CB_database->loadObjectList());
    $lists['type'] = moscomprofilerHTML::selectList($types, 'filter_type', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $filter_type, 2);
    $canAdmin = CBuser::getMyInstance()->authoriseAction('core.admin');
    $canEdit = CBuser::getMyInstance()->authoriseAction('core.edit');
    $canEditState = CBuser::getMyInstance()->authoriseAction('core.edit.state');
    HTML_comprofiler::showPlugins($rows, $pageNav, $option, $lists, $search, $canAdmin, $canEdit, $canEditState);
    return true;
}