function addmembers_submit(Pieform $form, $values) { global $SESSION; if (empty($values['users'])) { redirect(get_config('wwwroot') . 'group/addmembers.php?id=' . GROUP); } db_begin(); foreach ($values['users'] as $userid) { group_add_user(GROUP, $userid); } db_commit(); $SESSION->add_ok_msg(get_string('newmembersadded', 'group', count($values['users']))); redirect(get_config('wwwroot') . 'group/members.php?id=' . GROUP); }
function groupadminsform_submit(Pieform $form, $values) { global $SESSION, $group, $admins; $newadmins = array_diff($values['admins'], $admins); $demoted = array_diff($admins, $values['admins']); db_begin(); if ($demoted) { $demoted = join(',', array_map('intval', $demoted)); execute_sql("\n UPDATE {group_member}\n SET role = 'member'\n WHERE role = 'admin' AND \"group\" = ?\n AND member IN ({$demoted})", array($group->id)); } $dbnow = db_format_timestamp(time()); foreach ($newadmins as $id) { if (group_user_access($group->id, $id)) { group_change_role($group->id, $id, 'admin'); } else { group_add_user($group->id, $id, 'admin'); } } db_commit(); $SESSION->add_ok_msg(get_string('groupadminsupdated', 'admin')); redirect(get_config('wwwroot') . 'admin/groups/groups.php'); }
/** * Given a user, makes sure they have been added to all groups that are marked * as ones that users should be auto-added to * * @param array $eventdata Event data passed from activity_occured, the key 'id' = userid */ function add_user_to_autoadd_groups($eventdata) { require_once 'group.php'; $userid = $eventdata['id']; if ($autoaddgroups = get_column('group', 'id', 'usersautoadded', true)) { foreach ($autoaddgroups as $groupid) { if (!group_user_access($groupid, $userid)) { group_add_user($groupid, $userid); } } } }
function group_adduser_submit(Pieform $form, $values) { global $SESSION; $group = (int) $values['group']; if (group_user_access($group) != 'admin') { $SESSION->add_error_msg(get_string('accessdenied', 'error')); redirect('/group/members.php?id=' . $group . '&membershiptype=request'); } group_add_user($group, $values['member']); $SESSION->add_ok_msg(get_string('useradded', 'group')); if (count_records('group_member_request', 'group', $group)) { redirect('/group/members.php?id=' . $group . '&membershiptype=request'); } redirect('/group/members.php?id=' . $group); }
} if ($addtype == 'add') { db_begin(); //remove group membership if ($groupstoremove = array_diff($initialgroups, $resultgroups)) { $groupstoremovemail = ''; foreach ($groupstoremove as $groupid) { group_remove_user($groupid, $userid, $role = null); $groupstoremovemail .= $groupdata[$groupid]->name . "\n"; } } //add group membership if ($groupstoadd = array_diff($resultgroups, $initialgroups)) { $groupstoaddmail = ''; foreach ($groupstoadd as $groupid) { group_add_user($groupid, $userid, $role = null); $groupstoaddmail .= $groupdata[$groupid]->name . "\n"; } } db_commit(); // Users notification $userrecord = get_record('usr', 'id', $userid); $lang = get_user_language($userid); $n = new StdClass(); $n->users = array($userid); $n->subject = get_string_from_language($lang, 'changedgroupmembershipsubject', 'group'); $n->message = ''; if (isset($groupstoaddmail)) { $n->message .= get_string_from_language($lang, 'addedtongroupsmessage', 'group', count($groupstoadd), display_name($USER, $userrecord), $groupstoaddmail); } if (isset($groupstoremovemail)) {
function addmember_submit(Pieform $form, $values) { global $USER, $SESSION, $userid; $group = get_record('group', 'id', $values['group']); $ctitle = $group->name; $adduser = get_record('usr', 'id', $userid); try { group_add_user($values['group'], $userid, 'member'); $lang = get_user_language($userid); require_once get_config('libroot') . 'activity.php'; activity_occurred('maharamessage', array('users' => array($userid), 'subject' => get_string_from_language($lang, 'addedtogroupsubject', 'group'), 'message' => get_string_from_language($lang, 'addedtogroupmessage', 'group', display_name($USER, $adduser), $ctitle), 'url' => group_homepage_url($group, false), 'urltext' => $ctitle)); $SESSION->add_ok_msg(get_string('useradded', 'group')); } catch (SQLException $e) { $SESSION->add_error_msg(get_string('adduserfailed', 'group')); } redirect(profile_url($adduser)); }
function editgroup_submit(Pieform $form, $values) { global $USER, $SESSION, $group_data; db_begin(); $now = db_format_timestamp(time()); list($grouptype, $jointype) = explode('.', $values['grouptype']); $values['public'] = isset($values['public']) ? $values['public'] : 0; $values['usersautoadded'] = isset($values['usersautoadded']) ? $values['usersautoadded'] : 0; update_record('group', (object) array('id' => $values['id'], 'name' => $values['name'], 'description' => $values['description'], 'grouptype' => $grouptype, 'category' => empty($values['category']) ? null : intval($values['category']), 'jointype' => $jointype, 'mtime' => $now, 'usersautoadded' => intval($values['usersautoadded']), 'public' => intval($values['public']), 'viewnotify' => intval($values['viewnotify'])), 'id'); // When jointype changes from invite/request to anything else, // remove all open invitations/requests, --- // Except for when jointype changes from request to open. Then // we can just add group membership for everyone with an open // request. if ($group_data->jointype == 'invite' && $jointype != 'invite') { delete_records('group_member_invite', 'group', $group_data->id); } else { if ($group_data->jointype == 'request') { if ($jointype == 'open') { $userids = get_column_sql(' SELECT u.id FROM {usr} u JOIN {group_member_request} r ON u.id = r.member WHERE r.group = ? AND u.deleted = 0', array($group_data->id)); if ($userids) { foreach ($userids as $uid) { group_add_user($group_data->id, $uid); } } } else { if ($jointype != 'request') { delete_records('group_member_request', 'group', $group_data->id); } } } } // When group type changes from course to standard, make sure that tutors // are demoted to members. if ($group_data->grouptype == 'course' && $grouptype != 'course') { set_field('group_member', 'role', 'member', 'group', $values['id'], 'role', 'tutor'); } // When a group changes from public -> private or vice versa, set the // appropriate access permissions on the group homepage view. if ($group_data->public != $values['public']) { $homepageid = get_field('view', 'id', 'type', 'grouphomepage', 'group', $group_data->id); if ($group_data->public && !$values['public']) { delete_records('view_access', 'view', $homepageid, 'accesstype', 'public'); insert_record('view_access', (object) array('view' => $homepageid, 'accesstype' => 'loggedin')); } else { if (!$group_data->public && $values['public']) { delete_records('view_access', 'view', $homepageid, 'accesstype', 'loggedin'); insert_record('view_access', (object) array('view' => $homepageid, 'accesstype' => 'public')); } } } $SESSION->add_ok_msg(get_string('groupsaved', 'group')); db_commit(); redirect('/group/view.php?id=' . $values['id']); }