Commit 75a2bb18 authored by Nigel McNie's avatar Nigel McNie

Merge branch 'groupforums' of git+ssh://git.catalyst.net.nz/var/git/mahara into groupforums

Conflicts:

	htdocs/interaction/forum/lang/en.utf8/interaction.forum.php
	htdocs/interaction/forum/lib.php
parents 8b1759a1 a18397f1
......@@ -29,11 +29,10 @@ define('MENUITEM', 'groups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('interaction' ,'forum');
require_once('group.php');
define('TITLE', get_string('deletepost', 'interaction.forum'));
$postid = param_integer('id');
$post = get_record_sql(
'SELECT p.subject, p.body, p.topic, p.parent, p.poster, t.forum, p2.subject as topicsubject, f.group, f.title as forumtitle, g.name as groupname, COUNT(p3.*)
'SELECT p.subject, p.body, p.topic, p.parent, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.forum, p2.subject AS topicsubject, f.group, f.title AS forumtitle, g.name AS groupname, COUNT(p3.*)
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)
......@@ -44,10 +43,11 @@ $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',
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11',
array($postid)
);
if (!$post) {
throw new NotFoundException(get_string('cantfindpost', 'interaction.forum', $postid));
}
......@@ -62,6 +62,9 @@ if (!$moderator) {
throw new AccessDeniedException(get_string('cantdeletepost', 'interaction.forum'));
}
define('TITLE', get_string('deletepost', 'interaction.forum') . ' - ' . $post->topicsubject);
$post->ctime = strftime(get_string('strftimerecentfull'), $post->ctime);
$breadcrumbs = array(
array(
get_config('wwwroot') . 'group/view.php?id=' . $post->group,
......@@ -123,7 +126,6 @@ function deletepost_submit(Pieform $form, $values) {
$smarty = smarty();
$smarty->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('topicsubject', $post->topicsubject);
$smarty->assign('heading', TITLE);
$smarty->assign('post', $post);
$smarty->assign('deleteform', $form);
......
......@@ -32,7 +32,7 @@ require('group.php');
$topicid = param_integer('id');
$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.*), t.closed
'SELECT f."group", f.id AS forumid, f.title, g.name AS groupname, p.poster, p.subject, p.body, COUNT(p2.*), ' . db_format_tsfield('p.ctime', 'ctime') . ', t.closed
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
......@@ -42,7 +42,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',
GROUP BY 1, 2, 3, 4, 5, 6, 7, 9, 10',
array($topicid)
);
......@@ -56,11 +56,13 @@ $admin = (bool)($membership & GROUP_MEMBERSHIP_OWNER);
$moderator = $admin || is_forum_moderator((int)$topic->forumid);
$topic->ctime = strftime(get_string('strftimerecentfull'), $topic->ctime);
if (!$moderator) {
throw new AccessDeniedException(get_string('cantdeletetopic', 'interaction.forum'));
}
define('TITLE', get_string('deletetopicvariable', 'interaction.forum', $topic->subject));
define('TITLE', $topic->title . ' - ' . get_string('deletetopicvariable', 'interaction.forum', $topic->subject));
$breadcrumbs = array(
array(
......@@ -88,7 +90,7 @@ $breadcrumbs = array(
require_once('pieforms/pieform.php');
$form = pieform(array(
'name' => 'deletepost',
'name' => 'deletetopic',
'autofocus' => false,
'elements' => array(
'title' => array(
......@@ -98,28 +100,24 @@ $form = pieform(array(
'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $topicid,
),
'forum' => array(
'type' => 'hidden',
'value' => $topic->forumid
)
)
));
function deletepost_submit(Pieform $form, $values) {
function deletetopic_submit(Pieform $form, $values) {
global $SESSION;
$topicid = param_integer('id');
db_begin();
update_record(
'interaction_forum_topic',
array('deleted' => 1),
array('id' => $topicid)
);
$forumid = get_field_sql(
'SELECT forum
FROM interaction_forum_topic
WHERE id = ?',
array($topicid)
);
db_commit();
$SESSION->add_ok_msg(get_string('deletetopicsuccess', 'interaction.forum'));
redirect('/interaction/forum/view.php?id=' . $forumid);
redirect('/interaction/forum/view.php?id=' . $values['forum']);
}
$smarty = smarty();
......
......@@ -33,57 +33,64 @@ require('group.php');
$userid = $USER->get('id');
$postid = param_integer('id',0);
$topicid = 0;
if ($postid==0) {
$postid = param_integer('id', 0);
if ($postid == 0) { // post reply
unset($postid);
define('TITLE', get_string('postreply','interaction.forum'));
$parentid = param_integer('parent');
$topic = get_record_sql(
'SELECT p.topic AS id, p2.subject, t.closed, f.id AS forum, f.title AS forumtitle, f.group, g.name AS groupname
$parent = get_record_sql(
'SELECT p.subject, p.body, p.topic, p.parent, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.id AS topicid, t.forum, t.closed AS topicclosed, p2.subject AS topicsubject, f.group, f.title AS forumtitle, g.name AS groupname, COUNT(p3.*)
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)
INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted != 1)
INNER JOIN {group} g ON g.id = f.group
INNER JOIN {interaction_forum_post} p3 ON (p.poster = p3.poster AND p3.deleted != 1)
INNER JOIN {interaction_forum_topic} t2 ON (t2.deleted != 1 AND p3.topic = t2.id)
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',
AND p.deleted != 1
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13',
array($parentid)
);
if (!$topic) {
if (!$parent) {
throw new NotFoundException(get_string('cantfindpost', 'interaction.forum', $parentid));
}
$membership = user_can_access_group((int)$topic->group);
$membership = user_can_access_group((int)$parent->group);
$admin = (bool)($membership & GROUP_MEMBERSHIP_OWNER);
$moderator = $admin || is_forum_moderator((int)$topic->forum);
$moderator = $admin || is_forum_moderator((int)$parent->forum);
if (!$membership || (!$moderator && $topic->closed)) {
throw new AccessDeniedException(get_string('cantaddpost', 'interaction.forum'));
if (!$membership) {
throw new AccessDeniedException(get_string('cantaddposttoforum', 'interaction.forum'));
}
if (!$moderator && $parent->topicclosed) {
throw new AccessDeniedException(get_string('cantaddposttotopic', 'interaction.forum'));
}
$topicid = $topic->id;
$topicsubject = $topic->subject;
define('TITLE', $parent->topicsubject . ' - ' . get_string('postreply','interaction.forum'));
$topicid = $parent->topicid;
$parent->ctime = strftime(get_string('strftimerecentfull'), $parent->ctime);
$breadcrumbs = array(
array(
get_config('wwwroot') . 'group/view.php?id=' . $topic->group,
$topic->groupname
get_config('wwwroot') . 'group/view.php?id=' . $parent->group,
$parent->groupname
),
array(
get_config('wwwroot') . 'interaction/forum/index.php?group=' . $topic->group,
get_config('wwwroot') . 'interaction/forum/index.php?group=' . $parent->group,
get_string('nameplural', 'interaction.forum')
),
array(
get_config('wwwroot') . 'interaction/forum/view.php?id=' . $topic->forum,
$topic->forumtitle
get_config('wwwroot') . 'interaction/forum/view.php?id=' . $parent->forum,
$parent->forumtitle
),
array(
get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $topicid,
$topic->subject
$parent->topicsubject
),
array(
get_config('wwwroot') . 'interaction/forum/editpost.php?parent=' . $parentid,
......@@ -91,11 +98,9 @@ if ($postid==0) {
)
);
}
if (isset($postid)) {
define('TITLE', get_string('editpost','interaction.forum'));
else { // edit post
$post = get_record_sql(
'SELECT p.subject, p.body, p.parent, p.topic, p.poster, p.ctime, t.forum, p2.subject AS topicsubject, f.title AS forumtitle, f.group, g.name AS groupname
'SELECT p.subject, p.body, p.parent, p.topic, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.forum, p2.subject AS topicsubject, f.title AS forumtitle, f.group, g.name AS groupname
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)
......@@ -111,7 +116,6 @@ if (isset($postid)) {
}
$topicid = $post->topic;
$topicsubject = $post->topicsubject;
$membership = user_can_access_group((int)$post->group);
......@@ -119,12 +123,19 @@ if (isset($postid)) {
$moderator = $admin || is_forum_moderator((int)$post->forum);
if (!$moderator &&
($post->poster != $userid
|| (time() - strtotime($post->ctime)) > (30 * 60))) {
// no record for edits to own posts with 30 minutes
if ($post->poster == $userid && $post->ctime > (time() - 30 * 60)) {
$post->editrecord = false;
}
else if ($moderator) {
$post->editrecord = true;
}
else {
throw new AccessDeniedException(get_string('canteditpost', 'interaction.forum'));
}
define('TITLE', $post->topicsubject . ' - ' . get_string('editpost','interaction.forum'));
$breadcrumbs = array(
array(
get_config('wwwroot') . 'group/view.php?id=' . $post->group,
......@@ -140,7 +151,7 @@ if (isset($postid)) {
),
array(
get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $topicid,
$topicsubject
$post->topicsubject
),
array(
get_config('wwwroot') . 'interaction/forum/editpost.php?id=' . $postid,
......@@ -174,7 +185,7 @@ require_once('pieforms/pieform.php');
$editform = pieform(array(
'name' => 'editpost',
'method' => 'post',
'successcallback' => isset($post) ? 'editpost_submit' : 'addpost_submit',
'elements' => array(
'subject' => array(
'type' => 'text',
......@@ -199,71 +210,71 @@ $editform = pieform(array(
isset($post) ? get_string('edit') : get_string('post','interaction.forum'),
get_string('cancel')
),
'goto' => get_config('wwwroot') . 'interaction/forum/topic.php?id='.$topicid
'goto' => get_config('wwwroot') . 'interaction/forum/topic.php?id='.$topicid
),
'topic' => array(
'type' => 'hidden',
'value' => $topicid
),
'editrecord' => array(
'type' => 'hidden',
'value' => isset($post) ? $post->editrecord : false
)
),
));
function editpost_submit(Pieform $form, $values) {
global $USER;
$postid = param_integer('id',0);
if ($postid==0) {
$parentid = param_integer('parent');
$topic = get_record_sql(
'SELECT topic AS id
FROM {interaction_forum_post}
WHERE id = ?',
array($parentid)
);
global $USER, $SESSION;
$postid = param_integer('id');
db_begin();
update_record(
'interaction_forum_post',
array(
'subject' => $values['subject'],
'body' => $values['body']
),
array('id' => $postid)
);
if ($values['editrecord']) {
insert_record(
'interaction_forum_post',
'interaction_forum_edit',
(object)array(
'topic' => $topic->id,
'poster' => $USER->get('id'),
'parent' => $parentid,
'subject' => $values['subject'],
'body' => $values['body'],
'ctime' => db_format_timestamp(time())
),
'id'
);
}
else {
$topic = get_record_sql(
'SELECT topic AS id, poster, ctime AS posttime
FROM {interaction_forum_post}
WHERE id = ?',
array($postid)
);
update_record(
'interaction_forum_post',
array(
'subject' => $values['subject'],
'body' => $values['body']
),
array('id' => $postid)
'user' => $USER->get('id'),
'post' => $postid,
'ctime' => db_format_timestamp(time())
)
);
if ($topic->poster != $USER->get('id') ||
(time() - strtotime($topic->posttime)) > (30 * 60)) {
insert_record(
'interaction_forum_edit',
(object)array(
'user' => $USER->get('id'),
'post' => $postid,
'ctime' => db_format_timestamp(time())
)
);
}
}
redirect('/interaction/forum/topic.php?id='.$topic->id);
db_commit();
$SESSION->add_ok_msg(get_string('editpostsuccess', 'interaction.forum'));
redirect('/interaction/forum/topic.php?id=' . $values['topic']);
}
function addpost_submit(Pieform $form, $values) {
global $USER, $SESSION;
$parentid = param_integer('parent');
insert_record(
'interaction_forum_post',
(object)array(
'topic' => $values['topic'],
'poster' => $USER->get('id'),
'parent' => $parentid,
'subject' => $values['subject'],
'body' => $values['body'],
'ctime' => db_format_timestamp(time())
)
);
$SESSION->add_ok_msg(get_string('addpostsuccess', 'interaction.forum'));
redirect('/interaction/forum/topic.php?id=' . $values['topic']);
}
$smarty = smarty();
$smarty->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('topicsubject', $topicsubject);
$smarty->assign('heading', TITLE);
$smarty->assign('topic', $topicsubject);
$smarty->assign('editform', $editform);
if (isset($parent)) {
$smarty->assign('parent', $parent);
}
if (isset($inlinejs)) {
$smarty->assign('INLINEJAVASCRIPT', $inlinejs);
}
......
......@@ -31,14 +31,12 @@ safe_require('interaction', 'forum');
require_once('group.php');
$userid = $USER->get('id');
$moderator = false;
$topicid = param_integer('id',0);
if ($topicid==0) {
$topicid = param_integer('id', 0);
if ($topicid == 0) { // new topic
unset($topicid);
define('TITLE', get_string('addtopic','interaction.forum'));
$forumid = param_integer('forum');
$forum = get_record_sql(
'SELECT f.group AS group, f.title, g.name as groupname
'SELECT f.group AS group, f.title, g.name AS groupname
FROM {interaction_instance} f
INNER JOIN {group} g ON g.id = f.group
WHERE f.id = ?
......@@ -50,7 +48,6 @@ if ($topicid==0) {
throw new NotFoundException(get_string('cantfindforum', 'interaction.forum', $forumid));
}
$forumtitle = $forum->title;
$membership = user_can_access_group((int)$forum->group);
$admin = (bool)($membership & GROUP_MEMBERSHIP_OWNER);
......@@ -61,6 +58,8 @@ if ($topicid==0) {
throw new AccessDeniedException(get_string('cantaddtopic', 'interaction.forum'));
}
define('TITLE', $forum->title . ' - ' . get_string('addtopic','interaction.forum'));
$breadcrumbs = array(
array(
get_config('wwwroot') . 'group/view.php?id=' . $forum->group,
......@@ -81,10 +80,9 @@ if ($topicid==0) {
);
}
if (isset($topicid)) {
define('TITLE', get_string('edittopic','interaction.forum'));
else { // edit topic
$topic = get_record_sql(
'SELECT p.subject, p.body, p.topic AS id, t.sticky, t.closed, f.id as forumid, f.group AS group, f.title, g.name AS groupname
'SELECT p.subject, p.id AS postid, p.body, p.topic AS id, t.sticky, t.closed, f.id AS forumid, f.group AS group, f.title, g.name AS groupname
FROM {interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t ON (p.topic = t.id AND t.deleted != 1)
INNER JOIN {interaction_instance} f ON (f.id = t.forum AND f.deleted != 1)
......@@ -99,7 +97,6 @@ if (isset($topicid)) {
}
$forumid = $topic->forumid;
$forumtitle = $topic->title;
$membership = user_can_access_group((int)$topic->group);
......@@ -111,6 +108,8 @@ if (isset($topicid)) {
throw new AccessDeniedException(get_string('cantedittopic', 'interaction.forum'));
}
define('TITLE', $topic->title . ' - ' . get_string('edittopic','interaction.forum'));
$breadcrumbs = array(
array(
get_config('wwwroot') . 'group/view.php?id=' . $topic->group,
......@@ -180,6 +179,10 @@ $editform = array(
),
'goto' => get_config('wwwroot') . 'interaction/forum/' . (isset($topic) ? 'topic.php?id='.$topicid : 'view.php?id='.$forumid)
),
'post' => array(
'type' => 'hidden',
'value' => isset($topic) ? $topic->postid : false
)
),
);
......@@ -200,9 +203,7 @@ function addtopic_submit(Pieform $form, $values) {
'forum' => $forumid,
'sticky' => isset($values['sticky']) && $values['sticky'] ? 1 : 0,
'closed' => isset($values['closed']) && $values['closed'] ? 1 : 0
),
'id',
true
), 'id', true
);
insert_record(
'interaction_forum_post',
......@@ -212,8 +213,7 @@ function addtopic_submit(Pieform $form, $values) {
'subject' => $values['subject'],
'body' => $values['body'],
'ctime' => db_format_timestamp(time())
),
'id'
)
);
db_commit();
$SESSION->add_ok_msg(get_string('addtopicsuccess', 'interaction.forum'));
......@@ -223,13 +223,6 @@ function addtopic_submit(Pieform $form, $values) {
function edittopic_submit(Pieform $form, $values) {
global $SESSION, $USER;
$topicid = param_integer('id');
$post = get_record_sql(
'SELECT id
FROM {interaction_forum_post}
WHERE parent IS NULL
AND topic = ?',
array($topicid)
);
db_begin();
update_record(
'interaction_forum_post',
......@@ -237,13 +230,13 @@ function edittopic_submit(Pieform $form, $values) {
'subject' => $values['subject'],
'body' => $values['body']
),
array('id' => $post->id)
array('id' => $values['post'])
);
insert_record(
'interaction_forum_edit',
(object)array(
'user' => $USER->get('id'),
'post' => $post->id,
'post' => $values['post'],
'ctime' => db_format_timestamp(time())
)
);
......@@ -265,7 +258,6 @@ function edittopic_submit(Pieform $form, $values) {
$smarty = smarty();
$smarty->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('heading', TITLE);
$smarty->assign('forum', $forumtitle);
$smarty->assign('editform', $editform);
$smarty->display('interaction:forum:edittopic.tpl');
......
......@@ -29,12 +29,11 @@ define('MENUITEM', 'groups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('group.php');
safe_require('interaction', 'forum');
define('TITLE', get_string('nameplural', 'interaction.forum'));
$groupid = param_integer('group');
if (!record_exists('group', 'id', $groupid)) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
}
$groupname = get_field_sql(
......@@ -52,6 +51,8 @@ if (!$membership) {
$admin = (bool)($membership & GROUP_MEMBERSHIP_OWNER);
define('TITLE', $groupname . ' - ' . get_string('nameplural', 'interaction.forum'));
$breadcrumbs = array(
array(
get_config('wwwroot') . 'group/view.php?id=' . $groupid,
......@@ -97,6 +98,10 @@ if ($forums) {
'redirect' => array(
'type' => 'hidden',
'value' => '/interaction/forum/index.php?group=' . $groupid
),
'type' => array(
'type' => 'hidden',
'value' => $forum->subscribed ? 'unsubscribe' : 'subscribe'
)
)
));
......@@ -106,7 +111,7 @@ if ($forums) {
$smarty = smarty();
$smarty->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('groupid', $groupid);
$smarty->assign('groupname', $groupname);
$smarty->assign('heading', TITLE);
$smarty->assign('admin', $admin);
$smarty->assign('forums', $forums);
$smarty->display('interaction:forum:index.tpl');
......
......@@ -25,11 +25,13 @@
*
*/
$string['addpostsuccess'] = 'Added post successfully';
$string['addtitle'] = 'Add forum';
$string['addtopic'] = 'Add topic';
$string['addtopicsuccess'] = 'Added topic successfully';
$string['body'] = 'Body';
$string['cantaddpost'] = 'You are not allowed to post in this forum';
$string['cantaddposttoforum'] = 'You are not allowed to post in this forum';
$string['cantaddposttotopic'] = 'You are not allowed to post in this topic';
$string['cantaddtopic'] = 'You are not allowed to add topics to this forum';
$string['cantdeletepost'] = 'You are not allowed to delete posts in this forum';
$string['cantdeletetopic'] = 'You are not allowed to delete topics in this forum';
......@@ -57,12 +59,15 @@ $string['deletetopicsuccess'] = 'Topic deleted successfully';
$string['deletetopicsure'] = 'Are you sure you want to do this? It cannot be undone.';
$string['editedon'] = '%s on %s';
$string['editpost'] = 'Edit post';
$string['editpostsuccess'] = 'Post edited successfully';
$string['editstothispost'] = 'Edits to this post:';
$string['edittitle'] = 'Edit forum';
$string['edittopic'] = 'Edit topic';
$string['edittopicsuccess'] = 'Topic edited successfully';
$string['forumsuccessfulsubscribe'] = 'Forum subscribed successfully';
$string['forumsuccessfulunsubscribe'] = 'Forum unsubscribed successfully';
$string['lastpost'] = 'Last post';
$string['lastposton'] = '%s on %s';
$string['moderators'] = 'Moderators';
$string['moderatorsdescription'] = 'Moderators can edit and delete topics and posts. They can also open, close, set and unset topics as sticky';
$string['name'] = 'Forum';
......@@ -72,8 +77,10 @@ $string['newforumpostin'] = 'New forum post in %s';
$string['newpost'] = 'New post: ';
$string['newtopic'] = 'New topic';
$string['noforums'] = 'There are no forums in this group';
$string['noregulartopics'] = 'There are no regular topics in this forum';
$string['nostickytopics'] = 'There are no sticky topics in this forum';
$string['notopics'] = 'There are no topics in this forum';
$string['open'] = 'Open';
$string['order'] = 'Order';
$string['orderdescription'] = 'Choose where you want the forum to be ordered compared to the other forums';
$string['post'] = 'Post';
$string['postedin'] = '%s posted in %s';
$string['poster'] = 'Poster';
......@@ -84,22 +91,31 @@ $string['potentialmoderators'] = 'Potential Moderators';