Commit 89fdc919 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files
parents f2c95f8a 77ba7d21
...@@ -40,13 +40,15 @@ if (!$community = get_record('community', 'id', $id)) { ...@@ -40,13 +40,15 @@ if (!$community = get_record('community', 'id', $id)) {
$community->ownername = display_name(get_record('usr', 'id', $community->owner)); $community->ownername = display_name(get_record('usr', 'id', $community->owner));
$membership = user_can_access_community($id); $membership = user_can_access_community($id);
// $membership is a bit string summing all membership types
$ismember = (bool) ($membership & COMMUNITY_MEMBERSHIP_MEMBER);
if (!empty($joincontrol)) { if (!empty($joincontrol)) {
// leave, join, acceptinvite, request // leave, join, acceptinvite, request
switch ($joincontrol) { switch ($joincontrol) {
case 'leave': case 'leave':
// make sure they're a member and can leave // make sure they're a member and can leave
if ($membership == COMMUNITY_MEMBERSHIP_MEMBER && $community->jointype != 'controlled') { if ($ismember && $community->jointype != 'controlled') {
community_remove_member($id, $USER->get('id')); community_remove_member($id, $USER->get('id'));
$SESSION->add_ok_msg(get_string('leftcommunity')); $SESSION->add_ok_msg(get_string('leftcommunity'));
} }
...@@ -55,7 +57,7 @@ if (!empty($joincontrol)) { ...@@ -55,7 +57,7 @@ if (!empty($joincontrol)) {
} }
break; break;
case 'join': case 'join':
if (empty($membership) && $community->jointype == 'open') { if (!$ismember && $community->jointype == 'open') {
community_add_member($id, $USER->get('id')); community_add_member($id, $USER->get('id'));
$SESSION->add_ok_msg(get_string('joinedcommunity')); $SESSION->add_ok_msg(get_string('joinedcommunity'));
} }
...@@ -80,7 +82,7 @@ if (!empty($joincontrol)) { ...@@ -80,7 +82,7 @@ if (!empty($joincontrol)) {
$SESSION->add_ok_msg($message); $SESSION->add_ok_msg($message);
break; break;
case 'request': case 'request':
if (empty($membership) && $community->jointype == 'request' if (!$ismember && $community->jointype == 'request'
&& !record_exists('community_member_request', 'community', $id, 'member', $USER->get('id'))) { && !record_exists('community_member_request', 'community', $id, 'member', $USER->get('id'))) {
$cmr = new StdClass; $cmr = new StdClass;
$cmr->reason = param_variable('reason', null); $cmr->reason = param_variable('reason', null);
...@@ -135,14 +137,14 @@ $removefromwatchliststr = get_string('removefromwatchlist', 'activity'); ...@@ -135,14 +137,14 @@ $removefromwatchliststr = get_string('removefromwatchlist', 'activity');
$addtowatchliststr = get_string('addtowatchlist', 'activity'); $addtowatchliststr = get_string('addtowatchlist', 'activity');
// all the permissions stuff // all the permissions stuff
$tutor = (int)($membership < COMMUNITY_MEMBERSHIP_MEMBER); $tutor = (int)($membership && ($membership < COMMUNITY_MEMBERSHIP_MEMBER));
$controlled = (int)($community->jointype == 'controlled'); $controlled = (int)($community->jointype == 'controlled');
$admin = (int)($membership == COMMUNITY_MEMBERSHIP_ADMIN); $admin = (int)($membership & COMMUNITY_MEMBERSHIP_ADMIN != 0);
$canremove = (int)(($tutor && $controlled) || $admin); $canremove = (int)(($tutor && $controlled) || $admin);
$canpromote = (int)$tutor; $canpromote = (int)$tutor;
$canleave = ($membership == COMMUNITY_MEMBERSHIP_MEMBER && $community->jointype != 'controlled'); $canleave = ($ismember && $community->jointype != 'controlled');
$canrequestjoin = (empty($membership) && empty($invited) && empty($requested) && $community->jointype == 'request'); $canrequestjoin = (!$ismember && empty($invited) && empty($requested) && $community->jointype == 'request');
$canjoin = (empty($membership) && $community->jointype == 'open'); $canjoin = (!$ismember && $community->jointype == 'open');
$javascript = ''; $javascript = '';
if ($membership) { if ($membership) {
......
...@@ -200,9 +200,9 @@ function get_tutor_communities($userid=0, $jointype=null) { ...@@ -200,9 +200,9 @@ function get_tutor_communities($userid=0, $jointype=null) {
// constants for community membership type // constants for community membership type
define('COMMUNITY_MEMBERSHIP_ADMIN', 1); define('COMMUNITY_MEMBERSHIP_ADMIN', 1);
define('COMMUNITY_MEMBERSHIP_STAFF', 2); define('COMMUNITY_MEMBERSHIP_STAFF', 2);
define('COMMUNITY_MEMBERSHIP_OWNER', 3); define('COMMUNITY_MEMBERSHIP_OWNER', 4);
define('COMMUNITY_MEMBERSHIP_TUTOR', 4); define('COMMUNITY_MEMBERSHIP_TUTOR', 8);
define('COMMUNITY_MEMBERSHIP_MEMBER', 5); define('COMMUNITY_MEMBERSHIP_MEMBER', 16);
/** /**
...@@ -238,25 +238,27 @@ function user_can_access_community($community, $user=null) { ...@@ -238,25 +238,27 @@ function user_can_access_community($community, $user=null) {
throw new InvalidArgumentException("not useful community arg given to user_can_access_community: $community"); throw new InvalidArgumentException("not useful community arg given to user_can_access_community: $community");
} }
$membertypes = 0;
if ($user->get('admin')) { if ($user->get('admin')) {
return COMMUNITY_MEMBERSHIP_ADMIN; $membertypes = COMMUNITY_MEMBERSHIP_ADMIN;
} }
if ($user->get('staff')) { if ($user->get('staff')) {
return COMMUNITY_MEMBERSHIP_STAFF; $membertypes = $membertypes | COMMUNITY_MEMBERSHIP_STAFF;
} }
if ($community->owner == $user->get('id')) { if ($community->owner == $user->get('id')) {
return COMMUNITY_MEMBERSHIP_OWNER; $membertypes = $membertypes | COMMUNITY_MEMBERSHIP_OWNER;
} }
if (!$membership = get_record('community_member', 'community', $community->id, 'member', $user->get('id'))) { if (!$membership = get_record('community_member', 'community', $community->id, 'member', $user->get('id'))) {
return false; return $membertypes;
} }
if ($membership->tutor) { if ($membership->tutor) {
return COMMUNITY_MEMBERSHIP_TUTOR; $membertypes = $membertypes | COMMUNITY_MEMBERSHIP_TUTOR;
} }
return COMMUNITY_MEMBERSHIP_MEMBER; return ($membertypes | COMMUNITY_MEMBERSHIP_MEMBER);
} }
......
...@@ -169,7 +169,7 @@ function feedbackform() { ...@@ -169,7 +169,7 @@ function feedbackform() {
} }
} }
appendChildNodes(form, appendChildNodes(form,
TABLE(null, TABLE({'border':0, 'cellspacing':0, 'id':'feedback'},
TBODY(null, TBODY(null,
TR(null, TH(null, LABEL(null, {$getstring['message']}))), TR(null, TH(null, LABEL(null, {$getstring['message']}))),
TR(null, TD(null, TEXTAREA({'rows':5, 'cols':80, 'name':'message'}))), TR(null, TD(null, TEXTAREA({'rows':5, 'cols':80, 'name':'message'}))),
...@@ -200,7 +200,7 @@ function objectionform() { ...@@ -200,7 +200,7 @@ function objectionform() {
return false; return false;
} }
appendChildNodes(form, appendChildNodes(form,
TABLE({'border':0, 'cellspacing':0}, TABLE({'border':0, 'cellspacing':0, 'id':'objection'},
TBODY(null, TBODY(null,
TR(null, TH(null, LABEL(null, {$getstring['complaint']}))), TR(null, TH(null, LABEL(null, {$getstring['complaint']}))),
TR(null, TD(null, TEXTAREA({'rows':5, 'cols':80, 'name':'message'}))), TR(null, TD(null, TEXTAREA({'rows':5, 'cols':80, 'name':'message'}))),
......
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