PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_users/controllers/users.php

https://bitbucket.org/eternaware/joomus
PHP | 144 lines | 70 code | 15 blank | 59 comment | 7 complexity | 914d95ea29dd7044f0621f25cf471c21 MD5 | raw file
Possible License(s): LGPL-2.1
  1<?php
  2/**
  3 * @package     Joomla.Administrator
  4 * @subpackage  com_users
  5 *
  6 * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7 * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8 */
  9
 10defined('_JEXEC') or die;
 11
 12/**
 13 * Users list controller class.
 14 *
 15 * @package     Joomla.Administrator
 16 * @subpackage  com_users
 17 * @since       1.6
 18 */
 19class UsersControllerUsers extends JControllerAdmin
 20{
 21	/**
 22	 * @var    string  The prefix to use with controller messages.
 23	 * @since  1.6
 24	 */
 25	protected $text_prefix = 'COM_USERS_USERS';
 26
 27	/**
 28	 * Constructor.
 29	 *
 30	 * @param   array  $config  An optional associative array of configuration settings.
 31	 *
 32	 * @return  UsersControllerUsers
 33	 *
 34	 * @since   1.6
 35	 * @see     JController
 36	 */
 37	public function __construct($config = array())
 38	{
 39		parent::__construct($config);
 40
 41		$this->registerTask('block', 'changeBlock');
 42		$this->registerTask('unblock', 'changeBlock');
 43	}
 44
 45	/**
 46	 * Proxy for getModel.
 47	 *
 48	 * @param   string  $name    The model name. Optional.
 49	 * @param   string  $prefix  The class prefix. Optional.
 50	 * @param   array   $config  Configuration array for model. Optional.
 51	 *
 52	 * @return  object  The model.
 53	 *
 54	 * @since	1.6
 55	 */
 56	public function getModel($name = 'User', $prefix = 'UsersModel', $config = array('ignore_request' => true))
 57	{
 58		return parent::getModel($name, $prefix, $config);
 59	}
 60
 61	/**
 62	 * Method to change the block status on a record.
 63	 *
 64	 * @return  void
 65	 *
 66	 * @since   1.6
 67	 */
 68	public function changeBlock()
 69	{
 70		// Check for request forgeries.
 71		JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
 72
 73		$ids    = $this->input->get('cid', array(), 'array');
 74		$values = array('block' => 1, 'unblock' => 0);
 75		$task   = $this->getTask();
 76		$value  = JArrayHelper::getValue($values, $task, 0, 'int');
 77
 78		if (empty($ids))
 79		{
 80			JError::raiseWarning(500, JText::_('COM_USERS_USERS_NO_ITEM_SELECTED'));
 81		}
 82		else
 83		{
 84			// Get the model.
 85			$model = $this->getModel();
 86
 87			// Change the state of the records.
 88			if (!$model->block($ids, $value))
 89			{
 90				JError::raiseWarning(500, $model->getError());
 91			}
 92			else
 93			{
 94				if ($value == 1)
 95				{
 96					$this->setMessage(JText::plural('COM_USERS_N_USERS_BLOCKED', count($ids)));
 97				}
 98				elseif ($value == 0)
 99				{
100					$this->setMessage(JText::plural('COM_USERS_N_USERS_UNBLOCKED', count($ids)));
101				}
102			}
103		}
104
105		$this->setRedirect('index.php?option=com_users&view=users');
106	}
107
108	/**
109	 * Method to activate a record.
110	 *
111	 * @return  void
112	 *
113	 * @since   1.6
114	 */
115	public function activate()
116	{
117		// Check for request forgeries.
118		JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
119
120		$ids = $this->input->get('cid', array(), 'array');
121
122		if (empty($ids))
123		{
124			JError::raiseWarning(500, JText::_('COM_USERS_USERS_NO_ITEM_SELECTED'));
125		}
126		else
127		{
128			// Get the model.
129			$model = $this->getModel();
130
131			// Change the state of the records.
132			if (!$model->activate($ids))
133			{
134				JError::raiseWarning(500, $model->getError());
135			}
136			else
137			{
138				$this->setMessage(JText::plural('COM_USERS_N_USERS_ACTIVATED', count($ids)));
139			}
140		}
141
142		$this->setRedirect('index.php?option=com_users&view=users');
143	}
144}