/**
* Enable/Disable an existing user
* @param $args array
* @param $request PKPRequest
* @return string Serialized JSON object
*/
function disableUser($args, &$request)
{
// Identify the press
$press =& $request->getPress();
// Identify the user Id
$userId = $request->getUserVar('userId');
// Are we enabling or disabling this user
$enable = (bool) $request->getUserVar('enable');
if ($userId !== null && !Validation::canAdminister($press->getId(), $userId)) {
// We don't have administrative rights over this user.
$json = new JSON('false', Locale::translate('grid.user.cannotAdminister'));
} else {
// Form handling
import('controllers.grid.users.user.form.UserDisableForm');
$userForm = new UserDisableForm($userId, $enable);
$userForm->readInputData();
if ($userForm->validate()) {
$user =& $userForm->execute($args, $request);
// Successful enable/disable of an existing user
// Update grid row data
$row =& $this->getRowInstance();
$row->setGridId($this->getId());
$row->setId($user->getId());
$row->setData($user);
$row->initialize($request);
$json = new JSON('true', $this->_renderRowInternally($request, $row));
} else {
$json = new JSON('false', $userForm->display($args, $request));
}
}
return $json->getString();
}