X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=ND%2FInclude.pm;h=9bfb05ed39ad6b5e860ccec1390b917e147dea4b;hb=2d7464077ae805a1923bb4e2024afeb769f30e02;hp=87d13d0e3846e19fec9e4ba0173fcc4af429c16e;hpb=6a442a1f778230dccf47632b30ed9c7db3d6b3d2;p=ndwebbie.git diff --git a/ND/Include.pm b/ND/Include.pm index 87d13d0..9bfb05e 100644 --- a/ND/Include.pm +++ b/ND/Include.pm @@ -25,7 +25,7 @@ require Exporter; our @ISA = qw/Exporter/; -our @EXPORT = qw/min max log_message intel_log/; +our @EXPORT = qw/min max log_message intel_log unread_query/; sub min { my ($x,$y) = @_; @@ -51,4 +51,15 @@ sub intel_log { $log->execute($uid,$message,$planet) or $ND::ERROR .= p($ND::DBH->errstr); } +sub unread_query { + return $ND::DBH->prepare_cached(q{ + SELECT count(*) AS unread, max(ftv.time) AS last_vist +FROM forum_boards fb NATURAL JOIN forum_threads ft + JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN + (SELECT * FROM forum_thread_visits WHERE uid = $1) ftv ON ftv.ftid = ft.ftid +WHERE (ftv.time IS NULL OR fp.time > ftv.time) AND fbid > 0 AND + fbid IN (SELECT fbid FROM forum_access WHERE gid IN (SELECT groups($1))) + }); +} + 1;