package WebGUI::Widget::MessageBoard; our $namespace = "MessageBoard"; #------------------------------------------------------------------- # 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::Discussion; use WebGUI::HTML; use WebGUI::International; use WebGUI::Macro; use WebGUI::Privilege; use WebGUI::Session; use WebGUI::Shortcut; use WebGUI::SQL; use WebGUI::URL; use WebGUI::Utility; use WebGUI::Widget; #------------------------------------------------------------------- sub duplicate { my (%data, $newWidgetId, $pageId); tie %data, 'Tie::CPHash'; %data = getProperties($namespace,$_[0]); $pageId = $_[1] || $data{pageId}; $newWidgetId = create($pageId,$namespace,$data{title},$data{displayTitle}, $data{description},$data{processMacros},$data{templatePosition}); WebGUI::SQL->write("insert into MessageBoard values ($newWidgetId, $data{groupToPost}, '$data{messagesPerPage}', '$data{editTimeout}', $data{groupToModerate})"); WebGUI::Discussion::duplicate($_[0],$newWidgetId); } #------------------------------------------------------------------- sub purge { purgeWidget($_[0],$_[1],$namespace); WebGUI::Discussion::purgeWidget($_[0],$_[1]); } #------------------------------------------------------------------- sub widgetName { return WebGUI::International::get(2,$namespace); } #------------------------------------------------------------------- sub www_add { my ($output, %hash, @array); tie %hash, "Tie::IxHash"; if (WebGUI::Privilege::canEditPage()) { $output = helpLink(1,$namespace); $output .= '

'.WebGUI::International::get(1,$namespace).'

'; $output .= formHeader(); $output .= WebGUI::Form::hidden("widget",$namespace); $output .= WebGUI::Form::hidden("func","addSave"); $output .= ''; $output .= tableFormRow(WebGUI::International::get(99), WebGUI::Form::text("title",20,128,'Message Board')); $output .= tableFormRow(WebGUI::International::get(174),WebGUI::Form::checkbox("displayTitle",1,1)); $output .= tableFormRow(WebGUI::International::get(175),WebGUI::Form::checkbox("processMacros",1)); %hash = WebGUI::Widget::getPositions(); $output .= tableFormRow(WebGUI::International::get(363), WebGUI::Form::selectList("templatePosition",\%hash)); $output .= tableFormRow(WebGUI::International::get(85), WebGUI::Form::textArea("description",'',50,5,1)); $output .= tableFormRow(WebGUI::International::get(3,$namespace), WebGUI::Form::groupList("groupToPost",2)); $output .= tableFormRow(WebGUI::International::get(21,$namespace), WebGUI::Form::groupList("groupToModerate",4)); $output .= tableFormRow(WebGUI::International::get(4,$namespace), WebGUI::Form::text("messagesPerPage",20,2,30)); $output .= tableFormRow(WebGUI::International::get(5,$namespace), WebGUI::Form::text("editTimeout",20,3,1)); $output .= formSave(); $output .= '
'; return $output; } else { return WebGUI::Privilege::insufficient(); } return $output; } #------------------------------------------------------------------- sub www_addSave { my ($widgetId); if (WebGUI::Privilege::canEditPage()) { $widgetId = create($session{page}{pageId},$session{form}{widget},$session{form}{title},$session{form}{displayTitle},$session{form}{description},$session{form}{processMacros},$session{form}{templatePosition}); WebGUI::SQL->write("insert into MessageBoard values ($widgetId, $session{form}{groupToPost}, '$session{form}{messagesPerPage}', '$session{form}{editTimeout}', $session{form}{groupToModerate})"); return ""; } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_copy { if (WebGUI::Privilege::canEditPage()) { duplicate($session{form}{wid}); return ""; } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_deleteMessage { my (%board, %message); tie %board, 'Tie::CPHash'; tie %message, 'Tie::CPHash'; %board = getProperties($namespace,$session{form}{wid}); %message = WebGUI::Discussion::getMessage($session{form}{mid}); if ((time()-$message{dateOfPost}) < 3600*$board{editTimeout} && $message{userId} eq $session{user}{userId} || WebGUI::Privilege::isInGroup($board{groupToModerate})) { return WebGUI::Discussion::deleteMessage(); } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_deleteMessageConfirm { my (%board,%message); tie %board, 'Tie::CPHash'; tie %message, 'Tie::CPHash'; %board = getProperties($namespace,$session{form}{wid}); %message = WebGUI::Discussion::getMessage($session{form}{mid}); if ((time()-$message{dateOfPost}) < 3600*$board{editTimeout} && $message{userId} eq $session{user}{userId} || WebGUI::Privilege::isInGroup($board{groupToModerate})) { return WebGUI::Discussion::deleteMessageConfirm(); } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_edit { my ($output, %board, %hash, @array); tie %hash, "Tie::IxHash"; if (WebGUI::Privilege::canEditPage()) { tie %board, 'Tie::CPHash'; %board = getProperties($namespace,$session{form}{wid}); $output = helpLink(1,$namespace); $output .= '

'.WebGUI::International::get(6,$namespace).'

'; $output .= formHeader(); $output .= WebGUI::Form::hidden("wid",$session{form}{wid}); $output .= WebGUI::Form::hidden("func","editSave"); $output .= ''; $output .= tableFormRow(WebGUI::International::get(99), WebGUI::Form::text("title",20,128,$board{title})); $output .= tableFormRow(WebGUI::International::get(174), WebGUI::Form::checkbox("displayTitle","1",$board{displayTitle})); $output .= tableFormRow(WebGUI::International::get(175), WebGUI::Form::checkbox("processMacros","1",$board{processMacros})); %hash = WebGUI::Widget::getPositions(); $array[0] = $board{templatePosition}; $output .= tableFormRow(WebGUI::International::get(363), WebGUI::Form::selectList("templatePosition",\%hash,\@array)); $output .= tableFormRow(WebGUI::International::get(85), WebGUI::Form::textArea("description",$board{description},50,5,1)); $output .= tableFormRow(WebGUI::International::get(3,$namespace), WebGUI::Form::groupList("groupToPost",$board{groupToPost})); $output .= tableFormRow(WebGUI::International::get(21,$namespace), WebGUI::Form::groupList("groupToModerate",$board{groupToModerate})); $output .= tableFormRow(WebGUI::International::get(4,$namespace), WebGUI::Form::text("messagesPerPage",20,2,$board{messagesPerPage})); $output .= tableFormRow(WebGUI::International::get(5,$namespace), WebGUI::Form::text("editTimeout",20,2,$board{editTimeout})); $output .= formSave(); $output .= '
'; return $output; } else { return WebGUI::Privilege::insufficient(); } return $output; } #------------------------------------------------------------------- sub www_editSave { if (WebGUI::Privilege::canEditPage()) { update(); WebGUI::SQL->write("update MessageBoard set groupToPost=$session{form}{groupToPost}, messagesPerPage=$session{form}{messagesPerPage}, editTimeout=$session{form}{editTimeout}, groupToModerate=$session{form}{groupToModerate} where widgetId=$session{form}{wid}"); return ""; } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_editMessage { my (%board,%message); tie %board, 'Tie::CPHash'; tie %message, 'Tie::CPHash'; %board = getProperties($namespace,$session{form}{wid}); %message = WebGUI::Discussion::getMessage($session{form}{mid}); if ((time()-$message{dateOfPost}) < 3600*$board{editTimeout} && $message{userId} eq $session{user}{userId} || WebGUI::Privilege::isInGroup($board{groupToModerate})) { return WebGUI::Discussion::editMessage(); } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_editMessageSave { my (%board,%message); tie %board, 'Tie::CPHash'; tie %message, 'Tie::CPHash'; %board = getProperties($namespace,$session{form}{wid}); %message = WebGUI::Discussion::getMessage($session{form}{mid}); if ((time()-$message{dateOfPost}) < 3600*$board{editTimeout} && $message{userId} eq $session{user}{userId} || WebGUI::Privilege::isInGroup($board{groupToModerate})) { WebGUI::Discussion::editMessageSave(); return www_showMessage(); } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_postNewMessage { my (%board); tie %board, 'Tie::CPHash'; %board = getProperties($namespace,$session{form}{wid}); if (WebGUI::Privilege::isInGroup($board{groupToPost},$session{user}{userId})) { return WebGUI::Discussion::postNewMessage(); } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_postNewMessageSave { my (%board); tie %board, 'Tie::CPHash'; %board = getProperties($namespace,$session{form}{wid}); if (WebGUI::Privilege::isInGroup($board{groupToPost},$session{user}{userId})) { return WebGUI::Discussion::postNewMessageSave(); } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_postReply { my (%board); tie %board, 'Tie::CPHash'; %board = getProperties($namespace,$session{form}{wid}); if (WebGUI::Privilege::isInGroup($board{groupToPost},$session{user}{userId})) { return WebGUI::Discussion::postReply(); } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_postReplySave { my (%board); tie %board, 'Tie::CPHash'; %board = getProperties($namespace,$session{form}{wid}); if (WebGUI::Privilege::isInGroup($board{groupToPost},$session{user}{userId})) { WebGUI::Discussion::postReplySave(); return www_showMessage(); } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_showMessage { my (@data, $html, %board, %message); tie %message, 'Tie::CPHash'; tie %board, 'Tie::CPHash'; %message = WebGUI::Discussion::getMessage($session{form}{mid}); %board = getProperties($namespace,$session{form}{wid}); if ($message{messageId}) { $html .= '

'.$message{subject}.'

'; $html .= ''; $html .= '
'; $html .= ''.WebGUI::International::get(7,$namespace).' '.$message{username}.'
'; $html .= "".WebGUI::International::get(8,$namespace)." ". epochToHuman($message{dateOfPost},"%w, %c %D, %y at %H:%n%p")."
"; $html .= "".WebGUI::International::get(9,$namespace)." ". $message{widgetId}."-".$message{rid}."-".$message{pid}."-".$message{messageId}."
"; $html .= '
'; $html .= ''.WebGUI::International::get(13,$namespace).'
'; if ((time()-$message{dateOfPost}) < 3600*$board{editTimeout} && $message{userId} eq $session{user}{userId} || WebGUI::Privilege::isInGroup($board{groupToModerate})) { $html .= ''.WebGUI::International::get(12,$namespace).'
'; $html .= ''.WebGUI::International::get(22,$namespace).'
'; } $html .= ''.WebGUI::International::get(11,$namespace).'
'; @data = WebGUI::SQL->quickArray("select max(messageId) from discussion where widgetId=$message{widgetId} and pid=0 and messageId<$message{rid}"); if ($data[0] ne "") { $html .= '« '.WebGUI::International::get(10,$namespace).'
'; } @data = WebGUI::SQL->quickArray("select min(messageId) from discussion where widgetId=$message{widgetId} and pid=0 and messageId>$message{rid}"); if ($data[0] ne "") { $html .= ''.WebGUI::International::get(14,$namespace).' »
'; } $html .= '
'; $html .= $message{message}; $html .= '
'; $html .= ''; $html .= ''; @data = WebGUI::SQL->quickArray("select messageId,subject,username,dateOfPost,userId from discussion where messageId=$message{rid}"); $data[1] = WebGUI::HTML::filter($data[1],'all'); $html .= ''.substr($data[1],0,30).''; $html .= WebGUI::Discussion::traverseReplyTree($message{rid},1); $html .= "
'.WebGUI::International::get(229). ''.WebGUI::International::get(15,$namespace). ''.WebGUI::International::get(16,$namespace).'
'.$data[2]. ''. epochToHuman($data[3],"%M/%D %H:%n%p").'
"; } else { $html = WebGUI::International::get(402); } return $html; } #------------------------------------------------------------------- sub www_view { my ($sth, @data, $html, %board, $itemsPerPage, $i, $pn, $lastId, @last, $replies); tie %board, 'Tie::CPHash'; %board = getProperties($namespace,$_[0]); $itemsPerPage = $board{messagesPerPage}; if ($session{form}{pn} < 1) { $pn = 0; } else { $pn = $session{form}{pn}; } if ($board{displayTitle}) { $html = '

'.$board{title}.'

'; } if ($board{description} ne "") { $html .= $board{description}.'

'; } if ($board{processMacros}) { $html = WebGUI::Macro::process($html); } $html .= ''. '
'. WebGUI::International::get(17,$namespace).'
'; $html .= ''; $html .= ''; $sth = WebGUI::SQL->read("select messageId,subject,username,dateOfPost,userId from discussion where widgetId=$_[0] and pid=0 order by messageId desc"); while (@data = $sth->array) { $data[1] = WebGUI::HTML::filter($data[1],'all'); if ($i >= ($itemsPerPage*$pn) && $i < ($itemsPerPage*($pn+1))) { @last = WebGUI::SQL->quickArray("select messageId,dateOfPost,username,subject,userId from discussion where widgetId=$_[0] and rid=$data[0] order by dateOfPost desc"); $last[3] = WebGUI::HTML::filter($last[3],'all'); ($replies) = WebGUI::SQL->quickArray("select count(*) from discussion where rid=$data[0]"); $replies -= 1; $html .= ''; } $i++; } $html .= '
'.WebGUI::International::get(229).''.WebGUI::International::get(15,$namespace).''.WebGUI::International::get(18,$namespace).''.WebGUI::International::get(19,$namespace).''.WebGUI::International::get(20,$namespace).'
'.substr($data[1],0,30). ''.$data[2]. ''.epochToHuman($data[3],"%M/%D %H:%n%p"). ''.$replies. ''. substr($last[3],0,30).' @ '.epochToHuman($last[1],"%M/%D %H:%n%p"). ' by '.$last[2]. '
'; if ($i > $itemsPerPage) { $html .= '

'; } return $html; } 1;