Commit e03c74cb authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

First cut at SuspendedUsers

parent eacbb492
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$dbprefix = get_config('dbprefix');
// NOTE: the check is not done on the 'active' column here, since suspended
// users are by definition not active. However deleted users are filtered out.
$count = get_field_sql('SELECT COUNT(*) FROM usr WHERE suspendedcusr IS NOT NULL AND deleted = 0');
$data = get_records_sql_array('SELECT u.id, u.firstname, u.lastname, u.studentid, u.suspendedreason AS reason,
i.displayname AS institution, ua.firstname AS cusrfirstname, ua.lastname AS cusrlastname
FROM ' . $dbprefix . 'usr u
LEFT JOIN ' . $dbprefix . 'institution i ON (u.institution = i.name)
LEFT JOIN usr ua on (ua.id = u.suspendedcusr)
WHERE u.suspendedcusr IS NOT NULL
AND u.deleted = 0
ORDER BY u.suspendedctime
LIMIT ?
OFFSET ?', array($limit, $offset));
if (!$data) {
$data = array();
}
else {
foreach ($data as &$record) {
$record->name = full_name($record);
$record->firstname = $record->cusrfirstname;
$record->lastname = $record->cusrlastname;
$record->cusrname = full_name($record);
unset($record->firstname, $record->lastname);
}
}
echo json_encode(array(
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'data' => $data
));
?>
......@@ -29,8 +29,100 @@ define('ADMIN', 1);
define('MENUITEM', 'configusers');
define('SUBMENUITEM', 'suspendedusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
$smarty = smarty(array('tablerenderer'));
$smarty->assign('INLINEJAVASCRIPT', <<<EOF
var suspendedlist = new TableRenderer(
'suspendedlist',
'suspended.json.php',
[
'name',
'studentid',
'institution',
'cusrname',
'reason',
function (rowdata) { return INPUT({'type': 'checkbox', 'name': 'usr_' + rowdata.id}); }
]
);
suspendedlist.updateOnLoad();
EOF
);
$form = new Pieform(array(
'name' => 'buttons',
'renderer' => 'oneline',
'elements' => array(
'unsuspend' => array(
'type' => 'submit',
'name' => 'unsuspend',
'value' => get_string('unsuspendusers')
),
'export' => array(
'type' => 'submit',
'name' => 'export',
'value' => get_string('exportuserprofiles')
),
'delete' => array(
'type' => 'submit',
'name' => 'delete',
'value' => get_string('deleteusers')
)
)
));
$smarty->assign('buttonformopen', $form->get_form_tag());
$smarty->assign('buttonform', $form->build(false));
$smarty = smarty();
$smarty->display('admin/users/suspended.tpl');
function buttons_submit_unsuspend($values) {
global $SESSION;
$ids = get_user_ids_from_post();
foreach ($ids as $userid) {
unsuspend_user($userid);
}
$SESSION->add_ok_msg(get_string('usersunsuspendedsuccessfully'));
redirect(get_config('wwwroot') . 'admin/users/suspended.php');
}
function buttons_submit_export($values) {
global $SESSION;
$ids = get_user_ids_from_post();
$SESSION->add_info_msg(get_string('exportingnotsupportedyet'));
redirect(get_config('wwwroot') . 'admin/users/suspended.php');
}
function buttons_submit_delete($values) {
global $SESSION;
$ids = get_user_ids_from_post();
foreach ($ids as $userid) {
delete_user($userid);
}
$SESSION->add_ok_msg(get_string('usersdeletedsuccessfully'));
redirect(get_config('wwwroot') . 'admin/users/suspended.php');
}
function get_user_ids_from_post() {
$ids = array();
foreach ($_POST as $key => $value) {
if (substr($key, 0, 4) == 'usr_') {
$ids[] = intval(substr($key, 4));
}
}
if (!$ids) {
global $SESSION;
$SESSION->add_info_msg(get_string('nousersselected'));
redirect(get_config('wwwroot') . 'admin/users/suspended.php');
}
return $ids;
}
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment