/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

  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. defined('_JEXEC') or die;
  10. /**
  11. * Users list controller class.
  12. *
  13. * @package Joomla.Administrator
  14. * @subpackage com_users
  15. * @since 1.6
  16. */
  17. class UsersControllerUsers extends JControllerAdmin
  18. {
  19. /**
  20. * @var string The prefix to use with controller messages.
  21. * @since 1.6
  22. */
  23. protected $text_prefix = 'COM_USERS_USERS';
  24. /**
  25. * Constructor.
  26. *
  27. * @param array $config An optional associative array of configuration settings.
  28. *
  29. * @return UsersControllerUsers
  30. *
  31. * @since 1.6
  32. * @see JController
  33. */
  34. public function __construct($config = array())
  35. {
  36. parent::__construct($config);
  37. $this->registerTask('block', 'changeBlock');
  38. $this->registerTask('unblock', 'changeBlock');
  39. }
  40. /**
  41. * Proxy for getModel.
  42. *
  43. * @param string $name The model name. Optional.
  44. * @param string $prefix The class prefix. Optional.
  45. * @param array $config Configuration array for model. Optional.
  46. *
  47. * @return object The model.
  48. *
  49. * @since 1.6
  50. */
  51. public function getModel($name = 'User', $prefix = 'UsersModel', $config = array('ignore_request' => true))
  52. {
  53. return parent::getModel($name, $prefix, $config);
  54. }
  55. /**
  56. * Method to change the block status on a record.
  57. *
  58. * @return void
  59. *
  60. * @since 1.6
  61. */
  62. public function changeBlock()
  63. {
  64. // Check for request forgeries.
  65. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  66. $ids = $this->input->get('cid', array(), 'array');
  67. $values = array('block' => 1, 'unblock' => 0);
  68. $task = $this->getTask();
  69. $value = JArrayHelper::getValue($values, $task, 0, 'int');
  70. if (empty($ids))
  71. {
  72. JError::raiseWarning(500, JText::_('COM_USERS_USERS_NO_ITEM_SELECTED'));
  73. }
  74. else
  75. {
  76. // Get the model.
  77. $model = $this->getModel();
  78. // Change the state of the records.
  79. if (!$model->block($ids, $value))
  80. {
  81. JError::raiseWarning(500, $model->getError());
  82. }
  83. else
  84. {
  85. if ($value == 1)
  86. {
  87. $this->setMessage(JText::plural('COM_USERS_N_USERS_BLOCKED', count($ids)));
  88. }
  89. elseif ($value == 0)
  90. {
  91. $this->setMessage(JText::plural('COM_USERS_N_USERS_UNBLOCKED', count($ids)));
  92. }
  93. }
  94. }
  95. $this->setRedirect('index.php?option=com_users&view=users');
  96. }
  97. /**
  98. * Method to activate a record.
  99. *
  100. * @return void
  101. *
  102. * @since 1.6
  103. */
  104. public function activate()
  105. {
  106. // Check for request forgeries.
  107. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  108. $ids = $this->input->get('cid', array(), 'array');
  109. if (empty($ids))
  110. {
  111. JError::raiseWarning(500, JText::_('COM_USERS_USERS_NO_ITEM_SELECTED'));
  112. }
  113. else
  114. {
  115. // Get the model.
  116. $model = $this->getModel();
  117. // Change the state of the records.
  118. if (!$model->activate($ids))
  119. {
  120. JError::raiseWarning(500, $model->getError());
  121. }
  122. else
  123. {
  124. $this->setMessage(JText::plural('COM_USERS_N_USERS_ACTIVATED', count($ids)));
  125. }
  126. }
  127. $this->setRedirect('index.php?option=com_users&view=users');
  128. }
  129. }