Blame view

administrator/components/com_jce/views/users/view.html.php 7.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
<?php

/**
 * @copyright 	Copyright (c) 2009-2017 Ryan Demmer. All rights reserved
 * @license   	GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * JCE is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses
 */
defined('_JEXEC') or die('RESTRICTED');

wfimport('admin.classes.view');

class WFViewUsers extends WFView
{
    public function display($tpl = null)
    {
        $app = JFactory::getApplication();
        $option = JRequest::getCmd('option');

        $client = 'admin';
        $view = JRequest::getWord('view');

        $db = JFactory::getDBO();
        $currentUser = JFactory::getUser();
        $acl = JFactory::getACL();

        $model = $this->getModel();

        $this->addScript('components/com_jce/media/js/users.js');

        $filter_order = $app->getUserStateFromRequest("$option.$view.filter_order", 'filter_order', 'a.name', 'cmd');
        $filter_order_Dir = $app->getUserStateFromRequest("$option.$view.filter_order_Dir", 'filter_order_Dir', '', 'word');
        $filter_type = $app->getUserStateFromRequest("$option.$view.filter_type", 'filter_type', '', 'int');
        $search = $app->getUserStateFromRequest("$option.$view.search", 'search', '', 'cmd');
        $search = JString::strtolower($search);

        $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'int');
        $limitstart = $app->getUserStateFromRequest("$option.$view.limitstart", 'limitstart', 0, 'int');

        $where = array();

        if (!empty($search)) {
            if (defined('JPATH_PLATFORM')) {
                $quoted = $db->quote('%'.$search.'%', false);
            } else {
                $quoted = $db->Quote('%'.$search.'%', false);
            }

            $where[] = 'a.username LIKE '.$quoted.' OR a.email LIKE '.$quoted.' OR a.name LIKE '.$quoted;
        }

        if (defined('JPATH_PLATFORM')) {
            if ($filter_type) {
                $where[] = 'map.group_id = LOWER('.$db->Quote($filter_type).') ';
            }
        } else {
            if ($filter_type) {
                $where[] = 'a.gid ='.(int) $filter_type;
            }
            // exclude any child group id's for this user
            $pgids = $acl->get_group_children($currentUser->get('gid'), 'ARO', 'RECURSE');

            if (is_array($pgids) && count($pgids) > 0) {
                JArrayHelper::toInteger($pgids);
                $where[] = 'a.gid NOT IN ('.implode(',', $pgids).')';
            }

            // Exclude ROOT, USERS, Super Administrator, Public Frontend, Public Backend
            $where[] = 'a.gid NOT IN (17,28,29,30)';
        }

        // Only unblocked users
        $where[] = 'a.block = 0';

        $orderby = array($filter_order, $filter_order_Dir);

        jimport('joomla.html.pagination');

        if (defined('JPATH_PLATFORM')) {
            $query = $db->getQuery(true);

            $query->select('COUNT(a.id)')->from('#__users AS a')->join('LEFT', '#__user_usergroup_map AS map ON map.user_id = a.id');

            if (count($where)) {
                $query->where($where);
            }

            $db->setQuery($query);
            $total = $db->loadResult();

            $pagination = new JPagination($total, $limitstart, $limit);

            $query = $db->getQuery(true);

            $query->select('a.id, a.name, a.username, g.title AS groupname');
            $query->from('#__users AS a');
            $query->join('LEFT', '#__user_usergroup_map AS map ON map.user_id = a.id');
            $query->join('LEFT', '#__usergroups AS g ON g.id = map.group_id');

            if (count($where)) {
                $query->where($where);
            }

            $query->group('a.id, a.name, a.username, g.title');
            $query->order(trim(implode(' ', $orderby)));
        } else {
            $query = 'SELECT COUNT(a.id)'
                    .' FROM #__users AS a'
                    .$where
            ;
            $db->setQuery($query);
            $total = $db->loadResult();
            $pagination = new JPagination($total, $limitstart, $limit);

            $query = 'SELECT a.id, a.name, a.username, g.name AS groupname'
                    .' FROM #__users AS a'
                    .' INNER JOIN #__core_acl_aro AS aro ON aro.value = a.id'
                    .' INNER JOIN #__core_acl_groups_aro_map AS gm ON gm.aro_id = aro.id'
                    .' INNER JOIN #__core_acl_aro_groups AS g ON g.id = gm.group_id'
                    .(count($where) ? ' WHERE ('.implode(') AND (', $where).')' : '')
                    .' GROUP BY a.id, a.name, a.username, g.name'
                    .' ORDER BY '.trim(implode(' ', $orderby))
            ;
        }

        $db->setQuery($query, $pagination->limitstart, $pagination->limit);
        $rows = $db->loadObjectList();

        $options = array(
            JHTML::_('select.option', '', '- '.WFText::_('WF_USERS_GROUP_SELECT').' -'),
        );

        if (defined('JPATH_PLATFORM')) {
            $query = $db->getQuery(true);

            $query->select('a.id AS value, a.title AS text')->from('#__usergroups AS a');

            // Add the level in the tree.
            $query->select('COUNT(DISTINCT b.id) AS level');
            $query->join('LEFT OUTER', '#__usergroups AS b ON a.lft > b.lft AND a.rgt < b.rgt');
            $query->group('a.id, a.lft, a.rgt, a.parent_id, a.title');
            $query->order('a.lft ASC');

            // Get the options.
            $db->setQuery($query);
            $items = $db->loadObjectList() or die($db->stdErr());

            // Pad the option text with spaces using depth level as a multiplier.
            for ($i = 0, $n = count($items); $i < $n; ++$i) {
                $options[] = JHTML::_('select.option', $items[$i]->value, str_repeat('- ', $items[$i]->level).$items[$i]->text);
            }
        } else {
            // get list of Groups for dropdown filter
            $query = 'SELECT id AS value, name AS text'
                    .' FROM #__core_acl_aro_groups'
                    // Exclude ROOT, USERS, Super Administrator, Public Frontend, Public Backend
                    .' WHERE id NOT IN (17,28,29,30)';
            $db->setQuery($query);
            $items = $db->loadObjectList();

            $i = '-';

            //$options[] = JHTML::_('select.option', '0', WFText::_('Guest'));

            foreach ($items as $item) {
                $options[] = JHTML::_('select.option', $item->value, $i.WFText::_($item->text));
                $i .= '-';
            }
        }

        $lists['group'] = JHTML::_('select.genericlist', $options, 'filter_type', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', (int) $filter_type);

        // table ordering
        $lists['order_Dir'] = $filter_order_Dir;
        $lists['order'] = $filter_order;

        // search filter
        $lists['search'] = $search;

        $this->assign('user', JFactory::getUser());
        $this->assign('lists', $lists);
        $this->assign('items', $rows);
        $this->assign('pagination', $pagination);

        $this->addStyleSheet(JURI::root(true).'/administrator/components/com_jce/media/css/users.css');

        parent::display($tpl);
    }
}