diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 90badd5be..83f66efdd 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -7,6 +7,13 @@ upgrading from one version to the next, or even between multiple versions. Be sure to heed the warnings contained herein as they will save you many hours of grief. +5.5.0 +-------------------------------------------------------------------- + * If you have any custom Message Board templates they will be + destroyed as they no longer apply to the new discussion + system. If you want to save them, please copy them to a + safe location prior to the upgrade. + 5.4.1 -------------------------------------------------------------------- diff --git a/docs/upgrades/upgrade_5.4.4-5.5.0.sql b/docs/upgrades/upgrade_5.4.4-5.5.0.sql index c9c01c696..4221841b7 100644 --- a/docs/upgrades/upgrade_5.4.4-5.5.0.sql +++ b/docs/upgrades/upgrade_5.4.4-5.5.0.sql @@ -186,5 +186,27 @@ update international set internationalId=1030, namespace='WebGUI' where internat delete from international where namespace='Article' and internationalId=27; delete from international where namespace='USS' and internationalId=28; delete from international where namespace='USS' and internationalId=45; +create table MessageBoard_forums (wobjectId int, forumId int); +alter table forum add column threads int not null default 0; +alter table forum add column lastPostId int not null default 0; +alter table forum add column lastPostDate int not null default 0; +alter table MessageBoard_forums add column title varchar(255); +alter table MessageBoard_forums add column description text; +alter table forum add column forumTemplateId int not null default 1; +alter table forum add column threadTemplateId int not null default 1; +alter table forum add column postTemplateId int not null default 1; +alter table forum add column postformTemplateId int not null default 1; +alter table forum add column notificationTemplateId int not null default 1; +insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1035,1,'WebGUI','Notification Template', 1066034661,'Tell the admin to select a template for the notification messages that come from this forum.'); +insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1034,1,'WebGUI','Post Form Template', 1066034620,'Tell the admin to select a template for post forms in this forum.'); +insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1033,1,'WebGUI','Post Template', 1066034603,'Tell the admin to select a template for posts in this forum.'); +insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1032,1,'WebGUI','Thread Template', 1066034586,'Tell the admin to select a template for threads in this forum.'); +insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1031,1,'WebGUI','Forum Template', 1066034528,'Tell the admin to select a template for this forum.'); +insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (75,1,'MessageBoard','Add a forum.', 1066038194,'A label for a link that allows an admin to add a forum to a message board.'); +insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1036,1,'WebGUI','Threads', 1066038155,'A label indicating how many threads there are in a particular forum.'); +delete from template where namespace='MessageBoard'; +alter table MessageBoard_forums add column sequenceNumber int not null default 1; + + diff --git a/lib/WebGUI/Forum.pm b/lib/WebGUI/Forum.pm index f896b5117..b48b5656b 100644 --- a/lib/WebGUI/Forum.pm +++ b/lib/WebGUI/Forum.pm @@ -44,8 +44,13 @@ sub isModerator { } sub incrementReplies { - my ($self) = @_; - WebGUI::SQL->write("update forum set replies=replies+1 where forumId=".$self->get("forumId")); + my ($self, $lastPostDate, $lastPostId) = @_; + WebGUI::SQL->write("update forum set replies=replies+1, lastPostId=$lastPostId, lastPostDate=$lastPostDate where forumId=".$self->get("forumId")); +} + +sub incrementThreads { + my ($self, $lastPostDate, $lastPostId) = @_; + WebGUI::SQL->write("update forum set threads=threads+1, lastPostId=$lastPostId, lastPostDate=$lastPostDate where forumId=".$self->get("forumId")); } sub incrementViews { @@ -61,9 +66,9 @@ sub isSubscribed { } sub new { - my ($self, $forumId) = @_; + my ($class, $forumId) = @_; my $properties = WebGUI::SQL->getRow("forum","forumId",$forumId); - bless {_properties=>$properties}, $self; + bless {_properties=>$properties}, $class; } sub purge { diff --git a/lib/WebGUI/Forum/Thread.pm b/lib/WebGUI/Forum/Thread.pm index a8206c1e1..ab27af94f 100644 --- a/lib/WebGUI/Forum/Thread.pm +++ b/lib/WebGUI/Forum/Thread.pm @@ -21,6 +21,7 @@ sub create { lastPostDate=>$post->get("dateOfPost") }); $self->{_post}{$post->get("forumPostId")} = $post; + $self->getForum->incrementThreads($post->get("dateOfPost"),$post->get("forumPostId")); return $self; } @@ -75,7 +76,7 @@ sub incrementReplies { my ($self, $dateOfReply, $replyId) = @_; WebGUI::SQL->write("update forumThread set replies=replies+1, lastPostId=$replyId, lastPostDate=$dateOfReply where forumThreadId=".$self->get("forumThreadId")); - $self->getForum->incrementReplies; + $self->getForum->incrementReplies($dateOfReply,$replyId); } sub incrementViews { diff --git a/lib/WebGUI/Forum/UI.pm b/lib/WebGUI/Forum/UI.pm index 613f6c21f..0971be34e 100644 --- a/lib/WebGUI/Forum/UI.pm +++ b/lib/WebGUI/Forum/UI.pm @@ -111,6 +111,36 @@ sub forumProperties { -name=>"forumId", -value=>$forumId || "new" ); + $f->template( + -name=>"forumTemplateId", + -label=>WebGUI::International::get(1031), + -namespace=>"Forum", + -uiLevel=>5 + ); + $f->template( + -name=>"threadTemplateId", + -label=>WebGUI::International::get(1032), + -namespace=>"Forum/Thread", + -uiLevel=>5 + ); + $f->template( + -name=>"postTemplateId", + -label=>WebGUI::International::get(1033), + -namespace=>"Forum/Post", + -uiLevel=>5 + ); + $f->template( + -name=>"postFormTemplateId", + -label=>WebGUI::International::get(1034), + -namespace=>"Forum/PostForm", + -uiLevel=>5 + ); + $f->template( + -name=>"notificationTemplateId", + -label=>WebGUI::International::get(1035), + -namespace=>"Forum/Notification", + -uiLevel=>5 + ); my ($interval, $units) = WebGUI::DateTime::secondsToInterval(($forum->get("editTimeout") || 3600)); $f->interval( -name=>"editTimeout", @@ -210,6 +240,79 @@ sub forumOp { } } +sub getForumTemplateVars { + my ($callback, $forum) = @_; + my (%var, @thread_loop); + $var{'user.isVisitor'} = ($session{user}{userId} == 1); + $var{'thread.new.url'} = formatNewThreadURL($callback,$forum->get("forumId")); + $var{'thread.new.label'} = WebGUI::International::get(1018); + $var{'forum.subscribe.label'} = WebGUI::International::get(1022); + $var{'forum.subscribe.url'} = formatForumSubscribeURL($callback,$forum->get("forumId")); + $var{'forum.unsubscribe.label'} = WebGUI::International::get(1023); + $var{'forum.unsubscribe.url'} = formatForumUnsubscribeURL($callback,$forum->get("forumId")); + $var{'user.isSubscribed'} = $forum->isSubscribed; + $var{'user.canPost'} = $forum->canPost; + $var{'thread.subject.label'} = WebGUI::International::get(229); + $var{'thread.date.label'} = WebGUI::International::get(245); + $var{'thread.user.label'} = WebGUI::International::get(244); + $var{"thread.views.label"} = WebGUI::International::get(514); + $var{"thread.replies.label"} = WebGUI::International::get(1016); + $var{'thread.rating.label'} = WebGUI::International::get(1020); + $var{"thread.last.label"} = WebGUI::International::get(1017); + my $p = WebGUI::Paginator->new($callback); + $p->setDataByQuery("select * from forumThread where forumId=".$forum->get("forumId")." order by isSticky desc, lastPostDate desc"); + $var{firstPage} = $p->getFirstPageLink; + $var{lastPage} = $p->getLastPageLink; + $var{nextPage} = $p->getNextPageLink; + $var{pageList} = $p->getPageLinks; + $var{previousPage} = $p->getPreviousPageLink; + $var{multiplePages} = ($p->getNumberOfPages > 1); + my $threads = $p->getPageData; + foreach my $thread (@$threads) { + my $root = WebGUI::Forum::Post->new($thread->{rootPostId}); + my $last; + if ($thread->{rootPostId} == $thread->{lastPostId}) { #saves the lookup if it's the same id + $last = $root; + } else { + $last = WebGUI::Forum::Post->new($thread->{lastPostId}); + } + my @rating_loop; + for (my $i=0;$i<=$thread->{rating};$i++) { + push(@rating_loop,{'thread.rating_loop.count'=>$i}); + } + push(@thread_loop,{ + 'thread.views'=>$thread->{views}, + 'thread.replies'=>$thread->{replies}, + 'thread.rating'=>$thread->{rating}, + 'thread.rating_loop'=>\@rating_loop, + 'thread.isSticky'=>$thread->{isSticky}, + 'thread.isLocked'=>$thread->{isLocked}, + 'thread.root.subject'=>chopSubject($root->get("subject")), + 'thread.root.url'=>formatThreadURL($callback,$root->get("forumPostId")), + 'thread.root.epoch'=>$root->get("dateOfPost"), + 'thread.root.date'=>formatPostDate($root->get("dateOfPost")), + 'thread.root.time'=>formatPostTime($root->get("dateOfPost")), + 'thread.root.user.profile'=>formatUserProfileURL($root->get("userId")), + 'thread.root.user.name'=>$root->get("username"), + 'thread.root.user.id'=>$root->get("userId"), + 'thread.root.user.isVisitor'=>($root->get("userId") == 1), + 'thread.root.status'=>formatStatus($root->get("status")), + 'thread.last.subject'=>chopSubject($last->get("subject")), + 'thread.last.url'=>formatThreadURL($callback,$last->get("forumPostId")), + 'thread.last.epoch'=>$last->get("dateOfPost"), + 'thread.last.date'=>formatPostDate($last->get("dateOfPost")), + 'thread.last.time'=>formatPostTime($last->get("dateOfPost")), + 'thread.last.user.profile'=>formatUserProfileURL($last->get("userId")), + 'thread.last.user.name'=>$last->get("username"), + 'thread.last.user.id'=>$last->get("userId"), + 'thread.last.user.isVisitor'=>($root->get("userId") == 1), + 'thread.last.status'=>formatStatus($last->get("status")) + }); + } + $var{thread_loop} = \@thread_loop; + return \%var; +} + sub getPostTemplateVars { my ($post, $thread, $forum, $callback, $var) = @_; $var->{'post.subject.label'} = WebGUI::International::get(229); @@ -277,10 +380,43 @@ sub getPostTemplateVars { $var->{'post.approve.url'} = formatApprovePostURL($callback,$post->get("forumPostId")); $var->{'post.deny.label'} = WebGUI::International::get(574); $var->{'post.deny.url'} = formatDenyPostURL($callback,$post->get("forumPostId")); - $var->{'post.full'} = WebGUI::Template::process(WebGUI::Template::get(1,"Forum/Post"), $var); + $var->{'post.full'} = WebGUI::Template::process(WebGUI::Template::get($forum->get("postTemplateId"),"Forum/Post"), $var); return $var; } +sub getThreadTemplateVars { + my ($callback, $post) = @_; + $post->markRead($session{user}{userId}); + my $thread = $post->getThread; + my $forum = $thread->getForum; + my $var = getPostTemplateVars($post, $thread, $forum, $callback); + my $root = WebGUI::Forum::Post->new($thread->get("rootPostId")); + $var->{'user.canPost'} = $forum->canPost; + $var->{'user.isSubscribed'} = $thread->isSubscribed; + $var->{'user.isVisitor'} = ($session{user}{userId} == 1); + $var->{'thread.subscribe.url'} = formatThreadSubscribeURL($callback,$post->get("forumPostId")); + $var->{'thread.subscribe.label'} = WebGUI::International::get(873); + $var->{'thread.unsubscribe.url'} = formatThreadUnsubscribeURL($callback,$post->get("forumPostId")); + $var->{'thread.unsubscribe.label'} = WebGUI::International::get(874); + $var->{post_loop} = recurseThread($root, $thread, $forum, 0, $callback, $post->get("forumPostId")); + $var->{'thread.layout.isFlat'} = ($session{user}{discussionLayout} eq "flat"); + $var->{'thread.layout.isNested'} = ($session{user}{discussionLayout} eq "nested"); + $var->{'thread.layout.isThreaded'} = ($session{user}{discussionLayout} eq "threaded" || !($var->{'thread.layout.isNested'} || $var->{'thread.layout.isFlat'})); + $var->{'thread.subject.label'} = WebGUI::International::get(229); + $var->{'thread.date.label'} = WebGUI::International::get(245); + $var->{'thread.user.label'} = WebGUI::International::get(244); + $var->{'thread.new.url'} = formatNewThreadURL($callback,$thread->get("forumId")); + $var->{'thread.new.label'} = WebGUI::International::get(1018); + $var->{'thread.previous.url'} = formatPreviousThreadURL($callback,$thread->get("forumThreadId")); + $var->{'thread.previous.label'} = WebGUI::International::get(513); + $var->{'thread.next.url'} = formatNextThreadURL($callback,$thread->get("forumThreadId")); + $var->{'thread.next.label'} = WebGUI::International::get(512); + $var->{'thread.list.url'} = formatForumURL($callback,$forum->get("forumId")); + $var->{'thread.list.label'} = WebGUI::International::get(1019); + return $var; +} + + sub notifySubscribers { my ($post, $thread, $forum, $callback) = @_; my %subscribers; @@ -299,7 +435,7 @@ sub notifySubscribers { }; $var = getPostTemplateVars($post, $thread, $forum, $callback, $var); my $subject = WebGUI::International::get(523); - my $message = WebGUI::Template::process(WebGUI::Template::get(1,"Forum/Notification"), $var); + my $message = WebGUI::Template::process(WebGUI::Template::get($forum->get("notificationTemplateId"),"Forum/Notification"), $var); foreach my $userId (keys %subscribers) { WebGUI::MessageLog::addEntry($userId,"",$subject,$message); } @@ -493,7 +629,7 @@ sub www_post { value=>$subject }); $var->{'form.end'} = ''; - return WebGUI::Template::process(WebGUI::Template::get(1,"Forum/PostForm"), $var); + return WebGUI::Template::process(WebGUI::Template::get($forum->get("postformTemplateId"),"Forum/PostForm"), $var); } sub www_postSave { @@ -585,110 +721,17 @@ sub www_threadUnsubscribe { sub www_viewForum { my ($callback, $forumId) = @_; $forumId = $session{form}{forumId} unless ($forumId); - my (%var, @thread_loop); my $forum = WebGUI::Forum->new($forumId); - $var{'user.isVisitor'} = ($session{user}{userId} == 1); - $var{'thread.new.url'} = formatNewThreadURL($callback,$forumId); - $var{'thread.new.label'} = WebGUI::International::get(1018); - $var{'forum.subscribe.label'} = WebGUI::International::get(1022); - $var{'forum.subscribe.url'} = formatForumSubscribeURL($callback,$forumId); - $var{'forum.unsubscribe.label'} = WebGUI::International::get(1023); - $var{'forum.unsubscribe.url'} = formatForumUnsubscribeURL($callback,$forumId); - $var{'user.isSubscribed'} = $forum->isSubscribed; - $var{'user.canPost'} = $forum->canPost; - $var{'thread.subject.label'} = WebGUI::International::get(229); - $var{'thread.date.label'} = WebGUI::International::get(245); - $var{'thread.user.label'} = WebGUI::International::get(244); - $var{"thread.views.label"} = WebGUI::International::get(514); - $var{"thread.replies.label"} = WebGUI::International::get(1016); - $var{'thread.rating.label'} = WebGUI::International::get(1020); - $var{"thread.last.label"} = WebGUI::International::get(1017); - my $p = WebGUI::Paginator->new($callback); - $p->setDataByQuery("select * from forumThread where forumId=".$forumId." order by isSticky desc, lastPostDate desc"); - $var{firstPage} = $p->getFirstPageLink; - $var{lastPage} = $p->getLastPageLink; - $var{nextPage} = $p->getNextPageLink; - $var{pageList} = $p->getPageLinks; - $var{previousPage} = $p->getPreviousPageLink; - $var{multiplePages} = ($p->getNumberOfPages > 1); - my $threads = $p->getPageData; - foreach my $thread (@$threads) { - my $root = WebGUI::Forum::Post->new($thread->{rootPostId}); - my $last; - if ($thread->{rootPostId} == $thread->{lastPostId}) { #saves the lookup if it's the same id - $last = $root; - } else { - $last = WebGUI::Forum::Post->new($thread->{lastPostId}); - } - my @rating_loop; - for (my $i=0;$i<=$thread->{rating};$i++) { - push(@rating_loop,{'thread.rating_loop.count'=>$i}); - } - push(@thread_loop,{ - 'thread.views'=>$thread->{views}, - 'thread.replies'=>$thread->{replies}, - 'thread.rating'=>$thread->{rating}, - 'thread.rating_loop'=>\@rating_loop, - 'thread.isSticky'=>$thread->{isSticky}, - 'thread.isLocked'=>$thread->{isLocked}, - 'thread.root.subject'=>chopSubject($root->get("subject")), - 'thread.root.url'=>formatThreadURL($callback,$root->get("forumPostId")), - 'thread.root.epoch'=>$root->get("dateOfPost"), - 'thread.root.date'=>formatPostDate($root->get("dateOfPost")), - 'thread.root.time'=>formatPostTime($root->get("dateOfPost")), - 'thread.root.user.profile'=>formatUserProfileURL($root->get("userId")), - 'thread.root.user.name'=>$root->get("username"), - 'thread.root.user.id'=>$root->get("userId"), - 'thread.root.user.isVisitor'=>($root->get("userId") == 1), - 'thread.root.status'=>formatStatus($root->get("status")), - 'thread.last.subject'=>chopSubject($last->get("subject")), - 'thread.last.url'=>formatThreadURL($callback,$last->get("forumPostId")), - 'thread.last.epoch'=>$last->get("dateOfPost"), - 'thread.last.date'=>formatPostDate($last->get("dateOfPost")), - 'thread.last.time'=>formatPostTime($last->get("dateOfPost")), - 'thread.last.user.profile'=>formatUserProfileURL($last->get("userId")), - 'thread.last.user.name'=>$last->get("username"), - 'thread.last.user.id'=>$last->get("userId"), - 'thread.last.user.isVisitor'=>($root->get("userId") == 1), - 'thread.last.status'=>formatStatus($last->get("status")) - }); - } - $var{thread_loop} = \@thread_loop; - return WebGUI::Template::process(WebGUI::Template::get(1,"Forum"), \%var); + my $var = getForumTemplateVars($callback, $forum); + return WebGUI::Template::process(WebGUI::Template::get($forum->get("forumTemplateId"),"Forum"), $var); } sub www_viewThread { my ($callback, $postId) = @_; $postId = $session{form}{forumPostId} unless ($postId); - my $post = WebGUI::Forum::Post->new($postId); - $post->markRead($session{user}{userId}); - my $thread = $post->getThread; - my $forum = $thread->getForum; - my $var = getPostTemplateVars($post, $thread, $forum, $callback); - my $root = WebGUI::Forum::Post->new($thread->get("rootPostId")); - $var->{'user.canPost'} = $forum->canPost; - $var->{'user.isSubscribed'} = $thread->isSubscribed; - $var->{'user.isVisitor'} = ($session{user}{userId} == 1); - $var->{'thread.subscribe.url'} = formatThreadSubscribeURL($callback,$postId); - $var->{'thread.subscribe.label'} = WebGUI::International::get(873); - $var->{'thread.unsubscribe.url'} = formatThreadUnsubscribeURL($callback,$postId); - $var->{'thread.unsubscribe.label'} = WebGUI::International::get(874); - $var->{post_loop} = recurseThread($root, $thread, $forum, 0, $callback, $postId); - $var->{'thread.layout.isFlat'} = ($session{user}{discussionLayout} eq "flat"); - $var->{'thread.layout.isNested'} = ($session{user}{discussionLayout} eq "nested"); - $var->{'thread.layout.isThreaded'} = ($session{user}{discussionLayout} eq "threaded" || !($var->{'thread.layout.isNested'} || $var->{'thread.layout.isFlat'})); - $var->{'thread.subject.label'} = WebGUI::International::get(229); - $var->{'thread.date.label'} = WebGUI::International::get(245); - $var->{'thread.user.label'} = WebGUI::International::get(244); - $var->{'thread.new.url'} = formatNewThreadURL($callback,$thread->get("forumId")); - $var->{'thread.new.label'} = WebGUI::International::get(1018); - $var->{'thread.previous.url'} = formatPreviousThreadURL($callback,$thread->get("forumThreadId")); - $var->{'thread.previous.label'} = WebGUI::International::get(513); - $var->{'thread.next.url'} = formatNextThreadURL($callback,$thread->get("forumThreadId")); - $var->{'thread.next.label'} = WebGUI::International::get(512); - $var->{'thread.list.url'} = $callback; - $var->{'thread.list.label'} = WebGUI::International::get(1019); - return WebGUI::Template::process(WebGUI::Template::get(1,"Forum/Thread"), $var); + my $post = WebGUI::Forum::Post->new($postId); + my $var = getThreadTemplateVars($callback, $post); + return WebGUI::Template::process(WebGUI::Template::get($post->getThread->getForum->get("threadTemplateId"),"Forum/Thread"), $var); } diff --git a/lib/WebGUI/SQL.pm b/lib/WebGUI/SQL.pm index 5eeb4e1d8..18a95a276 100644 --- a/lib/WebGUI/SQL.pm +++ b/lib/WebGUI/SQL.pm @@ -199,7 +199,7 @@ sub buildHashRef { return \%hash; } - + #------------------------------------------------------------------- =head2 errorCode { diff --git a/lib/WebGUI/Wobject/MessageBoard.pm b/lib/WebGUI/Wobject/MessageBoard.pm index 5d8928d33..f14c54d87 100644 --- a/lib/WebGUI/Wobject/MessageBoard.pm +++ b/lib/WebGUI/Wobject/MessageBoard.pm @@ -13,7 +13,8 @@ package WebGUI::Wobject::MessageBoard; use strict; use Tie::CPHash; use WebGUI::DateTime; -use WebGUI::Discussion; +use WebGUI::Forum; +use WebGUI::Forum::UI; use WebGUI::HTML; use WebGUI::HTMLForm; use WebGUI::Icon; @@ -28,6 +29,16 @@ use WebGUI::Wobject; our @ISA = qw(WebGUI::Wobject); +#------------------------------------------------------------------- +sub _formatControls { + my $controls = deleteIcon("func=deleteForum&wid=".$_[0]->get("wobjectId")."&forumId=".$_[1]) + .editIcon("func=editForum&wid=".$_[0]->get("wobjectId")."&forumId=".$_[1]) + .moveUpIcon("func=moveForumUp&wid=".$_[0]->get("wobjectId")."&forumId=".$_[1]) + .moveDownIcon("func=moveForumDown&wid=".$_[0]->get("wobjectId")."&forumId=".$_[1]); + return $controls; +} + + #------------------------------------------------------------------- sub name { return WebGUI::International::get(2,$_[0]->get("namespace")); @@ -60,6 +71,21 @@ sub status { } } +#------------------------------------------------------------------- +sub www_deleteForum { + return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditWobject($_[0]->get("wobjectId"))); + return $_[0]->confirm(WebGUI::International::get(76,$_[0]->get("namespace")), + WebGUI::URL::page('func=deleteForumConfirm&wid='.$_[0]->get("wobjectId").'&forumId='.$session{form}{forumId})); +} + +#------------------------------------------------------------------- +sub www_deleteForumConfirm { + return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditWobject($_[0]->get("wobjectId"))); + my $forum = WebGUI::Forum->new($session{form}{forumId}); + $forum->purge; + WebGUI::SQL->write("delete from MessageBoard_forums where forumId=".$session{form}{forumId}); +} + #------------------------------------------------------------------- sub www_edit { my $properties = WebGUI::HTMLForm->new; @@ -69,7 +95,6 @@ sub www_edit { -label=>WebGUI::International::get(4,$_[0]->get("namespace")), -value=>$_[0]->getValue("messagesPerPage") ); - $properties->raw($_[0]->SUPER::discussionProperties); return $_[0]->SUPER::www_edit( -layout=>$layout->printRowsOnly, -properties=>$properties->printRowsOnly, @@ -78,6 +103,68 @@ sub www_edit { ); } +#------------------------------------------------------------------- +sub www_editForum { + return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditWobject($_[0]->get("wobjectId"))); + my $forumMeta; + if ($session{form}{forumId} ne "new") { + $forumMeta = WebGUI::SQL->quickHashRef("select title,description from MessageBoard_forums where forumId=".$session{form}{forumId}); + } + my $forum = WebGUI::Forum->new($session{form}{forumId}); + my $f = WebGUI::HTMLForm->new; + $f->hidden( + -name=>"wid", + -value=>$_[0]->get("wobjectId") + ); + $f->hidden( + -name=>"func", + -value=>"editForumSave" + ); + $f->text( + -name=>"title", + -value=>$forumMeta->{title}, + -label=>WebGUI::International::get(99) + ); + $f->HTMLArea( + -name=>"description", + -value=>$forumMeta->{description}, + -label=>WebGUI::International::get(85) + ); + $f->raw(WebGUI::Forum::UI::forumProperties($forum->get("forumId"))); + $f->submit; + return '

'.WebGUI::International::get(77,$_[0]->get("namespace")).'

'.$f->print; +} + +#------------------------------------------------------------------- +sub www_editForumSave { + return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditWobject($_[0]->get("wobjectId"))); + my $forumId = WebGUI::Forum::UI::forumPropertiesSave(); + if ($session{form}{forumId} eq "new") { + my ($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from MessageBoard_forums where wobjectId=".$_[0]->get("wobjectId")); + $seq++; + WebGUI::SQL->write("insert into MessageBoard_forums (wobjectId, forumId, title, description, sequenceNumber) values (" + .$_[0]->get("wobjectId").", ".$forumId.", ".quote($session{form}{title}).", ".quote($session{form}{description}) + .", ".$seq.")"); + } else { + WebGUI::SQL->write("update MessageBoard_forums set title=".quote($session{form}{title}).", description=" + .quote($session{form}{description})." where forumId=".$forumId." and wobjectId=".$_[0]->get("wobjectId")); + } + return ""; +} + +#------------------------------------------------------------------- +sub www_moveForumDown { + return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditWobject($_[0]->get("wobjectId"))); + $_[0]->moveCollateralDown("MessageBoard_forums","forumId",$session{form}{forumId}); + return ""; +} + +#------------------------------------------------------------------- +sub www_moveForumUp { + return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditWobject($_[0]->get("wobjectId"))); + $_[0]->moveCollateralUp("MessageBoard_forums","forumId",$session{form}{forumId}); + return ""; +} #------------------------------------------------------------------- sub www_showMessage { @@ -86,9 +173,61 @@ sub www_showMessage { #------------------------------------------------------------------- sub www_view { - my ($p, $data, %var, @message_loop, $rows, @last, $replies); + my $callback = WebGUI::URL::page("func=view&wid=".$_[0]->get("wobjectId")); + return WebGUI::Forum::UI::forumOp($callback) if ($session{form}{forumOp}); + my %var; $var{title} = $_[0]->get("title"); $var{description} = $_[0]->get("description"); + $var{'forum.add.url'} = WebGUI::URL::page("func=editForum&forumId=new&wid=".$_[0]->get("wobjectId")); + $var{'forum.add.label'} = WebGUI::International::get(75,$_[0]->get("namespace")); + $var{'title.label'} = WebGUI::International::get(99); + $var{'views.label'} = WebGUI::International::get(514); + $var{'rating.label'} = WebGUI::International::get(1020); + $var{'threads.label'} = WebGUI::International::get(1036); + $var{'replies.label'} = WebGUI::International::get(1016); + $var{'lastpost.label'} = WebGUI::International::get(1017); + my $count = 1; + my @forum_loop; + my $sth = WebGUI::SQL->read("select * from MessageBoard_forums where wobjectId=".$_[0]->get("wobjectId")." order by sequenceNumber"); + while (my $forumMeta = $sth->hashRef) { + my $forum = WebGUI::Forum->new($forumMeta->{forumId}); + if ($count == 1) { + $var{'default.listing'} = WebGUI::Forum::UI::www_viewForum($callback,$forumMeta->{forumId}); + $var{'default.description'} = $forumMeta->{description}; + $var{'default.title'} = $forumMeta->{title}; + $var{'default.controls'} = $_[0]->_formatControls($forum->get("forumId")); + } + my $lastPost = WebGUI::Forum::Post->new($forum->get("lastPostId")); + push(@forum_loop, { + 'forum.controls' => $_[0]->_formatControls($forum->get("forumId")), + 'forum.count' => $count, + 'forum.title' => $forumMeta->{title}, + 'forum.description' => $forumMeta->{description}, + 'forum.replies' => $forum->get("replies"), + 'forum.rating' => $forum->get("rating"), + 'forum.views' => $forum->get("views"), + 'forum.threads' => $forum->get("threads"), + 'forum.url' => WebGUI::Forum::UI::formatForumURL($callback,$forum->get("forumId")), + 'forum.lastPost.url' => WebGUI::Forum::UI::formatThreadURL($callback,$lastPost->get("forumPostId")), + 'forum.lastPost.date' => WebGUI::Forum::UI::formatPostDate($lastPost->get("dateOfPost")), + 'forum.lastPost.time' => WebGUI::Forum::UI::formatPostDate($lastPost->get("dateOfPost")), + 'forum.lastPost.epoch' => $lastPost->get("dateOfPost"), + 'forum.lastPost.subject' => WebGUI::Forum::UI::formatSubject($lastPost->get("subject")), + 'forum.lastPost.user.id' => $lastPost->get("userId"), + 'forum.lastPost.user.name' => $lastPost->get("username"), + 'forum.lastPost.user.profile' => WebGUI::Forum::UI::formatUserProfileURL($lastPost->get("userId")), + 'forum.lastPost.user.isVisitor' => ($lastPost->get("userId") == 1) + }); + $count++; + } + $sth->finish; + $var{areMultipleForums} = ($count > 1); + $var{forum_loop} = \@forum_loop; + return $_[0]->processTemplate($_[0]->get("templateId"),\%var); + + + my ($p, $data, %var, @message_loop, $rows, @last, $replies); + $var{canPost} = WebGUI::Privilege::isInGroup($_[0]->get("groupToPost")); $var{"post.url"} = WebGUI::URL::page('func=post&mid=new&wid='.$_[0]->get("wobjectId")); $var{"post.label"} = WebGUI::International::get(17,$_[0]->get("namespace")); @@ -136,7 +275,6 @@ sub www_view { $var{pageList} = $p->getPageLinks; $var{previousPage} = $p->getPreviousPageLink; $var{multiplePages} = ($p->getNumberOfPages > 1); - return $_[0]->processTemplate($_[0]->get("templateId"),\%var); } 1;