X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=ND%2FInclude.pm;h=9bfb05ed39ad6b5e860ccec1390b917e147dea4b;hb=2d7464077ae805a1923bb4e2024afeb769f30e02;hp=8aa2bd4e76143680f1c8f24216b620cc2f695dc1;hpb=bbe1fae6b0307a9f77b2b5e7b8a71ebaa137f846;p=ndwebbie.git diff --git a/ND/Include.pm b/ND/Include.pm index 8aa2bd4..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/; +our @EXPORT = qw/min max log_message intel_log unread_query/; sub min { my ($x,$y) = @_; @@ -40,8 +40,26 @@ sub max { sub log_message { my ($uid, $message) = @_; my $log = $ND::DBH->prepare_cached(q{INSERT INTO forum_posts (ftid,uid,message) VALUES( - (SELECT ftid FROM forum_threads WHERE log_uid = $1),$1,$2)}); - $log->execute($uid,$message); + (SELECT ftid FROM users WHERE uid = $1),$1,$2)}); + $log->execute($uid,$message) or $ND::ERROR .= p($ND::DBH->errstr); +} + +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 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;