package WebGUI::Discussion; #------------------------------------------------------------------- # WebGUI is Copyright 2001-2002 Plain Black Software. #------------------------------------------------------------------- # 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::HTML; use WebGUI::International; use WebGUI::Session; use WebGUI::Shortcut; use WebGUI::SQL; use WebGUI::URL; #------------------------------------------------------------------- sub _deleteReplyTree { my ($sth, %data, $messageId); tie %data, 'Tie::CPHash'; $sth = WebGUI::SQL->read("select messageId from discussion where pid=$_[0] order by messageId"); while (%data = $sth->hash) { _deleteReplyTree($data{messageId}); WebGUI::SQL->write("delete from discussion where messageId=$data{messageId}"); } $sth->finish; } #------------------------------------------------------------------- sub _duplicateReplyTree { my ($sth, %data, $newMessageId); $sth = WebGUI::SQL->read("select * from discussion where pid=$_[0] order by messageId"); while (%data = $sth->hash) { $newMessageId = getNextId("messageId"); WebGUI::SQL->write("insert into discussion values ($newMessageId, $_[2], $_[3], $_[1], $data{userId}, " .quote($data{username}).", ".quote($data{subject}).", ".quote($data{message}). ", $data{dateOfPost}, $_[4])"); _duplicateReplyTree($data{messageId},$newMessageId,$_[2],$_[3],$_[4]); } $sth->finish; } #------------------------------------------------------------------- sub duplicate { my ($sth, %data, $newMessageId, $oldSubId, $newSubId); $oldSubId = $_[2] || 0; $newSubId = $_[3] || 0; $sth = WebGUI::SQL->read("select * from discussion where wobjectId=$_[0] and pid=0 and subId=$oldSubId order by messageId"); while (%data = $sth->hash) { $newMessageId = getNextId("messageId"); WebGUI::SQL->write("insert into discussion values ($newMessageId, $newMessageId, $_[1], 0, $data{userId}, ".quote($data{username}).", ".quote($data{subject}).", ".quote($data{message}).", $data{dateOfPost}, $newSubId)"); _duplicateReplyTree($data{messageId},$newMessageId,$newMessageId,$_[1],$newSubId); } $sth->finish; } #------------------------------------------------------------------- sub deleteMessage { my ($output); $output = '
'; $output .= '
| '.WebGUI::International::get(229). ' | '.WebGUI::Form::text("subject",30,255,$message{subject}).' |
| '.WebGUI::International::get(230). ' | '.WebGUI::Form::textArea("message",$message{message},50,6,1).' |
| '.WebGUI::Form::submit(WebGUI::International::get(62)).' |
/ig) {
$message{message} =~ s/\n/\
/g;
}
return %message;
}
#-------------------------------------------------------------------
sub postNewMessage {
my ($html);
$html = '
| '.WebGUI::International::get(229).' | '.WebGUI::Form::text("subject",30,255).' |
| '.WebGUI::International::get(230).' | '.WebGUI::Form::textArea("message",'',50,6,1).' |
| '.WebGUI::Form::submit(WebGUI::International::get(62)).' |
| '.WebGUI::International::get(229).' | '.WebGUI::Form::text("subject",30,255,$subject).' |
| '.WebGUI::International::get(230).' | '.WebGUI::Form::textArea("message",'',50,6,1).' |
| '.WebGUI::Form::submit(WebGUI::International::get(62)).' |
| ';
$html .= ''.WebGUI::International::get(238).'
'.$message{username}.' '; $html .= "".WebGUI::International::get(239)." ".epochToHuman($message{dateOfPost},"%z %Z")." "; $html .= ' | ';
$html .= '';
$html .= $_[0];
@data = WebGUI::SQL->quickArray("select max(messageId) from discussion
where wobjectId=$message{wobjectId} and pid=0 and messageId<$message{rid}".$sqlAdd);
if ($data[0] ne "") {
$html .= '« '.WebGUI::International::get(513).' '; } @data = WebGUI::SQL->quickArray("select min(messageId) from discussion where wobjectId=$message{wobjectId} and pid=0 and messageId>$message{rid}".$sqlAdd); if ($data[0] ne "") { $html .= ''.WebGUI::International::get(512).' » '; } $html .= ' |
| ';
$html .= $message{message}.' '; $html .= ' |
| '.WebGUI::International::get(229). ' | '.WebGUI::International::get(244). ' | '.WebGUI::International::get(245).' |
| '.$data[2]. ' | '. epochToHuman($data[3],"%z %Z").' |
| '.WebGUI::International::get(229).' | '.WebGUI::International::get(244).' | '.WebGUI::International::get(245).' |
| '.$data{username}. ' | '.epochToHuman($data{dateOfPost},"%z %Z"). ' |