Commit 7ff30f84 authored by Josh Schmidt's avatar Josh Schmidt Committed by Richard Mansfield
Browse files

Added feature to allow site admins to manage group admins + delete groups

parent 370f3af6
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2010 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2010 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'groupsearch');
//define('TITLE', 'Delete Group');
define('MENUITEM', 'managegroups/groups');
require_once('pieforms/pieform.php');
if (!$USER->get('admin')) {
//User not an admin, redirect away
redirect(get_config('wwwroot'));
}
$groupid = param_integer('id');
$exists = record_exists('group', 'id', $groupid);
if (!$exists) {
//Group doesn't exist
redirect(get_config('wwwroot').'admin/groups/group.php');
}
$group = get_record_sql("SELECT g.name FROM {group} g WHERE g.id = ? AND g.deleted = 0", array($groupid));
define('TITLE', get_string('deletespecifiedgroup', 'group', $group->name));
$views = count_records_sql(
'SELECT COUNT(*)
FROM {view_access_group} a
WHERE a.group = ?',
array($groupid)
);
$form = pieform(array(
'name' => 'admindeletegroup',
'renderer' => 'div',
'autofocus' => false,
'method' => 'post',
'elements' => array(
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no')),
//'goto' => get_config('wwwroot') . 'group/view.php?id=' . $groupid
)
),
));
$smarty = smarty();
$smarty->assign('subheading', hsc(TITLE));
$smarty->assign('message', $views ? get_string('groupconfirmdeletehasviews', 'group') : get_string('groupconfirmdelete', 'group'));
$smarty->assign('form', $form);
$smarty->display('group/delete.tpl');
function admindeletegroup_submit(Pieform $form, $values) {
global $SESSION, $groupid;
require_once('../../lib/group.php');
group_delete($groupid);
$SESSION->add_ok_msg(get_string('deletegroup', 'group'));
redirect(get_config('wwwroot').'admin/groups/groups.php');
}
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2010 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2010 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'groups');
define('TITLE', 'Groups');
define('MENUITEM', 'managegroups/groups');
if (!$USER->get('admin')) {
//User not an admin, redirect away
redirect(get_config('wwwroot'));
}
$groups = get_records_sql_array(
"SELECT g.id,g.name,g.grouptype,g.jointype,g.public AS visible,
(SELECT COUNT(*) FROM {group_member} gm WHERE gm.group=g.id) AS members,
(SELECT COUNT(*) FROM {group_member} gm WHERE gm.group=g.id AND gm.role='admin') AS admins
FROM {group} g WHERE g.deleted = 0 ORDER BY g.id DESC", array()
);
foreach ($groups as &$group) {
$group->type = get_string('grouptypedescription', 'group', get_string('name', 'grouptype.' . $group->grouptype), get_string('membershiptype.'.$group->jointype, 'group'));
//$group->type = "$group->grouptype > $group->jointype";
$group->visible = $group->visible ? 'Public' : 'Private';
}
$smarty = smarty();
$smarty->assign('groups', $groups);
$smarty->assign('PAGEHEADING', hsc('Administer Groups'));
$smarty->assign('siteadmin', true);
$smarty->display('admin/groups/groups.tpl');
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2010 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage admin
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2010 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'groupsearch');
define('MENUITEM', 'managegroups/groups');
require_once('pieforms/pieform.php');
if (!$USER->get('admin')) {
//User not an admin, redirect away
redirect(get_config('wwwroot'));
}
$id = param_integer('id');
$exists = record_exists('group', 'id', $id);
if (!$exists) {
//Group doesn't exist
redirect(get_config('wwwroot').'admin/groups/group.php');
}
$group = get_record_sql("SELECT g.name FROM {group} g WHERE g.id = ?", array($id));
define('TITLE', "Manage group '$group->name'");
$admins = get_records_sql_array(
"SELECT gm.member FROM {group_member} gm WHERE gm.role = 'admin' AND gm.group = ?", array($id)
);
foreach ($admins as $admin) {
$group_admins[] = $admin->member;
}
$subscribeform = array(
'name' => 'groupadminsform',
'renderer' => 'table',
'plugintype' => 'core',
'pluginname' => 'admin',
'jssuccesscallback' => 'checkReload',
'elements' => array(
'admins' => array(
'type' => 'userlist',
'title' => 'Group Admins',
'description' => 'Manage the admins for this group',
'defaultvalue' => $group_admins,
'group' => $id,
'includeadmins' => true,
'filter' => false,
'lefttitle' => 'Members',
'righttitle' => 'Admins',
),
'group' => array(
'type' => 'hidden',
'value' => $id,
),
'submit' => array(
'type' => 'submit',
'value' => 'Save',
),
),
);
$subscribeform = pieform($subscribeform);
function groupadminsform_submit(Pieform $form, $values) {
global $SESSION;
$gid = $values['group'];
$old_admins = array();
$results = get_records_sql_array(
"SELECT gm.member FROM {group_member} gm WHERE gm.role = 'admin' AND gm.group = ?", array($gid)
);
foreach ($results as $row) {
$old_admins[] = $row->member;
}
db_begin;
if (!empty($values['admins'])) {
foreach ($values['admins'] as $uid) {
if (!in_array($uid, $old_admins)) {
//An admin has been added
set_field('group_member', 'role', 'admin', 'group', $gid, 'member', $uid);
}
}
}
foreach ($old_admins as $uid) {
if (!in_array($uid, $values['admins'])) {
//An admin has been removed
set_field('group_member', 'role', 'member', 'group', $gid, 'member', $uid);
}
}
db_commit();
$SESSION->add_ok_msg("Group admins have been updated");
redirect(get_config('wwwroot').'admin/groups/groups.php');
}
$smarty = smarty();
$smarty->assign('PAGEHEADING', hsc(TITLE));
$smarty->assign('managegroupform', $subscribeform);
$smarty->display('admin/groups/manage.tpl');
?>
......@@ -675,4 +675,13 @@ $string['accountsettingslegend'] = 'Account Settings';
$string['securitysettingslegend'] = 'Security Settings';
$string['generalsettingslegend'] = 'General Settings';
$string['groupname'] = 'Group Name';
$string['groupmembers'] = 'Members';
$string['groupadmins'] = 'Admins';
$string['grouptype'] = 'Group Type';
$string['groupvisible'] = 'Visibility';
$string['groupmanage'] = 'Manage';
$string['groupdelete'] = 'Delete';
$string['managegroupdescription'] = 'Use the below form to promote and demote admins for this group.';
?>
......@@ -1759,6 +1759,18 @@ function admin_nav() {
'title' => get_string('Files', 'artefact.file'),
'weight' => 60,
),
array(
'path' => 'managegroups',
'url' => 'admin/groups/groups.php',
'title' => 'Manage Groups',
'weight' => 35,
),
array(
'path' => 'managegroups/groups',
'url' => 'admin/groups/groups.php',
'title' => 'Administer Groups',
'weight' => 10,
),
array(
'path' => 'configextensions',
'url' => 'admin/extensions/plugins.php',
......
{auto_escape off}
{include file="header.tpl"}
<table id="adminstitutionslist" class="fullwidth">
<thead>
<tr>
<th>{str tag="groupname" section="admin"}</th>
<th class="center">{str tag="groupmembers" section="admin"}</th>
<th class="center">{str tag="groupadmins" section="admin"}</th>
<th class="center">{str tag="grouptype" section="admin"}</th>
<th class="center">{str tag="groupvisible" section="admin"}</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
{foreach from=$groups item=group}
<tr class="{cycle values='r0,r1'}">
<td>{$group->name}</td>
<td class="center">{$group->members}</td>
<td class="center">{$group->admins}</td>
<td class="center">{$group->type}</td>
<td class="center">{$group->visible}</td>
<td class="center"><a href="{$WWWROOT}admin/groups/manage.php?id={$group->id}">{str tag="groupmanage" section="admin"}</a></td>
<td class="center"><a href="{$WWWROOT}admin/groups/delete.php?id={$group->id}">{str tag="groupdelete" section="admin"}</a></td>
</tr>
{/foreach}
</tbody>
</table>
{include file="footer.tpl"}
{/auto_escape}
{auto_escape off}
{include file="header.tpl"}
<p>{str tag=managegroupdescription section=admin}</p>
{$managegroupform}
{include file="footer.tpl"}
{/auto_escape}
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