You've already forked joomla_test
first commit
This commit is contained in:
243
administrator/components/com_users/models/debuggroup.php
Normal file
243
administrator/components/com_users/models/debuggroup.php
Normal file
@ -0,0 +1,243 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
require_once JPATH_COMPONENT . '/helpers/debug.php';
|
||||
|
||||
/**
|
||||
* Methods supporting a list of user records.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersModelDebuggroup extends JModelList
|
||||
{
|
||||
/**
|
||||
* Get a list of the actions.
|
||||
*
|
||||
* @return array
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getDebugActions()
|
||||
{
|
||||
$component = $this->getState('filter.component');
|
||||
|
||||
return UsersHelperDebug::getDebugActions($component);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override getItems method.
|
||||
*
|
||||
* @return array
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
$groupId = $this->getState('filter.group_id');
|
||||
|
||||
if (($assets = parent::getItems()) && $groupId)
|
||||
{
|
||||
|
||||
$actions = $this->getDebugActions();
|
||||
|
||||
foreach ($assets as &$asset)
|
||||
{
|
||||
$asset->checks = array();
|
||||
|
||||
foreach ($actions as $action)
|
||||
{
|
||||
$name = $action[0];
|
||||
$level = $action[1];
|
||||
|
||||
// Check that we check this action for the level of the asset.
|
||||
if ($level === null || $level >= $asset->level)
|
||||
{
|
||||
// We need to test this action.
|
||||
$asset->checks[$name] = JAccess::checkGroup($groupId, $name, $asset->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We ignore this action.
|
||||
$asset->checks[$name] = 'skip';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $assets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @return void
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
$app = JFactory::getApplication('administrator');
|
||||
|
||||
// Adjust the context to support modal layouts.
|
||||
$layout = $app->input->get('layout', 'default');
|
||||
if ($layout)
|
||||
{
|
||||
$this->context .= '.' . $layout;
|
||||
}
|
||||
|
||||
// Load the filter state.
|
||||
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
|
||||
$this->setState('filter.search', $search);
|
||||
|
||||
$value = $this->getUserStateFromRequest($this->context . '.filter.group_id', 'group_id', 0, 'int', false);
|
||||
$this->setState('filter.group_id', $value);
|
||||
|
||||
$levelStart = $this->getUserStateFromRequest($this->context . '.filter.level_start', 'filter_level_start', 0, 'int');
|
||||
$this->setState('filter.level_start', $levelStart);
|
||||
|
||||
$value = $this->getUserStateFromRequest($this->context . '.filter.level_end', 'filter_level_end', 0, 'int');
|
||||
if ($value > 0 && $value < $levelStart)
|
||||
{
|
||||
$value = $levelStart;
|
||||
}
|
||||
$this->setState('filter.level_end', $value);
|
||||
|
||||
$component = $this->getUserStateFromRequest($this->context . '.filter.component', 'filter_component');
|
||||
$this->setState('filter.component', $component);
|
||||
|
||||
// Load the parameters.
|
||||
$params = JComponentHelper::getParams('com_users');
|
||||
$this->setState('params', $params);
|
||||
|
||||
// List state information.
|
||||
parent::populateState('a.lft', 'asc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
*
|
||||
* @return string A store id.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= ':' . $this->getState('filter.search');
|
||||
$id .= ':' . $this->getState('filter.level_start');
|
||||
$id .= ':' . $this->getState('filter.level_end');
|
||||
$id .= ':' . $this->getState('filter.component');
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the group being debugged.
|
||||
*
|
||||
* @return JObject
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getGroup()
|
||||
{
|
||||
$groupId = (int) $this->getState('filter.group_id');
|
||||
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('id, title')
|
||||
->from('#__usergroups')
|
||||
->where('id = ' . $groupId);
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$group = $db->loadObject();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an SQL query to load the list data.
|
||||
*
|
||||
* @return JDatabaseQuery
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
// Create a new query object.
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Select the required fields from the table.
|
||||
$query->select(
|
||||
$this->getState(
|
||||
'list.select',
|
||||
'a.id, a.name, a.title, a.level, a.lft, a.rgt'
|
||||
)
|
||||
);
|
||||
$query->from($db->quoteName('#__assets') . ' AS a');
|
||||
|
||||
// Filter the items over the search string if set.
|
||||
if ($this->getState('filter.search'))
|
||||
{
|
||||
// Escape the search token.
|
||||
$token = $db->quote('%' . $db->escape($this->getState('filter.search')) . '%');
|
||||
|
||||
// Compile the different search clauses.
|
||||
$searches = array();
|
||||
$searches[] = 'a.name LIKE ' . $token;
|
||||
$searches[] = 'a.title LIKE ' . $token;
|
||||
|
||||
// Add the clauses to the query.
|
||||
$query->where('(' . implode(' OR ', $searches) . ')');
|
||||
}
|
||||
|
||||
// Filter on the start and end levels.
|
||||
$levelStart = (int) $this->getState('filter.level_start');
|
||||
$levelEnd = (int) $this->getState('filter.level_end');
|
||||
if ($levelEnd > 0 && $levelEnd < $levelStart)
|
||||
{
|
||||
$levelEnd = $levelStart;
|
||||
}
|
||||
if ($levelStart > 0)
|
||||
{
|
||||
$query->where('a.level >= ' . $levelStart);
|
||||
}
|
||||
if ($levelEnd > 0)
|
||||
{
|
||||
$query->where('a.level <= ' . $levelEnd);
|
||||
}
|
||||
|
||||
// Filter the items over the component if set.
|
||||
if ($this->getState('filter.component'))
|
||||
{
|
||||
$component = $this->getState('filter.component');
|
||||
$query->where('(a.name = ' . $db->quote($component) . ' OR a.name LIKE ' . $db->quote($component . '.%') . ')');
|
||||
}
|
||||
|
||||
// Add the list ordering clause.
|
||||
$query->order($db->escape($this->getState('list.ordering', 'a.lft')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
233
administrator/components/com_users/models/debuguser.php
Normal file
233
administrator/components/com_users/models/debuguser.php
Normal file
@ -0,0 +1,233 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
require_once JPATH_COMPONENT . '/helpers/debug.php';
|
||||
|
||||
/**
|
||||
* Methods supporting a list of user records.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersModelDebugUser extends JModelList
|
||||
{
|
||||
/**
|
||||
* Get a list of the actions.
|
||||
*
|
||||
* @return array
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getDebugActions()
|
||||
{
|
||||
$component = $this->getState('filter.component');
|
||||
|
||||
return UsersHelperDebug::getDebugActions($component);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override getItems method.
|
||||
*
|
||||
* @return array
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
$userId = $this->getState('filter.user_id');
|
||||
|
||||
if (($assets = parent::getItems()) && $userId)
|
||||
{
|
||||
|
||||
$actions = $this->getDebugActions();
|
||||
|
||||
foreach ($assets as &$asset)
|
||||
{
|
||||
$asset->checks = array();
|
||||
|
||||
foreach ($actions as $action)
|
||||
{
|
||||
$name = $action[0];
|
||||
$level = $action[1];
|
||||
|
||||
// Check that we check this action for the level of the asset.
|
||||
if ($level === null || $level >= $asset->level)
|
||||
{
|
||||
// We need to test this action.
|
||||
$asset->checks[$name] = JAccess::check($userId, $name, $asset->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We ignore this action.
|
||||
$asset->checks[$name] = 'skip';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $assets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @return void
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
$app = JFactory::getApplication('administrator');
|
||||
|
||||
// Adjust the context to support modal layouts.
|
||||
$layout = $app->input->get('layout', 'default');
|
||||
if ($layout)
|
||||
{
|
||||
$this->context .= '.' . $layout;
|
||||
}
|
||||
|
||||
// Load the filter state.
|
||||
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
|
||||
$this->setState('filter.search', $search);
|
||||
|
||||
$value = $this->getUserStateFromRequest($this->context . '.filter.user_id', 'user_id', 0, 'int');
|
||||
$this->setState('filter.user_id', $value);
|
||||
|
||||
$levelStart = $this->getUserStateFromRequest($this->context . '.filter.level_start', 'filter_level_start', 0, 'int');
|
||||
$this->setState('filter.level_start', $levelStart);
|
||||
|
||||
$value = $this->getUserStateFromRequest($this->context . '.filter.level_end', 'filter_level_end', 0, 'int');
|
||||
if ($value > 0 && $value < $levelStart)
|
||||
{
|
||||
$value = $levelStart;
|
||||
}
|
||||
$this->setState('filter.level_end', $value);
|
||||
|
||||
$component = $this->getUserStateFromRequest($this->context . '.filter.component', 'filter_component');
|
||||
$this->setState('filter.component', $component);
|
||||
|
||||
// Load the parameters.
|
||||
$params = JComponentHelper::getParams('com_users');
|
||||
$this->setState('params', $params);
|
||||
|
||||
// List state information.
|
||||
parent::populateState('a.lft', 'asc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
*
|
||||
* @return string A store id.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= ':' . $this->getState('filter.search');
|
||||
$id .= ':' . $this->getState('filter.user_id');
|
||||
$id .= ':' . $this->getState('filter.level_start');
|
||||
$id .= ':' . $this->getState('filter.level_end');
|
||||
$id .= ':' . $this->getState('filter.component');
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user being debugged.
|
||||
*
|
||||
* @return JUser
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
$userId = $this->getState('filter.user_id');
|
||||
|
||||
return JFactory::getUser($userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an SQL query to load the list data.
|
||||
*
|
||||
* @return JDatabaseQuery
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
// Create a new query object.
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Select the required fields from the table.
|
||||
$query->select(
|
||||
$this->getState(
|
||||
'list.select',
|
||||
'a.id, a.name, a.title, a.level, a.lft, a.rgt'
|
||||
)
|
||||
);
|
||||
$query->from($db->quoteName('#__assets') . ' AS a');
|
||||
|
||||
// Filter the items over the group id if set.
|
||||
if ($groupId = $this->getState('filter.group_id'))
|
||||
{
|
||||
$query->join('LEFT', '#__user_usergroup_map AS map2 ON map2.user_id = a.id')
|
||||
->where('map2.group_id = ' . (int) $groupId);
|
||||
}
|
||||
|
||||
// Filter the items over the search string if set.
|
||||
if ($this->getState('filter.search'))
|
||||
{
|
||||
// Escape the search token.
|
||||
$token = $db->quote('%' . $db->escape($this->getState('filter.search')) . '%');
|
||||
|
||||
// Compile the different search clauses.
|
||||
$searches = array();
|
||||
$searches[] = 'a.name LIKE ' . $token;
|
||||
$searches[] = 'a.title LIKE ' . $token;
|
||||
|
||||
// Add the clauses to the query.
|
||||
$query->where('(' . implode(' OR ', $searches) . ')');
|
||||
}
|
||||
|
||||
// Filter on the start and end levels.
|
||||
$levelStart = (int) $this->getState('filter.level_start');
|
||||
$levelEnd = (int) $this->getState('filter.level_end');
|
||||
if ($levelEnd > 0 && $levelEnd < $levelStart)
|
||||
{
|
||||
$levelEnd = $levelStart;
|
||||
}
|
||||
if ($levelStart > 0)
|
||||
{
|
||||
$query->where('a.level >= ' . $levelStart);
|
||||
}
|
||||
if ($levelEnd > 0)
|
||||
{
|
||||
$query->where('a.level <= ' . $levelEnd);
|
||||
}
|
||||
|
||||
// Filter the items over the component if set.
|
||||
if ($this->getState('filter.component'))
|
||||
{
|
||||
$component = $this->getState('filter.component');
|
||||
$query->where('(a.name = ' . $db->quote($component) . ' OR a.name LIKE ' . $db->quote($component . '.%') . ')');
|
||||
}
|
||||
|
||||
// Add the list ordering clause.
|
||||
$query->order($db->escape($this->getState('list.ordering', 'a.lft')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
JFormHelper::loadFieldClass('list');
|
||||
|
||||
/**
|
||||
* Form Field class for the Joomla Framework.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class JFormFieldGroupParent extends JFormFieldList
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $type = 'GroupParent';
|
||||
|
||||
/**
|
||||
* Method to get the field options.
|
||||
*
|
||||
* @return array The field option objects.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
$options = array();
|
||||
|
||||
$db = JFactory::getDbo();
|
||||
$user = JFactory::getUser();
|
||||
$query = $db->getQuery(true)
|
||||
->select('a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level')
|
||||
->from('#__usergroups AS a')
|
||||
->join('LEFT', $db->quoteName('#__usergroups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt');
|
||||
|
||||
// Prevent parenting to children of this item.
|
||||
if ($id = $this->form->getValue('id'))
|
||||
{
|
||||
$query->join('LEFT', $db->quoteName('#__usergroups') . ' AS p ON p.id = ' . (int) $id)
|
||||
->where('NOT(a.lft >= p.lft AND a.rgt <= p.rgt)');
|
||||
}
|
||||
|
||||
$query->group('a.id, a.title, a.lft, a.rgt')
|
||||
->order('a.lft ASC');
|
||||
|
||||
// Get the options.
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$options = $db->loadObjectList();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
JError::raiseWarning(500, $e->getMessage());
|
||||
}
|
||||
|
||||
// Pad the option text with spaces using depth level as a multiplier.
|
||||
for ($i = 0, $n = count($options); $i < $n; $i++)
|
||||
{
|
||||
// Show groups only if user is super admin or group is not super admin
|
||||
if ($user->authorise('core.admin') || (!JAccess::checkGroup($options[$i]->value, 'core.admin')))
|
||||
{
|
||||
$options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($options[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Merge any additional options in the XML definition.
|
||||
$options = array_merge(parent::getOptions(), $options);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
35
administrator/components/com_users/models/forms/group.xml
Normal file
35
administrator/components/com_users/models/forms/group.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset>
|
||||
<field name="id" type="hidden"
|
||||
default="0"
|
||||
required="true"
|
||||
readonly="true"
|
||||
/>
|
||||
|
||||
<field name="title" type="text"
|
||||
class="inputbox" required="true"
|
||||
description="COM_USERS_GROUP_FIELD_TITLE_DESC"
|
||||
label="COM_USERS_GROUP_FIELD_TITLE_LABEL"
|
||||
size="40"
|
||||
/>
|
||||
|
||||
<field name="parent_id" type="groupparent"
|
||||
class="inputbox"
|
||||
description="COM_USERS_GROUP_FIELD_PARENT_DESC"
|
||||
label="COM_USERS_GROUP_FIELD_PARENT_LABEL"
|
||||
required="true"
|
||||
/>
|
||||
|
||||
<field name="actions" type="hidden"
|
||||
multiple="true"
|
||||
/>
|
||||
|
||||
<field name="lft" type="hidden"
|
||||
filter="unset"
|
||||
/>
|
||||
<field name="rgt" type="hidden"
|
||||
filter="unset"
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
27
administrator/components/com_users/models/forms/level.xml
Normal file
27
administrator/components/com_users/models/forms/level.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset>
|
||||
<field name="id" type="hidden"
|
||||
default="0"
|
||||
readonly="true"
|
||||
required="true"
|
||||
/>
|
||||
|
||||
<field name="title" type="text"
|
||||
class="inputbox" required="true"
|
||||
description="COM_USERS_LEVEL_FIELD_TITLE_DESC"
|
||||
label="COM_USERS_LEVEL_FIELD_TITLE_LABEL"
|
||||
size="50"
|
||||
/>
|
||||
|
||||
<field name="ordering" type="text"
|
||||
default="0"
|
||||
description="JFIELD_ORDERING_DESC"
|
||||
label="JFIELD_ORDERING_LABEL"
|
||||
/>
|
||||
|
||||
<field name="rules" type="hidden"
|
||||
filter="int_array"
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
55
administrator/components/com_users/models/forms/mail.xml
Normal file
55
administrator/components/com_users/models/forms/mail.xml
Normal file
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset>
|
||||
|
||||
<field name="recurse" type="checkbox"
|
||||
description="COM_USERS_MAIL_FIELD_RECURSE_DESC"
|
||||
label="COM_USERS_MAIL_FIELD_RECURSE_LABEL"
|
||||
value="1"
|
||||
/>
|
||||
|
||||
<field name="mode" type="checkbox"
|
||||
description="COM_USERS_MAIL_FIELD_SEND_IN_HTML_MODE_DESC"
|
||||
label="COM_USERS_MAIL_FIELD_SEND_IN_HTML_MODE_LABEL"
|
||||
value="1"
|
||||
/>
|
||||
|
||||
<field name="disabled" type="checkbox"
|
||||
description="COM_USERS_MAIL_FIELD_EMAIL_DISABLED_USERS_DESC"
|
||||
label="COM_USERS_MAIL_FIELD_EMAIL_DISABLED_USERS_LABEL"
|
||||
value="1"
|
||||
/>
|
||||
|
||||
<field name="group" type="usergroup"
|
||||
default="0"
|
||||
description="COM_USERS_MAIL_FIELD_GROUP_DESC"
|
||||
label="COM_USERS_MAIL_FIELD_GROUP_LABEL"
|
||||
size="10"
|
||||
>
|
||||
<option value="0">COM_USERS_MAIL_FIELD_VALUE_ALL_USERS_GROUPS</option>
|
||||
</field>
|
||||
|
||||
<field name="bcc" type="checkbox"
|
||||
default="1"
|
||||
description="COM_USERS_MAIL_FIELD_SEND_AS_BLIND_CARBON_COPY_DESC"
|
||||
label="COM_USERS_MAIL_FIELD_SEND_AS_BLIND_CARBON_COPY_LABEL"
|
||||
value="1"
|
||||
/>
|
||||
|
||||
<field name="subject" type="text"
|
||||
class="inputbox span8"
|
||||
description="COM_USERS_MAIL_FIELD_SUBJECT_DESC"
|
||||
label="COM_USERS_MAIL_FIELD_SUBJECT_LABEL"
|
||||
maxlength="150"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field name="message" type="textarea"
|
||||
class="inputbox span11"
|
||||
cols="70"
|
||||
description="COM_USERS_MAIL_FIELD_MESSAGE_DESC"
|
||||
label="COM_USERS_MAIL_FIELD_MESSAGE_LABEL"
|
||||
rows="20"
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
126
administrator/components/com_users/models/forms/note.xml
Normal file
126
administrator/components/com_users/models/forms/note.xml
Normal file
@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset>
|
||||
<field
|
||||
name="id"
|
||||
type="hidden"
|
||||
class="readonly"
|
||||
size="6"
|
||||
default="0"
|
||||
readonly="true"
|
||||
label="COM_USERS_FIELD_ID_LABEL"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="user_id"
|
||||
type="user"
|
||||
size="50"
|
||||
class="inputbox"
|
||||
required="true"
|
||||
label="COM_USERS_FIELD_USER_ID_LABEL"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="catid"
|
||||
type="category"
|
||||
class="inputbox"
|
||||
extension="com_users"
|
||||
label="COM_USERS_FIELD_CATEGORY_ID_LABEL"
|
||||
description="JFIELD_CATEGORY_DESC" >
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="subject"
|
||||
type="text"
|
||||
class="inputbox"
|
||||
size="80"
|
||||
label="COM_USERS_FIELD_SUBJECT_LABEL"
|
||||
description="COM_USERS_FIELD_SUBJECT_DESC"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="body"
|
||||
type="editor"
|
||||
class="inputbox"
|
||||
rows="10"
|
||||
cols="80"
|
||||
filter="safehtml"
|
||||
label="COM_USERS_FIELD_NOTEBODY_LABEL"
|
||||
description="COM_USERS_FIELD_NOTEBODY_DESC"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="state"
|
||||
type="list"
|
||||
label="JSTATUS"
|
||||
description="COM_USERS_FIELD_STATE_DESC"
|
||||
class="inputbox"
|
||||
size="1"
|
||||
default="1">
|
||||
<option
|
||||
value="1">JPUBLISHED</option>
|
||||
<option
|
||||
value="0">JUNPUBLISHED</option>
|
||||
<option
|
||||
value="2">JARCHIVED</option>
|
||||
<option
|
||||
value="-2">JTRASHED</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="review_time"
|
||||
type="calendar"
|
||||
class="inputbox"
|
||||
label="COM_USERS_FIELD_REVIEW_TIME_LABEL"
|
||||
description="COM_USERS_FIELD_REVIEW_TIME_DESC"
|
||||
default="0000-00-00"
|
||||
format="%Y-%m-%d"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="checked_out"
|
||||
type="hidden"
|
||||
filter="unset"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="checked_out_time"
|
||||
type="hidden"
|
||||
filter="unset"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="created_user_id"
|
||||
type="hidden"
|
||||
filter="unset"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="created_time"
|
||||
type="hidden"
|
||||
filter="unset"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="modified_user_id"
|
||||
type="hidden"
|
||||
filter="unset"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="modified_time"
|
||||
type="hidden"
|
||||
filter="unset"
|
||||
/>
|
||||
|
||||
<field name="publish_up" type="calendar"
|
||||
label="JGLOBAL_FIELD_PUBLISH_UP_LABEL" description="JGLOBAL_FIELD_PUBLISH_UP_DESC"
|
||||
class="inputbox" format="%Y-%m-%d %H:%M:%S" size="22"
|
||||
filter="user_utc" />
|
||||
|
||||
<field name="publish_down" type="calendar"
|
||||
label="JGLOBAL_FIELD_PUBLISH_DOWN_LABEL" description="JGLOBAL_FIELD_PUBLISH_DOWN_DESC"
|
||||
class="inputbox" format="%Y-%m-%d %H:%M:%S" size="22"
|
||||
filter="user_utc" />
|
||||
</fieldset>
|
||||
</form>
|
188
administrator/components/com_users/models/forms/user.xml
Normal file
188
administrator/components/com_users/models/forms/user.xml
Normal file
@ -0,0 +1,188 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset name="user_details">
|
||||
<field name="name" type="text"
|
||||
class="inputbox"
|
||||
description="COM_USERS_USER_FIELD_NAME_DESC"
|
||||
label="COM_USERS_USER_FIELD_NAME_LABEL"
|
||||
required="true"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field name="username" type="text"
|
||||
class="inputbox"
|
||||
description="COM_USERS_USER_FIELD_USERNAME_DESC"
|
||||
label="COM_USERS_USER_FIELD_USERNAME_LABEL"
|
||||
required="true"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field name="password" type="password"
|
||||
autocomplete="off"
|
||||
class="inputbox validate-password"
|
||||
description="COM_USERS_USER_FIELD_PASSWORD_DESC"
|
||||
filter="raw"
|
||||
validate="password"
|
||||
label="JGLOBAL_PASSWORD"
|
||||
size="30"
|
||||
/>
|
||||
|
||||
<field name="password2" type="password"
|
||||
autocomplete="off"
|
||||
class="inputbox validate-password"
|
||||
description="COM_USERS_USER_FIELD_PASSWORD2_DESC"
|
||||
filter="raw"
|
||||
label="COM_USERS_USER_FIELD_PASSWORD2_LABEL"
|
||||
size="30"
|
||||
validate="equals"
|
||||
field="password"
|
||||
/>
|
||||
|
||||
<field name="email" type="email"
|
||||
class="inputbox"
|
||||
description="COM_USERS_USER_FIELD_EMAIL_DESC"
|
||||
label="JGLOBAL_EMAIL"
|
||||
required="true"
|
||||
size="30"
|
||||
validate="email"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="registerDate"
|
||||
type="calendar"
|
||||
class="readonly"
|
||||
label="COM_USERS_USER_FIELD_REGISTERDATE_LABEL"
|
||||
description="COM_USERS_USER_FIELD_REGISTERDATE_DESC"
|
||||
readonly="true"
|
||||
format="%Y-%m-%d %H:%M:%S"
|
||||
size="22"
|
||||
filter="user_utc"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="lastvisitDate"
|
||||
type="calendar"
|
||||
class="readonly"
|
||||
label="COM_USERS_USER_FIELD_LASTVISIT_LABEL"
|
||||
description="COM_USERS_USER_FIELD_LASTVISIT_DESC"
|
||||
readonly="true"
|
||||
format="%Y-%m-%d %H:%M:%S"
|
||||
size="22"
|
||||
filter="user_utc"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="lastResetTime"
|
||||
type="calendar"
|
||||
class="readonly"
|
||||
label="COM_USERS_USER_FIELD_LASTRESET_LABEL"
|
||||
description="COM_USERS_USER_FIELD_LASTRESET_DESC"
|
||||
readonly="true"
|
||||
format="%Y-%m-%d %H:%M:%S"
|
||||
size="22"
|
||||
filter="user_utc"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="resetCount"
|
||||
type="text"
|
||||
class="readonly"
|
||||
label="COM_USERS_USER_FIELD_RESETCOUNT_LABEL"
|
||||
description ="COM_USERS_USER_FIELD_RESETCOUNT_DESC"
|
||||
default="0"
|
||||
readonly="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="sendEmail"
|
||||
type="radio"
|
||||
default="0"
|
||||
class="btn-group"
|
||||
label="COM_USERS_USER_FIELD_SENDEMAIL_LABEL"
|
||||
description="COM_USERS_USER_FIELD_SENDEMAIL_DESC">
|
||||
<option
|
||||
value="0">JNO</option>
|
||||
<option
|
||||
value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="block"
|
||||
type="radio"
|
||||
class="btn-group"
|
||||
default="0"
|
||||
label="COM_USERS_USER_FIELD_BLOCK_LABEL"
|
||||
description="COM_USERS_USER_FIELD_BLOCK_DESC">
|
||||
<option
|
||||
value="0">JNO</option>
|
||||
<option
|
||||
value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="id"
|
||||
type="text"
|
||||
class="readonly"
|
||||
label="JGLOBAL_FIELD_ID_LABEL"
|
||||
description ="JGLOBAL_FIELD_ID_DESC"
|
||||
default="0"
|
||||
readonly="true"
|
||||
/>
|
||||
|
||||
</fieldset>
|
||||
<field name="groups" type="hidden" />
|
||||
|
||||
<fields name="params">
|
||||
|
||||
<!-- Basic user account settings. -->
|
||||
<fieldset name="settings" label="COM_USERS_SETTINGS_FIELDSET_LABEL">
|
||||
|
||||
<field name="admin_style" type="templatestyle"
|
||||
client="administrator"
|
||||
description="COM_USERS_USER_FIELD_BACKEND_TEMPLATE_DESC"
|
||||
label="COM_USERS_USER_FIELD_BACKEND_TEMPLATE_LABEL"
|
||||
>
|
||||
<option value="">JOPTION_USE_DEFAULT</option>
|
||||
</field>
|
||||
|
||||
<field name="admin_language" type="language"
|
||||
client="administrator"
|
||||
description="COM_USERS_USER_FIELD_BACKEND_LANGUAGE_DESC"
|
||||
label="COM_USERS_USER_FIELD_BACKEND_LANGUAGE_LABEL"
|
||||
>
|
||||
<option value="">JOPTION_USE_DEFAULT</option>
|
||||
</field>
|
||||
|
||||
<field name="language" type="language"
|
||||
client="site"
|
||||
description="COM_USERS_USER_FIELD_FRONTEND_LANGUAGE_DESC"
|
||||
label="COM_USERS_USER_FIELD_FRONTEND_LANGUAGE_LABEL"
|
||||
>
|
||||
<option value="">JOPTION_USE_DEFAULT</option>
|
||||
</field>
|
||||
|
||||
<field name="editor" type="plugins" folder="editors"
|
||||
description="COM_USERS_USER_FIELD_EDITOR_DESC"
|
||||
label="COM_USERS_USER_FIELD_EDITOR_LABEL"
|
||||
>
|
||||
<option value="">JOPTION_USE_DEFAULT</option>
|
||||
</field>
|
||||
|
||||
<field name="helpsite" type="helpsite"
|
||||
label="COM_USERS_USER_FIELD_HELPSITE_LABEL"
|
||||
description="COM_USERS_USER_FIELD_HELPSITE_DESC"
|
||||
>
|
||||
<option value="">JOPTION_USE_DEFAULT</option>
|
||||
</field>
|
||||
|
||||
<field name="timezone" type="timezone"
|
||||
label="COM_USERS_USER_FIELD_TIMEZONE_LABEL"
|
||||
description="COM_USERS_USER_FIELD_TIMEZONE_DESC"
|
||||
>
|
||||
<option value="">JOPTION_USE_DEFAULT</option>
|
||||
</field>
|
||||
|
||||
</fieldset>
|
||||
|
||||
</fields>
|
||||
</form>
|
261
administrator/components/com_users/models/group.php
Normal file
261
administrator/components/com_users/models/group.php
Normal file
@ -0,0 +1,261 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* User group model.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersModelGroup extends JModelAdmin
|
||||
{
|
||||
/**
|
||||
* @var string The event to trigger after saving the data.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $event_after_save = 'onUserAfterSaveGroup';
|
||||
|
||||
/**
|
||||
* @var string The event to trigger after before the data.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $event_before_save = 'onUserBeforeSaveGroup';
|
||||
|
||||
/**
|
||||
* Returns a reference to the a Table object, always creating it.
|
||||
*
|
||||
* @param type The table type to instantiate
|
||||
* @param string A prefix for the table class name. Optional.
|
||||
* @param array Configuration array for model. Optional.
|
||||
* @return JTable A database object
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getTable($type = 'Usergroup', $prefix = 'JTable', $config = array())
|
||||
{
|
||||
$return = JTable::getInstance($type, $prefix, $config);
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
* @return JForm A JForm object on success, false on failure
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_users.group', 'group', array('control' => 'jform', 'load_data' => $loadData));
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return mixed The data for the form.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
// Check the session for previously entered form data.
|
||||
$data = JFactory::getApplication()->getUserState('com_users.edit.group.data', array());
|
||||
|
||||
if (empty($data))
|
||||
{
|
||||
$data = $this->getItem();
|
||||
}
|
||||
|
||||
$this->preprocessData('com_users.group', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override preprocessForm to load the user plugin group instead of content.
|
||||
*
|
||||
* @param object A form object.
|
||||
* @param mixed The data expected for the form.
|
||||
* @throws Exception if there is an error in the form event.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function preprocessForm(JForm $form, $data, $groups = '')
|
||||
{
|
||||
$obj = is_array($data) ? JArrayHelper::toObject($data, 'JObject') : $data;
|
||||
if (isset($obj->parent_id) && $obj->parent_id == 0 && $obj->id > 0)
|
||||
{
|
||||
$form->setFieldAttribute('parent_id', 'type', 'hidden');
|
||||
$form->setFieldAttribute('parent_id', 'hidden', 'true');
|
||||
}
|
||||
parent::preprocessForm($form, $data, 'user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save the form data.
|
||||
*
|
||||
* @param array The form data.
|
||||
* @return boolean True on success.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
// Include the content plugins for events.
|
||||
JPluginHelper::importPlugin('user');
|
||||
|
||||
// Check the super admin permissions for group
|
||||
// We get the parent group permissions and then check the group permissions manually
|
||||
// We have to calculate the group permissions manually because we haven't saved the group yet
|
||||
$parentSuperAdmin = JAccess::checkGroup($data['parent_id'], 'core.admin');
|
||||
// Get core.admin rules from the root asset
|
||||
$rules = JAccess::getAssetRules('root.1')->getData('core.admin');
|
||||
// Get the value for the current group (will be true (allowed), false (denied), or null (inherit)
|
||||
$groupSuperAdmin = $rules['core.admin']->allow($data['id']);
|
||||
|
||||
// We only need to change the $groupSuperAdmin if the parent is true or false. Otherwise, the value set in the rule takes effect.
|
||||
if ($parentSuperAdmin === false)
|
||||
{
|
||||
// If parent is false (Denied), effective value will always be false
|
||||
$groupSuperAdmin = false;
|
||||
}
|
||||
elseif ($parentSuperAdmin === true)
|
||||
{
|
||||
// If parent is true (allowed), group is true unless explicitly set to false
|
||||
$groupSuperAdmin = ($groupSuperAdmin === false) ? false : true;
|
||||
}
|
||||
|
||||
// Check for non-super admin trying to save with super admin group
|
||||
$iAmSuperAdmin = JFactory::getUser()->authorise('core.admin');
|
||||
if ((!$iAmSuperAdmin) && ($groupSuperAdmin))
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new Exception(JText::_('JLIB_USER_ERROR_NOT_SUPERADMIN'));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for super-admin changing self to be non-super-admin
|
||||
// First, are we a super admin>
|
||||
if ($iAmSuperAdmin)
|
||||
{
|
||||
// Next, are we a member of the current group?
|
||||
$myGroups = JAccess::getGroupsByUser(JFactory::getUser()->get('id'), false);
|
||||
if (in_array($data['id'], $myGroups))
|
||||
{
|
||||
// Now, would we have super admin permissions without the current group?
|
||||
$otherGroups = array_diff($myGroups, array($data['id']));
|
||||
$otherSuperAdmin = false;
|
||||
foreach ($otherGroups as $otherGroup)
|
||||
{
|
||||
$otherSuperAdmin = ($otherSuperAdmin) ? $otherSuperAdmin : JAccess::checkGroup($otherGroup, 'core.admin');
|
||||
}
|
||||
// If we would not otherwise have super admin permissions
|
||||
// and the current group does not have super admin permissions, throw an exception
|
||||
if ((!$otherSuperAdmin) && (!$groupSuperAdmin))
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new Exception(JText::_('JLIB_USER_ERROR_CANNOT_DEMOTE_SELF'));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Proceed with the save
|
||||
return parent::save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delete rows.
|
||||
*
|
||||
* @param array An array of item ids.
|
||||
* @return boolean Returns true on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function delete(&$pks)
|
||||
{
|
||||
// Typecast variable.
|
||||
$pks = (array) $pks;
|
||||
$user = JFactory::getUser();
|
||||
$groups = JAccess::getGroupsByUser($user->get('id'));
|
||||
|
||||
// Get a row instance.
|
||||
$table = $this->getTable();
|
||||
|
||||
// Load plugins.
|
||||
JPluginHelper::importPlugin('user');
|
||||
$dispatcher = JEventDispatcher::getInstance();
|
||||
|
||||
// Check if I am a Super Admin
|
||||
$iAmSuperAdmin = $user->authorise('core.admin');
|
||||
|
||||
// do not allow to delete groups to which the current user belongs
|
||||
foreach ($pks as $pk)
|
||||
{
|
||||
if (in_array($pk, $groups))
|
||||
{
|
||||
JError::raiseWarning(403, JText::_('COM_USERS_DELETE_ERROR_INVALID_GROUP'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Iterate the items to delete each one.
|
||||
foreach ($pks as $i => $pk)
|
||||
{
|
||||
if ($table->load($pk))
|
||||
{
|
||||
// Access checks.
|
||||
$allow = $user->authorise('core.edit.state', 'com_users');
|
||||
// Don't allow non-super-admin to delete a super admin
|
||||
$allow = (!$iAmSuperAdmin && JAccess::checkGroup($pk, 'core.admin')) ? false : $allow;
|
||||
|
||||
if ($allow)
|
||||
{
|
||||
// Fire the onUserBeforeDeleteGroup event.
|
||||
$dispatcher->trigger('onUserBeforeDeleteGroup', array($table->getProperties()));
|
||||
|
||||
if (!$table->delete($pk))
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
} else {
|
||||
// Trigger the onUserAfterDeleteGroup event.
|
||||
$dispatcher->trigger('onUserAfterDeleteGroup', array($table->getProperties(), true, $this->getError()));
|
||||
}
|
||||
} else {
|
||||
// Prune items that you can't change.
|
||||
unset($pks[$i]);
|
||||
JError::raiseWarning(403, JText::_('JERROR_CORE_DELETE_NOT_PERMITTED'));
|
||||
}
|
||||
} else {
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
202
administrator/components/com_users/models/groups.php
Normal file
202
administrator/components/com_users/models/groups.php
Normal file
@ -0,0 +1,202 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Methods supporting a list of user group records.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersModelGroups extends JModelList
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array An optional associative array of configuration settings.
|
||||
* @see JController
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
if (empty($config['filter_fields']))
|
||||
{
|
||||
$config['filter_fields'] = array(
|
||||
'id', 'a.id',
|
||||
'parent_id', 'a.parent_id',
|
||||
'title', 'a.title',
|
||||
'lft', 'a.lft',
|
||||
'rgt', 'a.rgt',
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
// Load the filter state.
|
||||
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
|
||||
$this->setState('filter.search', $search);
|
||||
|
||||
// Load the parameters.
|
||||
$params = JComponentHelper::getParams('com_users');
|
||||
$this->setState('params', $params);
|
||||
|
||||
// List state information.
|
||||
parent::populateState('a.lft', 'asc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
*
|
||||
* @return string A store id.
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= ':' . $this->getState('filter.search');
|
||||
$id .= ':' . $this->getState('filter.search');
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of groups and adds expensive joins to the result set.
|
||||
*
|
||||
* @return mixed An array of data items on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
$db = $this->getDbo();
|
||||
// Get a storage key.
|
||||
$store = $this->getStoreId();
|
||||
|
||||
// Try to load the data from internal storage.
|
||||
if (empty($this->cache[$store]))
|
||||
{
|
||||
$items = parent::getItems();
|
||||
|
||||
// Bail out on an error or empty list.
|
||||
if (empty($items))
|
||||
{
|
||||
$this->cache[$store] = $items;
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
// First pass: get list of the group id's and reset the counts.
|
||||
$groupIds = array();
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$groupIds[] = (int) $item->id;
|
||||
$item->user_count = 0;
|
||||
}
|
||||
|
||||
// Get the counts from the database only for the users in the list.
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Count the objects in the user group.
|
||||
$query->select('map.group_id, COUNT(DISTINCT map.user_id) AS user_count')
|
||||
->from($db->quoteName('#__user_usergroup_map') . ' AS map')
|
||||
->where('map.group_id IN (' . implode(',', $groupIds) . ')')
|
||||
->group('map.group_id');
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
// Load the counts into an array indexed on the user id field.
|
||||
try
|
||||
{
|
||||
$users = $db->loadObjectList('group_id');
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError($e->getMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Second pass: collect the group counts into the master items array.
|
||||
foreach ($items as &$item)
|
||||
{
|
||||
if (isset($users[$item->id]))
|
||||
{
|
||||
$item->user_count = $users[$item->id]->user_count;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the items to the internal cache.
|
||||
$this->cache[$store] = $items;
|
||||
}
|
||||
|
||||
return $this->cache[$store];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an SQL query to load the list data.
|
||||
*
|
||||
* @return JDatabaseQuery
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
// Create a new query object.
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Select the required fields from the table.
|
||||
$query->select(
|
||||
$this->getState(
|
||||
'list.select',
|
||||
'a.*'
|
||||
)
|
||||
);
|
||||
$query->from($db->quoteName('#__usergroups') . ' AS a');
|
||||
|
||||
// Add the level in the tree.
|
||||
$query->select('COUNT(DISTINCT c2.id) AS level')
|
||||
->join('LEFT OUTER', $db->quoteName('#__usergroups') . ' AS c2 ON a.lft > c2.lft AND a.rgt < c2.rgt')
|
||||
->group('a.id, a.lft, a.rgt, a.parent_id, a.title');
|
||||
|
||||
// Filter the comments over the search string if set.
|
||||
$search = $this->getState('filter.search');
|
||||
if (!empty($search))
|
||||
{
|
||||
if (stripos($search, 'id:') === 0)
|
||||
{
|
||||
$query->where('a.id = ' . (int) substr($search, 3));
|
||||
}
|
||||
else
|
||||
{
|
||||
$search = $db->quote('%' . $db->escape($search, true) . '%');
|
||||
$query->where('a.title LIKE ' . $search);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the list ordering clause.
|
||||
$query->order($db->escape($this->getState('list.ordering', 'a.lft')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
|
||||
|
||||
//echo nl2br(str_replace('#__','jos_',$query));
|
||||
return $query;
|
||||
}
|
||||
}
|
1
administrator/components/com_users/models/index.html
Normal file
1
administrator/components/com_users/models/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
205
administrator/components/com_users/models/level.php
Normal file
205
administrator/components/com_users/models/level.php
Normal file
@ -0,0 +1,205 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* User view level model.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersModelLevel extends JModelAdmin
|
||||
{
|
||||
/**
|
||||
* @var array A list of the access levels in use.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $levelsInUse = null;
|
||||
|
||||
/**
|
||||
* Method to test whether a record can be deleted.
|
||||
*
|
||||
* @param object $record A record object.
|
||||
*
|
||||
* @return boolean True if allowed to delete the record. Defaults to the permission set in the component.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function canDelete($record)
|
||||
{
|
||||
// Check if the access level is being used by any content.
|
||||
if ($this->levelsInUse === null)
|
||||
{
|
||||
// Populate the list once.
|
||||
$this->levelsInUse = array();
|
||||
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('DISTINCT access');
|
||||
// from is added dynamically
|
||||
|
||||
// Get all the tables and the prefix
|
||||
$tables = $db->getTableList();
|
||||
//$fields = $db->getTableFields($tables);
|
||||
$prefix = $db->getPrefix();
|
||||
|
||||
foreach ($tables as $table)
|
||||
{
|
||||
// Get all of the columns in the table
|
||||
$fields = $db->getTableColumns($table);
|
||||
|
||||
// We are looking for the access field. If custom tables are using something other
|
||||
// than the 'access' field they are on their own unfortunately.
|
||||
// Also make sure the table prefix matches the live db prefix (eg, it is not a "bak_" table)
|
||||
if ((strpos($table, $prefix) === 0) && (isset($fields['access'])))
|
||||
{
|
||||
// Lookup the distinct values of the field.
|
||||
$query->clear('from')
|
||||
->from($db->quoteName($table));
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$values = $db->loadColumn();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->levelsInUse = array_merge($this->levelsInUse, $values);
|
||||
|
||||
// TODO Could assemble an array of the tables used by each view level list those,
|
||||
// giving the user a clue in the error where to look.
|
||||
}
|
||||
}
|
||||
|
||||
// Get uniques.
|
||||
$this->levelsInUse = array_unique($this->levelsInUse);
|
||||
|
||||
// Ok, after all that we are ready to check the record :)
|
||||
}
|
||||
|
||||
if (in_array($record->id, $this->levelsInUse))
|
||||
{
|
||||
$this->setError(JText::sprintf('COM_USERS_ERROR_VIEW_LEVEL_IN_USE', $record->id, $record->title));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return parent::canDelete($record);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the a Table object, always creating it.
|
||||
*
|
||||
* @param type The table type to instantiate
|
||||
* @param string A prefix for the table class name. Optional.
|
||||
* @param array Configuration array for model. Optional.
|
||||
* @return JTable A database object
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getTable($type = 'Viewlevel', $prefix = 'JTable', $config = array())
|
||||
{
|
||||
$return = JTable::getInstance($type, $prefix, $config);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a single record.
|
||||
*
|
||||
* @param integer The id of the primary key.
|
||||
* @return mixed Object on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
$result = parent::getItem($pk);
|
||||
|
||||
// Convert the params field to an array.
|
||||
$result->rules = json_decode($result->rules);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
* @return JForm A JForm object on success, false on failure
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_users.level', 'level', array('control' => 'jform', 'load_data' => $loadData));
|
||||
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return mixed The data for the form.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
// Check the session for previously entered form data.
|
||||
$data = JFactory::getApplication()->getUserState('com_users.edit.level.data', array());
|
||||
|
||||
if (empty($data))
|
||||
{
|
||||
$data = $this->getItem();
|
||||
}
|
||||
|
||||
$this->preprocessData('com_users.level', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override preprocessForm to load the user plugin group instead of content.
|
||||
*
|
||||
* @param object A form object.
|
||||
* @param mixed The data expected for the form.
|
||||
* @throws Exception if there is an error in the form event.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function preprocessForm(JForm $form, $data, $groups = '')
|
||||
{
|
||||
parent::preprocessForm($form, $data, 'user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save the form data.
|
||||
*
|
||||
* @param array The form data.
|
||||
* @return boolean True on success.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
if (!isset($data['rules']))
|
||||
{
|
||||
$data['rules'] = array();
|
||||
}
|
||||
|
||||
return parent::save($data);
|
||||
}
|
||||
}
|
219
administrator/components/com_users/models/levels.php
Normal file
219
administrator/components/com_users/models/levels.php
Normal file
@ -0,0 +1,219 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Methods supporting a list of user access level records.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersModelLevels extends JModelList
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array An optional associative array of configuration settings.
|
||||
* @see JController
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
if (empty($config['filter_fields']))
|
||||
{
|
||||
$config['filter_fields'] = array(
|
||||
'id', 'a.id',
|
||||
'title', 'a.title',
|
||||
'ordering', 'a.ordering',
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
// Load the filter state.
|
||||
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
|
||||
$this->setState('filter.search', $search);
|
||||
|
||||
// Load the parameters.
|
||||
$params = JComponentHelper::getParams('com_users');
|
||||
$this->setState('params', $params);
|
||||
|
||||
// List state information.
|
||||
parent::populateState('a.title', 'asc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
*
|
||||
* @return string A store id.
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= ':' . $this->getState('filter.search');
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an SQL query to load the list data.
|
||||
*
|
||||
* @return JDatabaseQuery
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
// Create a new query object.
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Select the required fields from the table.
|
||||
$query->select(
|
||||
$this->getState(
|
||||
'list.select',
|
||||
'a.*'
|
||||
)
|
||||
);
|
||||
$query->from($db->quoteName('#__viewlevels') . ' AS a');
|
||||
|
||||
// Add the level in the tree.
|
||||
$query->group('a.id, a.title, a.ordering, a.rules');
|
||||
|
||||
// Filter the items over the search string if set.
|
||||
$search = $this->getState('filter.search');
|
||||
if (!empty($search))
|
||||
{
|
||||
if (stripos($search, 'id:') === 0)
|
||||
{
|
||||
$query->where('a.id = ' . (int) substr($search, 3));
|
||||
}
|
||||
else
|
||||
{
|
||||
$search = $db->quote('%' . $db->escape($search, true) . '%');
|
||||
$query->where('a.title LIKE ' . $search);
|
||||
}
|
||||
}
|
||||
|
||||
$query->group('a.id');
|
||||
|
||||
// Add the list ordering clause.
|
||||
$query->order($db->escape($this->getState('list.ordering', 'a.lft')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
|
||||
|
||||
//echo nl2br(str_replace('#__','jos_',$query));
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to adjust the ordering of a row.
|
||||
*
|
||||
* @param integer The ID of the primary key to move.
|
||||
* @param integer Increment, usually +1 or -1
|
||||
* @return boolean False on failure or error, true otherwise.
|
||||
*/
|
||||
public function reorder($pk, $direction = 0)
|
||||
{
|
||||
// Sanitize the id and adjustment.
|
||||
$pk = (!empty($pk)) ? $pk : (int) $this->getState('level.id');
|
||||
$user = JFactory::getUser();
|
||||
|
||||
// Get an instance of the record's table.
|
||||
$table = JTable::getInstance('viewlevel');
|
||||
|
||||
// Load the row.
|
||||
if (!$table->load($pk))
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Access checks.
|
||||
$allow = $user->authorise('core.edit.state', 'com_users');
|
||||
|
||||
if (!$allow)
|
||||
{
|
||||
$this->setError(JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Move the row.
|
||||
// TODO: Where clause to restrict category.
|
||||
$table->move($pk);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the manually set order of records.
|
||||
*
|
||||
* @param array An array of primary key ids.
|
||||
* @param integer +/-1
|
||||
*/
|
||||
public function saveorder($pks, $order)
|
||||
{
|
||||
$table = JTable::getInstance('viewlevel');
|
||||
$user = JFactory::getUser();
|
||||
$conditions = array();
|
||||
|
||||
if (empty($pks))
|
||||
{
|
||||
return JError::raiseWarning(500, JText::_('COM_USERS_ERROR_LEVELS_NOLEVELS_SELECTED'));
|
||||
}
|
||||
|
||||
// update ordering values
|
||||
foreach ($pks as $i => $pk)
|
||||
{
|
||||
$table->load((int) $pk);
|
||||
|
||||
// Access checks.
|
||||
$allow = $user->authorise('core.edit.state', 'com_users');
|
||||
|
||||
if (!$allow)
|
||||
{
|
||||
// Prune items that you can't change.
|
||||
unset($pks[$i]);
|
||||
JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
|
||||
}
|
||||
elseif ($table->ordering != $order[$i])
|
||||
{
|
||||
$table->ordering = $order[$i];
|
||||
if (!$table->store())
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Execute reorder for each category.
|
||||
foreach ($conditions as $cond)
|
||||
{
|
||||
$table->load($cond[0]);
|
||||
$table->reorder($cond[1]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
192
administrator/components/com_users/models/mail.php
Normal file
192
administrator/components/com_users/models/mail.php
Normal file
@ -0,0 +1,192 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Users mail model.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersModelMail extends JModelAdmin
|
||||
{
|
||||
/**
|
||||
* Method to get the row form.
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
* @return JForm A JForm object on success, false on failure
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_users.mail', 'mail', array('control' => 'jform', 'load_data' => $loadData));
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return mixed The data for the form.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
// Check the session for previously entered form data.
|
||||
$data = JFactory::getApplication()->getUserState('com_users.display.mail.data', array());
|
||||
|
||||
$this->preprocessData('com_users.mail', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override preprocessForm to load the user plugin group instead of content.
|
||||
*
|
||||
* @param object A form object.
|
||||
* @param mixed The data expected for the form.
|
||||
* @throws Exception if there is an error in the form event.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function preprocessForm(JForm $form, $data, $group = 'user')
|
||||
{
|
||||
parent::preprocessForm($form, $data, $group);
|
||||
}
|
||||
|
||||
public function send()
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
$data = $app->input->post->get('jform', array(), 'array');
|
||||
$user = JFactory::getUser();
|
||||
$access = new JAccess;
|
||||
$db = $this->getDbo();
|
||||
|
||||
$mode = array_key_exists('mode', $data) ? (int) $data['mode'] : 0;
|
||||
$subject = array_key_exists('subject', $data) ? $data['subject'] : '';
|
||||
$grp = array_key_exists('group', $data) ? (int) $data['group'] : 0;
|
||||
$recurse = array_key_exists('recurse', $data) ? (int) $data['recurse'] : 0;
|
||||
$bcc = array_key_exists('bcc', $data) ? (int) $data['bcc'] : 0;
|
||||
$disabled = array_key_exists('disabled', $data) ? (int) $data['disabled'] : 0;
|
||||
$message_body = array_key_exists('message', $data) ? $data['message'] : '';
|
||||
|
||||
// automatically removes html formatting
|
||||
if (!$mode)
|
||||
{
|
||||
$message_body = JFilterInput::getInstance()->clean($message_body, 'string');
|
||||
}
|
||||
|
||||
// Check for a message body and subject
|
||||
if (!$message_body || !$subject)
|
||||
{
|
||||
$app->setUserState('com_users.display.mail.data', $data);
|
||||
$this->setError(JText::_('COM_USERS_MAIL_PLEASE_FILL_IN_THE_FORM_CORRECTLY'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// get users in the group out of the acl
|
||||
$to = $access->getUsersByGroup($grp, $recurse);
|
||||
|
||||
// Get all users email and group except for senders
|
||||
$query = $db->getQuery(true)
|
||||
->select('email')
|
||||
->from('#__users')
|
||||
->where('id != '.(int) $user->get('id'));
|
||||
if ($grp !== 0)
|
||||
{
|
||||
if (empty($to))
|
||||
{
|
||||
$query->where('0');
|
||||
} else {
|
||||
$query->where('id IN (' . implode(',', $to) . ')');
|
||||
}
|
||||
}
|
||||
|
||||
if ($disabled == 0){
|
||||
$query->where("block = 0");
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
$rows = $db->loadColumn();
|
||||
|
||||
// Check to see if there are any users in this group before we continue
|
||||
if (!count($rows))
|
||||
{
|
||||
$app->setUserState('com_users.display.mail.data', $data);
|
||||
if (in_array($user->id, $to))
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_MAIL_ONLY_YOU_COULD_BE_FOUND_IN_THIS_GROUP'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_MAIL_NO_USERS_COULD_BE_FOUND_IN_THIS_GROUP'));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the Mailer
|
||||
$mailer = JFactory::getMailer();
|
||||
$params = JComponentHelper::getParams('com_users');
|
||||
|
||||
// Build email message format.
|
||||
$mailer->setSender(array($app->getCfg('mailfrom'), $app->getCfg('fromname')));
|
||||
$mailer->setSubject($params->get('mailSubjectPrefix') . stripslashes($subject));
|
||||
$mailer->setBody($message_body . $params->get('mailBodySuffix'));
|
||||
$mailer->IsHTML($mode);
|
||||
|
||||
// Add recipients
|
||||
if ($bcc)
|
||||
{
|
||||
$mailer->addBCC($rows);
|
||||
$mailer->addRecipient($app->getCfg('mailfrom'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$mailer->addRecipient($rows);
|
||||
}
|
||||
|
||||
// Send the Mail
|
||||
$rs = $mailer->Send();
|
||||
|
||||
// Check for an error
|
||||
if ($rs instanceof Exception)
|
||||
{
|
||||
$app->setUserState('com_users.display.mail.data', $data);
|
||||
$this->setError($rs->getError());
|
||||
return false;
|
||||
} elseif (empty($rs))
|
||||
{
|
||||
$app->setUserState('com_users.display.mail.data', $data);
|
||||
$this->setError(JText::_('COM_USERS_MAIL_THE_MAIL_COULD_NOT_BE_SENT'));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fill the data (specially for the 'mode', 'group' and 'bcc': they could not exist in the array
|
||||
// when the box is not checked and in this case, the default value would be used instead of the '0'
|
||||
// one)
|
||||
$data['mode'] = $mode;
|
||||
$data['subject'] = $subject;
|
||||
$data['group'] = $grp;
|
||||
$data['recurse'] = $recurse;
|
||||
$data['bcc'] = $bcc;
|
||||
$data['message'] = $message_body;
|
||||
$app->setUserState('com_users.display.mail.data', array());
|
||||
$app->enqueueMessage(JText::plural('COM_USERS_MAIL_EMAIL_SENT_TO_N_USERS', count($rows)), 'message');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
186
administrator/components/com_users/models/note.php
Normal file
186
administrator/components/com_users/models/note.php
Normal file
@ -0,0 +1,186 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* User note model.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
* @since 2.5
|
||||
*/
|
||||
class UsersModelNote extends JModelAdmin
|
||||
{
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data Data for the form.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return mixed A JForm object on success, false on failure
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_users.note', 'note', array('control' => 'jform', 'load_data' => $loadData));
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a single record.
|
||||
*
|
||||
* @param integer $pk The id of the primary key.
|
||||
*
|
||||
* @return mixed Object on success, false on failure.
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
$result = parent::getItem($pk);
|
||||
|
||||
// Get the dispatcher and load the users plugins.
|
||||
$dispatcher = JEventDispatcher::getInstance();
|
||||
JPluginHelper::importPlugin('user');
|
||||
|
||||
// Trigger the data preparation event.
|
||||
$dispatcher->trigger('onContentPrepareData', array('com_users.note', $result));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a table object, load it if necessary.
|
||||
*
|
||||
* @param string $name The table name. Optional.
|
||||
* @param string $prefix The class prefix. Optional.
|
||||
* @param array $options Configuration array for model. Optional.
|
||||
*
|
||||
* @return JTable The table object
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
public function getTable($name = 'Note', $prefix = 'UsersTable', $options = array())
|
||||
{
|
||||
return JTable::getInstance($name, $prefix, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return mixed The data for the form.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
// Get the application
|
||||
$app = JFactory::getApplication();
|
||||
|
||||
// Check the session for previously entered form data.
|
||||
$data = $app->getUserState('com_users.edit.note.data', array());
|
||||
|
||||
if (empty($data))
|
||||
{
|
||||
$data = $this->getItem();
|
||||
|
||||
// Prime some default values.
|
||||
if ($this->getState('note.id') == 0)
|
||||
{
|
||||
$data->set('catid', $app->input->get('catid', $app->getUserState('com_users.notes.filter.category_id'), 'int'));
|
||||
}
|
||||
|
||||
$userId = $app->input->get('u_id', 0, 'int');
|
||||
|
||||
if ($userId != 0)
|
||||
{
|
||||
$data->user_id = $userId;
|
||||
}
|
||||
}
|
||||
|
||||
$this->preprocessData('com_users.note', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
parent::populateState();
|
||||
|
||||
$userId = JFactory::getApplication()->input->get('u_id', 0, 'int');
|
||||
$this->setState('note.user_id', $userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save the form data.
|
||||
*
|
||||
* @param array $data The form data.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
/*public function save($data)
|
||||
{
|
||||
$pk = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('note.id');
|
||||
$table = $this->getTable();
|
||||
$isNew = empty($pk);
|
||||
|
||||
if (!$table->bind($data))
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// JTableCategory doesn't bind the params, so we need to do that by hand.
|
||||
if (isset($data['params']) && is_array($data['params']))
|
||||
{
|
||||
$registry = new JRegistry();
|
||||
$registry->loadArray($data['params']);
|
||||
$table->params = $registry->toString();
|
||||
// This will give us INI format.
|
||||
}
|
||||
|
||||
if (!$table->check())
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$table->store())
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->setState('note.id', $table->id);
|
||||
|
||||
return true;
|
||||
}*/
|
||||
}
|
224
administrator/components/com_users/models/notes.php
Normal file
224
administrator/components/com_users/models/notes.php
Normal file
@ -0,0 +1,224 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* User notes model class.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
* @since 2.5
|
||||
*/
|
||||
class UsersModelNotes extends JModelList
|
||||
{
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
// Set the list ordering fields.
|
||||
if (empty($config['filter_fields']))
|
||||
{
|
||||
$config['filter_fields'] = array(
|
||||
'id',
|
||||
'a.id',
|
||||
'user_id',
|
||||
'a.user_id',
|
||||
'u.name',
|
||||
'subject',
|
||||
'a.subject',
|
||||
'catid',
|
||||
'a.catid',
|
||||
'state', 'a.state',
|
||||
'c.title',
|
||||
'review_time',
|
||||
'a.review_time',
|
||||
'publish_up', 'a.publish_up',
|
||||
'publish_down', 'a.publish_down',
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an SQL query to load the list data.
|
||||
*
|
||||
* @return JDatabaseQuery A JDatabaseQuery object to retrieve the data set.
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$section = $this->getState('filter.category_id');
|
||||
|
||||
// Select the required fields from the table.
|
||||
$query->select(
|
||||
$this->getState('list.select',
|
||||
'a.id, a.subject, a.checked_out, a.checked_out_time,' .
|
||||
'a.catid, a.created_time, a.review_time,' .
|
||||
'a.state, a.publish_up, a.publish_down'
|
||||
)
|
||||
);
|
||||
$query->from('#__user_notes AS a');
|
||||
|
||||
// Join over the category
|
||||
$query->select('c.title AS category_title, c.params AS category_params')
|
||||
->join('LEFT', '#__categories AS c ON c.id = a.catid');
|
||||
|
||||
// Join over the users for the note user.
|
||||
$query->select('u.name AS user_name')
|
||||
->join('LEFT', '#__users AS u ON u.id = a.user_id');
|
||||
|
||||
// Join over the users for the checked out user.
|
||||
$query->select('uc.name AS editor')
|
||||
->join('LEFT', '#__users AS uc ON uc.id = a.checked_out');
|
||||
|
||||
// Filter by search in title
|
||||
$search = $this->getState('filter.search');
|
||||
if (!empty($search))
|
||||
{
|
||||
if (stripos($search, 'id:') === 0)
|
||||
{
|
||||
$query->where('a.id = ' . (int) substr($search, 3));
|
||||
}
|
||||
elseif (stripos($search, 'uid:') === 0)
|
||||
{
|
||||
$query->where('a.user_id = ' . (int) substr($search, 4));
|
||||
}
|
||||
else
|
||||
{
|
||||
$search = $db->quote('%' . $db->escape($search, true) . '%');
|
||||
$query->where('((a.subject LIKE ' . $search . ') OR (u.name LIKE ' . $search . ') OR (u.username LIKE ' . $search . '))');
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by published state
|
||||
$published = $this->getState('filter.state');
|
||||
if (is_numeric($published))
|
||||
{
|
||||
$query->where('a.state = '.(int) $published);
|
||||
} elseif ($published === '')
|
||||
{
|
||||
$query->where('(a.state IN (0, 1))');
|
||||
}
|
||||
|
||||
// Filter by a single or group of categories.
|
||||
$categoryId = (int) $this->getState('filter.category_id');
|
||||
if ($categoryId)
|
||||
{
|
||||
if (is_scalar($section))
|
||||
{
|
||||
$query->where('a.catid = ' . $categoryId);
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by a single user.
|
||||
$userId = (int) $this->getState('filter.user_id');
|
||||
if ($userId)
|
||||
{
|
||||
// Add the body and where filter.
|
||||
$query->select('a.body')
|
||||
->where('a.user_id = ' . $userId);
|
||||
}
|
||||
|
||||
// Add the list ordering clause.
|
||||
$orderCol = $this->state->get('list.ordering');
|
||||
$orderDirn = $this->state->get('list.direction');
|
||||
$query->order($db->escape($orderCol . ' ' . $orderDirn));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
*
|
||||
* @return string A store id.
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= ':' . $this->getState('filter.search');
|
||||
$id .= ':' . $this->getState('filter.state');
|
||||
$id .= ':' . $this->getState('filter.category_id');
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a user object if the user filter is set.
|
||||
*
|
||||
* @return JUser The JUser object
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
$user = new JUser;
|
||||
|
||||
// Filter by search in title
|
||||
$search = JFactory::getApplication()->input->get('u_id', 0, 'int');
|
||||
if ($search != 0)
|
||||
{
|
||||
$user->load((int) $search);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
$input = $app->input;
|
||||
|
||||
// Adjust the context to support modal layouts.
|
||||
if ($layout = $input->get('layout'))
|
||||
{
|
||||
$this->context .= '.' . $layout;
|
||||
}
|
||||
|
||||
$value = $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
|
||||
$this->setState('filter.search', $value);
|
||||
|
||||
$published = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_published', '', 'string');
|
||||
$this->setState('filter.state', $published);
|
||||
|
||||
$section = $app->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id');
|
||||
$this->setState('filter.category_id', $section);
|
||||
|
||||
$userId = $input->get('u_id', 0, 'int');
|
||||
$this->setState('filter.user_id', $userId);
|
||||
|
||||
parent::populateState('a.review_time', 'DESC');
|
||||
}
|
||||
}
|
698
administrator/components/com_users/models/user.php
Normal file
698
administrator/components/com_users/models/user.php
Normal file
@ -0,0 +1,698 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* User model.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersModelUser extends JModelAdmin
|
||||
{
|
||||
/**
|
||||
* Returns a reference to the a Table object, always creating it.
|
||||
*
|
||||
* @param string $type The table type to instantiate
|
||||
* @param string $prefix A prefix for the table class name. Optional.
|
||||
* @param array $config Configuration array for model. Optional.
|
||||
*
|
||||
* @return JTable A database object
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getTable($type = 'User', $prefix = 'JTable', $config = array())
|
||||
{
|
||||
$table = JTable::getInstance($type, $prefix, $config);
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a single record.
|
||||
*
|
||||
* @param integer $pk The id of the primary key.
|
||||
*
|
||||
* @return mixed Object on success, false on failure.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
$result = parent::getItem($pk);
|
||||
|
||||
$result->tags = new JHelperTags;
|
||||
$result->tags->getTagIds($result->id, 'com_users.user');
|
||||
|
||||
// Get the dispatcher and load the users plugins.
|
||||
$dispatcher = JEventDispatcher::getInstance();
|
||||
JPluginHelper::importPlugin('user');
|
||||
|
||||
// Trigger the data preparation event.
|
||||
$dispatcher->trigger('onContentPrepareData', array('com_users.user', $result));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return mixed A JForm object on success, false on failure
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
$plugin = JPluginHelper::getPlugin('user', 'joomla');
|
||||
$pluginParams = new JRegistry($plugin->params);
|
||||
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_users.user', 'user', array('control' => 'jform', 'load_data' => $loadData));
|
||||
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Passwords fields are required when mail to user is set to No in joomla user plugin
|
||||
$userId = $form->getValue('id');
|
||||
if ($userId === 0 && $pluginParams->get('mail_to_user') === "0")
|
||||
{
|
||||
$form->setFieldAttribute('password', 'required', 'true');
|
||||
$form->setFieldAttribute('password2', 'required', 'true');
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return mixed The data for the form.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
// Check the session for previously entered form data.
|
||||
$data = JFactory::getApplication()->getUserState('com_users.edit.user.data', array());
|
||||
|
||||
if (empty($data))
|
||||
{
|
||||
$data = $this->getItem();
|
||||
}
|
||||
|
||||
JPluginHelper::importPlugin('user');
|
||||
|
||||
$this->preprocessData('com_users.profile', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override JModelAdmin::preprocessForm to ensure the correct plugin group is loaded.
|
||||
*
|
||||
* @param JForm $form A JForm object.
|
||||
* @param mixed $data The data expected for the form.
|
||||
* @param string $group The name of the plugin group to import (defaults to "content").
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
* @throws Exception if there is an error in the form event.
|
||||
*/
|
||||
protected function preprocessForm(JForm $form, $data, $group = 'user')
|
||||
{
|
||||
parent::preprocessForm($form, $data, $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save the form data.
|
||||
*
|
||||
* @param array $data The form data.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$pk = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('user.id');
|
||||
$user = JUser::getInstance($pk);
|
||||
|
||||
$my = JFactory::getUser();
|
||||
|
||||
if ($data['block'] && $pk == $my->id && !$my->block)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_USERS_ERROR_CANNOT_BLOCK_SELF'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure that we are not removing ourself from Super Admin group
|
||||
$iAmSuperAdmin = $my->authorise('core.admin');
|
||||
if ($iAmSuperAdmin && $my->get('id') == $pk)
|
||||
{
|
||||
// Check that at least one of our new groups is Super Admin
|
||||
$stillSuperAdmin = false;
|
||||
$myNewGroups = $data['groups'];
|
||||
foreach ($myNewGroups as $group)
|
||||
{
|
||||
$stillSuperAdmin = ($stillSuperAdmin) ? ($stillSuperAdmin) : JAccess::checkGroup($group, 'core.admin');
|
||||
}
|
||||
if (!$stillSuperAdmin)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_USERS_ERROR_CANNOT_DEMOTE_SELF'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Bind the data.
|
||||
if (!$user->bind($data))
|
||||
{
|
||||
$this->setError($user->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the data.
|
||||
if (!$user->save())
|
||||
{
|
||||
$this->setError($user->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->setState('user.id', $user->id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delete rows.
|
||||
*
|
||||
* @param array &$pks An array of item ids.
|
||||
*
|
||||
* @return boolean Returns true on success, false on failure.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function delete(&$pks)
|
||||
{
|
||||
$user = JFactory::getUser();
|
||||
$table = $this->getTable();
|
||||
$pks = (array) $pks;
|
||||
|
||||
// Check if I am a Super Admin
|
||||
$iAmSuperAdmin = $user->authorise('core.admin');
|
||||
|
||||
// Trigger the onUserBeforeSave event.
|
||||
JPluginHelper::importPlugin('user');
|
||||
$dispatcher = JEventDispatcher::getInstance();
|
||||
|
||||
if (in_array($user->id, $pks))
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_USERS_ERROR_CANNOT_DELETE_SELF'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Iterate the items to delete each one.
|
||||
foreach ($pks as $i => $pk)
|
||||
{
|
||||
if ($table->load($pk))
|
||||
{
|
||||
// Access checks.
|
||||
$allow = $user->authorise('core.delete', 'com_users');
|
||||
// Don't allow non-super-admin to delete a super admin
|
||||
$allow = (!$iAmSuperAdmin && JAccess::check($pk, 'core.admin')) ? false : $allow;
|
||||
|
||||
if ($allow)
|
||||
{
|
||||
// Get users data for the users to delete.
|
||||
$user_to_delete = JFactory::getUser($pk);
|
||||
|
||||
// Fire the onUserBeforeDelete event.
|
||||
$dispatcher->trigger('onUserBeforeDelete', array($table->getProperties()));
|
||||
|
||||
if (!$table->delete($pk))
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Trigger the onUserAfterDelete event.
|
||||
$dispatcher->trigger('onUserAfterDelete', array($user_to_delete->getProperties(), true, $this->getError()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Prune items that you can't change.
|
||||
unset($pks[$i]);
|
||||
JError::raiseWarning(403, JText::_('JERROR_CORE_DELETE_NOT_PERMITTED'));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to block user records.
|
||||
*
|
||||
* @param array &$pks The ids of the items to publish.
|
||||
* @param integer $value The value of the published state
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function block(&$pks, $value = 1)
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
$dispatcher = JEventDispatcher::getInstance();
|
||||
$user = JFactory::getUser();
|
||||
|
||||
// Check if I am a Super Admin
|
||||
$iAmSuperAdmin = $user->authorise('core.admin');
|
||||
$table = $this->getTable();
|
||||
$pks = (array) $pks;
|
||||
|
||||
JPluginHelper::importPlugin('user');
|
||||
|
||||
// Access checks.
|
||||
foreach ($pks as $i => $pk)
|
||||
{
|
||||
if ($value == 1 && $pk == $user->get('id'))
|
||||
{
|
||||
// Cannot block yourself.
|
||||
unset($pks[$i]);
|
||||
JError::raiseWarning(403, JText::_('COM_USERS_USERS_ERROR_CANNOT_BLOCK_SELF'));
|
||||
|
||||
}
|
||||
elseif ($table->load($pk))
|
||||
{
|
||||
$old = $table->getProperties();
|
||||
$allow = $user->authorise('core.edit.state', 'com_users');
|
||||
// Don't allow non-super-admin to delete a super admin
|
||||
$allow = (!$iAmSuperAdmin && JAccess::check($pk, 'core.admin')) ? false : $allow;
|
||||
|
||||
// Prepare the logout options.
|
||||
$options = array(
|
||||
'clientid' => 0
|
||||
);
|
||||
|
||||
if ($allow)
|
||||
{
|
||||
// Skip changing of same state
|
||||
if ($table->block == $value)
|
||||
{
|
||||
unset($pks[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$table->block = (int) $value;
|
||||
// If unblocking, also change password reset count to zero to unblock reset
|
||||
if ($table->block === 0)
|
||||
{
|
||||
$table->resetCount = 0;
|
||||
}
|
||||
// Allow an exception to be thrown.
|
||||
try
|
||||
{
|
||||
if (!$table->check())
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Trigger the onUserBeforeSave event.
|
||||
$result = $dispatcher->trigger('onUserBeforeSave', array($old, false, $table->getProperties()));
|
||||
if (in_array(false, $result, true))
|
||||
{
|
||||
// Plugin will have to raise it's own error or throw an exception.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the table.
|
||||
if (!$table->store())
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Trigger the onAftereStoreUser event
|
||||
$dispatcher->trigger('onUserAfterSave', array($table->getProperties(), false, true, null));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->setError($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Log the user out.
|
||||
if ($value)
|
||||
{
|
||||
$app->logout($table->id, $options);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Prune items that you can't change.
|
||||
unset($pks[$i]);
|
||||
JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to activate user records.
|
||||
*
|
||||
* @param array &$pks The ids of the items to activate.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function activate(&$pks)
|
||||
{
|
||||
$dispatcher = JEventDispatcher::getInstance();
|
||||
$user = JFactory::getUser();
|
||||
|
||||
// Check if I am a Super Admin
|
||||
$iAmSuperAdmin = $user->authorise('core.admin');
|
||||
$table = $this->getTable();
|
||||
$pks = (array) $pks;
|
||||
|
||||
JPluginHelper::importPlugin('user');
|
||||
|
||||
// Access checks.
|
||||
foreach ($pks as $i => $pk)
|
||||
{
|
||||
if ($table->load($pk))
|
||||
{
|
||||
$old = $table->getProperties();
|
||||
$allow = $user->authorise('core.edit.state', 'com_users');
|
||||
// Don't allow non-super-admin to delete a super admin
|
||||
$allow = (!$iAmSuperAdmin && JAccess::check($pk, 'core.admin')) ? false : $allow;
|
||||
|
||||
if (empty($table->activation))
|
||||
{
|
||||
// Ignore activated accounts.
|
||||
unset($pks[$i]);
|
||||
}
|
||||
elseif ($allow)
|
||||
{
|
||||
$table->block = 0;
|
||||
$table->activation = '';
|
||||
|
||||
// Allow an exception to be thrown.
|
||||
try
|
||||
{
|
||||
if (!$table->check())
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Trigger the onUserBeforeSave event.
|
||||
$result = $dispatcher->trigger('onUserBeforeSave', array($old, false, $table->getProperties()));
|
||||
if (in_array(false, $result, true))
|
||||
{
|
||||
// Plugin will have to raise it's own error or throw an exception.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the table.
|
||||
if (!$table->store())
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fire the onAftereStoreUser event
|
||||
$dispatcher->trigger('onUserAfterSave', array($table->getProperties(), false, true, null));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->setError($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Prune items that you can't change.
|
||||
unset($pks[$i]);
|
||||
JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to perform batch operations on an item or a set of items.
|
||||
*
|
||||
* @param array $commands An array of commands to perform.
|
||||
* @param array $pks An array of item ids.
|
||||
* @param array $contexts An array of item contexts.
|
||||
*
|
||||
* @return boolean Returns true on success, false on failure.
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
public function batch($commands, $pks, $contexts)
|
||||
{
|
||||
// Sanitize user ids.
|
||||
$pks = array_unique($pks);
|
||||
JArrayHelper::toInteger($pks);
|
||||
|
||||
// Remove any values of zero.
|
||||
if (array_search(0, $pks, true))
|
||||
{
|
||||
unset($pks[array_search(0, $pks, true)]);
|
||||
}
|
||||
|
||||
if (empty($pks))
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_USERS_NO_ITEM_SELECTED'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$done = false;
|
||||
|
||||
if (!empty($commands['group_id']))
|
||||
{
|
||||
$cmd = JArrayHelper::getValue($commands, 'group_action', 'add');
|
||||
|
||||
if (!$this->batchUser((int) $commands['group_id'], $pks, $cmd))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$done = true;
|
||||
}
|
||||
|
||||
if (!$done)
|
||||
{
|
||||
$this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clear the cache
|
||||
$this->cleanCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform batch operations
|
||||
*
|
||||
* @param integer $group_id The group ID which assignments are being edited
|
||||
* @param array $user_ids An array of user IDs on which to operate
|
||||
* @param string $action The action to perform
|
||||
*
|
||||
* @return boolean True on success, false on failure
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function batchUser($group_id, $user_ids, $action)
|
||||
{
|
||||
// Get the DB object
|
||||
$db = $this->getDbo();
|
||||
|
||||
JArrayHelper::toInteger($user_ids);
|
||||
|
||||
// Non-super admin cannot work with super-admin group
|
||||
if ((!JFactory::getUser()->get('isRoot') && JAccess::checkGroup($group_id, 'core.admin')) || $group_id < 1)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_ERROR_INVALID_GROUP'));
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($action)
|
||||
{
|
||||
// Sets users to a selected group
|
||||
case 'set':
|
||||
$doDelete = 'all';
|
||||
$doAssign = true;
|
||||
break;
|
||||
|
||||
// Remove users from a selected group
|
||||
case 'del':
|
||||
$doDelete = 'group';
|
||||
break;
|
||||
|
||||
// Add users to a selected group
|
||||
case 'add':
|
||||
default:
|
||||
$doAssign = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// Remove the users from the group if requested.
|
||||
if (isset($doDelete))
|
||||
{
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Remove users from the group
|
||||
$query->delete($db->quoteName('#__user_usergroup_map'))
|
||||
->where($db->quoteName('user_id') . ' IN (' . implode(',', $user_ids) . ')');
|
||||
|
||||
// Only remove users from selected group
|
||||
if ($doDelete == 'group')
|
||||
{
|
||||
$query->where($db->quoteName('group_id') . ' = ' . (int) $group_id);
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$db->execute();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Assign the users to the group if requested.
|
||||
if (isset($doAssign))
|
||||
{
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// First, we need to check if the user is already assigned to a group
|
||||
$query->select($db->quoteName('user_id'))
|
||||
->from($db->quoteName('#__user_usergroup_map'))
|
||||
->where($db->quoteName('group_id') . ' = ' . (int) $group_id);
|
||||
$db->setQuery($query);
|
||||
$users = $db->loadColumn();
|
||||
|
||||
// Build the values clause for the assignment query.
|
||||
$query->clear();
|
||||
$groups = false;
|
||||
foreach ($user_ids as $id)
|
||||
{
|
||||
if (!in_array($id, $users))
|
||||
{
|
||||
$query->values($id . ',' . $group_id);
|
||||
$groups = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If we have no users to process, throw an error to notify the user
|
||||
if (!$groups)
|
||||
{
|
||||
$this->setError(JText::_('COM_USERS_ERROR_NO_ADDITIONS'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$query->insert($db->quoteName('#__user_usergroup_map'))
|
||||
->columns(array($db->quoteName('user_id'), $db->quoteName('group_id')));
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$db->execute();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the available groups.
|
||||
*
|
||||
* @return array An array of groups
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getGroups()
|
||||
{
|
||||
$user = JFactory::getUser();
|
||||
if ($user->authorise('core.edit', 'com_users') && $user->authorise('core.manage', 'com_users'))
|
||||
{
|
||||
$model = JModelLegacy::getInstance('Groups', 'UsersModel', array('ignore_request' => true));
|
||||
return $model->getItems();
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the groups this object is assigned to
|
||||
*
|
||||
* @param integer $userId The user ID to retrieve the groups for
|
||||
*
|
||||
* @return array An array of assigned groups
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getAssignedGroups($userId = null)
|
||||
{
|
||||
$userId = (!empty($userId)) ? $userId : (int) $this->getState('user.id');
|
||||
|
||||
if (empty($userId))
|
||||
{
|
||||
$result = array();
|
||||
$config = JComponentHelper::getParams('com_users');
|
||||
if ($groupId = $config->get('new_usertype'))
|
||||
{
|
||||
$result[] = $groupId;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = JUserHelper::getUserGroups($userId);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
416
administrator/components/com_users/models/users.php
Normal file
416
administrator/components/com_users/models/users.php
Normal file
@ -0,0 +1,416 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Methods supporting a list of user records.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_users
|
||||
* @since 1.6
|
||||
*/
|
||||
class UsersModelUsers extends JModelList
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
*
|
||||
* @see JController
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
if (empty($config['filter_fields']))
|
||||
{
|
||||
$config['filter_fields'] = array(
|
||||
'id', 'a.id',
|
||||
'name', 'a.name',
|
||||
'username', 'a.username',
|
||||
'email', 'a.email',
|
||||
'block', 'a.block',
|
||||
'sendEmail', 'a.sendEmail',
|
||||
'registerDate', 'a.registerDate',
|
||||
'lastvisitDate', 'a.lastvisitDate',
|
||||
'activation', 'a.activation',
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
$app = JFactory::getApplication('administrator');
|
||||
|
||||
// Adjust the context to support modal layouts.
|
||||
if ($layout = $app->input->get('layout', 'default', 'cmd'))
|
||||
{
|
||||
$this->context .= '.' . $layout;
|
||||
}
|
||||
|
||||
// Load the filter state.
|
||||
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
|
||||
$this->setState('filter.search', $search);
|
||||
|
||||
$active = $this->getUserStateFromRequest($this->context . '.filter.active', 'filter_active');
|
||||
$this->setState('filter.active', $active);
|
||||
|
||||
$state = $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state');
|
||||
$this->setState('filter.state', $state);
|
||||
|
||||
$groupId = $this->getUserStateFromRequest($this->context . '.filter.group', 'filter_group_id', null, 'int');
|
||||
$this->setState('filter.group_id', $groupId);
|
||||
|
||||
$range = $this->getUserStateFromRequest($this->context . '.filter.range', 'filter_range');
|
||||
$this->setState('filter.range', $range);
|
||||
|
||||
$groups = json_decode(base64_decode($app->input->get('groups', '', 'BASE64')));
|
||||
if (isset($groups))
|
||||
{
|
||||
JArrayHelper::toInteger($groups);
|
||||
}
|
||||
$this->setState('filter.groups', $groups);
|
||||
|
||||
$excluded = json_decode(base64_decode($app->input->get('excluded', '', 'BASE64')));
|
||||
if (isset($excluded))
|
||||
{
|
||||
JArrayHelper::toInteger($excluded);
|
||||
}
|
||||
$this->setState('filter.excluded', $excluded);
|
||||
|
||||
// Load the parameters.
|
||||
$params = JComponentHelper::getParams('com_users');
|
||||
$this->setState('params', $params);
|
||||
|
||||
// List state information.
|
||||
parent::populateState('a.name', 'asc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
*
|
||||
* @return string A store id.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= ':' . $this->getState('filter.search');
|
||||
$id .= ':' . $this->getState('filter.active');
|
||||
$id .= ':' . $this->getState('filter.state');
|
||||
$id .= ':' . $this->getState('filter.group_id');
|
||||
$id .= ':' . $this->getState('filter.range');
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of users and adds expensive joins to the result set.
|
||||
*
|
||||
* @return mixed An array of data items on success, false on failure.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
// Get a storage key.
|
||||
$store = $this->getStoreId();
|
||||
|
||||
// Try to load the data from internal storage.
|
||||
if (empty($this->cache[$store]))
|
||||
{
|
||||
$groups = $this->getState('filter.groups');
|
||||
$groupId = $this->getState('filter.group_id');
|
||||
if (isset($groups) && (empty($groups) || $groupId && !in_array($groupId, $groups)))
|
||||
{
|
||||
$items = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
$items = parent::getItems();
|
||||
}
|
||||
|
||||
// Bail out on an error or empty list.
|
||||
if (empty($items))
|
||||
{
|
||||
$this->cache[$store] = $items;
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
// Joining the groups with the main query is a performance hog.
|
||||
// Find the information only on the result set.
|
||||
|
||||
// First pass: get list of the user id's and reset the counts.
|
||||
$userIds = array();
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$userIds[] = (int) $item->id;
|
||||
$item->group_count = 0;
|
||||
$item->group_names = '';
|
||||
$item->note_count = 0;
|
||||
}
|
||||
|
||||
// Get the counts from the database only for the users in the list.
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Join over the group mapping table.
|
||||
$query->select('map.user_id, COUNT(map.group_id) AS group_count')
|
||||
->from('#__user_usergroup_map AS map')
|
||||
->where('map.user_id IN (' . implode(',', $userIds) . ')')
|
||||
->group('map.user_id')
|
||||
// Join over the user groups table.
|
||||
->join('LEFT', '#__usergroups AS g2 ON g2.id = map.group_id');
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
// Load the counts into an array indexed on the user id field.
|
||||
try
|
||||
{
|
||||
$userGroups = $db->loadObjectList('user_id');
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
$query->clear()
|
||||
->select('n.user_id, COUNT(n.id) As note_count')
|
||||
->from('#__user_notes AS n')
|
||||
->where('n.user_id IN (' . implode(',', $userIds) . ')')
|
||||
->where('n.state >= 0')
|
||||
->group('n.user_id');
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
// Load the counts into an array indexed on the aro.value field (the user id).
|
||||
try
|
||||
{
|
||||
$userNotes = $db->loadObjectList('user_id');
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Second pass: collect the group counts into the master items array.
|
||||
foreach ($items as &$item)
|
||||
{
|
||||
if (isset($userGroups[$item->id]))
|
||||
{
|
||||
$item->group_count = $userGroups[$item->id]->group_count;
|
||||
//Group_concat in other databases is not supported
|
||||
$item->group_names = $this->_getUserDisplayedGroups($item->id);
|
||||
}
|
||||
|
||||
if (isset($userNotes[$item->id]))
|
||||
{
|
||||
$item->note_count = $userNotes[$item->id]->note_count;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the items to the internal cache.
|
||||
$this->cache[$store] = $items;
|
||||
}
|
||||
|
||||
return $this->cache[$store];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an SQL query to load the list data.
|
||||
*
|
||||
* @return JDatabaseQuery
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
// Create a new query object.
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Select the required fields from the table.
|
||||
$query->select(
|
||||
$this->getState(
|
||||
'list.select',
|
||||
'a.*'
|
||||
)
|
||||
);
|
||||
|
||||
$query->from($db->quoteName('#__users') . ' AS a');
|
||||
|
||||
// If the model is set to check item state, add to the query.
|
||||
$state = $this->getState('filter.state');
|
||||
|
||||
if (is_numeric($state))
|
||||
{
|
||||
$query->where('a.block = ' . (int) $state);
|
||||
}
|
||||
|
||||
// If the model is set to check the activated state, add to the query.
|
||||
$active = $this->getState('filter.active');
|
||||
|
||||
if (is_numeric($active))
|
||||
{
|
||||
if ($active == '0')
|
||||
{
|
||||
$query->where('a.activation = ' . $db->quote(''));
|
||||
}
|
||||
elseif ($active == '1')
|
||||
{
|
||||
$query->where($query->length('a.activation') . ' = 32');
|
||||
}
|
||||
}
|
||||
|
||||
// Filter the items over the group id if set.
|
||||
$groupId = $this->getState('filter.group_id');
|
||||
$groups = $this->getState('filter.groups');
|
||||
|
||||
if ($groupId || isset($groups))
|
||||
{
|
||||
$query->join('LEFT', '#__user_usergroup_map AS map2 ON map2.user_id = a.id')
|
||||
->group($db->quoteName(array('a.id', 'a.name', 'a.username', 'a.password', 'a.block', 'a.sendEmail', 'a.registerDate', 'a.lastvisitDate', 'a.activation', 'a.params', 'a.email')));
|
||||
|
||||
if ($groupId)
|
||||
{
|
||||
$query->where('map2.group_id = ' . (int) $groupId);
|
||||
}
|
||||
|
||||
if (isset($groups))
|
||||
{
|
||||
$query->where('map2.group_id IN (' . implode(',', $groups) . ')');
|
||||
}
|
||||
}
|
||||
|
||||
// Filter the items over the search string if set.
|
||||
if ($this->getState('filter.search') !== '' && $this->getState('filter.search') !== null)
|
||||
{
|
||||
// Escape the search token.
|
||||
$token = $db->quote('%' . $db->escape($this->getState('filter.search')) . '%');
|
||||
|
||||
// Compile the different search clauses.
|
||||
$searches = array();
|
||||
$searches[] = 'a.name LIKE ' . $token;
|
||||
$searches[] = 'a.username LIKE ' . $token;
|
||||
$searches[] = 'a.email LIKE ' . $token;
|
||||
|
||||
// Add the clauses to the query.
|
||||
$query->where('(' . implode(' OR ', $searches) . ')');
|
||||
}
|
||||
|
||||
// Add filter for registration ranges select list
|
||||
$range = $this->getState('filter.range');
|
||||
|
||||
// Apply the range filter.
|
||||
if ($range)
|
||||
{
|
||||
// Get UTC for now.
|
||||
$dNow = new JDate;
|
||||
$dStart = clone $dNow;
|
||||
|
||||
switch ($range)
|
||||
{
|
||||
case 'past_week':
|
||||
$dStart->modify('-7 day');
|
||||
break;
|
||||
|
||||
case 'past_1month':
|
||||
$dStart->modify('-1 month');
|
||||
break;
|
||||
|
||||
case 'past_3month':
|
||||
$dStart->modify('-3 month');
|
||||
break;
|
||||
|
||||
case 'past_6month':
|
||||
$dStart->modify('-6 month');
|
||||
break;
|
||||
|
||||
case 'post_year':
|
||||
case 'past_year':
|
||||
$dStart->modify('-1 year');
|
||||
break;
|
||||
|
||||
case 'today':
|
||||
// Ranges that need to align with local 'days' need special treatment.
|
||||
$app = JFactory::getApplication();
|
||||
$offset = $app->getCfg('offset');
|
||||
|
||||
// Reset the start time to be the beginning of today, local time.
|
||||
$dStart = new JDate('now', $offset);
|
||||
$dStart->setTime(0, 0, 0);
|
||||
|
||||
// Now change the timezone back to UTC.
|
||||
$tz = new DateTimeZone('GMT');
|
||||
$dStart->setTimezone($tz);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($range == 'post_year')
|
||||
{
|
||||
$query->where(
|
||||
'a.registerDate < ' . $db->quote($dStart->format('Y-m-d H:i:s'))
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->where(
|
||||
'a.registerDate >= ' . $db->quote($dStart->format('Y-m-d H:i:s')) .
|
||||
' AND a.registerDate <=' . $db->quote($dNow->format('Y-m-d H:i:s'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by excluded users
|
||||
$excluded = $this->getState('filter.excluded');
|
||||
if (!empty($excluded))
|
||||
{
|
||||
$query->where('id NOT IN (' . implode(',', $excluded) . ')');
|
||||
}
|
||||
|
||||
// Add the list ordering clause.
|
||||
$query->order($db->escape($this->getState('list.ordering', 'a.name')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
//sqlsrv change
|
||||
function _getUserDisplayedGroups($user_id)
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$query = "SELECT title FROM " . $db->quoteName('#__usergroups') . " ug left join " .
|
||||
$db->quoteName('#__user_usergroup_map') . " map on (ug.id = map.group_id)" .
|
||||
" WHERE map.user_id=" . $user_id;
|
||||
|
||||
$db->setQuery($query);
|
||||
$result = $db->loadColumn();
|
||||
return implode("\n", $result);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user