package WebGUI::Wobject::MessageBoard;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black LLC.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use Tie::CPHash;
use WebGUI::DateTime;
use WebGUI::Discussion;
use WebGUI::HTML;
use WebGUI::HTMLForm;
use WebGUI::Icon;
use WebGUI::International;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::URL;
use WebGUI::Utility;
use WebGUI::Wobject;
our @ISA = qw(WebGUI::Wobject);
our $namespace = "MessageBoard";
our $name = WebGUI::International::get(2,$namespace);
our %status =("Approved"=>WebGUI::International::get(560),
"Denied"=>WebGUI::International::get(561),
"Pending"=>WebGUI::International::get(562));
#-------------------------------------------------------------------
sub duplicate {
my ($w);
$w = $_[0]->SUPER::duplicate($_[1]);
$w = WebGUI::Wobject::MessageBoard->new({wobjectId=>$w,namespace=>$namespace});
$w->set({
messagesPerPage=>$_[0]->get("messagesPerPage")
});
}
#-------------------------------------------------------------------
sub set {
$_[0]->SUPER::set($_[1],[qw(messagesPerPage)]);
}
#-------------------------------------------------------------------
sub www_edit {
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
my ($output, $f, $messagesPerPage);
$messagesPerPage = $_[0]->get("messagesPerPage") || 50;
$output = helpIcon(1,$namespace);
$output .= '
'.WebGUI::International::get(6,$namespace).'
';
$f = WebGUI::HTMLForm->new;
$f->integer("messagesPerPage",WebGUI::International::get(4,$namespace),$messagesPerPage);
$f->raw($_[0]->SUPER::discussionProperties);
$output .= $_[0]->SUPER::www_edit($f->printRowsOnly);
return $output;
}
#-------------------------------------------------------------------
sub www_editSave {
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
$_[0]->SUPER::www_editSave({
messagesPerPage=>$session{form}{messagesPerPage}
});
return "";
}
#-------------------------------------------------------------------
sub www_showMessage {
return $_[0]->SUPER::www_showMessage(''.WebGUI::International::get(11,$namespace).'
');
}
#-------------------------------------------------------------------
sub www_view {
my ($sth, %data, $html, $i, $pn, $lastId, @last, $replies);
tie %data, 'Tie::CPHash';
if ($session{form}{pn} < 1) {
$pn = 0;
} else {
$pn = $session{form}{pn};
}
$html = $_[0]->displayTitle;
$html .= $_[0]->description;
$html = $_[0]->processMacros($html);
$html .= '';
$html .= '';
$html .= '
';
$sth = WebGUI::SQL->read("select messageId,subject,username,dateOfPost,userId,views,status
from discussion where wobjectId=".$_[0]->get("wobjectId")." and pid=0
and (status='Approved' or userId=$session{user}{userId}) order by messageId desc");
while (%data = $sth->hash) {
$data{subject} = WebGUI::Discussion::formatSubject($data{subject});
if ($i >= ($_[0]->get("messagesPerPage")*$pn) && $i < ($_[0]->get("messagesPerPage")*($pn+1))) {
@last = WebGUI::SQL->quickArray("select messageId,dateOfPost,username,subject,userId
from discussion where wobjectId=".$_[0]->get("wobjectId")." and rid=$data{messageId}
and status='Approved' order by dateOfPost desc");
$last[3] = WebGUI::HTML::filter($last[3],'all');
($replies) = WebGUI::SQL->quickArray("select count(*) from discussion
where rid=$data{messageId} and status='Approved'");
$replies--;
$html .= '| '.substr($data{subject},0,30).'';
if ($data{userId} == $session{user}{userId}) {
$html .= ' ('.$status{$data{status}}.')';
}
$html .= ' |
'
.$data{username}.' |
'.epochToHuman($data{dateOfPost},"%z %Z").' |
'.$data{views}.' |
'.$replies.' |
'
.substr($last[3],0,30).'
@ '.epochToHuman($last[1],"%z %Z").' by '.$last[2].'
|
';
}
$i++;
}
$html .= '
';
if ($i > $_[0]->get("messagesPerPage")) {
$html .= '';
}
return $html;
}
1;