/administrator/components/com_users/controllers/users.php
https://github.com/joebushi/joomla · PHP · 194 lines · 110 code · 27 blank · 57 comment · 13 complexity · c43d0fd4d82bb1ed6d3b77eab4e10ab4 MD5 · raw file
- <?php
- /**
- * @version $Id$
- * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
- * @license GNU General Public License version 2 or later; see LICENSE.txt
- */
- // No direct access.
- defined('_JEXEC') or die;
- jimport('joomla.application.component.controller');
- /**
- * Users list controller class.
- *
- * @package Joomla.Administrator
- * @subpackage com_users
- * @since 1.6
- */
- class UsersControllerUsers extends JController
- {
- /**
- * Constructor.
- *
- * @param array An optional associative array of configuration settings.
- * @see JController
- */
- public function __construct($config = array())
- {
- parent::__construct($config);
- $this->registerTask('block', 'changeBlock');
- $this->registerTask('unblock', 'changeBlock');
- }
- /**
- * Display is not supported by this class.
- */
- public function display()
- {
- }
- /**
- * Proxy for getModel.
- */
- public function &getModel($name = 'User', $prefix = 'UsersModel')
- {
- $model = parent::getModel($name, $prefix, array('ignore_request' => true));
- return $model;
- }
- /**
- * Method to remove a record.
- */
- public function delete()
- {
- // Check for request forgeries.
- JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
- // Initialise variables.
- $user = JFactory::getUser();
- $ids = JRequest::getVar('cid', array(), '', 'array');
- if (empty($ids)) {
- JError::raiseWarning(500, JText::_('JError_No_items_selected'));
- }
- else {
- // Get the model.
- $model = $this->getModel();
- // Remove the items.
- if (!$model->delete($ids)) {
- JError::raiseWarning(500, $model->getError());
- }
- else {
- $this->setMessage(JText::sprintf('JController_N_Items_deleted', count($ids)));
- }
- }
- $this->setRedirect('index.php?option=com_users&view=users');
- }
- /**
- * Method to remove a record.
- */
- public function changeBlock()
- {
- // Check for request forgeries.
- JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
- // Initialise variables.
- $ids = JRequest::getVar('cid', array(), '', 'array');
- $values = array('block' => 1, 'unblock' => 0);
- $task = $this->getTask();
- $value = JArrayHelper::getValue($values, $task, 0, 'int');
- if (empty($ids)) {
- JError::raiseWarning(500, JText::_('JError_No_items_selected'));
- }
- else
- {
- // Get the model.
- $model = $this->getModel();
- // Change the state of the records.
- if (!$model->block($ids, $value)) {
- JError::raiseWarning(500, $model->getError());
- }
- else
- {
- if ($value == 1) {
- $text = 'Users_N_Users_Blocked';
- }
- else {
- $text = 'Users_N_Users_UnBlocked';
- }
- $this->setMessage(JText::sprintf($text, count($ids)));
- }
- }
- $this->setRedirect('index.php?option=com_users&view=users');
- }
- /**
- * Method to remove a record.
- */
- public function activate()
- {
- // Check for request forgeries.
- JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
- // Initialise variables.
- $ids = JRequest::getVar('cid', array(), '', 'array');
- if (empty($ids)) {
- JError::raiseWarning(500, JText::_('JError_No_items_selected'));
- }
- else
- {
- // Get the model.
- $model = $this->getModel();
- // Change the state of the records.
- if (!$model->activate($ids)) {
- JError::raiseWarning(500, $model->getError());
- }
- else
- {
- $this->setMessage(JText::sprintf('Users_N_Users_Activated', count($ids)));
- }
- }
- $this->setRedirect('index.php?option=com_users&view=users');
- }
- /**
- * Method to run batch opterations.
- *
- * @return void
- */
- function batch()
- {
- // Check for request forgeries.
- JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
- // Initialise variables.
- $app = JFactory::getApplication();
- $model = &$this->getModel('User');
- $vars = JRequest::getVar('batch', array(), 'post', 'array');
- $cid = JRequest::getVar('cid', array(), 'post', 'array');
- // Sanitize user ids.
- $cid = array_unique($cid);
- JArrayHelper::toInteger($cid);
- // Remove any values of zero.
- if (array_search(0, $cid, true)) {
- unset($cid[array_search(0, $cid, true)]);
- }
- // Attempt to run the batch operation.
- if (!$model->batch($vars, $cid))
- {
- // Batch operation failed, go back to the users list and display a notice.
- $message = JText::sprintf('USERS_USER_BATCH_FAILED', $model->getError());
- $this->setRedirect('index.php?option=com_users&view=users', $message, 'error');
- return false;
- }
- $message = JText::_('USERS_USER_BATCH_SUCCESS');
- $this->setRedirect('index.php?option=com_users&view=users', $message);
- return true;
- }
- }