]> ruin.nu Git - ndwebbie.git/blobdiff - ND/Include.pm
keep track of last forum visit, so we can check if posts are really new, or just...
[ndwebbie.git] / ND / Include.pm
index 836010a280a88910c7beaa53d6778055546f70ad..53e7a4c17580a48c1e26c2c0d6d36b0690547d51 100644 (file)
 
 package ND::Include;
 use strict;
-use warnings FATAL => 'all';
+use warnings;
 use CGI qw{:standard};
 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, count(NULLIF(fp.time > $2,FALSE)) AS new
+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;