Templatized the message board.

This commit is contained in:
JT Smith 2002-11-30 18:17:13 +00:00
parent 618f193482
commit ee750a0471
2 changed files with 66 additions and 78 deletions

View file

@ -41,13 +41,14 @@ sub duplicate {
$w = $_[0]->SUPER::duplicate($_[1]);
$w = WebGUI::Wobject::MessageBoard->new({wobjectId=>$w,namespace=>$namespace});
$w->set({
messagesPerPage=>$_[0]->get("messagesPerPage")
messagesPerPage=>$_[0]->get("messagesPerPage"),
templateId=>$_[0]->get("templateId")
});
}
#-------------------------------------------------------------------
sub set {
$_[0]->SUPER::set($_[1],[qw(messagesPerPage)]);
$_[0]->SUPER::set($_[1],[qw(templateId messagesPerPage)]);
}
#-------------------------------------------------------------------
@ -59,6 +60,13 @@ sub www_edit {
$output .= '<h1>'.WebGUI::International::get(6,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->integer("messagesPerPage",WebGUI::International::get(4,$namespace),$messagesPerPage);
$f->template(
-name=>"templateId",
-value=>$_[0]->get("templateId"),
-namespace=>$namespace,
-label=>WebGUI::International::get(72,$namespace),
-afterEdit=>'func=edit&wid='.$_[0]->get("wobjectId")
);
$f->raw($_[0]->SUPER::discussionProperties);
$output .= $_[0]->SUPER::www_edit($f->printRowsOnly);
return $output;
@ -68,7 +76,8 @@ sub www_edit {
sub www_editSave {
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
$_[0]->SUPER::www_editSave({
messagesPerPage=>$session{form}{messagesPerPage}
messagesPerPage=>$session{form}{messagesPerPage},
templateId=>$session{form}{templateId}
});
return "";
}
@ -80,84 +89,57 @@ sub www_showMessage {
#-------------------------------------------------------------------
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 .= '<table width="100%" cellpadding=2 cellspacing=1 border=0><tr>'.
'<td align="right" valign="bottom" class="tableMenu">';
if (WebGUI::Privilege::isInGroup($_[0]->get("groupToPost"))) {
$html .= '<a href="'.
WebGUI::URL::page('func=post&mid=new&wid='.$_[0]->get("wobjectId")).'">'.
WebGUI::International::get(17,$namespace).'</a> &middot; ';
}
$html .= '<a href="'.WebGUI::URL::page('func=search&wid='.$_[0]->get("wobjectId")).'">'
.WebGUI::International::get(364).'</a></td></tr></table>';
$html .= '<table border=0 cellpadding=2 cellspacing=1 width="100%">';
$html .= '<tr><td class="tableHeader">'.WebGUI::International::get(229).'</td>
<td class="tableHeader">'.WebGUI::International::get(15,$namespace).'</td>
<td class="tableHeader">'.WebGUI::International::get(18,$namespace).'</td>
<td class="tableHeader">'.WebGUI::International::get(514).'</td>
<td class="tableHeader">'.WebGUI::International::get(19,$namespace).'</td>
<td class="tableHeader">'.WebGUI::International::get(20,$namespace).'</td></tr>';
$sth = WebGUI::SQL->read("select messageId,subject,username,dateOfPost,userId,views,status
my ($data, $html, %var, @message_loop, $rows, $lastId, @last, $replies);
$var{title} = $_[0]->processMacros($_[0]->get("title"));
$var{description} = $_[0]->processMacros($_[0]->get("description"));
$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,$namespace);
$var{"search.url"} = WebGUI::URL::page('func=search&wid='.$_[0]->get("wobjectId"));
$var{"search.label"} = WebGUI::International::get(364);
$var{"subject.label"} = WebGUI::International::get(229);
$var{"user.label"} = WebGUI::International::get(15,$namespace);
$var{"date.label"} = WebGUI::International::get(18,$namespace);
$var{"views.label"} = WebGUI::International::get(514);
$var{"replies.label"} = WebGUI::International::get(19,$namespace);
$var{"last.label"} = WebGUI::International::get(20,$namespace);
$p = WebGUI::Paginator->new('wid='.$_[0]->get("wobjectId").'&func=view');
$p->setDataByQuery("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 dateOfPost desc");
while (%data = $sth->hash) {
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 .= '<tr><td class="tableData"><a
href="'.WebGUI::URL::page('func=showMessage&mid='.$data{messageId}.'&wid='.$_[0]->get("wobjectId"))
.'">'.substr($data{subject},0,30).'</a>';
if ($data{userId} == $session{user}{userId}) {
$html .= ' ('.$status{$data{status}}.')';
}
$html .= '</td>
<td class="tableData"><a href="'.WebGUI::URL::page('op=viewProfile&uid='.$data{userId}).'">'
.$data{username}.'</a></td>
<td class="tableData">'.epochToHuman($data{dateOfPost},"%z %Z").'</td>
<td class="tableData">'.$data{views}.'</td>
<td class="tableData">'.$replies.'</td>
<td class="tableData"><span style="font-size: 8pt;"><a
href="'.WebGUI::URL::page('func=showMessage&mid='.$last[0].'&wid='.$_[0]->get("wobjectId")).'">'
.substr($last[3],0,30).'</a>
@ '.epochToHuman($last[1],"%z %Z").' by <a href="'
.WebGUI::URL::page('op=viewProfile&uid='.$last[4]).'">'.$last[2].'</a>
</span></td></tr>';
}
$i++;
$rows = $p->getPageData;
foreach $data (@$rows) {
@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");
($replies) = WebGUI::SQL->quickArray("select count(*) from discussion
where rid=$data->{messageId} and status='Approved'");
$replies--;
@message_loop = ({
"last.url" => WebGUI::URL::page('func=showMessage&mid='.$last[0].'&wid='.$_[0]->get("wobjectId")),
"last.subject" => substr(WebGUI::HTML::filter($last[3],'all'),0,30),
"last.date" => epochToHuman($last[1]),
"last.userProfile" => WebGUI::URL::page('op=viewProfile&uid='.$last[4]),
"last.username" => $last[2],
"message.replies" => $replies,
"message.url" => WebGUI::URL::page('func=showMessage&mid='.$data->{messageId}.'&wid='.$_[0]->get("wobjectId")),
"message.subject" => substr($data{subject},0,30),
"message.currentUser" => ($data{userId} == $session{user}{userId}),
"message.status" => $status{$data{status}},
"message.userProfile" => WebGUI::URL::page('op=viewProfile&uid='.$data{userId}),
"message.username" => $data{username},
"message.date" => epochToHuman($data{dateOfPost}),
"message.views" => $data{views}
});
}
$html .= '</table>';
if ($i > $_[0]->get("messagesPerPage")) {
$html .= '<div class="pagination">';
if ($pn > 0) {
$html .= '<a href="'.WebGUI::URL::page('pn='.($pn-1)).'">&laquo;'.
WebGUI::International::get(91).'</a>';
} else {
$html .= '&laquo;'.WebGUI::International::get(91);
}
$html .= ' &middot; ';
if (($pn+1) < round(($i/$_[0]->get("messagesPerPage")))) {
$html .= '<a href="'.WebGUI::URL::page('pn='.($pn+1)).'">'.
WebGUI::International::get(92).'&raquo;</a>';
} else {
$html .= WebGUI::International::get(92).'&raquo;';
}
$html .= '</div>';
}
return $html;
$var{message_loop} = \@message_loop;
$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);
return $_[0]->processTemplate($_[0]->get("templateId"),\%var);
}
1;