Commit d566bd7c authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

Changed breadcrumbs

Added start of body to topics
Added profileicons to topic starters
General changing around of how stuff looks + works
parent ce310b5f
......@@ -3,42 +3,50 @@
{include file="columnleftstart.tpl"}
<p>
<a href="{$breadcrumbs[0][0]|escape}">{$breadcrumbs[0][1]|escape}</a>
{foreach from=$breadcrumbs[1] item=item}
&raquo <a href="{$item[0]|escape}">{$item[1]|escape}</a>
{/foreach}
</p>
<h2>{$groupname|escape}</h2>
<h3>{$forum->title|escape}</h3>
<p>{$forum->description}</p>
<h2>{$groupname|escape} - {$forum->title|escape}</h3>
{include file="interaction:forum:breadcrumbs.tpl" breadcrumbs=$breadcrumbs}
<div>
{$forum->description}
</div>
<div class="fr"><span class="addicon">
<a href="{$WWWROOT}interaction/forum/edittopic.php?forum={$forum->id|escape}">{str tag="newtopic" section="interaction.forum}</a>
</span></div>
{if $admin}
<a href="{$WWWROOT}interaction/edit.php?id={$forum->id|escape}">{str tag="edit"}</a>
<a href="{$WWWROOT}interaction/delete.php?id={$forum->id|escape}">{str tag="delete"}</a>
<div>
<a href="{$WWWROOT}interaction/edit.php?id={$forum->id|escape}">{str tag="edittitle" section="interaction.forum"}</a>
| <a href="{$WWWROOT}interaction/delete.php?id={$forum->id|escape}">{str tag="deleteforum" section="interaction.forum"}</a>
</div>
{/if}
{$forum->subscribe}
<form action="" method="post">
{if $moderator}<input type="submit" name="update" value="{str tag="update"}">{/if}
{if $moderator && ($stickytopics || $regulartopics)}<input type="submit" name="update" value="{str tag="update"}" class="submit">{/if}
{if $stickytopics}
<h4>{str tag="stickytopics" section="interaction.forum"}</h4>
<table>
<tr>
<th></th>
<th>{str tag="subject" section="interaction.forum"}</th>
<th>{str tag="topic" section="interaction.forum"}</th>
<th>{str tag="poster" section="interaction.forum"}</th>
<th>{str tag="count" 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></td>
<td>{$topic->poster|display_name|escape}</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>
......@@ -56,35 +64,42 @@
{/if}
{if !$forum->subscribed}
{if $topic->subscribed}
<td><input type="submit" name="subscribe[{$topic->id}]" value="{str tag="unsubscribe" section="interaction.forum"}"></td>
<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"}"></td>
<td><input type="submit" name="subscribe[{$topic->id}]" value="{str tag="subscribe" section="interaction.forum"}" class="submit"></td>
{/if}
{/if}
</tr>
{/foreach}
</table>
{else}
<h4>{str tag="nostickytopics" section="interaction.forum"}</h4>
{/if}
{if $regulartopics}
<h4>{str tag="regulartopics" section="interaction.forum"}</h4>
<table>
<tr>
<th></th>
<th>{str tag="subject" section="interaction.forum"}</th>
<th>{str tag="topic" section="interaction.forum"}</th>
<th>{str tag="poster" section="interaction.forum"}</th>
<th>{str tag="count" 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></td>
<td>{$topic->poster|display_name|escape}</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>
......@@ -101,18 +116,18 @@
{/if}
{if !$forum->subscribed}
{if $topic->subscribed}
<td><input type="submit" name="subscribe[{$topic->id}]" value="{str tag="unsubscribe" section="interaction.forum"}"></td>
<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"}"></td>
<td><input type="submit" name="subscribe[{$topic->id}]" value="{str tag="subscribe" section="interaction.forum"}" class="submit"></td>
{/if}
{/if}
</tr>
{/foreach}
</table>
<span class="center">{$pagination}</span>
{else}
<h4>{str tag="noregulartopics" section="interaction.forum"}</h4>
{/if}
{$pagination}
</form>
{include file="columnleftend.tpl"}
......
......@@ -37,17 +37,11 @@ $userid = $USER->get('id');
$topicsperpage = 25;
$forum = get_record_sql(
'SELECT f.title, f.description, f.id, COUNT(t.*), s.forum AS subscribed, g.id as groupid, g.name as groupname
'SELECT f.title, f.description, f.id, COUNT(t.*), s.forum AS subscribed, g.id as group, g.name as groupname
FROM {interaction_instance} f
INNER JOIN {group} g
ON g.id = f."group"
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" = ?
INNER JOIN {group} g ON g.id = f."group"
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',
......@@ -58,7 +52,7 @@ if (!$forum) {
throw new InteractionInstanceNotFoundException(get_string('cantfindforum', 'interaction.forum', $forumid));
}
$membership = user_can_access_group((int)$forum->groupid);
$membership = user_can_access_group((int)$forum->group);
if (!$membership) {
throw new AccessDeniedException(get_string('cantviewforums', 'interaction.forum'));
......@@ -68,7 +62,7 @@ $admin = (bool)($membership & GROUP_MEMBERSHIP_OWNER);
$moderator = $admin || is_forum_moderator($forumid);
if (isset($_POST['subscribe'])) {
if (isset($_POST['subscribe'])) { // TODO: make safe
$values = array_flip($_POST['subscribe']);
if (isset($values[get_string('subscribe', 'interaction.forum')])) {
insert_record(
......@@ -78,6 +72,7 @@ if (isset($_POST['subscribe'])) {
'user' => $USER->get('id')
)
);
$SESSION->add_ok_msg(get_string('topicsuccessfulsubscribe', 'interaction.forum'));
}
else {
delete_records(
......@@ -85,10 +80,11 @@ if (isset($_POST['subscribe'])) {
'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'])) {
if ($moderator && isset($_POST['update'])) { // TODO: make safe + nice
if (!isset($_POST['sticky']) || !is_numeric(implode(array_keys($_POST['sticky'])))) {
$_POST['sticky'] = array();
}
......@@ -105,18 +101,21 @@ if ($moderator && isset($_POST['update'])) {
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(
array(
get_config('wwwroot') . 'interaction/forum/index.php?group=' . $forum->groupid,
get_config('wwwroot') . 'group/view.php?id=' . $forum->group,
$forum->groupname
),
array(
get_config('wwwroot') . 'interaction/forum/index.php?group=' . $forum->group,
get_string('nameplural', 'interaction.forum')
),
array(
array(
get_config('wwwroot') . 'interaction/forum/view.php?id=' . $forumid,
$forum->title
)
get_config('wwwroot') . 'interaction/forum/view.php?id=' . $forumid,
$forum->title
)
);
......@@ -124,61 +123,57 @@ require_once('pieforms/pieform.php');
$forum->subscribe = pieform(array(
'name' => 'subscribe_forum',
'autofocus' => false,
'elements' => array(
'submit' => array(
'type' => 'submit',
'value' => $forum->subscribed ? get_string('unsubscribe', 'interaction.forum') : get_string('subscribe', 'interaction.forum')
),
'forum' => array(
'type' => 'hidden',
'value' => $forumid
),
'redirect' => array(
'type' => 'hidden',
'value' => '/interaction/forum/view.php?id=' . $forumid . '&offset=' . $offset
)
)
));
$stickytopics = get_records_sql_array(
'SELECT t.id, p1.subject, p1.poster, COUNT(p2.*), t.closed, s.topic AS subscribed
$sql = 'SELECT t.id, p1.subject, p1.poster, p1.body, COUNT(p2.*), t.closed, s.topic AS subscribed
FROM {interaction_forum_topic} t
INNER JOIN {interaction_forum_post} p1
ON p1.topic = t.id
AND p1.parent IS NULL
LEFT JOIN {interaction_forum_post} p2
ON p2.topic = t.id
AND p2.deleted != 1
LEFT JOIN {interaction_forum_subscription_topic} s
ON s.topic = t.id
AND s."user" = ?
INNER JOIN {interaction_forum_post} p1 ON (p1.topic = t.id AND p1.parent IS NULL)
LEFT JOIN {interaction_forum_post} p2 ON (p2.topic = t.id AND p2.deleted != 1)
LEFT JOIN {interaction_forum_subscription_topic} s ON (s.topic = t.id AND s."user" = ?)
WHERE t.forum = ?
AND t.sticky = 1
AND t.sticky = ?
AND t.deleted != 1
GROUP BY 1, 2, 3, 5, 6
ORDER BY MAX(p2.ctime) DESC',
array($userid, $forumid)
);
GROUP BY 1, 2, 3, 4, 6, 7
ORDER BY MAX(p2.ctime) DESC';
$regulartopics = get_records_sql_array(
'SELECT t.id, p1.subject, p1.poster, COUNT(p2.*), t.closed, s.topic AS subscribed
FROM {interaction_forum_topic} t
INNER JOIN {interaction_forum_post} p1
ON p1.topic = t.id
AND p1.parent IS NULL
LEFT JOIN {interaction_forum_post} p2
ON p2.topic = t.id
AND p2.deleted != 1
LEFT JOIN {interaction_forum_subscription_topic} s
ON s.topic = t.id
AND s."user" = ?
WHERE t.forum = ?
AND t.sticky != 1
AND t.deleted != 1
GROUP BY 1, 2, 3, 5, 6
ORDER BY MAX(p2.ctime) DESC',
array($userid, $forumid),
$offset,
$topicsperpage
);
$stickytopics = get_records_sql_array($sql, array($userid, $forumid, 1));
$regulartopics = get_records_sql_array($sql, array($userid, $forumid, 0), $offset, $topicsperpage);
if ($stickytopics) {
foreach ($stickytopics as $topic) {
$topic->body = substr(strip_tags($topic->body), 0, 50);
}
}
if ($regulartopics) {
foreach ($regulartopics as $topic) {
$topic->body = substr(strip_tags($topic->body), 0, 50);
}
}
$pagination = build_pagination(array(
'url' => 'view.php?id=' . $forumid,
'count' => $forum->count,
'limit' => $topicsperpage,
'offset' => $offset,
'resultcounttextsingular' => get_string('topiclower', 'interaction.forum'),
'resultcounttextplural' => get_string('topicslower', 'interaction.forum')
));
$smarty = smarty();
......@@ -192,39 +187,6 @@ $smarty->assign('regulartopics', $regulartopics);
$smarty->assign('pagination', $pagination['html']);
$smarty->display('interaction:forum:view.tpl');
function subscribe_forum_submit(Pieform $form, $values) {
global $USER;
$forumid = param_integer('id');
$offset = param_integer('offset', 0);
if ($values['submit'] == get_string('subscribe', 'interaction.forum')) {
insert_record(
'interaction_forum_subscription_forum',
(object)array(
'forum' => $forumid,
'user' => $USER->get('id')
)
);
delete_records_sql(
'DELETE FROM {interaction_forum_subscription_topic}
WHERE topic IN (
SELECT id
FROM {interaction_forum_topic}
WHERE forum = ?
AND "user" = ?
)',
array($forumid, $USER->get('id'))
);
}
else {
delete_records(
'interaction_forum_subscription_forum',
'forum', $forumid,
'user', $USER->get('id')
);
}
redirect('/interaction/forum/view.php?id=' . $forumid . '&offset=' . $offset);
}
function updatetopics($new, $old, $set) {
$keydiff = array_keys(array_diff_key($new, $old));
if (!empty($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