Commit 999bd7b4 authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

Change to use template for topics

Single checkbox + buttons for sticky/closed/subscribe stuff
General improvements
parent d566bd7c
<table>
<tr>
<th></th>
{if !$forum->subscribed || $moderator}<th></th>{/if}
<th>{str tag="topic" section="interaction.forum"}</th>
<th>{str tag="poster" section="interaction.forum"}</th>
<th>{str tag="posts" section="interaction.forum"}</th>
{if $moderator}
<th></th>
<th></th>
{/if}
<th></th>
</tr>
{foreach from=$topics item=topic}
<tr>
<td>
{if $topic->closed}C{else}O{/if}
{if $topic->subscribed}S{else}U{/if}
</td>
{if !$forum->subscribed || $moderator}
<td>
<input type="checkbox" name="checkbox[{$topic->id|escape}]">
<input type="hidden" name="topics[{$topic->id|escape}]">
</td>
{/if}
<td>
<a href="{$WWWROOT}interaction/forum/topic.php?id={$topic->id|escape}">{$topic->subject|escape}</a>
<div>{$topic->body|escape}</div>
</td>
<td>
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;size=20x20&amp;id={$topic->poster}" alt="">
{$topic->poster|display_name|escape}
</td>
<td>{$topic->count|escape}</td>
{if $moderator}
</td>
<td><a href="{$WWWROOT}interaction/forum/edittopic.php?id={$topic->id|escape}">{str tag="edit"}</a></td>
<td><a href="{$WWWROOT}interaction/forum/deletetopic.php?id={$topic->id|escape}">{str tag="delete"}</a></td>
{/if}
</tr>
{/foreach}
</table>
\ No newline at end of file
......@@ -19,115 +19,31 @@
{/if}
{$forum->subscribe}
<form action="" method="post">
{if $moderator && ($stickytopics || $regulartopics)}<input type="submit" name="update" value="{str tag="update"}" class="submit">{/if}
{if !$forum->subscribed && ($stickytopics || $regulartopics)}
<input type="submit" name="subscribe" value="{str tag="subscribe" section="interaction.forum"}" class="submit">
{if $moderator}
<input type="submit" name="sticky" value="{str tag="sticky" section="interaction.forum"}" class="submit">
<input type="submit" name="closed" value="{str tag="closed" section="interaction.forum"}" class="submit">
{/if}
{/if}
{if $stickytopics}
<h4>{str tag="stickytopics" section="interaction.forum"}</h4>
<table>
<tr>
<th></th>
<th>{str tag="topic" section="interaction.forum"}</th>
<th>{str tag="poster" section="interaction.forum"}</th>
<th>{str tag="posts" section="interaction.forum"}</th>
{if $moderator}
<th>{str tag="sticky" section="interaction.forum"}</th>
<th>{str tag="closed" section="interaction.forum"}</th>
<th></th>
<th></th>
{/if}
<th></th>
</tr>
{foreach from=$stickytopics item=topic}
<tr>
<td>X</td>
<td>
<a href="{$WWWROOT}interaction/forum/topic.php?id={$topic->id|escape}">{$topic->subject|escape}</a>
<div>{$topic->body|escape}</div>
</td>
<td>
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;size=20x20&amp;id={$topic->poster}" alt="">
{$topic->poster|display_name|escape}
</td>
<td>{$topic->count|escape}</td>
{if $moderator}
<td><input type="checkbox" name="sticky[{$topic->id|escape}]" checked="checked"></td>
<input type=hidden name="prevsticky[{$topic->id|escape}]">
<td>
{if $topic->closed}
<input type="checkbox" name="closed[{$topic->id|escape}]" checked="checked">
<input type=hidden name="prevclosed[{$topic->id|escape}]">
{else}
<input type="checkbox" name="closed[{$topic->id|escape}]">
{/if}
</td>
<td><a href="{$WWWROOT}interaction/forum/edittopic.php?id={$topic->id|escape}">{str tag="edit"}</a></td>
<td><a href="{$WWWROOT}interaction/forum/deletetopic.php?id={$topic->id|escape}">{str tag="delete"}</a></td>
{/if}
{if !$forum->subscribed}
{if $topic->subscribed}
<td><input type="submit" name="subscribe[{$topic->id}]" value="{str tag="unsubscribe" section="interaction.forum"}" class="submit"></td>
{else}
<td><input type="submit" name="subscribe[{$topic->id}]" value="{str tag="subscribe" section="interaction.forum"}" class="submit"></td>
{/if}
{/if}
</tr>
{/foreach}
</table>
{include file="interaction:forum:topics.tpl" topics=$stickytopics moderator=$moderator forum=$forum}
{/if}
{if $regulartopics}
<h4>{str tag="regulartopics" section="interaction.forum"}</h4>
<table>
<tr>
<th></th>
<th>{str tag="topic" section="interaction.forum"}</th>
<th>{str tag="poster" section="interaction.forum"}</th>
<th>{str tag="posts" section="interaction.forum"}</th>
{if $moderator}
<th>{str tag="sticky" section="interaction.forum"}</th>
<th>{str tag="closed" section="interaction.forum"}</th>
<th></th>
<th></th>
{/if}
<th></th>
</tr>
{foreach from=$regulartopics item=topic}
<tr>
<td>X</td>
<td>
<a href="{$WWWROOT}interaction/forum/topic.php?id={$topic->id|escape}">{$topic->subject|escape}</a>
<div>{$topic->body|escape}</div>
</td>
<td>
<img src="{$WWWROOT}thumb.php?type=profileicon&amp;size=20x20&amp;id={$topic->poster}" alt="">
{$topic->poster|display_name|escape}
</td>
<td>{$topic->count|escape}</td>
{if $moderator}
<td><input type="checkbox" name="sticky[{$topic->id|escape}]"></td>
<td>
{if $topic->closed}
<input type="checkbox" name="closed[{$topic->id|escape}]" checked="checked">
<input type=hidden name="prevclosed[{$topic->id|escape}]">
{else}
<input type="checkbox" name="closed[{$topic->id|escape}]">
{/if}
</td>
<td><a href="{$WWWROOT}interaction/forum/edittopic.php?id={$topic->id|escape}">{str tag="edit"}</a></td>
<td><a href="{$WWWROOT}interaction/forum/deletetopic.php?id={$topic->id|escape}">{str tag="delete"}</a></td>
{/if}
{if !$forum->subscribed}
{if $topic->subscribed}
<td><input type="submit" name="subscribe[{$topic->id}]" value="{str tag="unsubscribe" section="interaction.forum"}" class="submit"></td>
{else}
<td><input type="submit" name="subscribe[{$topic->id}]" value="{str tag="subscribe" section="interaction.forum"}" class="submit"></td>
{/if}
{/if}
</tr>
{/foreach}
</table>
{include file="interaction:forum:topics.tpl" topics=$regulartopics moderator=$moderator forum=$forum}
<span class="center">{$pagination}</span>
{else}
<h4>{str tag="noregulartopics" section="interaction.forum"}</h4>
{/if}
{if !$forum->subscribed && ($stickytopics || $regulartopics)}
<input type="submit" name="subscribe" value="{str tag="subscribe" section="interaction.forum"}" class="submit">
{if $moderator}
<input type="submit" name="sticky" value="{str tag="sticky" section="interaction.forum"}" class="submit">
<input type="submit" name="closed" value="{str tag="closed" section="interaction.forum"}" class="submit">
{/if}
{/if}
</form>
{include file="columnleftend.tpl"}
......
<?php
/**
* This program is part of Mahara
*
......@@ -62,46 +63,60 @@ $admin = (bool)($membership & GROUP_MEMBERSHIP_OWNER);
$moderator = $admin || is_forum_moderator($forumid);
if (isset($_POST['subscribe'])) { // TODO: make safe
$values = array_flip($_POST['subscribe']);
if (isset($values[get_string('subscribe', 'interaction.forum')])) {
insert_record(
'interaction_forum_subscription_topic',
(object)array(
'topic' => $values[get_string('subscribe', 'interaction.forum')],
'user' => $USER->get('id')
)
);
$SESSION->add_ok_msg(get_string('topicsuccessfulsubscribe', 'interaction.forum'));
if (isset($_POST['topics'])) {
$topics = array_keys($_POST['topics']);
if (isset($_POST['checkbox'])) {
$checked = array_keys($_POST['checkbox']);
}
else {
delete_records(
'interaction_forum_subscription_topic',
'topic', $values[get_string('unsubscribe', 'interaction.forum')],
'user', $USER->get('id')
);
$SESSION->add_ok_msg(get_string('topicsuccessfulunsubscribe', 'interaction.forum'));
}
}
if ($moderator && isset($_POST['update'])) { // TODO: make safe + nice
if (!isset($_POST['sticky']) || !is_numeric(implode(array_keys($_POST['sticky'])))) {
$_POST['sticky'] = array();
}
if (!isset($_POST['closed']) || !is_numeric(implode(array_keys($_POST['closed'])))) {
$_POST['closed'] = array();
$checked = array();
}
if (!isset($_POST['prevsticky']) || !is_numeric(implode(array_keys($_POST['prevsticky'])))) {
$_POST['prevsticky'] = array();
// check that user is only messing with topics from this forum
$alltopics = get_column('interaction_forum_topic', 'id', 'forum', $forumid, 'deleted', 0);
if ($topics == array_intersect($topics, $alltopics) && $checked == array_intersect($checked, $topics)) { // $topics and $checked are ok
$unchecked = array_diff($topics, $checked);
db_begin();
if ($moderator && isset($_POST['sticky'])) {
if (!empty($checked)) {
set_field_select('interaction_forum_topic', 'sticky', 1, 'id in (' . implode($checked, ',') . ')', array());
}
if (!empty($unchecked)) {
set_field_select('interaction_forum_topic', 'sticky', 0, 'id in (' . implode($unchecked, ',') . ')', array());
}
$SESSION->add_ok_msg(get_string('topicstickysuccess', 'interaction.forum'));
}
else if ($moderator && isset($_POST['closed'])) {
if (!empty($checked)) {
set_field_select('interaction_forum_topic', 'sticky', 1, 'id in (' . implode($checked, ',') . ')', array());
}
if (!empty($unchecked)) {
set_field_select('interaction_forum_topic', 'sticky', 0, 'id in (' . implode($unchecked, ',') . ')', array());
}
$SESSION->add_ok_msg(get_string('topicclosedsuccess', 'interaction.forum'));
}
else if (isset($_POST['subscribe']) && !$forum->subscribed) {
if (!empty($unchecked)) {
delete_records_sql('DELETE FROM {interaction_forum_subscription_topic}
WHERE topic in (' . implode($unchecked, ',') . ') AND "user" = ?',
array($USER->get('id')
));
}
foreach ($checked as $key => $value) {
insert_record('interaction_forum_subscription_topic',
(object) array(
'user' => $USER->get('id'),
'topic' => $value
));
}
$SESSION->add_ok_msg(get_string('topicsubscribesuccess', 'interaction.forum'));
}
db_commit();
redirect('/interaction/forum/view.php?id=' . $forumid);
}
if (!isset($_POST['prevclosed']) || !is_numeric(implode(array_keys($_POST['prevclosed'])))) {
$_POST['prevclosed'] = array();
else {
$SESSION->add_error_msg(get_string('topicupdatefailed', 'interaction.forum'));
redirect('/interaction/forum/view.php?id=' . $forumid);
}
updatetopics($_POST['sticky'], $_POST['prevsticky'], 'sticky = 1');
updatetopics($_POST['prevsticky'], $_POST['sticky'], 'sticky = 0');
updatetopics($_POST['closed'], $_POST['prevclosed'], 'closed = 1');
updatetopics($_POST['prevclosed'], $_POST['closed'], 'closed = 0');
$SESSION->add_ok_msg(get_string('updatesuccessful', 'interaction.forum'));
}
$breadcrumbs = array(
......@@ -122,20 +137,20 @@ $breadcrumbs = array(
require_once('pieforms/pieform.php');
$forum->subscribe = pieform(array(
'name' => 'subscribe_forum',
'name' => 'subscribe_forum',
'autofocus' => false,
'elements' => array(
'submit' => array(
'type' => 'submit',
'type' => 'submit',
'value' => $forum->subscribed ? get_string('unsubscribe', 'interaction.forum') : get_string('subscribe', 'interaction.forum')
),
'forum' => array(
'type' => 'hidden',
'value' => $forumid
'type' => 'hidden',
'value' => $forumid
),
'redirect' => array(
'type' => 'hidden',
'value' => '/interaction/forum/view.php?id=' . $forumid . '&offset=' . $offset
'type' => 'hidden',
'value' => '/interaction/forum/view.php?id=' . $forumid . '&amp;offset=' . $offset
)
)
));
......@@ -186,16 +201,4 @@ $smarty->assign('stickytopics', $stickytopics);
$smarty->assign('regulartopics', $regulartopics);
$smarty->assign('pagination', $pagination['html']);
$smarty->display('interaction:forum:view.tpl');
function updatetopics($new, $old, $set) {
$keydiff = array_keys(array_diff_key($new, $old));
if (!empty($keydiff)) {
execute_sql(
'UPDATE {interaction_forum_topic}
SET ' . $set .
'WHERE id in (' . implode(',', $keydiff) . ')'
);
}
}
?>
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