############################################################################### # Poll.pl # ############################################################################### # YaBB: Yet another Bulletin Board # # Open-Source Community Software for Webmasters # # Version: YaBB 2.4 # # Packaged: April 12, 2009 # # Distributed by: http://www.yabbforum.com # # =========================================================================== # # Copyright (c) 2000-2009 YaBB (www.yabbforum.com) - All Rights Reserved. # # Software by: The YaBB Development Team # # with assistance from the YaBB community. # # Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com # # Your source for web hosting, web design, and domains. # ############################################################################### $pollplver = 'YaBB 2.4 $Revision$'; if ($GLOBAL::ACTION eq 'detailedversion') { return 1; } &LoadLanguage('Poll'); sub DoVote { $pollnum = $INFO{'num'}; $start = $INFO{'start'}; unless (&checkfor_DBorFILE("$datadir/$pollnum.poll")) { &fatal_error('poll_not_found',$pollnum); } $novote = 0; $vote = ""; @poll_data = &read_DBorFILE(1,'',$datadir,$pollnum,'poll'); $poll_question = shift(@poll_data); (undef, $poll_locked, undef, undef, undef, undef, $guest_vote, undef, $multi_vote, undef, undef, undef, $vote_limit,undef) = split(/\|/, $poll_question, 14); for (my $i = 0; $i < @poll_data; $i++) { chomp $poll_data[$i]; ($votes[$i], $options[$i], $slicecols[$i], $split[$i]) = split(/\|/, $poll_data[$i]); $tmp_vote = $FORM{"option$i"}; if ($multi_vote && $tmp_vote ne "") { $votes[$i]++; $novote = 1; if ($vote ne '') { $vote .= ","; } $vote .= $tmp_vote; } } $tmp_vote = $FORM{'option'}; if (!$multi_vote && $tmp_vote ne '') { $vote = $tmp_vote; $votes[$tmp_vote]++; $novote = 1; } if ($novote == 0 || $vote eq '') { &fatal_error('no_vote_option'); } if ($iamguest && !$guest_vote) { &fatal_error('members_only'); } if ($poll_locked) { &fatal_error('locked_poll_no_count'); } @polled = &read_DBorFILE(1,'',$datadir,$pollnum,'polled'); for (my $i = 0; $i < @polled; $i++) { ($voters_ip, $voters_name, $voters_vote, $vote_time) = split(/\|/, $polled[$i]); chomp $voters_vote; if ($iamguest && $voters_name eq 'Guest' && lc $voters_ip eq lc $user_ip) { &fatal_error('ip_guest_used'); } elsif ($iamguest && $voters_name ne 'Guest' && lc $voters_ip eq lc $user_ip) { &fatal_error('ip_member_used'); } elsif (!$iamguest && $voters_name ne 'Guest' && lc $username eq lc $voters_name) { &fatal_error('voted_already'); } elsif (!$iamguest && $voters_name eq 'Guest' && lc $voters_ip eq lc $user_ip) { foreach $oldvote (split(/\,/, $voters_vote)) { $votes[$oldvote]--; } $polled[$i] = ''; last; } } @_ = ($poll_question); for (my $i = 0; $i < @poll_data; $i++) { push(@_, "$votes[$i]|$options[$i]|$slicecols[$i]|$split[$i]\n"); } &write_DBorFILE(1,'',$datadir,$pollnum,'poll',@_); &write_DBorFILE(1,'',$datadir,$pollnum,'polled',("$user_ip|$username|$vote|$date\n", @polled)); if ($INFO{'scp'}) { $yySetLocation = qq~$scripturl~; } else { $start = $start ? "/$start" : ''; $yySetLocation = qq~$scripturl?num=$pollnum$start~; } &redirectexit; } sub UndoVote { $pollnum = $INFO{'num'}; unless (&checkfor_DBorFILE("$datadir/$pollnum.poll")) { &fatal_error('poll_not_found',$pollnum); } &check_deletepoll; if (!$iamadmin && $poll_nodelete{$username}) { &fatal_error('no_access'); } @poll_data = &read_DBorFILE(0,'',$datadir,$pollnum,'poll'); $poll_question = shift(@poll_data); $poll_locked = (split /\|/, $poll_question, 2)[1]; my @options; my @votes; for (my $i = 0; $i < @poll_data; $i++) { chomp $poll_data[$i]; ($votes[$i], $options[$i], $slicecols[$i], $split[$i]) = split(/\|/, $poll_data[$i]); } @polled = &read_DBorFILE(1,'',$datadir,$pollnum,'polled'); if ($FORM{'multidel'} eq "1") { &is_admin; for (my $i = 0; $i < @polled; $i++) { ($voters_ip, $voters_name, $voters_vote, $vote_date) = split(/\|/, $polled[$i]); if ($FORM{"$voters_ip-$voters_name"} == 1) { foreach $oldvote (split(/,/, $voters_vote)) { $votes[$oldvote]--; } $polled[$i] = ''; } } } else { if ($iamguest) { &fatal_error('not_allowed'); } if ($poll_lock) { &fatal_error('locked_poll_no_delete'); } $found = 0; for (my $i = 0; $i < @polled; $i++) { ($voters_ip, $voters_name, $voters_vote, $vote_date) = split(/\|/, $polled[$i]); if ($voters_name eq $username) { $found = 1; foreach $oldvote (split(/,/, $voters_vote)) { $votes[$oldvote]--; } $polled[$i] = ''; last; } } if (!$found) { &fatal_error('not_completed'); } } @_ = ($poll_question); for (my $i = 0; $i < @poll_data; $i++) { push(@_, "$votes[$i]|$options[$i]|$slicecols[$i]|$split[$i]\n"); } &write_DBorFILE(1,'',$datadir,$pollnum,'poll',@_); if (join('', @polled)) { &write_DBorFILE(1,'',$datadir,$pollnum,'polled',@polled); } else { &delete_DBorFILE("$datadir/$pollnum.polled"); } if ($INFO{'scp'}) { $yySetLocation = qq~$scripturl~; } else { $start = $start ? "/$start" : ''; $yySetLocation = qq~$scripturl?num=$pollnum$start~; } &redirectexit; } sub LockPoll { $pollnum = $INFO{'num'}; unless (&checkfor_DBorFILE("$datadir/$pollnum.poll")) { &fatal_error('poll_not_found',$pollnum); } @poll_data = &read_DBorFILE(1,'',$datadir,$pollnum,'poll'); my ($poll_question, $poll_locked, $poll_uname, $poll_name, $poll_email, $poll_date, $guest_vote, $hide_results, $multi_vote, $poll_mod, $poll_modname, $poll_comment, $vote_limit, $pie_radius, $pie_legends, $poll_end) = split(/\|/, shift(@poll_data)); unless ($username eq $poll_uname || $staff) { &fatal_error('not_allowed'); } $poll_locked = $poll_locked ? 0 : 1; &write_DBorFILE(1,'',$datadir,$pollnum,'poll',("$poll_question|$poll_locked|$poll_uname|$poll_name|$poll_email|$poll_date|$guest_vote|$hide_results|$multi_vote|$poll_mod|$poll_modname|$poll_comment|$vote_limit|$pie_radius|$pie_legends|\n", @poll_data)); if ($INFO{'scp'}){ $yySetLocation = qq~$scripturl~; } else { $start = $start ? "/$start" : ''; $yySetLocation = qq~$scripturl?num=$pollnum$start~; } &redirectexit; } sub votedetails { &is_admin; $pollnum = $INFO{'num'}; unless (&checkfor_DBorFILE("$datadir/$pollnum.poll")) { &fatal_error('poll_not_found',$pollnum); } if ($start) { $start = "/$start"; } &LoadCensorList; # Figure out the name of the category ($curcat, $catperms) = split(/\|/, $catinfo{"$cat"}); @poll_data = &read_DBorFILE(0,'',$datadir,$pollnum,'poll'); $poll_question = shift(@poll_data); ($poll_question, $poll_locked, $poll_uname, $poll_name, $poll_email, $poll_date, $guest_vote, $hide_results, $multi_vote, $poll_mod, $poll_modname, $poll_comment, undef) = split(/\|/, $poll_question, 13); unless (ref($thread_arrayref{$pollnum})) { @{$thread_arrayref{$pollnum}} = &read_DBorFILE(1,'',$datadir,$pollnum,'txt'); } $psub = (split /\|/, ${$thread_arrayref{$pollnum}}[0], 2)[0]; &ToChars($psub); # Censor the options. $poll_question = &Censor($poll_question); if ($ubbcpolls) { if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; } $message = $poll_question; &DoUBBC; $poll_question = $message; } &ToChars($poll_question); my @options; my @votes; my $totalvotes = 0; my $maxvote = 0; for (my $i = 0; $i < @poll_data; $i++) { chomp $poll_data[$i]; ($votes[$i], $options[$i]) = split(/\|/, $poll_data[$i]); $totalvotes += int($votes[$i]); if (int($votes[$i]) >= $maxvote) { $maxvote = int($votes[$i]); } $options[$i] = &Censor($options[$i]); if ($ubbcpolls) { $message = $options[$i]; &DoUBBC; $options[$i] = $message; } &ToChars($options[$i]); } @polled = &read_DBorFILE(0,'',$datadir,$pollnum,'polled'); if ($poll_modname ne '' && $poll_mod ne '') { $poll_mod = &timeformat($poll_mod); &LoadUser($poll_modname); $displaydate = qq~« $polltxt{'45a'}: ${$uid.$poll_modname}{'realname'} $polltxt{'46'}: $poll_mod »~; } if ($poll_uname ne '' && $poll_date ne '') { $poll_date = &timeformat($poll_date); if ($poll_uname ne 'Guest' && &checkfor_DBorFILE("$memberdir/$poll_uname.vars")) { &LoadUser($poll_uname); $displaydate = qq~« $polltxt{'45'}: ${$uid.$poll_uname}{'realname'} $polltxt{'46'}: $poll_date »~; } else { $displaydate = qq~« $polltxt{'45'}: $poll_name $polltxt{'46'}: $poll_date »~; } } &ToChars($boardname); $yytitle = $polltxt{'42'}; $template_home = qq~$mbname~; $template_cat = qq~$cat~; $template_board = qq~$boardname~; $curthreadurl = qq~$psub › $polltxt{'42'}~; $yynavigation = qq~› $template_cat › $template_board › $curthreadurl~; $yymain .= qq~
~; foreach $entry (@polled) { chomp $entry; $voted = ''; ($voters_ip, $voters_name, $voters_vote, $vote_date) = split(/\|/, $entry); $id = qq~$voters_ip-$voters_name~; if ($voters_name ne 'Guest' && &checkfor_DBorFILE("$memberdir/$voters_name.vars")) { &LoadUser($voters_name); $voters_name = qq~${$uid.$voters_name}{'realname'}~; } foreach $oldvote (split(/\,/, $voters_vote)) { if ($ubbcpolls) { $message = $options[$oldvote]; &DoUBBC; $options[$oldvote] = $message; } &ToChars($options[$oldvote]); $voted .= qq~$options[$oldvote]
~; } $vote_date = &timeformat($vote_date); $yymain .= qq~ ~; } $yymain .= qq~
$img{'pollicon'} $polltxt{'42'}

$polltxt{'16'}: $poll_question

  $polltxt{'35'} $polltxt{'30'} $polltxt{'31'} $polltxt{'24'}
$voters_name $voters_ip $vote_date $voted
~; $display_template =~ s/({|<)yabb home(}|>)/$template_home/g; $display_template =~ s/({|<)yabb category(}|>)/$template_cat/g; $display_template =~ s/({|<)yabb board(}|>)/$template_board/g; $display_template =~ s/({|<)yabb threadurl(}|>)/$curthreadurl/g; &template; } sub display_poll { ($pollnum, $brdpoll) = @_; # $pollnum = number of poll; $brdpoll => if 1 = show on BoardIndex (showcasepoll) $scp = ''; $viewthread = ''; $boardpoll = ''; if ($brdpoll) { $scp = qq~;scp=1~; $viewthread = qq~$img{'viewthread'}~; $boardpoll = qq~ / $polltxt{'showcaserem'}~ if $iamadmin || $iamgmod; } elsif (&checkfor_DBorFILE("$datadir/poll.showcase")) { $boardpoll = qq~ / $polltxt{'showcased'}~ if $pollnum == (&read_DBorFILE(1,'',$datadir,'poll','showcase'))[0]; if ($iamadmin || $iamgmod) { $boardpoll = $boardpoll ? qq~ / $polltxt{'showcaserem'}~ : qq~ / $polltxt{'setshowcased'}~; } } else { $boardpoll = qq~ / $polltxt{'setshowcased'}~ if $iamadmin || $iamgmod; } # showcase poll end &LoadCensorList; @poll_data = &read_DBorFILE(0,'',$datadir,$pollnum,'poll'); $poll_question = shift(@poll_data); chomp $poll_question; ($poll_question, $poll_locked, $poll_uname, $poll_name, $poll_email, $poll_date, $guest_vote, $hide_results, $multi_vote, $poll_mod, $poll_modname, $poll_comment, $vote_limit, $pie_radius, $pie_legends, $poll_end) = split(/\|/, $poll_question); if ($poll_end && !$poll_locked && $poll_end < $date) { $poll_locked = 1; $poll_end = ''; &write_DBorFILE(1,'',$datadir,$pollnum,'poll',("$poll_question|$poll_locked|$poll_uname|$poll_name|$poll_email|$poll_date|$guest_vote|$hide_results|$multi_vote|$poll_mod|$poll_modname|$poll_comment|$vote_limit|$pie_radius|$pie_legends|$poll_end\n",@poll_data)); } $pie_radius ||= 100; $pie_legends ||= 0; $users_votetext = ''; $has_voted = 0; if (!$guest_vote && $iamguest) { $has_voted = 4; } else { foreach $tmpLine (&read_DBorFILE(1,'',$datadir,$pollnum,'polled')) { chomp $tmpline; ($voters_ip, $voters_name, $voters_vote, $vote_date) = split(/\|/, $tmpLine); if ($iamguest && $voters_name eq 'Guest' && lc $voters_ip eq lc $user_ip) { $has_voted = 1; last; } elsif ($iamguest && $voters_name ne 'Guest' && lc $voters_ip eq lc $user_ip) { $has_voted = 2; last; } elsif (!$iamguest && lc $username eq lc $voters_name) { $has_voted = 3; $users_votedate = &timeformat($vote_date); @users_vote = split(/\,/, $voters_vote); my $users_votecount = @users_vote; if ($users_votecount == 1) { $users_votetext = qq~
$polltxt{'64'}: $users_votedate
$polltxt{'65'}: ~; } else { $users_votetext = qq~
$polltxt{'64'}: $users_votedate
$polltxt{'66'}: ~; } last; } } } my @options; my @votes; my $totalvotes = 0; my $maxvote = 0; my $piearray = qq~[~; for (my $i = 0; $i < @poll_data; $i++) { chomp $poll_data[$i]; ($votes[$i], $options[$i], $slicecolor[$i], $split[$i]) = split(/\|/, $poll_data[$i]); # Censor the options. $options[$i] = &Censor($options[$i]); $options[$i] =~ s~[\n\r]~~g; if ($ubbcpolls) { if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; } $message = $options[$i]; &DoUBBC; $options[$i] = $message; } &ToChars($options[$i]); $piearray .= qq~"$votes[$i]|$options[$i]|$slicecolor[$i]|$split[$i]", ~; $totalvotes += int($votes[$i]); if (int($votes[$i]) >= $maxvote) { $maxvote = int($votes[$i]); } } $piearray =~ s/\, $//i; $piearray .= qq~]~; my ($endedtext, $displayvoters); if (!$iamguest && ($username eq $poll_uname || $staff)) { if ($poll_locked) { $lockpoll = qq~$img{'openpoll'}~; } else { $lockpoll = qq~$img{'closepoll'}~; } $modifypoll = qq~$menusep$img{'modifypoll'}~; $deletepoll = qq~$menusep$img{'deletepoll'}~ if $staff; if ($iamadmin) { $displayvoters = $menusep if $viewthread; $displayvoters .= qq~$img{'viewvotes'}~; } if ($hide_results) { $endedtext = qq~$polltxt{'53'}
~; $hide_results = 0; $bgclass = 'windowbg2'; } } if ($poll_modname ne '' && $poll_mod ne '' && $showmodify) { $poll_mod = &timeformat($poll_mod); &LoadUser($poll_modname); $displaydate = qq~« $polltxt{'45a'}: ${$uid.$poll_modname}{'realname'} $polltxt{'46'}: $poll_mod »~; } elsif ($poll_uname ne '' && $poll_date ne '') { $poll_date = &timeformat($poll_date); if ($poll_uname ne 'Guest' && &checkfor_DBorFILE("$memberdir/$poll_uname.vars")) { &LoadUser($poll_uname); $displaydate = qq~« $polltxt{'45'}: ${$uid.$poll_uname}{'realname'} $polltxt{'46'}: $poll_date »~; } elsif ($poll_name ne '') { $displaydate = qq~« $polltxt{'45'}: $poll_name $polltxt{'46'}: $poll_date »~; } else { $displaydate = ''; } } else { $displaydate = ''; } if ($poll_locked) { $bgclass = 'windowbg2'; $endedtext = qq~$polltxt{'22'}
~; $poll_icon = $img{'polliconclosed'}; $has_voted = 5; } else { $bgclass = 'windowbg2'; $poll_icon = $img{'pollicon'}; } # Censor the question. $poll_question = &Censor($poll_question); if ($ubbcpolls) { if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; } my $message = $poll_question; &DoUBBC; $poll_question = $message; } &ToChars($poll_question); $deletevote = ''; if ($has_voted) { if ($users_votetext) { if (!$yyYaBBCloaded && $ubbcpolls) { require "$sourcedir/YaBBC.pl"; } $footer = $users_votetext; for ($i = 0; $i < @users_vote; $i++) { $optnum = $users_vote[$i]; # Censor the user answer. $options[$optnum] = &Censor($options[$optnum]); if ($ubbcpolls) { $message = $options[$optnum]; &DoUBBC; $options[$optnum] = $message; } &ToChars($options[$optnum]); $footer .= qq~$options[$optnum], ~; } } $footer =~ s/, \Z//; $footer .= qq~

$polltxt{'17'}: $totalvotes~; $width = ''; $deletevote .= $menusep if $viewthread; $deletevote .= qq~$img{'deletevote'}~; $deletevote .= $menusep if !$viewthread && $displayvoters; } else { $footer = qq~~; $width = qq~ width="80%"~; $bgclass = 'windowbg2'; } &check_deletepoll; if ($iamguest || $poll_locked || $poll_nodelete{$username}) { $deletevote = ''; } $pollmain = qq~
$poll_icon $polltxt{'15'}$boardpoll
$lockpoll$modifypoll$deletepoll
$polltxt{'16'}: $poll_question
~; if ($has_voted) { unless($hide_results && !$poll_locked) { $pollmain .= qq~
~; } } $pollmain .= qq~
$endedtext

~; if ($has_voted && $hide_results && !$poll_locked) { # Display Poll Hidden Message $pollmain .= qq~$polltxt{'47'}
($polltxt{'48'})
~; } else { if ($has_voted) { if($INFO{'view'} eq "pie") { $pollmain .= qq~ ~; } else { for ($i = 0; $i < @options; $i++) { unless ($options[$i]) { next; } # Display Poll Results $pollpercent = 0; $pollbar = 0; if ($totalvotes > 0 && $maxvote > 0) { $pollpercent = (100 * $votes[$i]) / $totalvotes; $pollpercent = sprintf("%.1f", $pollpercent); $pollbar = int(150 * $votes[$i] / $maxvote); } $pollbar .= 'px'; $pollmain .= qq~
$options[$i]    
  $votes[$i] ($pollpercent%)
~; } } } else { for ($i = 0; $i < @options; $i++) { unless ($options[$i]) { next; } # Display Poll Options if ($multi_vote) { $input = qq~~; } else { $input = qq~~; } $pollmain .= qq~
$input
~; } } } $pollmain .= qq~

$footer
~; if ($poll_comment ne '') { $poll_comment = &Censor($poll_comment); $message = $poll_comment; if ($enable_ubbc) { if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; } &DoUBBC; } $poll_comment = $message; &ToChars($poll_comment); $pollmain .= qq~

$poll_comment
~; } if (!$poll_locked && $poll_end) { my $x = $poll_end - $date; my $days = int($x / 86400); my $hours = int(($x - ($days * 86400)) / 3600); my $min = int(($x - ($days * 86400) - ($hours * 3600)) / 60); $poll_end = "$post_polltxt{'100'} "; $poll_end .= "$days $post_polltxt{'100a'}" . ($hours ? ", " : " $post_polltxt{'100c'} ") if $days; $poll_end .= "$hours $post_polltxt{'100b'} $post_polltxt{'100c'} " if $hours; $poll_end .= "$min $post_polltxt{'100d'}
"; } else { $poll_end = ''; } $pollmain .= qq~
$poll_end$displaydate
$viewthread$deletevote$displayvoters
~; } sub check_deletepoll { my $poll_chech = (&read_DBorFILE(1,'',$datadir,$pollnum,'poll'))[0]; my $vote_limit = (split /\|/, $poll_chech, 14)[12]; $poll_nodelete{$username} = 0; if (!$vote_limit) { $poll_nodelete{$username} = 1; return; } foreach (&read_DBorFILE(1,'',$datadir,$pollnum,'polled')) { my ($dummy, $chvotersname, $dummy, $chvotedate) = split(/\|/, $_); if ($chvotersname eq $username) { $chdiff = $date - $chvotedate; if ($chdiff > ($vote_limit * 60)) { $poll_nodelete{$username} = 1; last; } } } } sub ShowcasePoll { &is_admin_or_gmod; my $thrdid = $INFO{'num'}; &write_DBorFILE(1,'',$datadir,'poll','showcase',($thrdid)); $yySetLocation = qq~$scripturl~; &redirectexit; } sub DelShowcasePoll{ &is_admin_or_gmod; if (&checkfor_DBorFILE("$datadir/poll.showcase")) { &delete_DBorFILE("$datadir/poll.showcase"); } $yySetLocation = qq~$scripturl~; &redirectexit; } 1;