Commit 088b278d authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review

Merge changes Ibe567586,Ic4d987d3,Ifd70b30b,I413df0ab,Ifaf91ea5,I4618b665,Id2550e57

* changes:
  Hide member counts when user can't list members
  Allow members of invitefriends groups to invite users on profile (bug #845290)
  Notify members when a group is deleted (bug #845293)
  Remove unneccessary view submission code from groupmessage activity
  Add friend invites and friend suggestions to groups (bug #845290)
  Add friends filter to groupmembersearch ajax script (bug #845290)
  Add 'hidemembersfrommembers' group setting (bug #504830)
parents e49290f6 9f8cf990
......@@ -53,6 +53,9 @@ $ALLOWEDKEYS = array(
'editroles',
'hidden',
'hidemembers',
'hidemembersfrommembers',
'invitefriends',
'suggestfriends',
);
if ($USER->get('admin')) {
$ALLOWEDKEYS[] = 'usersautoadded';
......
......@@ -63,13 +63,7 @@ class PluginBlocktypeGroupInfo extends SystemBlocktype {
$data = self::get_data($groupid);
$dwoo = smarty_core();
$dwoo->assign('group', $data['group']);
$dwoo->assign('groupid', $data['group']->id);
$dwoo->assign('membercount', count_records('group_member', 'group', $data['group']->id));
$dwoo->assign('viewcount', count_records('view', 'group', $data['group']->id));
$dwoo->assign('filecount', $data['filecounts']->files);
$dwoo->assign('foldercount', $data['filecounts']->folders);
$dwoo->assign('group', $data);
return $dwoo->fetch('blocktype:groupinfo:groupinfo.tpl');
}
......@@ -96,8 +90,6 @@ class PluginBlocktypeGroupInfo extends SystemBlocktype {
throw new AccessDeniedException();
}
list($group, $filecounts) = group_get_groupinfo_data($group);
return array('group'=>$group, 'filecounts'=>$filecounts);
return group_get_groupinfo_data($group);
}
}
......@@ -66,13 +66,14 @@ class PluginBlocktypeGroupMembers extends SystemBlocktype {
$groupid = $instance->get_view()->get('group');
// If the group has hidden membership, display nothing to non-members
// If the group has hidden membership, display nothing
$usergroups = $USER->get('grouproles');
if (!isset($usergroups[$groupid])) {
$group = defined('GROUP') && $groupid == GROUP ? group_current_group() : get_record('group', 'id', $groupid);
if ($group->hidemembers) {
return '';
}
$group = defined('GROUP') && $groupid == GROUP ? group_current_group() : get_record('group', 'id', $groupid);
if ($group->hidemembersfrommembers && (!isset($usergroups[$groupid]) || $usergroups[$groupid] != 'admin')) {
return '';
}
if ($group->hidemembers && !isset($usergroups[$groupid])) {
return '';
}
require_once('searchlib.php');
......
......@@ -70,6 +70,9 @@ else {
'editroles' => 'all',
'hidden' => 0,
'hidemembers' => 0,
'hidemembersfrommembers' => 0,
'invitefriends' => 0,
'suggestfriends' => 0,
);
}
......@@ -181,6 +184,20 @@ if (!empty($forcegrouptype) || count($grouptypeoptions) < 2) {
);
}
$elements['invitefriends'] = array(
'type' => 'checkbox',
'title' => get_string('friendinvitations', 'group'),
'description' => get_string('invitefriendsdescription', 'group'),
'defaultvalue' => $group_data->invitefriends,
);
$elements['suggestfriends'] = array(
'type' => 'checkbox',
'title' => get_string('Recommendations', 'group'),
'description' => get_string('suggestfriendsdescription', 'group'),
'defaultvalue' => $group_data->suggestfriends,
);
$elements['pages'] = array(
'type' => 'html',
'title' => get_string('views'),
......@@ -250,6 +267,12 @@ if ($cancreatecontrolled) {
'description' => get_string('hidemembersdescription', 'group'),
'defaultvalue' => $group_data->hidemembers,
);
$elements['hidemembersfrommembers'] = array(
'type' => 'checkbox',
'title' => get_string('hidemembersfrommembers', 'group'),
'description' => get_string('hidemembersfrommembersdescription', 'group'),
'defaultvalue' => $group_data->hidemembersfrommembers,
);
}
else {
$form['elements']['hidden'] = array(
......@@ -260,6 +283,10 @@ else {
'type' => 'hidden',
'value' => $group_data->hidemembers,
);
$form['elements']['hidemembersfrommembers'] = array(
'type' => 'hidden',
'value' => $group_data->hidemembersfrommembers,
);
}
$elements['general'] = array(
......@@ -322,6 +349,9 @@ function editgroup_validate(Pieform $form, $values) {
$form->set_error('request', get_string('membershipopenrequest', 'group'));
}
}
if (!empty($values['invitefriends']) && !empty($values['suggestfriends'])) {
$form->set_error('invitefriends', get_string('suggestinvitefriends', 'group'));
}
}
function editgroup_cancel_submit() {
......@@ -349,6 +379,9 @@ function editgroup_submit(Pieform $form, $values) {
'editroles' => $values['editroles'],
'hidden' => intval($values['hidden']),
'hidemembers' => intval($values['hidemembers']),
'hidemembersfrommembers' => intval($values['hidemembersfrommembers']),
'invitefriends' => intval($values['invitefriends']),
'suggestfriends' => intval($values['suggestfriends']),
);
db_begin();
......@@ -388,6 +421,16 @@ $j(function() {
$j("#editgroup_request").removeAttr("disabled");
}
});
$j("#editgroup_invitefriends").click(function() {
if ($(this).checked) {
$j("#editgroup_suggestfriends").removeAttr("checked");
}
});
$j("#editgroup_suggestfriends").click(function() {
if ($(this).checked) {
$j("#editgroup_invitefriends").removeAttr("checked");
}
});
});
';
......
......@@ -92,12 +92,12 @@ if ($groups['data']) {
foreach ($groups['data'] as $group) {
$groupids[] = $group->id;
}
$groups['data'] = get_records_sql_array(
"SELECT g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.role, g1.membershiptype,
g1.submittableto, g1.membercount, COUNT(gmr.member) AS requests
$groups['data'] = get_records_sql_array("
SELECT g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.submittableto,
g1.hidemembers, g1.hidemembersfrommembers, g1.role, g1.membershiptype, g1.membercount, COUNT(gmr.member) AS requests
FROM (
SELECT g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto, t.role,
t.membershiptype, COUNT(gm.member) AS membercount
SELECT g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
g.hidemembers, g.hidemembersfrommembers, t.role, t.membershiptype, COUNT(gm.member) AS membercount
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)
LEFT JOIN (
......@@ -118,12 +118,12 @@ if ($groups['data']) {
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id
WHERE g.id IN (" . implode($groupids, ',') . ')
GROUP BY g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto, t.role,
t.membershiptype
GROUP BY g.id, g.name, g.description, g.public, g.jointype, g.request, g.grouptype, g.submittableto,
g.hidemembers, g.hidemembersfrommembers, t.role, t.membershiptype
) g1
LEFT JOIN {group_member_request} gmr ON (gmr.group = g1.id)
GROUP BY g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.role, g1.membershiptype,
g1.submittableto, g1.membercount
GROUP BY g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.request, g1.grouptype, g1.submittableto,
g1.hidemembers, g1.hidemembersfrommembers, g1.role, g1.membershiptype, g1.membercount
ORDER BY g1.name',
array($USER->get('id'), $USER->get('id'), $USER->get('id'), $USER->get('id'))
);
......
......@@ -33,14 +33,10 @@ require_once(get_config('libroot') . 'group.php');
$id = param_integer('id');
$group = get_record('group', 'id', $id);
list($group, $filecounts) = group_get_groupinfo_data($group);
$group = group_get_groupinfo_data($group);
$smarty = smarty_core();
$smarty->assign('group', $group);
$smarty->assign('membercount', count_records('group_member', 'group', $group->id));
$smarty->assign('viewcount', count_records('view', 'group', $group->id));
$smarty->assign('filecount', $filecounts->files);
$smarty->assign('foldercount', $filecounts->folders);
ob_start();
$smarty->display('group/groupdata.tpl');
$html = ob_get_contents();
......
......@@ -41,8 +41,12 @@ if (!$user) {
throw new UserNotFoundException(get_string('usernotfound', 'group', $userid));
}
if (group_user_access($groupid) != 'admin') {
throw new AccessDeniedException(get_string('cannotinvitetogroup', 'group'));
$role = group_user_access($groupid);
if ($role != 'admin' && !group_user_can_assess_submitted_views($group->id, $USER->get('id'))) {
if (!$group->invitefriends || !is_friend($user->id, $USER->get('id'))) {
throw new AccessDeniedException(get_string('cannotinvitetogroup', 'group'));
}
}
if (record_exists('group_member', 'group', $groupid, 'member', $userid)
......@@ -74,6 +78,7 @@ $form = pieform(array(
'options' => $roles,
'title' => get_string('Role', 'group'),
'defaultvalue' => call_static_method('GroupType' . $group->grouptype, 'default_role'),
'ignore' => $role != 'admin',
),
'submit' => array(
'type' => 'submitcancel',
......@@ -90,7 +95,7 @@ $smarty->display('group/invite.tpl');
function invitetogroup_submit(Pieform $form, $values) {
global $SESSION, $USER, $group, $user;
group_invite_user($group, $user->id, $USER, $values['role']);
group_invite_user($group, $user->id, $USER, isset($values['role']) ? $values['role'] : null);
$SESSION->add_ok_msg(get_string('userinvited', 'group'));
redirect('/user/view.php?id=' . $user->id);
}
......@@ -39,9 +39,15 @@ if (!is_logged_in() && !$group->public) {
throw new AccessDeniedException();
}
$friends = param_integer('friends', 0);
$role = group_user_access($group->id);
if ($role != 'admin') {
throw new AccessDeniedException();
// Allow non-admins to get to this page when invitefriends is
// enabled and they're filtering by their friends.
if (!$friends || !$role || !$group->invitefriends) {
throw new AccessDeniedException();
}
}
define('TITLE', $group->name . ' - ' . get_string('sendinvitations', 'group'));
......@@ -61,6 +67,7 @@ $form = pieform(array(
'limit' => 100,
'html' => 0,
'membershiptype' => 'notinvited',
'friends' => $friends,
),
),
'submit' => array(
......@@ -77,10 +84,10 @@ $smarty->display('group/form.tpl');
exit;
function addmembers_submit(Pieform $form, $values) {
global $SESSION, $group, $USER;
global $SESSION, $group, $USER, $friends;
if (empty($values['users'])) {
redirect(get_config('wwwroot') . 'group/inviteusers.php?id=' . GROUP);
redirect(get_config('wwwroot') . 'group/inviteusers.php?id=' . GROUP . ($friends ? '&friends=1' : ''));
}
db_begin();
......@@ -90,5 +97,8 @@ function addmembers_submit(Pieform $form, $values) {
db_commit();
$SESSION->add_ok_msg(get_string('invitationssent', 'group', count($values['users'])));
if ($friends) {
redirect(get_config('wwwroot') . 'group/view.php?id=' . GROUP);
}
redirect(get_config('wwwroot') . 'group/members.php?id=' . GROUP);
}
......@@ -45,8 +45,13 @@ define('TITLE', $group->name . ' - ' . get_string('Members', 'group'));
$role = group_user_access($group->id);
if ($group->hidemembers && !$role && !$USER->get('admin') && !$USER->get('staff')) {
throw new AccessDeniedException();
if (!$USER->get('admin') && !$USER->get('staff')) {
if (!$role && ($group->hidemembers || $group->hidemembersfrommembers)) {
throw new AccessDeniedException();
}
if ($role != 'admin' && $group->hidemembersfrommembers) {
throw new AccessDeniedException();
}
}
if (!empty($membershiptype) && $role != 'admin') {
......
......@@ -45,19 +45,31 @@ if (!is_logged_in() && !$group->public) {
$role = group_user_access($group->id);
if ($group->hidemembers && !$role && !$USER->get('admin') && !$USER->get('staff')) {
json_reply('local', get_string('accessdenied', 'error'));
if (!$USER->get('admin') && !$USER->get('staff')) {
if (!$role && ($group->hidemembers || $group->hidemembersfrommembers)) {
json_reply('local', get_string('accessdenied', 'error'));
}
if ($role != 'admin' && $group->hidemembersfrommembers) {
json_reply('local', get_string('accessdenied', 'error'));
}
}
$membershiptype = param_variable('membershiptype', '');
$friends = param_integer('friends', 0);
if (!empty($membershiptype)) {
if ($role != 'admin') {
json_reply('local', get_string('accessdenied', 'error'));
// Non-admins are allowed to find the 'notinvited' users, but only if 'invitefriends'
// or 'suggestfriends' is enabled, and they're filtering by their friends list
if ($membershiptype != 'notinvited' || !$role || !($group->invitefriends || $group->suggestfriends) || !$friends) {
json_reply('local', get_string('accessdenied', 'error'));
}
}
}
$results = get_group_user_search_results($group->id, $query, $offset, $limit, $membershiptype);
$results = get_group_user_search_results(
$group->id, $query, $offset, $limit, $membershiptype, null,
$friends ? $USER->get('id') : null
);
if (!param_integer('html', 1)) {
foreach ($results['data'] as &$result) {
$result = array('id' => $result['id'], 'name' => $result['name']);
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2011 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 Richard Mansfield
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
*
*/
define('PUBLIC', 1);
define('INTERNAL', 1);
define('MENUITEM', 'groups/members');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('group.php');
require_once('pieforms/pieform.php');
define('GROUP', param_integer('id'));
$group = group_current_group();
if (!is_logged_in() && !$group->public) {
throw new AccessDeniedException();
}
$role = group_user_access($group->id);
if (!$role || !$group->suggestfriends) {
throw new AccessDeniedException();
}
$subheading = get_string('suggesttofriends', 'group');
define('TITLE', $group->name . ' - ' . $subheading);
$form = pieform(array(
'name' => 'addmembers',
'elements' => array(
'users' => array(
'type' => 'userlist',
'lefttitle' => get_string('potentialmembers', 'group'),
'righttitle' => get_string('userstosendrecommendationsto', 'group'),
'searchscript' => 'group/membersearchresults.json.php',
'defaultvalue' => array(),
'filter' => false,
'searchparams' => array(
'id' => GROUP,
'limit' => 100,
'html' => 0,
'membershiptype' => 'notinvited',
'friends' => 1,
),
),
'submit' => array(
'type' => 'submit',
'value' => get_string('submit'),
)
)
));
$smarty = smarty();
$smarty->assign('subheading', $subheading);
$smarty->assign('form', $form);
$smarty->display('group/form.tpl');
exit;
function addmembers_submit(Pieform $form, $values) {
global $SESSION, $group, $USER;
if (empty($values['users'])) {
redirect(get_config('wwwroot') . 'group/suggest.php?id=' . GROUP);
}
require_once('activity.php');
activity_occurred('maharamessage', array(
'users' => $values['users'],
'subject' => '',
'message' => '',
'strings' => (object) array(
'subject' => (object) array(
'key' => 'suggestgroupnotificationsubject',
'section' => 'group',
'args' => array(display_name($USER)),
),
'message' => (object) array(
'key' => 'suggestgroupnotificationmessage',
'section' => 'group',
'args' => array(display_name($USER), hsc($group->name), get_config('sitename')),
),
),
'url' => get_config('wwwroot') . 'group/view.php?id=' . GROUP,
'urltext' => hsc($group->name),
));
$SESSION->add_ok_msg(get_string('recommendationssent', 'group', count($values['users'])));
redirect(get_config('wwwroot') . 'group/view.php?id=' . GROUP);
}
......@@ -100,6 +100,19 @@ $string['hiddengroup'] = 'Hidden group';
$string['hiddengroupdescription'] = 'Do not list this group on the Find Groups page.';
$string['hidemembers'] = 'Hide membership';
$string['hidemembersdescription'] = 'Hide the group\'s membership listing from non-members.';
$string['hidemembersfrommembers'] = 'Hide membership from members';
$string['hidemembersfrommembersdescription'] = 'Members cannot be listed except by group admins. Admins will still be listed on the group home page.';
$string['friendinvitations'] = 'Friend invitations';
$string['invitefriendsdescription'] = 'If checked, members will be allowed to invite friends to join the group. Regardless of this setting, group admins can always send invitations to anyone.';
$string['invitefriends'] = 'Invite friends';
$string['Recommendations'] = 'Recommendations';
$string['suggestfriendsdescription'] = 'If checked, members can easily send a recommendation about this group to their friends from a button on the group homepage.';
$string['suggesttofriends'] = 'Suggest to friends';
$string['userstosendrecommendationsto'] = 'Users who will be sent a recommendation';
$string['suggestgroupnotificationsubject'] = '%s suggested you join a group';
$string['suggestgroupnotificationmessage'] = '%s suggested that you join the group "%s" on %s';
$string['recommendationssent'] = '%d recommendation(s) sent';
$string['suggestinvitefriends'] = 'You cannot enable both friend invitations and recommendations.';
$string['editgroupmembership'] = 'Edit group membership';
$string['editmembershipforuser'] = 'Edit membership for %s';
......@@ -188,6 +201,8 @@ $string['notmembermayjoin'] = 'You must join the group \'%s\' to see this page.'
$string['declinerequestsuccess'] = 'Group membership request has been declined sucessfully.';
$string['notpublic'] = 'This group is not public.';
$string['moregroups'] = 'More groups';
$string['deletegroupnotificationsubject'] = 'The group "%s" was deleted';
$string['deletegroupnotificationmessage'] = 'You were a member of the group %s on %s. This group has now been deleted.';
// Bulk add, invite
$string['addmembers'] = 'Add members';
......
......@@ -982,14 +982,10 @@ class ActivityTypeGroupMessage extends ActivityType {
protected $group;
protected $roles;
protected $submittedview;
private $viewinfo;
private $groupinfo;
protected $deletedgroup;
/**
* @param array $data Parameters:
* - subject (string)
* - message (string)
* - group (integer)
* - roles (list of roles)
*/
......@@ -997,35 +993,14 @@ class ActivityTypeGroupMessage extends ActivityType {
require_once('group.php');
parent::__construct($data, $cron);
$this->groupinfo = get_record('group', 'id', $this->group);
$members = group_get_member_ids($this->group, isset($this->roles) ? $this->roles : null);
$this->users = activity_get_users($this->get_id(), $members);
if ($this->submittedview) {
$this->viewinfo = get_record('view', 'id', $this->submittedview);
$this->viewinfo->ownername = display_name($this->viewinfo->owner);
$this->url = get_config('wwwroot') . 'view/view.php?id=' . $this->submittedview;
}
}
public function get_subject($user) {
if ($this->submittedview) {
return get_string_from_language($user->lang, 'viewsubmittedsubject', 'activity', $this->groupinfo->name);
}
return $this->subject;
}
public function get_message($user) {
if ($this->submittedview) {
return get_string_from_language($user->lang, 'viewsubmittedmessage', 'activity', $this->viewinfo->ownername, $this->viewinfo->title, $this->groupinfo->name);
$members = group_get_member_ids($this->group, isset($this->roles) ? $this->roles : null, $this->deletedgroup);
if (!empty($members)) {
$this->users = activity_get_users($this->get_id(), $members);
}
return $this->subject;
}
public function get_required_parameters() {
return array('message', 'subject', 'group');
return array('group');
}
}
......
......@@ -346,6 +346,9 @@
<FIELD NAME="editroles" TYPE="char" LENGTH="20" NOTNULL="true" ENUM="true" ENUMVALUES="'all', 'notmember', 'admin'" DEFAULT="all" />
<FIELD NAME="hidden" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="hidemembers" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="hidemembersfrommembers" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="invitefriends" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="suggestfriends" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......
......@@ -2720,6 +2720,21 @@ function xmldb_core_upgrade($oldversion=0) {
$field = new XMLDBField('hidemembers');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
// Setting to hide group members from members
$field = new XMLDBField('hidemembersfrommembers');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
// Allow group members to invite friends
$field = new XMLDBField('invitefriends');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
// Allow group members to recommend the group to friends
$field = new XMLDBField('suggestfriends');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
}
return $status;
......
......@@ -280,10 +280,17 @@ function group_create($data) {
$data['public'] = (isset($data['public'])) ? intval($data['public']) : 0;
$data['hidden'] = (isset($data['hidden'])) ? intval($data['hidden']) : 0;
$data['hidemembers'] = (isset($data['hidemembers'])) ? intval($data['hidemembers']) : 0;
$data['hidemembersfrommembers'] = (isset($data['hidemembersfrommembers'])) ? intval($data['hidemembersfrommembers']) : 0;
$data['usersautoadded'] = (isset($data['usersautoadded'])) ? intval($data['usersautoadded']) : 0;
$data['quota'] = get_config_plugin('artefact', 'file', 'defaultgroupquota');
if (!empty($data['invitefriends']) && !empty($data['suggestfriends'])) {
throw new InvalidArgumentException("group_create: a group cannot enable both invitefriends and suggestfriends");
}
$data['invitefriends'] = (isset($data['invitefriends'])) ? intval($data['invitefriends']) : 0;
$data['suggestfriends'] = (isset($data['suggestfriends'])) ? intval($data['suggestfriends']) : 0;
if (isset($data['shortname']) && strlen($data['shortname'])) {
// This is a group whose details and membership can be updated automatically, using a
// webservice api or possibly csv upload.
......@@ -356,6 +363,9 @@ function group_create($data) {
'editroles' => $data['editroles'],
'hidden' => $data['hidden'],
'hidemembers' => $data['hidemembers'],
'hidemembersfrommembers' => $data['hidemembersfrommembers'],
'invitefriends' => $data['invitefriends'],
'suggestfriends' => $data['suggestfriends'],
),
'id',
true
......@@ -462,7 +472,8 @@ function group_update($new, $create=false) {
unset($new->institution);
unset($new->shortname);
foreach (array('id', 'grouptype', 'public', 'request', 'submittableto', 'editroles', 'hidden', 'hidemembers') as $f) {
foreach (array('id', 'grouptype', 'public', 'request', 'submittableto', 'editroles',
'hidden', 'hidemembers', 'hidemembersfrommembers') as $f) {
if (!isset($new->$f)) {
$new->$f = $old->$f;
}
......@@ -498,6 +509,17 @@ function group_update($new, $create=false) {
unset($new->open);
unset($new->controlled);
// Ensure only one of invitefriends,suggestfriends gets enabled.
if (!empty($new->invitefriends)) {
$new->suggestfriends = 0;
}
else if (!isset($new->invitefriends)) {
$new->invitefriends = (int) ($old->invitefriends && empty($new->suggestfriends));
}
if (!isset($new->suggestfriends)) {
$new->suggestfriends = $old->suggestfriends;
}
$diff = array_diff_assoc((array)$new, (array)$old);
if (empty($diff)) {
return null;
......@@ -622,26 +644,50 @@ function group_get_groups_for_editing($ids=null) {
* {{@internal Maybe later we can have a group_can_be_deleted function if
* necessary}}
*/
function group_delete($groupid, $shortname=null, $institution=null) {
function group_delete($groupid, $shortname=null, $institution=null, $notifymembers=true) {
if (empty($groupid) && !empty($institution) && !is_null($shortname) && strlen($shortname)) {
// External call to delete a group, check permission of $USER.