PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_users/views/users/view.html.php

https://bitbucket.org/asosso/joomla15
PHP | 177 lines | 128 code | 22 blank | 27 comment | 23 complexity | 9e2ad4db11ac481f7750d1f4775d0d1b MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id: view.html.php 19343 2010-11-03 18:12:02Z ian $
  4. * @package Joomla
  5. * @subpackage Users
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14. // Check to ensure this file is included in Joomla!
  15. defined('_JEXEC') or die( 'Restricted access' );
  16. jimport( 'joomla.application.component.view');
  17. /**
  18. * HTML View class for the Users component
  19. *
  20. * @static
  21. * @package Joomla
  22. * @subpackage Users
  23. * @since 1.0
  24. */
  25. class UsersViewUsers extends JView
  26. {
  27. function display($tpl = null)
  28. {
  29. global $mainframe, $option;
  30. $db =& JFactory::getDBO();
  31. $currentUser =& JFactory::getUser();
  32. $acl =& JFactory::getACL();
  33. $filter_order = $mainframe->getUserStateFromRequest( "$option.filter_order", 'filter_order', 'a.name', 'cmd' );
  34. $filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.filter_order_Dir", 'filter_order_Dir', '', 'word' );
  35. $filter_type = $mainframe->getUserStateFromRequest( "$option.filter_type", 'filter_type', 0, 'string' );
  36. $filter_logged = $mainframe->getUserStateFromRequest( "$option.filter_logged", 'filter_logged', 0, 'int' );
  37. $search = $mainframe->getUserStateFromRequest( "$option.search", 'search', '', 'string' );
  38. if (strpos($search, '"') !== false) {
  39. $search = str_replace(array('=', '<'), '', $search);
  40. }
  41. $search = JString::strtolower($search);
  42. $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
  43. $limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
  44. $where = array();
  45. if (isset( $search ) && $search!= '')
  46. {
  47. $searchEscaped = $db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
  48. $where[] = 'a.username LIKE '.$searchEscaped.' OR a.email LIKE '.$searchEscaped.' OR a.name LIKE '.$searchEscaped;
  49. }
  50. if ( $filter_type )
  51. {
  52. if ( $filter_type == 'Public Frontend' )
  53. {
  54. $where[] = ' a.usertype = \'Registered\' OR a.usertype = \'Author\' OR a.usertype = \'Editor\' OR a.usertype = \'Publisher\' ';
  55. }
  56. else if ( $filter_type == 'Public Backend' )
  57. {
  58. $where[] = 'a.usertype = \'Manager\' OR a.usertype = \'Administrator\' OR a.usertype = \'Super Administrator\' ';
  59. }
  60. else
  61. {
  62. $where[] = 'a.usertype = LOWER( '.$db->Quote($filter_type).' ) ';
  63. }
  64. }
  65. if ( $filter_logged == 1 )
  66. {
  67. $where[] = 's.userid = a.id';
  68. }
  69. else if ($filter_logged == 2)
  70. {
  71. $where[] = 's.userid IS NULL';
  72. }
  73. // exclude any child group id's for this user
  74. $pgids = $acl->get_group_children( $currentUser->get('gid'), 'ARO', 'RECURSE' );
  75. if (is_array( $pgids ) && count( $pgids ) > 0)
  76. {
  77. JArrayHelper::toInteger($pgids);
  78. $where[] = 'a.gid NOT IN (' . implode( ',', $pgids ) . ')';
  79. }
  80. $filter = '';
  81. if ($filter_logged == 1 || $filter_logged == 2)
  82. {
  83. $filter = ' INNER JOIN #__session AS s ON s.userid = a.id';
  84. }
  85. // ensure filter_order has a valid value.
  86. if (!in_array($filter_order, array('a.name', 'a.username', 'a.block', 'groupname', 'a.email', 'a.lastvisitDate', 'a.id'))) {
  87. $filter_order = 'a.name';
  88. }
  89. if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC'))) {
  90. $filter_order_Dir = '';
  91. }
  92. $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir;
  93. $where = ( count( $where ) ? ' WHERE (' . implode( ') AND (', $where ) . ')' : '' );
  94. $query = 'SELECT COUNT(a.id)'
  95. . ' FROM #__users AS a'
  96. . $filter
  97. . $where
  98. ;
  99. $db->setQuery( $query );
  100. $total = $db->loadResult();
  101. jimport('joomla.html.pagination');
  102. $pagination = new JPagination( $total, $limitstart, $limit );
  103. $query = 'SELECT a.*, g.name AS groupname'
  104. . ' FROM #__users AS a'
  105. . ' INNER JOIN #__core_acl_aro AS aro ON aro.value = a.id'
  106. . ' INNER JOIN #__core_acl_groups_aro_map AS gm ON gm.aro_id = aro.id'
  107. . ' INNER JOIN #__core_acl_aro_groups AS g ON g.id = gm.group_id'
  108. . $filter
  109. . $where
  110. . ' GROUP BY a.id'
  111. . $orderby
  112. ;
  113. $db->setQuery( $query, $pagination->limitstart, $pagination->limit );
  114. $rows = $db->loadObjectList();
  115. $n = count( $rows );
  116. $template = 'SELECT COUNT(s.userid)'
  117. . ' FROM #__session AS s'
  118. . ' WHERE s.userid = %d'
  119. ;
  120. for ($i = 0; $i < $n; $i++)
  121. {
  122. $row = &$rows[$i];
  123. $query = sprintf( $template, intval( $row->id ) );
  124. $db->setQuery( $query );
  125. $row->loggedin = $db->loadResult();
  126. }
  127. // get list of Groups for dropdown filter
  128. $query = 'SELECT name AS value, name AS text'
  129. . ' FROM #__core_acl_aro_groups'
  130. . ' WHERE name != "ROOT"'
  131. . ' AND name != "USERS"'
  132. ;
  133. $db->setQuery( $query );
  134. $types[] = JHTML::_('select.option', '0', '- '. JText::_( 'Select Group' ) .' -' );
  135. foreach( $db->loadObjectList() as $obj )
  136. {
  137. $types[] = JHTML::_('select.option', $obj->value, JText::_( $obj->text ) );
  138. }
  139. $lists['type'] = JHTML::_('select.genericlist', $types, 'filter_type', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', "$filter_type" );
  140. // get list of Log Status for dropdown filter
  141. $logged[] = JHTML::_('select.option', 0, '- '. JText::_( 'Select Log Status' ) .' -');
  142. $logged[] = JHTML::_('select.option', 1, JText::_( 'Logged In' ) );
  143. $lists['logged'] = JHTML::_('select.genericlist', $logged, 'filter_logged', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', "$filter_logged" );
  144. // table ordering
  145. $lists['order_Dir'] = $filter_order_Dir;
  146. $lists['order'] = $filter_order;
  147. // search filter
  148. $lists['search']= $search;
  149. $this->assignRef('user', JFactory::getUser());
  150. $this->assignRef('lists', $lists);
  151. $this->assignRef('items', $rows);
  152. $this->assignRef('pagination', $pagination);
  153. parent::display($tpl);
  154. }
  155. }