}
my $categories = $DBH->prepare(q{SELECT fcid AS id,category FROM forum_categories ORDER BY fcid});
-my $threads = $DBH->prepare(q{SELECT ft.ftid AS id,ft.subject,count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread,count(fp.fpid) AS posts
+my $threads = $DBH->prepare(q{SELECT ft.ftid AS id,ft.subject,count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread,count(fp.fpid) AS posts, max(fp.time)::timestamp as last_post
FROM forum_threads ft JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid
WHERE ft.fbid = $1
GROUP BY ft.ftid, ft.subject
-HAVING count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) >= $3});
+HAVING count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) >= $3
+ORDER BY last_post DESC});
if ($thread){ #Display the thread
$BODY->param(Thread => viewForumThread $thread);
WHERE fb.fcid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers
WHERE uid = $2))
GROUP BY fb.fbid,fb.board
+ORDER BY fb.fbid
});
while (my $category = $categories->fetchrow_hashref){
$boards->execute($category->{id},$ND::UID) or $ERROR .= p($DBH->errstr);
<th>Unread</th>
<th>Total</th>
<th>Subject</th>
+ <th>Last post</th>
</tr>
<TMPL_LOOP Threads>
<tr class="<TMPL_IF ODD>odd<TMPL_ELSE>even</TMPL_IF>">
<td align="center"><TMPL_VAR NAME=Unread></td>
<td align="center"><TMPL_VAR NAME=Posts></td>
<td><a href="<TMPL_VAR NAME=PAGE>?t=<TMPL_VAR NAME=Id>#NewPosts"> <TMPL_VAR NAME=Subject> </a></td>
+ <td align="center"><TMPL_VAR NAME=Last_post></td>
</tr>
</TMPL_LOOP>
</table>
<th>Unread</th>
<th>Total</th>
<th>Subject</th>
+ <th>Last post</th>
</tr>
<TMPL_LOOP Categories>
<tr><th colspan="2"><TMPL_VAR NAME=Category></th></tr>
<td align="center"><TMPL_VAR NAME=Unread></td>
<td align="center"><TMPL_VAR NAME=Posts></td>
<td><a href="<TMPL_VAR NAME=PAGE>?t=<TMPL_VAR NAME=Id>#NewPosts"> <TMPL_VAR NAME=Subject> </a></td>
+ <td align="center"><TMPL_VAR NAME=Last_post></td>
</tr>
</TMPL_LOOP>
</TMPL_LOOP>