1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
22 use warnings FATAL => 'all';
23 use CGI qw{:standard};
26 our @ISA = qw/Exporter/;
28 our @EXPORT = qw/min max log_message intel_log unread_query/;
32 return ($x > $y ? $y : $x);
37 return ($x < $y ? $y : $x);
41 my ($uid, $message) = @_;
42 my $log = $ND::DBH->prepare_cached(q{INSERT INTO forum_posts (ftid,uid,message) VALUES(
43 (SELECT ftid FROM users WHERE uid = $1),$1,$2)});
44 $log->execute($uid,$message) or $ND::ERROR .= p($ND::DBH->errstr);
48 my ($uid,$planet, $message) = @_;
49 my $log = $ND::DBH->prepare_cached(q{INSERT INTO forum_posts (ftid,uid,message) VALUES(
50 (SELECT ftid FROM planets WHERE id = $3),$1,$2)});
51 $log->execute($uid,$message,$planet) or $ND::ERROR .= p($ND::DBH->errstr);
55 return $ND::DBH->prepare_cached(q{
56 SELECT count(*) AS unread, max(ftv.time) AS last_vist
57 FROM forum_boards fb NATURAL JOIN forum_threads ft
58 JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN
59 (SELECT * FROM forum_thread_visits WHERE uid = $1) ftv ON ftv.ftid = ft.ftid
60 WHERE (ftv.time IS NULL OR fp.time > ftv.time) AND fbid > 0 AND
61 fbid IN (SELECT fbid FROM forum_access WHERE gid IN (SELECT groups($1)))