Commit e7602c00 authored by Richard Mansfield's avatar Richard Mansfield

Specify a role when inviting a user to a group

parent 9dbad93d
......@@ -45,12 +45,17 @@ if (!$user) {
if ($group->jointype != 'invite'
|| record_exists('group_member', 'group', $groupid, 'member', $userid)
|| record_exists('group_member_invite', 'group', $groupid, 'member', $userid)
|| $group->owner != $USER->get('id')) {
|| group_user_access($groupid) != 'admin') {
throw new AccessDeniedException(get_string('cannotinvitetogroup', 'group'));
}
define('TITLE', get_string('invitemembertogroup', 'group', display_name($userid), $group->name));
$roles = group_get_role_info($groupid);
foreach ($roles as $k => &$v) {
$v = $v->display;
}
$form = pieform(array(
'name' => 'invitetogroup',
'autofocus' => false,
......@@ -62,6 +67,11 @@ $form = pieform(array(
'rows' => 4,
'title' => get_string('reason'),
),
'role' => array(
'type' => 'select',
'options' => $roles,
'title' => get_string('Role', 'group'),
),
'submit' => array(
'type' => 'submitcancel',
'value' => array(get_string('invite', 'group'), get_string('cancel')),
......@@ -83,7 +93,7 @@ function invitetogroup_submit(Pieform $form, $values) {
$data->group = $group->id;
$data->member= $user->id;
$data->ctime = db_format_timestamp(time());
$data->tutor = 0;
$data->role = $values['role'];
insert_record('group_member_invite', $data);
$lang = get_user_language($user->id);
activity_occurred('maharamessage',
......
......@@ -291,6 +291,7 @@
<FIELD NAME="member" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="reason" TYPE="text" NOTNULL="false" />
<FIELD NAME="role" TYPE="char" LENGTH="255" NOTNULL="false" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="group,member" />
......
......@@ -1193,6 +1193,10 @@ function xmldb_core_upgrade($oldversion=0) {
execute_sql('ALTER TABLE {grouptype} ALTER COLUMN defaultrole SET NOT NULL');
}
if ($oldversion < 2008062309) {
execute_sql('ALTER TABLE {group_member_invite} ADD COLUMN role VARCHAR(255)');
}
return $status;
}
......
......@@ -320,10 +320,11 @@ function joingroup_submit(Pieform $form, $values) {
function group_invite_submit(Pieform $form, $values) {
global $SESSION, $USER;
if (get_record('group_member_invite', 'member', $USER->get('id'), 'group', $values['group'])) {
$inviterecord = get_record('group_member_invite', 'member', $USER->get('id'), 'group', $values['group']);
if ($inviterecord) {
delete_records('group_member_invite', 'group', $values['group'], 'member', $USER->get('id'));
if (isset($values['accept'])) {
group_add_member($values['group'], $USER->get('id'));
group_add_member($values['group'], $USER->get('id'), $inviterecord->role);
$SESSION->add_ok_msg(get_string('groupinviteaccepted', 'group'));
redirect('/group/view.php?id=' . $values['group']);
}
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2008062308;
$config->version = 2008062309;
$config->release = '1.1.0alpha';
$config->minupgradefrom = 2007080700;
$config->minupgraderelease = '0.8.0 (release tag 0.8.0_RELEASE)';
......
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