Commit 308a740e authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie

Fix the forums after the group owner -> admins change.

parent 0f028df8
......@@ -39,7 +39,7 @@ $id = param_integer('id', 0);
if (!empty($id)) {
$instance = interaction_instance_from_id($id);
$plugin = $instance->get('plugin');
$groupid = $instance->get('group');
$groupid = (int)$instance->get('group');
define('TITLE', get_string('edittitle', 'interaction.' . $plugin));
}
else {
......@@ -53,8 +53,8 @@ safe_require('interaction', $plugin);
if (!$group = get_record('group', 'id', $groupid, 'deleted', 0)) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
}
$membership = user_can_access_group((int)$groupid);
if (!(bool)($membership & (GROUP_MEMBERSHIP_OWNER | GROUP_MEMBERSHIP_ADMIN | GROUP_MEMBERSHIP_STAFF))) {
$membership = group_user_access($groupid);
if ($membership != 'admin') {
throw new AccessDeniedException(get_string('notallowedtoeditinteractions', 'group'));
}
......@@ -86,7 +86,4 @@ $smarty->assign('heading', TITLE);
$smarty->assign('group', $group);
$smarty->display('interaction/edit.tpl');
?>
......@@ -34,7 +34,7 @@ require_once('pieforms/pieform.php');
$postid = param_integer('id');
$post = get_record_sql(
'SELECT p.subject, p.body, p.topic, p.parent, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . ', m.user AS moderator, t.forum, p2.subject AS topicsubject, f.group, f.title AS forumtitle, g.name AS groupname, g.owner AS groupowner, COUNT(p3.id)
'SELECT p.subject, p.body, p.topic, p.parent, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . ', m.user AS moderator, t.forum, p2.subject AS topicsubject, f.group, f.title AS forumtitle, g.name AS groupname, COUNT(p3.id)
FROM {interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t ON (p.topic = t.id AND t.deleted != 1)
INNER JOIN {interaction_forum_post} p2 ON (p2.topic = t.id AND p2.parent IS NULL)
......@@ -50,7 +50,7 @@ $post = get_record_sql(
INNER JOIN {interaction_instance} f2 ON (t2.forum = f2.id AND f2.deleted != 1 AND f2.group = f.group)
WHERE p.id = ?
AND p.deleted != 1
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13',
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12',
array(0, $postid)
);
......@@ -140,7 +140,7 @@ $smarty->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('heading', TITLE);
$smarty->assign('post', $post);
$smarty->assign('deleteform', $form);
$smarty->assign('groupowner', $post->groupowner);
$smarty->assign('groupadmins', group_get_admin_ids($post->group));
$smarty->display('interaction:forum:deletepost.tpl');
?>
......@@ -36,7 +36,7 @@ $topicid = param_integer('id');
$returnto = param_alpha('returnto', 'topic');
$topic = get_record_sql(
'SELECT f.group, f.id AS forumid, f.title, g.name AS groupname, p.poster, p.subject, p.body, COUNT(p2.id), ' . db_format_tsfield('p.ctime', 'ctime') . ', t.closed, m.user AS moderator, g.owner AS groupowner
'SELECT f.group, f.id AS forumid, f.title, g.name AS groupname, p.poster, p.subject, p.body, COUNT(p2.id), ' . db_format_tsfield('p.ctime', 'ctime') . ', t.closed, m.user AS moderator
FROM {interaction_forum_topic} t
INNER JOIN {interaction_instance} f ON (f.id = t.forum AND f.deleted != 1)
INNER JOIN {group} g ON (g.id = f.group AND g.deleted = ?)
......@@ -51,7 +51,7 @@ $topic = get_record_sql(
INNER JOIN {interaction_instance} f2 ON (t2.forum = f2.id AND f2.deleted != 1 AND f2.group = f.group)
WHERE t.id = ?
AND t.deleted != 1
GROUP BY 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12',
GROUP BY 1, 2, 3, 4, 5, 6, 7, 9, 10, 11',
array(0, $topicid)
);
......@@ -131,6 +131,7 @@ $smarty->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('forum', $topic->title);
$smarty->assign('heading', TITLE);
$smarty->assign('topic', $topic);
$smarty->assign('groupadmins', group_get_admin_ids($topic->group));
$smarty->assign('deleteform', $form);
$smarty->display('interaction:forum:deletetopic.tpl');
......
......@@ -54,7 +54,7 @@ else { // edit post
}
$parent = get_record_sql(
'SELECT p.subject, p.body, p.topic, p.parent, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . ', m.user AS moderator, t.id AS topic, t.forum, t.closed AS topicclosed, p2.subject AS topicsubject, f.group AS "group", f.title AS forumtitle, g.name AS groupname, g.owner AS groupowner, COUNT(p3.id)
'SELECT p.subject, p.body, p.topic, p.parent, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . ', m.user AS moderator, t.id AS topic, t.forum, t.closed AS topicclosed, p2.subject AS topicsubject, f.group AS "group", f.title AS forumtitle, g.name AS groupname, COUNT(p3.id)
FROM {interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t ON (p.topic = t.id AND t.deleted != 1)
INNER JOIN {interaction_forum_post} p2 ON (p2.topic = t.id AND p2.parent IS NULL)
......@@ -70,7 +70,7 @@ $parent = get_record_sql(
INNER JOIN {interaction_instance} f2 ON (t2.forum = f2.id AND f2.deleted != 1 AND f2.group = f.group)
WHERE p.id = ?
AND p.deleted != 1
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15',
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14',
array(0, $parentid)
);
......@@ -244,6 +244,8 @@ $smarty->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('heading', TITLE);
$smarty->assign('editform', $editform);
$smarty->assign('parent', $parent);
$smarty->assign('groupadmins', group_get_admin_ids($parent->group));
if (isset($inlinejs)) {
$smarty->assign('INLINEJAVASCRIPT', $inlinejs);
}
......
......@@ -38,15 +38,12 @@ if (!record_exists('group', 'id', $groupid, 'deleted', 0)) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
}
$membership = user_can_access_group((int)$groupid);
$admin = (bool)($membership & (GROUP_MEMBERSHIP_OWNER | GROUP_MEMBERSHIP_ADMIN | GROUP_MEMBERSHIP_STAFF));
$membership = group_user_access($groupid);
if (!$membership) {
throw new AccessDeniedException(get_string('cantviewforums', 'interaction.forum'));
}
$admin = (bool)($membership & (GROUP_MEMBERSHIP_OWNER | GROUP_MEMBERSHIP_ADMIN | GROUP_MEMBERSHIP_STAFF));
$group = get_record('group', 'id', $groupid);
define('TITLE', $group->name . ' - ' . get_string('nameplural', 'interaction.forum'));
......@@ -138,9 +135,9 @@ if ($forums) {
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(interaction_sideblock($groupid))));
$smarty->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('groupid', $groupid);
$smarty->assign('groupowner', $group->owner);
$smarty->assign('heading', TITLE);
$smarty->assign('admin', $admin);
$smarty->assign('admin', $membership == 'admin');
$smarty->assign('groupadmins', group_get_admin_ids($groupid));
$smarty->assign('forums', $forums);
$smarty->display('interaction:forum:index.tpl');
......
......@@ -5,4 +5,4 @@
<p><strong>Sticky</strong>: selected topics will appear at the top of every page</p>
<p><strong>Unsticky</strong>: selected topics will appear no longer appear top of every page.</p>
<p><strong>Open</strong>: all group members will be able to post to selected topics.</p>
<p><strong>Close</strong>: only the group owner and forum moderators will be able to post to selected topics.</p>
<p><strong>Close</strong>: only the group admins and forum moderators will be able to post to selected topics.</p>
......@@ -46,7 +46,7 @@ $string['chooseanaction'] = 'Choose an action';
$string['clicksetsubject'] = 'Click to set a subject';
$string['Closed'] = 'Closed';
$string['Close'] = 'Close';
$string['closeddescription'] = 'Closed topics can only be replied to by moderators and the group owner';
$string['closeddescription'] = 'Closed topics can only be replied to by moderators and the group administrators';
$string['Count'] = 'Count';
$string['currentmoderators'] = 'Current Moderators';
$string['deleteforum'] = 'Delete forum';
......@@ -66,8 +66,8 @@ $string['edittopic'] = 'Edit topic';
$string['edittopicsuccess'] = 'Topic edited successfully';
$string['forumsuccessfulsubscribe'] = 'Forum subscribed successfully';
$string['forumsuccessfulunsubscribe'] = 'Forum unsubscribed successfully';
$string['groupowner'] = 'Group owner';
$string['groupownerlist'] = 'Group owner:';
$string['groupadmins'] = 'Group administrators';
$string['groupadminlist'] = 'Group admins:';
$string['Key'] = 'Key';
$string['lastpost'] = 'Last post';
$string['Moderators'] = 'Moderators';
......@@ -107,7 +107,7 @@ $string['Topic'] = 'Topic';
$string['topiclower'] = 'topic';
$string['topicslower'] = 'topics';
$string['topicclosedsuccess'] = 'Topics closed successfully';
$string['topicisclosed'] = 'This topic is closed. Only moderators and the group owner can post new replies';
$string['topicisclosed'] = 'This topic is closed. Only moderators and the group admins can post new replies';
$string['topicopenedsuccess'] = 'Topics opened successfully';
$string['topicstickysuccess'] = 'Topics set as sticky successfully';
$string['topicsubscribesuccess'] = 'Topics subscribed successfully';
......
......@@ -86,7 +86,7 @@ class PluginInteractionForum extends PluginInteraction {
'description' => get_string('moderatorsdescription', 'interaction.forum'),
'defaultvalue' => isset($moderators) ? $moderators : null,
'group' => $group->id,
'owner' => false,
'includeadmins' => false,
'filter' => false,
'lefttitle' => get_string('potentialmoderators', 'interaction.forum'),
'righttitle' => get_string('currentmoderators', 'interaction.forum')
......@@ -334,16 +334,16 @@ function user_can_access_forum($forumid, $userid=null) {
$membership = 0;
$groupid = get_field('interaction_instance', '"group"', 'id', $forumid);
$groupmembership = user_can_access_group((int)$groupid, (int)$userid);
$groupmembership = group_user_access((int)$groupid, (int)$userid);
if (!$groupmembership) {
return $membership;
}
$membership = $membership | INTERACTION_FORUM_MEMBER;
if ($groupmembership & (GROUP_MEMBERSHIP_OWNER | GROUP_MEMBERSHIP_ADMIN | GROUP_MEMBERSHIP_STAFF)) {
if ($groupmembership == 'admin') {
$membership = $membership | INTERACTION_FORUM_ADMIN | INTERACTION_FORUM_MOD;
}
if(record_exists('interaction_forum_moderator', 'forum', $forumid, 'user', $userid)) {
if (record_exists('interaction_forum_moderator', 'forum', $forumid, 'user', $userid)) {
$membership = $membership | INTERACTION_FORUM_MOD;
}
return $membership;
......
......@@ -9,7 +9,7 @@
<div class="message">{$deleteform}</div>
{include file="interaction:forum:simplepost.tpl" post=$post groupowner=$post->groupowner}
{include file="interaction:forum:simplepost.tpl" post=$post groupadmins=$groupadmins}
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
......@@ -9,7 +9,7 @@
<div class="message">{$deleteform}</div>
{include file="interaction:forum:simplepost.tpl" post=$topic groupowner=$topic->groupowner}
{include file="interaction:forum:simplepost.tpl" post=$topic groupadmins=$groupadmins}
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
......@@ -9,7 +9,7 @@
{$editform}
<h4>{str tag="replyto" section="interaction.forum"}</h4>
{include file="interaction:forum:simplepost.tpl" post=$parent groupowner=$parent->groupowner}
{include file="interaction:forum:simplepost.tpl" post=$parent groupadmins=$groupadmins}
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
......@@ -14,10 +14,10 @@
</div>
{/if}
<br>
{str tag="groupownerlist" section="interaction.forum"}
<a href="{$WWWROOT}user/view.php?id={$groupowner}" class="groupowner">
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=20&amp;id={$groupowner}" alt="">
{$groupowner|display_name|escape}</a>
{str tag="groupadminlist" section="interaction.forum"}
{foreach name=groupadmins from=$groupadmins item=groupadmin}<a href="{$WWWROOT}user/view.php?id={$groupadmin}" class="groupadmin">
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=20&amp;id={$groupadmin}" alt="">
{$groupadmin|display_name|escape}</a>{if !$smarty.foreach.groupadmins.last}, {/if}{/foreach}
</div>
{if $forums}
<table id="forumslist">
......
......@@ -2,9 +2,9 @@
<h4>{str tag="deletedpost" section="interaction.forum}</h4>
{else}
{if $post->parent}
{include file="interaction:forum:simplepost.tpl" post=$post groupowner=$groupowner}
{include file="interaction:forum:simplepost.tpl" post=$post groupadmins=$groupadmins}
{else}
{include file="interaction:forum:simplepost.tpl" post=$post groupowner=$groupowner nosubject=true}
{include file="interaction:forum:simplepost.tpl" post=$post groupadmins=$groupadmins nosubject=true}
{/if}
<div class="postbtns">
{if $moderator || !$closed}<a href="{$WWWROOT}interaction/forum/editpost.php?parent={$post->id|escape}" id="btn-reply">{str tag="Reply" section=interaction.forum}</a>{/if}
......@@ -18,7 +18,7 @@
{foreach from=$post->edit item=edit}
<li>
<a href="{$WWWROOT}user/view.php?id={$edit.editor}"
{if $edit.editor == $groupowner} class="groupowner"
{if in_array($edit.editor, $groupadmins)} class="groupadmin"
{elseif $edit.moderator} class="moderator"
{/if}
>
......
......@@ -12,7 +12,7 @@
<td class="forumpostleft">
<div class="posttime">{$post->ctime}</div>
<h5><a href="{$WWWROOT}user/view.php?id={$post->poster}"
{if $post->poster == $groupowner} class="groupowner"
{if in_array($post->poster, $groupadmins)} class="groupadmin"
{elseif $post->moderator} class="moderator"
{/if}
>
......@@ -21,4 +21,4 @@
<h5>{$post->postcount}</h5></td>
<td>{$post->body}</td>
</tr>
</table>
\ No newline at end of file
</table>
......@@ -19,7 +19,7 @@
</td>
<td class="forumposter">
<a href="{$WWWROOT}user/view.php?id={$topic->poster}"
{if $topic->poster == $groupowner} class="groupowner"
{if in_array($topic->poster, $groupadmins)} class="groupadmin"
{elseif $topic->moderator} class="moderator"
{/if}
>
......@@ -31,7 +31,7 @@
<td class="lastpost">
{if !$topic->lastpostdeleted}
<a href="{$WWWROOT}user/view.php?id={$topic->lastposter}"
{if $topic->lastposter == $groupowner} class="groupowner"
{if in_array($topic->lastposter, $groupadmins)} class="groupadmin"
{elseif $topic->lastpostermoderator} class="moderator"
{/if}
>
......
......@@ -21,11 +21,10 @@
<a href="{$WWWROOT}interaction/forum/edittopic.php?forum={$forum->id|escape}">{str tag="newtopic" section="interaction.forum}</a>
</span>
{str tag="groupownerlist" section="interaction.forum"}
<a href="{$WWWROOT}user/view.php?id={$groupowner}" class="groupowner">
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=20&amp;id={$groupowner}" alt="">
{$groupowner|display_name|escape}
</a>
{str tag="groupadminlist" section="interaction.forum"}
{foreach name=groupadmins from=$groupadmins item=groupadmin}<a href="{$WWWROOT}user/view.php?id={$groupadmin}" class="groupadmin">
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=20&amp;id={$groupadmin}" alt="">
{$groupadmin|display_name|escape}</a>{if !$smarty.foreach.groupadmins.last}, {/if}{/foreach}
{if $moderators}
<br>
{str tag="moderatorslist" section="interaction.forum"}
......@@ -107,7 +106,7 @@
<ul id="forumkeylist">
<li><img src="{$closedicon|escape}" alt="{str tag="Closed" section="interaction.forum"}"> {str tag="Closed" section="interaction.forum"}</li>
<li><img src="{$subscribedicon|escape}" alt="{str tag="Subscribed" section="interaction.forum"}"> {str tag="Subscribed" section="interaction.forum"}</li>
<li><span class="groupowner">{str tag="groupowner" section="interaction.forum"}</span></li>
<li><span class="groupadmin">{str tag="groupadmins" section="interaction.forum"}</span></li>
<li><span class="moderator">{str tag="Moderators" section="interaction.forum"}</span></li>
</ul>
......
......@@ -35,7 +35,7 @@ require_once('pieforms/pieform.php');
$topicid = param_integer('id');
$topic = get_record_sql(
'SELECT p.subject, p.poster, p.id AS firstpost, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.id, f.group AS groupid, g.name AS groupname, f.id AS forumid, f.title AS forumtitle, t.closed, sf.forum AS forumsubscribed, st.topic AS topicsubscribed, g.owner
'SELECT p.subject, p.poster, p.id AS firstpost, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.id, f.group AS groupid, g.name AS groupname, f.id AS forumid, f.title AS forumtitle, t.closed, sf.forum AS forumsubscribed, st.topic AS topicsubscribed
FROM {interaction_forum_topic} t
INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted != 1)
INNER JOIN {group} g ON (g.id = f.group AND g.deleted = ?)
......@@ -61,6 +61,8 @@ $topic->canedit = $moderator || user_can_edit_post($topic->poster, $topic->ctime
define('TITLE', $topic->forumtitle . ' - ' . $topic->subject);
$groupadmins = group_get_admin_ids($topic->groupid);
$breadcrumbs = array(
array(
get_config('wwwroot') . 'group/view.php?id=' . $topic->groupid,
......@@ -174,7 +176,7 @@ $smarty->display('interaction:forum:topic.tpl');
*/
function buildpost($postindex, $parentsubject, &$posts){
global $moderator, $topic;
global $moderator, $topic, $groupadmins;
$localposts = $posts;
if ($posts[$postindex]->subject) {
$parentsubject = $posts[$postindex]->subject;
......@@ -190,7 +192,7 @@ function buildpost($postindex, $parentsubject, &$posts){
}
$smarty = smarty_core();
$smarty->assign('post', $posts[$postindex]);
$smarty->assign('groupowner', $topic->owner);
$smarty->assign('groupadmins', $groupadmins);
$smarty->assign('children', $children);
$smarty->assign('moderator', $moderator);
$smarty->assign('closed', $topic->closed);
......
......@@ -41,14 +41,14 @@ $topicsperpage = 25;
$offset = (int)($offset / $topicsperpage) * $topicsperpage;
$forum = get_record_sql(
'SELECT f.title, f.description, f.id, COUNT(t.id) AS topiccount, s.forum AS subscribed, g.id AS groupid, g.name AS groupname, g.owner as groupowner
'SELECT f.title, f.description, f.id, COUNT(t.id) AS topiccount, s.forum AS subscribed, g.id AS groupid, g.name AS groupname
FROM {interaction_instance} f
INNER JOIN {group} g ON (g.id = f."group" AND g.deleted = ?)
LEFT JOIN {interaction_forum_topic} t ON (t.forum = f.id AND t.deleted != 1 AND t.sticky != 1)
LEFT JOIN {interaction_forum_subscription_forum} s ON (s.forum = f.id AND s."user" = ?)
WHERE f.id = ?
AND f.deleted != 1
GROUP BY 1, 2, 3, 5, 6, 7, 8',
GROUP BY 1, 2, 3, 5, 6, 7',
array(0, $userid, $forumid)
);
......@@ -251,10 +251,10 @@ $smarty->assign('heading', TITLE);
$smarty->assign('forum', $forum);
$smarty->assign('moderator', $moderator);
$smarty->assign('admin', $admin);
$smarty->assign('groupadmins', group_get_admin_ids($forum->groupid));
$smarty->assign('stickytopics', $stickytopics);
$smarty->assign('regulartopics', $regulartopics);
$smarty->assign('moderators', $moderators);
$smarty->assign('groupowner', $forum->groupowner);
$smarty->assign('closedicon', theme_get_url('images/closed.gif', 'interaction/forum/'));
$smarty->assign('subscribedicon', theme_get_url('images/subscribed.gif', 'interaction/forum/'));
$smarty->assign('pagination', $pagination['html']);
......
......@@ -2012,7 +2012,7 @@ span.breadcrumbs a {
font-size: 11px;
padding: 0 5px;
}
.groupowner, a.groupowner {
.groupadmin, a.groupadmin {
color: #d32a8a;
}
.moderator, a.moderator{
......
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