PageRenderTime 60ms CodeModel.GetById 36ms RepoModel.GetById 1ms app.codeStats 0ms

/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
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. */
  7. // No direct access.
  8. defined('_JEXEC') or die;
  9. jimport('joomla.application.component.controller');
  10. /**
  11. * Users list controller class.
  12. *
  13. * @package Joomla.Administrator
  14. * @subpackage com_users
  15. * @since 1.6
  16. */
  17. class UsersControllerUsers extends JController
  18. {
  19. /**
  20. * Constructor.
  21. *
  22. * @param array An optional associative array of configuration settings.
  23. * @see JController
  24. */
  25. public function __construct($config = array())
  26. {
  27. parent::__construct($config);
  28. $this->registerTask('block', 'changeBlock');
  29. $this->registerTask('unblock', 'changeBlock');
  30. }
  31. /**
  32. * Display is not supported by this class.
  33. */
  34. public function display()
  35. {
  36. }
  37. /**
  38. * Proxy for getModel.
  39. */
  40. public function &getModel($name = 'User', $prefix = 'UsersModel')
  41. {
  42. $model = parent::getModel($name, $prefix, array('ignore_request' => true));
  43. return $model;
  44. }
  45. /**
  46. * Method to remove a record.
  47. */
  48. public function delete()
  49. {
  50. // Check for request forgeries.
  51. JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
  52. // Initialise variables.
  53. $user = JFactory::getUser();
  54. $ids = JRequest::getVar('cid', array(), '', 'array');
  55. if (empty($ids)) {
  56. JError::raiseWarning(500, JText::_('JError_No_items_selected'));
  57. }
  58. else {
  59. // Get the model.
  60. $model = $this->getModel();
  61. // Remove the items.
  62. if (!$model->delete($ids)) {
  63. JError::raiseWarning(500, $model->getError());
  64. }
  65. else {
  66. $this->setMessage(JText::sprintf('JController_N_Items_deleted', count($ids)));
  67. }
  68. }
  69. $this->setRedirect('index.php?option=com_users&view=users');
  70. }
  71. /**
  72. * Method to remove a record.
  73. */
  74. public function changeBlock()
  75. {
  76. // Check for request forgeries.
  77. JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
  78. // Initialise variables.
  79. $ids = JRequest::getVar('cid', array(), '', 'array');
  80. $values = array('block' => 1, 'unblock' => 0);
  81. $task = $this->getTask();
  82. $value = JArrayHelper::getValue($values, $task, 0, 'int');
  83. if (empty($ids)) {
  84. JError::raiseWarning(500, JText::_('JError_No_items_selected'));
  85. }
  86. else
  87. {
  88. // Get the model.
  89. $model = $this->getModel();
  90. // Change the state of the records.
  91. if (!$model->block($ids, $value)) {
  92. JError::raiseWarning(500, $model->getError());
  93. }
  94. else
  95. {
  96. if ($value == 1) {
  97. $text = 'Users_N_Users_Blocked';
  98. }
  99. else {
  100. $text = 'Users_N_Users_UnBlocked';
  101. }
  102. $this->setMessage(JText::sprintf($text, count($ids)));
  103. }
  104. }
  105. $this->setRedirect('index.php?option=com_users&view=users');
  106. }
  107. /**
  108. * Method to remove a record.
  109. */
  110. public function activate()
  111. {
  112. // Check for request forgeries.
  113. JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
  114. // Initialise variables.
  115. $ids = JRequest::getVar('cid', array(), '', 'array');
  116. if (empty($ids)) {
  117. JError::raiseWarning(500, JText::_('JError_No_items_selected'));
  118. }
  119. else
  120. {
  121. // Get the model.
  122. $model = $this->getModel();
  123. // Change the state of the records.
  124. if (!$model->activate($ids)) {
  125. JError::raiseWarning(500, $model->getError());
  126. }
  127. else
  128. {
  129. $this->setMessage(JText::sprintf('Users_N_Users_Activated', count($ids)));
  130. }
  131. }
  132. $this->setRedirect('index.php?option=com_users&view=users');
  133. }
  134. /**
  135. * Method to run batch opterations.
  136. *
  137. * @return void
  138. */
  139. function batch()
  140. {
  141. // Check for request forgeries.
  142. JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
  143. // Initialise variables.
  144. $app = JFactory::getApplication();
  145. $model = &$this->getModel('User');
  146. $vars = JRequest::getVar('batch', array(), 'post', 'array');
  147. $cid = JRequest::getVar('cid', array(), 'post', 'array');
  148. // Sanitize user ids.
  149. $cid = array_unique($cid);
  150. JArrayHelper::toInteger($cid);
  151. // Remove any values of zero.
  152. if (array_search(0, $cid, true)) {
  153. unset($cid[array_search(0, $cid, true)]);
  154. }
  155. // Attempt to run the batch operation.
  156. if (!$model->batch($vars, $cid))
  157. {
  158. // Batch operation failed, go back to the users list and display a notice.
  159. $message = JText::sprintf('USERS_USER_BATCH_FAILED', $model->getError());
  160. $this->setRedirect('index.php?option=com_users&view=users', $message, 'error');
  161. return false;
  162. }
  163. $message = JText::_('USERS_USER_BATCH_SUCCESS');
  164. $this->setRedirect('index.php?option=com_users&view=users', $message);
  165. return true;
  166. }
  167. }