Commit 19133531 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Use group_add_user, etc. functions in more places

The admin 'manage groups' and user profile pages added users to groups
by changing the group_member table directly rather than using
group_add_user and friends.  It's cleaner to keep this code in one
place, in case we want to make changes to the group_member tables

Change-Id: I687764fb25e8924a3da85da7494cd3fbcad53bc1
Signed-off-by: default avatarRichard Mansfield <>
parent c7522fec
......@@ -113,22 +113,11 @@ function groupadminsform_submit(Pieform $form, $values) {
$dbnow = db_format_timestamp(time());
foreach ($newadmins as $id) {
if (record_exists('group_member', 'group', $group->id, 'member', $id)) {
UPDATE {group_member}
SET role = 'admin'
WHERE \"group\" = ? AND member = ?",
array($group->id, $id)
if (group_user_access($group->id, $id)) {
group_change_role($group->id, $id, 'admin');
else {
insert_record('group_member', (object) array(
'group' => $group->id,
'member' => $id,
'role' => 'admin',
'ctime' => $dbnow,
'mtime' => $dbnow,
group_add_user($group->id, $id, 'admin');
......@@ -298,17 +298,11 @@ function invite_submit(Pieform $form, $values) {
function addmember_submit(Pieform $form, $values) {
global $USER, $SESSION, $userid;
$data = new StdClass;
$data->group = $values['group'];
$data->member = $userid;
$data->ctime = db_format_timestamp(time());
$data->role = 'member'; // TODO: modify the dropdown to allow the role to be chosen
$ctitle = get_field('group', 'name', 'id', $data->group);
$adduser = get_record('usr', 'id', $data->member);
$ctitle = get_field('group', 'name', 'id', $values['group']);
$adduser = get_record('usr', 'id', $userid);
try {
insert_record('group_member', $data);
delete_records('group_member_request', 'member', $userid, 'group', $data->group);
group_add_user($values['group'], $userid, 'member');
$lang = get_user_language($userid);
require_once(get_config('libroot') . 'activity.php');
activity_occurred('maharamessage', array(
Supports Markdown
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