Commit a63ca9bb authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan

Split out post as a template

Minor additions + fixups (adding messages, descriptions, etc)
parent 363f4b8d
......@@ -29,6 +29,7 @@ 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(
......@@ -38,7 +39,7 @@ $post = get_record_sql(
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_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 = ?
......@@ -61,8 +62,6 @@ if (!$moderator) {
throw new AccessDeniedException(get_string('cantdeletepost', 'interaction.forum'));
}
define('TITLE', get_string('deletepostvariable', 'interaction.forum', $post->subject));
$breadcrumbs = array(
array(
get_config('wwwroot') . 'group/view.php?id=' . $post->group,
......@@ -90,6 +89,7 @@ require_once('pieforms/pieform.php');
$form = pieform(array(
'name' => 'deletepost',
'autofocus' => false,
'elements' => array(
'title' => array(
'value' => get_string('deletepostsure', 'interaction.forum'),
......@@ -98,19 +98,27 @@ $form = pieform(array(
'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $post->topic,
),
'post' => array(
'type' => 'hidden',
'value' => $postid
),
'topic' => array(
'type' => 'hidden',
'value' => $post->topic
)
)
));
function deletepost_submit(Pieform $form, $values) {
global $postid;
global $post;
global $SESSION;
update_record(
'interaction_forum_post',
array('deleted' => 1),
array('id' => $postid)
array('id' => $values['post'])
);
redirect('/interaction/forum/topic.php?id=' . $post->topic);
$SESSION->add_ok_msg(get_string('deletepostsuccess', 'interaction.forum'));
redirect('/interaction/forum/topic.php?id=' . $values['topic']);
}
$smarty = smarty();
......
......@@ -89,6 +89,7 @@ require_once('pieforms/pieform.php');
$form = pieform(array(
'name' => 'deletepost',
'autofocus' => false,
'elements' => array(
'title' => array(
'value' => get_string('deletetopicsure', 'interaction.forum'),
......@@ -102,7 +103,9 @@ $form = pieform(array(
));
function deletepost_submit(Pieform $form, $values) {
global $SESSION;
$topicid = param_integer('id');
db_begin();
update_record(
'interaction_forum_topic',
array('deleted' => 1),
......@@ -114,6 +117,8 @@ function deletepost_submit(Pieform $form, $values) {
WHERE id = ?',
array($topicid)
);
db_commit();
$SESSION->add_ok_msg(get_string('deletetopicsuccess', 'interaction.forum'));
redirect('/interaction/forum/view.php?id=' . $forumid);
}
......
......@@ -139,8 +139,9 @@ if (isset($topicid)) {
require_once('pieforms/pieform.php');
$editform = array(
'name' => 'edittopic',
'name' => isset($topic) ? 'edittopic' : 'addtopic',
'method' => 'post',
'autofocus' => false,
'elements' => array(
'subject' => array(
'type' => 'text',
......@@ -162,11 +163,13 @@ $editform = array(
'sticky' => array(
'type' => 'checkbox',
'title' => get_string('sticky', 'interaction.forum'),
'description' => get_string('stickydescription', 'interaction.forum'),
'defaultvalue' => isset($topic) && $topic->sticky == 1 ? 'checked' : null
),
'closed' => array(
'type' => 'checkbox',
'title' => get_string('closed', 'interaction.forum'),
'description' => get_string('closeddescription', 'interaction.forum'),
'defaultvalue' => isset($topic) && $topic->closed == 1 ? 'checked' : null
),
'submit' => array(
......@@ -187,72 +190,75 @@ if(!$moderator){
$editform = pieform($editform);
function addtopic_submit(Pieform $form, $values) {
global $USER, $SESSION;
$forumid = param_integer('forum');
db_begin();
$topicid = insert_record(
'interaction_forum_topic',
(object)array(
'forum' => $forumid,
'sticky' => isset($values['sticky']) && $values['sticky'] ? 1 : 0,
'closed' => isset($values['closed']) && $values['closed'] ? 1 : 0
),
'id',
true
);
insert_record(
'interaction_forum_post',
(object)array(
'topic' => $topicid,
'poster' => $USER->get('id'),
'subject' => $values['subject'],
'body' => $values['body'],
'ctime' => db_format_timestamp(time())
),
'id'
);
db_commit();
$SESSION->add_ok_msg(get_string('addtopicsuccess', 'interaction.forum'));
redirect('/interaction/forum/topic.php?id='.$topicid);
}
function edittopic_submit(Pieform $form, $values) {
global $USER;
$topicid = param_integer('id',0);
if ($topicid==0) {
$forumid = param_integer('forum');
db_begin();
$topicid = insert_record(
'interaction_forum_topic',
(object)array(
'forum' => $forumid,
'sticky' => isset($values['sticky']) && $values['sticky'] ? 1 : 0,
'closed' => isset($values['closed']) && $values['closed'] ? 1 : 0
),
'id',
true
);
insert_record(
'interaction_forum_post',
(object)array(
'topic' => $topicid,
'poster' => $USER->get('id'),
'subject' => $values['subject'],
'body' => $values['body'],
'ctime' => db_format_timestamp(time())
),
'id'
);
db_commit();
}
else {
$post = get_record_sql(
'SELECT id
FROM {interaction_forum_post}
WHERE parent IS NULL
AND topic = ?',
array($topicid)
);
db_begin();
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',
array(
'subject' => $values['subject'],
'body' => $values['body']
),
array('id' => $post->id)
);
insert_record(
'interaction_forum_edit',
(object)array(
'user' => $USER->get('id'),
'post' => $post->id,
'ctime' => db_format_timestamp(time())
)
);
if(isset($values['sticky'])){
update_record(
'interaction_forum_post',
'interaction_forum_topic',
array(
'subject' => $values['subject'],
'body' => $values['body']
'sticky' => isset($values['sticky']) && $values['sticky'] == 1 ? 1 : 0,
'closed' => isset($values['closed']) && $values['closed'] == 1 ? 1 : 0
),
array('id' => $post->id)
);
insert_record(
'interaction_forum_edit',
(object)array(
'user' => $USER->get('id'),
'post' => $post->id,
'ctime' => db_format_timestamp(time())
)
array('id' => $topicid)
);
if(isset($values['sticky'])){
update_record(
'interaction_forum_topic',
array(
'sticky' => isset($values['sticky']) && $values['sticky'] == 1 ? 1 : 0,
'closed' => isset($values['closed']) && $values['closed'] == 1 ? 1 : 0
),
array('id' => $topicid)
);
}
db_commit();
}
db_commit();
$SESSION->add_ok_msg(get_string('edittopicsuccess', 'interaction.forum'));
redirect('/interaction/forum/topic.php?id='.$topicid);
}
......
......@@ -27,6 +27,7 @@
$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['cantaddtopic'] = 'You are not allowed to add topics to this forum';
......@@ -40,22 +41,25 @@ $string['cantfindtopic'] = 'Couldn\'t find topic with id %s';
$string['cantviewforums'] = 'You are not allowed to view forums in this group';
$string['cantviewtopic'] = 'You are not allowed to view topics in this forum';
$string['closed'] = 'Closed';
$string['closeddescription'] = 'Closed topics can only be replied to by moderators and the group owner';
$string['count'] = 'Count';
$string['currentmoderators'] = 'Current Moderators';
$string['delete'] = 'Delete';
$string['deleteforum'] = 'Delete forum';
$string['deletedpost'] = 'This post has been deleted';
$string['deletepost'] = 'Delete post';
$string['deletepostvariable'] = 'Delete post \'%s\'';
$string['deletepostsuccess'] = 'Post deleted successfully';
$string['deletepostsure'] = 'Are you sure you want to do this? It cannot be undone.';
$string['deletetopic'] = 'Delete topic';
$string['deletetopicvariable'] = 'Delete topic \'%s\'';
$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['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['moderators'] = 'Moderators';
......@@ -80,6 +84,7 @@ $string['re'] ='Re: %s';
$string['regulartopics'] = 'Regular topics';
$string['reply'] = 'Reply';
$string['sticky'] = 'Sticky';
$string['stickydescription'] = 'Sticky topics are at the top of every page';
$string['stickytopics'] = 'Sticky topics';
$string['subscribe'] = 'Subscribe';
$string['subject'] = 'Subject';
......
......@@ -7,13 +7,9 @@
{include file="interaction:forum:breadcrumbs.tpl" breadcrumbs=$breadcrumbs}
<h4>{$post->subject|escape}</h4>
<h5>{$post->poster|display_name|escape}</h5>
<h5>{str tag="posts" section=interaction.forum} {$post->count|escape}</h5>
<div><img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=100&amp;id={$post->poster}" alt=""></div>
<p>{$post->body}</p>
<div class="message">{$deleteform}</div>
{$deleteform}
{include file="interaction:forum:simplepost.tpl" post=$post}
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
......@@ -7,13 +7,9 @@
{include file="interaction:forum:breadcrumbs.tpl" breadcrumbs=$breadcrumbs}
<h4>{$topic->subject|escape}</h4>
<h5>{$topic->poster|display_name|escape}</h5>
<h5>{str tag="posts" section=interaction.forum} {$topic->count|escape}</h5>
<div><img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=100&amp;id={$topic->poster}" alt=""></div>
<p>{$topic->body}</p>
<div class="message">{$deleteform}</div>
{$deleteform}
{include file="interaction:forum:simplepost.tpl" post=$topic}
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
{if $post->deleted}
<h4>{str tag="deletedpost" section="interaction.forum}</h4>
{else}
<h4>{$post->subject|escape}</h4>
<h5>{$post->poster|display_name|escape}</h5>
<h5>{str tag="postsvariable" section=interaction.forum args=$post->count}</h5>
<div><img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=100&amp;id={$post->poster}" alt=""></div>
{$post->body}
{include file="interaction:forum:simplepost.tpl" post=$post}
<div>
{if $moderator || !$closed}<a href="{$WWWROOT}interaction/forum/editpost.php?parent={$post->id|escape}">{str tag="reply" section=interaction.forum}</a>{/if}
{if $moderator || (!$closed && $post->editor)} | {/if}
......
{if $post->subject}<h4>{$post->subject|escape}</h4>{/if}
<h5>{$post->poster|display_name|escape}</h5>
<h5>{str tag="posts" section=interaction.forum} {$post->count|escape}</h5>
<div><img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=100&amp;id={$post->poster}" alt=""></div>
{$post->body}
\ No newline at end of file
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