X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;ds=sidebyside;f=ND%2FInclude.pm;h=9bfb05ed39ad6b5e860ccec1390b917e147dea4b;hb=2d7464077ae805a1923bb4e2024afeb769f30e02;hp=836010a280a88910c7beaa53d6778055546f70ad;hpb=8663c593fac5806edc0c948e8234f8e838f8fd35;p=ndwebbie.git diff --git a/ND/Include.pm b/ND/Include.pm index 836010a..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) = @_; @@ -47,8 +47,19 @@ sub log_message { sub intel_log { my ($uid,$planet, $message) = @_; my $log = $ND::DBH->prepare_cached(q{INSERT INTO forum_posts (ftid,uid,message) VALUES( - (SELECT ftid FROM forum_threads WHERE planet = $3),$1,$2)}); + (SELECT ftid FROM planets WHERE id = $3),$1,$2)}); $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;