]> ruin.nu Git - ndwebbie.git/blobdiff - forum.pl
some restructuring, put intel messages in forum board instead of separate table
[ndwebbie.git] / forum.pl
index fdd8f1ade58f2018841f5789e8467be0063e9af1..eb59bac95b3a584f611da61fe514294f603022b4 100644 (file)
--- a/forum.pl
+++ b/forum.pl
@@ -19,6 +19,8 @@
 
 use strict;
 use warnings FATAL => 'all';
+no warnings 'uninitialized';
+use ND::Web::Forum;
 
 $ND::TEMPLATE->param(TITLE => 'Forum');
 
@@ -47,21 +49,13 @@ if(param('t')){
        $thread = $DBH->selectrow_hashref($findThread,undef,param('t'),$ND::UID) or $ERROR .= p($DBH->errstr);
 }
 
-if (defined param('cmd') && param('cmd') eq 'submit'){
+if (defined param('cmd') && param('cmd') eq 'forumpost'){
        $DBH->begin_work;
        if ($board && $board->{post}){
-               my $insert = $DBH->prepare(q{INSERT INTO forum_threads (fbid,subject) VALUES($1,$2)});
-               if ($insert->execute($board->{id},escapeHTML(param('subject')))){
-                       $thread = $DBH->selectrow_hashref($findThread,undef,
-                               $DBH->last_insert_id(undef,undef,undef,undef,"forum_threads_ftid_seq"),$ND::UID)
-                               or $ERROR .= p($DBH->errstr);
-               }else{
-                       $ERROR .= p($DBH->errstr);
-               }
+               $thread = addForumThread $DBH,$board,$ND::UID,param('subject');
        }
        if ($thread && $thread->{post}){
-               my $insert = $DBH->prepare(q{INSERT INTO forum_posts (ftid,message,uid) VALUES($1,$2,$3)});
-               $insert->execute($thread->{id},escapeHTML(param('message')),$ND::UID) or $ERROR .= p($DBH->errstr);
+               addForumPost($DBH,$thread,$ND::UID,param('message'));
        }
        $DBH->commit or $ERROR .= p($DBH->errstr);
 }
@@ -74,30 +68,7 @@ GROUP BY ft.ftid, ft.subject
 HAVING count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) >= $3});
 
 if ($thread){ #Display the thread
-       $BODY->param(Thread => 1);
-       $BODY->param(Subject => $thread->{subject});
-       $BODY->param(Id => $thread->{id});
-       $BODY->param(Post => $thread->{post});
-
-       my $posts = $DBH->prepare(q{SELECT u.username,date_trunc('minute',fp.time::timestamp) AS time,fp.message,COALESCE(fp.time > ftv.time,TRUE) AS unread
-FROM forum_threads ft JOIN forum_posts fp USING (ftid) NATURAL JOIN users u LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid
-WHERE ft.ftid = $1
-ORDER BY fp.time ASC
-});
-       $posts->execute($thread->{id},$ND::UID) or $ERROR .= p($DBH->errstr);
-       my @posts;
-       my $old = 1;
-       while (my $post = $posts->fetchrow_hashref){
-               if ($old && $post->{unread}){
-                       $old = 0;
-                       $post->{NewPosts} = 1;
-               }
-               $post->{message} = parseMarkup($post->{message});
-               push @posts,$post;
-       }
-       $BODY->param(Posts => \@posts);
-
-       markThreadAsRead($thread->{id});
+       $BODY->param(Thread => viewForumThread $thread);
 
 }elsif($board){ #List threads in this board
        $BODY->param(Board => $board->{board});