package WebGUI::Widget::Poll; our $namespace = "Poll"; #------------------------------------------------------------------- # WebGUI is Copyright 2001 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::International; use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; use WebGUI::Utility; use WebGUI::Widget; #------------------------------------------------------------------- sub _viewPoll { my (%poll, $i, $output, $widgetId); tie %poll, 'Tie::CPHash'; $widgetId = shift; %poll = WebGUI::SQL->quickHash("select * from widget,Poll where widget.widgetId=Poll.widgetId and widget.widgetId='$widgetId'",$session{dbh}); if (defined %poll) { if ($poll{displayTitle} == 1) { $output = "
'; } $output .= '
'; } return $output; } #------------------------------------------------------------------- sub _viewResults { my (%poll, @data, $i, $output, $widgetId, $totalResponses); tie %poll, 'Tie::CPHash'; $widgetId = shift; %poll = WebGUI::SQL->quickHash("select * from widget,Poll where widget.widgetId=Poll.widgetId and widget.widgetId='$widgetId'",$session{dbh}); if (defined %poll) { if ($poll{displayTitle} == 1) { $output = "';
}
$output .= ''.$poll{question}.'';
($totalResponses) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where widgetId=$widgetId",$session{dbh});
if ($totalResponses < 1) {
$totalResponses = 1;
}
for ($i=1; $i<=20; $i++) {
if ($poll{'a'.$i} =~ /\w/) {
$output .= '
'.$poll{'a'.$i}.'
';
@data = WebGUI::SQL->quickArray("select count(*), answer from Poll_answer where answer='a$i' and widgetId=$widgetId group by answer",$session{dbh});
$output .= '
| '.round(100*$data[0]/$totalResponses).'% |
';
$output .= '
';
$output .= '