F:\WEBSITES\testbed\zipped\yabb_svn_new\branches\2.5.2\cgi-bin\yabb2\Sources\Poll.pl F:\WEBSITES\testbed\zipped\yabb_svn_new\trunk\cgi-bin\yabb2\Sources\Poll.pm
############################################################################### ###############################################################################
# Poll.pl                                                                     # # Poll.pm                                                                     #
  # $Date: 01.05.16 $                                                           #
############################################################################### ###############################################################################
# YaBB: Yet another Bulletin Board                                            # # YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               # # Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2.5.2                                                  # # Version:        YaBB 2.6.12                                                 #
# Packaged:       October 21, 2012                                            # # Packaged:       January 5, 2016                                             #
# Distributed by: http://www.yabbforum.com                                    # # Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== # # =========================================================================== #
# Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved.     # # Copyright (c) 2000-2016 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by:  The YaBB Development Team                                     # # Software by:  The YaBB Development Team                                     #
#               with assistance from the YaBB community.                      # #               with assistance from the YaBB community.                      #
############################################################################### ###############################################################################
  use CGI::Carp qw(fatalsToBrowser);
  our $VERSION = '2.6.12';
   
$pollplver = 'YaBB 2.5.2 $Revision: 1.0 $'; $pollpmver = 'YaBB 2.6.12 $Revision: 1710 $';
if ($action eq 'detailedversion') { return 1; } if ($action eq 'detailedversion') { return 1; }
   
&LoadLanguage('Poll');  LoadLanguage('Poll'); 
  get_micon();
  get_template('Poll');
   
sub DoVote { sub DoVote {
   $pollnum = $INFO{'num'};    $pollnum = $INFO{'num'};
   $start   = $INFO{'start'};    $start   = $INFO{'start'};
   unless (-e "$datadir/$pollnum.poll") { &fatal_error('poll_not_found',$pollnum); }     if ( !-e "$datadir/$pollnum.poll" ) { 
         fatal_error( 'poll_not_found', $pollnum );
   $novote = 0;     } 
   $vote   = "";  
   fopen(FILE, "$datadir/$pollnum.poll");     $novote = 0; 
   $poll_question = <FILE>;     $vote   = q{}; 
   @poll_data     = <FILE>;     fopen(FILE, "$datadir/$pollnum.poll"); 
   fclose(FILE);     $poll_question = <FILE>; 
   chomp $poll_question;     @poll_data     = <FILE>; 
   (undef, $poll_locked, undef, undef, undef, undef, $guest_vote, undef, $multi_vote, undef, undef, undef, $vote_limit,undef) = split(/\|/, $poll_question, 14);     fclose(FILE); 
   for (my $i = 0; $i < @poll_data; $i++) {     chomp $poll_question; 
       chomp $poll_data[$i];     ( 
       ($votes[$i], $options[$i], $slicecols[$i], $split[$i]) = split(/\|/, $poll_data[$i]);         undef, $poll_locked, undef,       undef,       undef, 
       $tmp_vote = qq~$FORM{"option$i"}~;         undef, $guest_vote,  undef,       $multi_vote, undef, 
       if ($multi_vote && $tmp_vote ne "") {         undef, undef,        $vote_limit, undef 
           $votes[$i]++;     ) = split /\|/xsm, $poll_question, 14; 
           $novote = 1;  
           if ($vote ne '') { $vote .= ","; }     for my $i ( 0 .. $#poll_data ) { 
           $vote .= $tmp_vote;         chomp $poll_data[$i]; 
       }         ( $votes[$i], $options[$i], $slicecols[$i], $split[$i] ) = 
   }           split /\|/xsm, $poll_data[$i]; 
   $tmp_vote = $FORM{'option'};         $tmp_vote = qq~$FORM{"option$i"}~; 
   if (!$multi_vote && $tmp_vote ne '') { $vote = $tmp_vote; $votes[$tmp_vote]++; $novote = 1; }         if ( $multi_vote && $tmp_vote ne q{} ) { 
             $votes[$i]++;
   if ($novote == 0 || $vote eq '') { &fatal_error('no_vote_option'); }             $novote = 1; 
   if ($iamguest && !$guest_vote) { &fatal_error('members_only'); }            if ( $vote ne q{} ) { $vote .= q{,}; }
   if ($poll_locked) { &fatal_error('locked_poll_no_count'); }             $vote .= $tmp_vote; 
         }
   fopen(FILE, "$datadir/$pollnum.polled");     } 
   @polled = <FILE>;     $tmp_vote = $FORM{'option'}; 
   fclose(FILE);     if ( !$multi_vote && $tmp_vote ne q{} ) { 
         $vote = $tmp_vote;
   for (my $i = 0; $i < @polled; $i++) {         $votes[$tmp_vote]++; 
       ($voters_ip, $voters_name, $voters_vote, $vote_time) = split(/\|/, $polled[$i]);         $novote = 1; 
       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'); }    if ( $novote == 0 || $vote eq q{} ) { fatal_error('no_vote_option'); }
       elsif (!$iamguest && $voters_name ne 'Guest' && lc $username  eq lc $voters_name) { &fatal_error('voted_already'); }    if ( $iamguest && !$guest_vote ) { fatal_error('members_only'); }
       elsif (!$iamguest && $voters_name eq 'Guest' && lc $voters_ip eq lc $user_ip) {     if ($poll_locked) { fatal_error('locked_poll_no_count'); } 
           foreach $oldvote (split(/\,/, $voters_vote)) {  
               $votes[$oldvote]--;     fopen(FILE, "$datadir/$pollnum.polled"); 
           }     @polled = <FILE>; 
           $polled[$i] = '';     fclose(FILE); 
           last;  
       }     for my $i ( 0 .. $#polled ) { 
   }         ( $voters_ip, $voters_name, $voters_vote, $vote_time ) = split /\|/xsm, 
           $polled[$i];
   fopen(FILE, ">$datadir/$pollnum.poll");         chomp $voters_vote; 
   print FILE "$poll_question\n";         if (   $iamguest 
   for (my $i = 0; $i < @poll_data; $i++) { print FILE "$votes[$i]|$options[$i]|$slicecols[$i]|$split[$i]\n"; }             && $voters_name  eq 'Guest' 
   fclose(FILE);             && lc $voters_ip eq lc $user_ip ) 
         {
   fopen(FILE, ">$datadir/$pollnum.polled");             fatal_error('ip_guest_used'); 
   print FILE "$user_ip|$username|$vote|$date\n";         } 
   print FILE @polled;         elsif ($iamguest 
   fclose(FILE);             && $voters_name ne 'Guest' 
             && lc $voters_ip eq lc $user_ip )
   if ($start) { $start = "/$start"; }         { 
   if ($INFO{'scp'}) {             fatal_error('ip_member_used'); 
       $yySetLocation = qq~$scripturl~;         } 
   } else {         elsif ( !$iamguest 
       $yySetLocation = qq~$scripturl?num=$pollnum$start~;             && $voters_name ne 'Guest' 
   }             && lc $username eq lc $voters_name ) 
   &redirectexit;         { 
             fatal_error('voted_already');
         }
         elsif ( !$iamguest
             && $voters_name  eq 'Guest' 
             && lc $voters_ip eq lc $user_ip )
         {
             foreach my $oldvote ( split /\,/xsm, $voters_vote ) {
                 $votes[$oldvote]--;
             }
             $polled[$i] = q{};
             last;
         }
     }
   
     fopen(FILE, ">$datadir/$pollnum.poll");
     print {FILE} "$poll_question\n" or croak "$croak{'print'} POLL FILE";
     for my $i ( 0 .. $#poll_data ) {
         print {FILE} "$votes[$i]|$options[$i]|$slicecols[$i]|$split[$i]\n" 
           or croak "$croak{'print'} POLL FILE";
     }
     fclose(FILE);
   
     fopen(FILE, ">$datadir/$pollnum.polled");
     print {FILE} "$user_ip|$username|$vote|$date\n" 
       or croak "$croak{'print'} POLL FILE";
     print {FILE} @polled or croak "$croak{'print'} POLL FILE";
     fclose(FILE);
   
     if ($start) { $start = "/$start"; }
     if ($INFO{'scp'}) {
         $yySetLocation = qq~$scripturl~;
     }
     else {
         $yySetLocation = qq~$scripturl?num=$pollnum$start~;
     }
     redirectexit();
     return;
} }
   
sub UndoVote { sub UndoVote {
   $pollnum = $INFO{'num'};    $pollnum = $INFO{'num'};
   unless (-e "$datadir/$pollnum.poll") { &fatal_error('poll_not_found',$pollnum); }     if ( !-e "$datadir/$pollnum.poll" ) { 
         fatal_error( 'poll_not_found', $pollnum );
   &check_deletepoll;     } 
   if (!$iamadmin && $poll_nodelete{$username}) { &fatal_error('no_access'); }  
     check_deletepoll();
   fopen(FILE, "$datadir/$pollnum.poll");     if ( !$iamadmin && $poll_nodelete{$username} ) { fatal_error('no_access'); } 
   $poll_question = <FILE>;  
   @poll_data     = <FILE>;     fopen(FILE, "$datadir/$pollnum.poll"); 
   fclose(FILE);     $poll_question = <FILE>; 
   $poll_locked = (split /\|/, $poll_question, 2)[1];     @poll_data     = <FILE>; 
   my @options;     fclose(FILE); 
   my @votes;     $poll_locked = ( split /\|/xsm, $poll_question, 2 )[1]; 
     my @options;
   for (my $i = 0; $i < @poll_data; $i++) {     my @votes; 
       chomp $poll_data[$i];  
       ($votes[$i], $options[$i], $slicecols[$i], $split[$i]) = split(/\|/, $poll_data[$i]);     for my $i ( 0 .. $#poll_data ) { 
   }         chomp $poll_data[$i]; 
         ( $votes[$i], $options[$i], $slicecols[$i], $split[$i] ) =
   fopen(FILE, "$datadir/$pollnum.polled");           split /\|/xsm, $poll_data[$i]; 
   @polled = <FILE>;     } 
   fclose(FILE);  
     fopen(FILE, "$datadir/$pollnum.polled");
   if ($FORM{'multidel'} eq "1") {     @polled = <FILE>; 
       &is_admin;     fclose(FILE); 
       for (my $i = 0; $i < @polled; $i++) {  
           ($voters_ip, $voters_name, $voters_vote, $vote_date) = split(/\|/, $polled[$i]);     if ( $FORM{'multidel'} == 1 ) { 
           chomp $voters_vote;         is_admin(); 
           $id = $FORM{"$voters_ip-$voters_name"};         for my $i ( 0 .. $#polled ) { 
           if ($id eq "1") {             ( $voters_ip, $voters_name, $voters_vote, $vote_date ) = 
               foreach $oldvote (split(/\,/, $voters_vote)) {               split /\|/xsm, $polled[$i]; 
                   $votes[$oldvote]--;             chomp $voters_vote; 
               }             $id = $FORM{"$voters_ip-$voters_name"}; 
               $polled[$i] = '';             if ( $id == 1 ) { 
           }                 foreach my $oldvote ( split /\,/xsm, $voters_vote ) { 
       }                     $votes[$oldvote]--; 
   } else {                 } 
       if ($iamguest)  { &fatal_error('not_allowed'); }                 $polled[$i] = q{}; 
       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]);      else { 
           chomp $voters_vote;         if ($iamguest)  { fatal_error('not_allowed'); } 
           if ($voters_name eq $username) {         if ($poll_lock) { fatal_error('locked_poll_no_delete'); } 
               $found = 1;         $found = 0; 
               foreach $oldvote (split(/\,/, $voters_vote)) {        for my $i ( 0 .. $#polled ) {
                   $votes[$oldvote]--;             ( $voters_ip, $voters_name, $voters_vote, $vote_date ) = 
               }               split /\|/xsm, $polled[$i]; 
               $polled[$i] = '';             chomp $voters_vote; 
               last;             if ($voters_name eq $username) { 
           }                 $found = 1; 
       }                 for my $oldvote ( split /\,/xsm, $voters_vote ) { 
       if (!$found) { &fatal_error('not_completed'); }                     $votes[$oldvote]--; 
   }                }
                 $polled[$i] = q{};
   fopen(FILE, ">$datadir/$pollnum.poll");                 last; 
   print FILE $poll_question;             } 
   for (my $i = 0; $i < @poll_data; $i++) { print FILE "$votes[$i]|$options[$i]|$slicecols[$i]|$split[$i]\n"; }        }
   fclose(FILE);         if ( !$found ) { fatal_error('not_completed'); } 
     }
   fopen(FILE, ">$datadir/$pollnum.polled");  
   print FILE @polled;     fopen(FILE, ">$datadir/$pollnum.poll"); 
   fclose(FILE);     print {FILE} $poll_question or croak "$croak{'print'} POLL FILE"; 
     for my $i ( 0 .. $#poll_data ) {
   if ($start) { $start = "/$start"; }         print {FILE} "$votes[$i]|$options[$i]|$slicecols[$i]|$split[$i]\n" 
   if ($INFO{'scp'}) {           or croak "$croak{'print'} POLL FILE"; 
       $yySetLocation = qq~$scripturl~;     } 
   } else {     fclose(FILE); 
       $yySetLocation = qq~$scripturl?num=$pollnum$start~;  
   }     fopen(FILE, ">$datadir/$pollnum.polled"); 
   &redirectexit;     print {FILE} @polled or croak "$croak{'print'} POLL FILE"; 
     fclose(FILE);
   
     if ($start) { $start = "/$start"; }
     if ($INFO{'scp'}) {
         $yySetLocation = qq~$scripturl~;
     }
     else {
         $yySetLocation = qq~$scripturl?num=$pollnum$start~;
     }
     redirectexit();
     return;
} }
   
sub LockPoll { sub LockPoll {
   $pollnum = $INFO{'num'};    $pollnum = $INFO{'num'};
   unless (-e "$datadir/$pollnum.poll") { &fatal_error('poll_not_found',$pollnum); }     if ( !-e "$datadir/$pollnum.poll" ) { 
         fatal_error( 'poll_not_found', $pollnum );
   fopen(FILE, "$datadir/$pollnum.poll");     } 
   $poll_question = <FILE>;  
   @poll_data     = <FILE>;     fopen(FILE, "$datadir/$pollnum.poll"); 
   fclose(FILE);     $poll_question = <FILE>; 
   chomp $poll_question;     @poll_data     = <FILE>; 
   ($poll_question, $poll_locked, $poll_uname, $poll_stuff) = split(/\|/, $poll_question, 4);     fclose(FILE); 
   unless ($username eq $poll_uname || $iamadmin || $iamgmod || $iammod) { &fatal_error('not_allowed'); }     chomp $poll_question; 
     ( $poll_question, $poll_locked, $poll_uname, $poll_stuff ) = split /\|/xsm,
   if ($poll_locked) { $poll_locked = 0; }       $poll_question, 4; 
   else { $poll_locked = 1; }    if ( $username ne $poll_uname && !$staff ) { fatal_error('not_allowed'); }
   
   fopen(FILE, ">$datadir/$pollnum.poll");     if ($poll_locked) { $poll_locked = 0; } 
   print FILE "$poll_question|$poll_locked|$poll_uname|$poll_stuff\n";     else { $poll_locked = 1; } 
   print FILE @poll_data;  
   fclose(FILE);     fopen(FILE, ">$datadir/$pollnum.poll"); 
     print {FILE} "$poll_question|$poll_locked|$poll_uname|$poll_stuff\n" 
   if ($start) { $start = "/$start"; }       or croak "$croak{'print'} POLL FILE"; 
   if ($INFO{'scp'}){     print {FILE} @poll_data or croak "$croak{'print'} POLL FILE"; 
       $yySetLocation = qq~$scripturl~;     fclose(FILE); 
   } else {  
       $yySetLocation = qq~$scripturl?num=$pollnum$start~;     if ($start) { $start = "/$start"; } 
   }     if ($INFO{'scp'}){ 
   &redirectexit;         $yySetLocation = qq~$scripturl~; 
     }
     else {
         $yySetLocation = qq~$scripturl?num=$pollnum$start~;
     }
     redirectexit();
     return;
} }
   
sub votedetails { sub votedetails {
   &is_admin;     is_admin(); 
   
   $pollnum = $INFO{'num'};    $pollnum = $INFO{'num'};
   unless (-e "$datadir/$pollnum.poll") { &fatal_error('poll_not_found',$pollnum); }     if ( !-e "$datadir/$pollnum.poll" ) { 
   if ($start) { $start = "/$start"; }         fatal_error( 'poll_not_found', $pollnum ); 
     }
   &LoadCensorList;     if ($start) { $start = "/$start"; } 
   
   # Figure out the name of the category     LoadCensorList(); 
   unless ($mloaded == 1) { require "$boardsdir/forum.master"; }  
   ($curcat, $catperms) = split(/\|/, $catinfo{"$cat"});     # Figure out the name of the category 
     get_forum_master();
   fopen(FILE, "$datadir/$pollnum.poll");     ( $curcat, $catperms ) = split /\|/xsm, $catinfo{"$cat"}; 
   $poll_question = <FILE>;  
   @poll_data     = <FILE>;     fopen(FILE, "$datadir/$pollnum.poll"); 
   fclose(FILE);     $poll_question = <FILE>; 
   chomp $poll_question;     @poll_data     = <FILE>; 
   ($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);     fclose(FILE); 
   unless (ref($thread_arrayref{$pollnum})) {     chomp $poll_question; 
       fopen(POLLTP, "$datadir/$pollnum.txt");     ( 
       @{$thread_arrayref{$pollnum}} = <POLLTP>;         $poll_question, $poll_locked, $poll_uname, $poll_name, 
       fclose(POLLTP);         $poll_email, $poll_date, $guest_vote, $hide_results, 
   }         $multi_vote, $poll_mod, $poll_modname, $poll_comment, 
   $psub = (split /\|/, ${$thread_arrayref{$pollnum}}[0], 2)[0];         undef 
   &ToChars($psub);     ) = split /\|/xsm, $poll_question, 13; 
   
   # Censor the options.     if ( !ref $thread_arrayref{$pollnum} ) { 
   $poll_question = &Censor($poll_question);         fopen(POLLTP, "$datadir/$pollnum.txt"); 
   if ($ubbcpolls) {         @{$thread_arrayref{$pollnum}} = <POLLTP>; 
       if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; }         fclose(POLLTP); 
       $message = $poll_question;     } 
       &DoUBBC;     $psub = ( split /\|/xsm, ${ $thread_arrayref{$pollnum} }[0], 2 )[0]; 
       $poll_question = $message;     ToChars($psub); 
   }  
   &ToChars($poll_question);     # Censor the options. 
     $poll_question = Censor($poll_question);
   my @options;     if ($ubbcpolls) { 
   my @votes;         enable_yabbc(); 
   my $totalvotes = 0;         $message = $poll_question; 
   my $maxvote    = 0;         DoUBBC(); 
   for (my $i = 0; $i < @poll_data; $i++) {         $poll_question = $message; 
       chomp $poll_data[$i];     } 
       ($votes[$i], $options[$i]) = split(/\|/, $poll_data[$i]);     ToChars($poll_question); 
       $totalvotes += int($votes[$i]);  
       if (int($votes[$i]) >= $maxvote) { $maxvote = int($votes[$i]); }     my @options; 
       $options[$i] = &Censor($options[$i]);     my @votes; 
       if ($ubbcpolls) {     my $totalvotes = 0; 
           $message = $options[$i];     my $maxvote    = 0; 
           &DoUBBC;     for my $i ( 0 .. $#poll_data ) { 
           $options[$i] = $message;         chomp $poll_data[$i]; 
       }         ( $votes[$i], $options[$i] ) = split /\|/xsm, $poll_data[$i]; 
       &ToChars($options[$i]);         $totalvotes += int $votes[$i]; 
   }        if ( int( $votes[$i] ) >= $maxvote ) { $maxvote = int $votes[$i]; }
         $options[$i] = Censor( $options[$i] );
   fopen(FILE, "$datadir/$pollnum.polled");         if ($ubbcpolls) { 
   @polled = <FILE>;             $message = $options[$i]; 
   fclose(FILE);             DoUBBC(); 
             $options[$i] = $message;
   if ($poll_modname ne '' && $poll_mod ne '') {         } 
       $poll_mod = &timeformat($poll_mod);         ToChars( $options[$i] ); 
       &LoadUser($poll_modname);     } 
       $displaydate = qq~<span class="small">&#171; $polltxt{'45a'}: <a href="$scripturl?action=viewprofile;username=$useraccount{$poll_modname}">${$uid.$poll_modname}{'realname'}</a> $polltxt{'46'}: $poll_mod &#187;</span>~;  
   }     fopen(FILE, "$datadir/$pollnum.polled"); 
   if ($poll_uname ne '' && $poll_date ne '') {     @polled = <FILE>; 
       $poll_date = &timeformat($poll_date);     fclose(FILE); 
       if ($poll_uname ne 'Guest' && -e "$memberdir/$poll_uname.vars") {  
           &LoadUser($poll_uname);     if ( $poll_modname ne q{} && $poll_mod ne q{} ) { 
           $displaydate = qq~<span class="small">&#171; $polltxt{'45'}: <a href="$scripturl?action=viewprofile;username=$useraccount{$poll_uname}">${$uid.$poll_uname}{'realname'}</a> $polltxt{'46'}: $poll_date &#187;</span>~;         $poll_mod = timeformat($poll_mod); 
       } else {         LoadUser($poll_modname); 
           $displaydate = qq~<span class="small">&#171; $polltxt{'45'}: $poll_name $polltxt{'46'}: $poll_date &#187;</span>~;         if ( $iamguest ) { 
       }             $displaydate = 
   }  qq~<span class="small">&#171; $polltxt{'45a'}: $format_unbold{$poll_modname} $polltxt{'46'}: $poll_mod &#187;</span>~; 
   &ToChars($boardname);         } 
   $yytitle = $polltxt{'42'};         else { 
             $displaydate =
   $template_home = qq~<a href="$scripturl" class="nav">$mbname</a>~;  qq~<span class="small">&#171; $polltxt{'45a'}: <a href="$scripturl?action=viewprofile;username=$useraccount{$poll_modname}">$format_unbold{$poll_modname}</a> $polltxt{'46'}: $poll_mod &#187;</span>~; 
   $template_cat = qq~<a href="$scripturl?catselect=$curcat" class="nav">$cat</a>~;         } 
   $template_board = qq~<a href="$scripturl?board=$currentboard" class="nav">$boardname</a>~;     } 
   $curthreadurl = qq~<a href="$scripturl?num=$pollnum" class="nav">$psub</a> &rsaquo; $polltxt{'42'}~;     if ( $poll_uname ne q{} && $poll_date ne q{} ) { 
         $poll_date = timeformat($poll_date);
   $yynavigation = qq~&rsaquo; $template_cat &rsaquo; $template_board &rsaquo; $curthreadurl~;         if ($poll_uname ne 'Guest' && -e "$memberdir/$poll_uname.vars") { 
             LoadUser($poll_uname);
   $yymain .= qq~             if ( $iamguest ) { 
<br />                 $displaydate = 
<form action="$scripturl?action=undovote;num=$pollnum$start" method="post" style="display: inline;">  qq~<span class="small">&#171; $polltxt{'45a'}: $format_unbold{$poll_uname} $polltxt{'46'}: $poll_mod &#187;</span>~; 
<input type="hidden" name="multidel" value="1" />             } 
<table cellpadding="4" cellspacing="1" border="0" width="90%" class="bordercolor" align="center">             else { 
       <tr>                 $displaydate = 
         <td class="titlebg" colspan="5">$img{'pollicon'} <span class="text1"><b>$polltxt{'42'}</b></span></td>  qq~<span class="small">&#171; $polltxt{'45'}: <a href="$scripturl?action=viewprofile;username=$useraccount{$poll_uname}">$format_unbold{$poll_uname}</a> $polltxt{'46'}: $poll_date &#187;</span>~; 
       </tr><tr>             } 
         <td class="windowbg2" colspan="5"><br /><b>$polltxt{'16'}:</b> $poll_question<br /><br /></td>         } 
       </tr><tr>         else { 
         <td class="catbg" align="center"><b>&nbsp;</b></td>             $displaydate = 
         <td class="catbg" align="center"><b>$polltxt{'35'}</b></td>  qq~<span class="small">&#171; $polltxt{'45'}: $poll_name $polltxt{'46'}: $poll_date &#187;</span>~; 
         <td class="catbg" align="center"><b>$polltxt{'30'}</b></td>         } 
         <td class="catbg" align="center"><b>$polltxt{'31'}</b></td>     } 
         <td class="catbg" align="center"><b>$polltxt{'24'}</b></td>     ToChars($boardname); 
       </tr><tr>~;     $yytitle = $polltxt{'42'}; 
   
   foreach $entry (@polled) {     $template_home = qq~<a href="$scripturl" class="nav">$mbname</a>~; 
       chomp $entry;     $template_cat = 
       $voted = '';       qq~<a href="$scripturl?catselect=$curcat" class="nav">$cat</a>~; 
       ($voters_ip, $voters_name, $voters_vote, $vote_date) = split(/\|/, $entry);     $template_board = 
       $id = qq~$voters_ip-$voters_name~;       qq~<a href="$scripturl?board=$currentboard" class="nav">$boardname</a>~; 
       if ($voters_name ne 'Guest' && -e "$memberdir/$voters_name.vars") {     $curthreadurl = 
           &LoadUser($voters_name);  qq~<a href="$scripturl?num=$pollnum" class="nav">$psub</a> &rsaquo; $polltxt{'42'}~; 
           $voters_name = qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$voters_name}">${$uid.$voters_name}{'realname'}</a>~;  
       }     $yynavigation = 
       foreach $oldvote (split(/\,/, $voters_vote)) {  qq~&rsaquo; $template_cat &rsaquo; $template_board &rsaquo; $curthreadurl~; 
           if ($ubbcpolls) {  
               $message = $options[$oldvote];     foreach my $entry (@polled) { 
               &DoUBBC;         chomp $entry; 
               $options[$oldvote] = $message;         $voted = q{}; 
           }         ( $voters_ip, $voters_name, $voters_vote, $vote_date ) = split /\|/xsm, 
           &ToChars($options[$oldvote]);           $entry; 
           $voted .= qq~$options[$oldvote]<br />~;         $id = qq~$voters_ip-$voters_name~; 
       }         if ($voters_name ne 'Guest' && -e "$memberdir/$voters_name.vars") { 
             LoadUser($voters_name);
       $vote_date = &timeformat($vote_date);             if ( $iamguest ) { 
       $yymain .= qq~                 $voters_name = qq~$format_unbold{$voters_name}~; 
         <td class="windowbg2" align="center"><input type="checkbox" name="$id" value="1" /></td>             } 
         <td class="windowbg2">$voters_name</td>             else { 
         <td class="windowbg2" align="center">$voters_ip</td>                 $voters_name = 
         <td class="windowbg2" align="center">$vote_date</td>  qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$voters_name}">$format_unbold{$voters_name}</a>~; 
         <td class="windowbg2">$voted</td>             } 
       </tr><tr>~;         } 
   }         foreach my $oldvote ( split /\,/xsm, $voters_vote ) { 
             if ($ubbcpolls) {
   $yymain .= qq~                 $message = $options[$oldvote]; 
         <td class="titlebg" align="center" colspan="5"><input type="submit" value="$polltxt{'49'}" class="button" /></td>                 DoUBBC(); 
       </tr>                 $options[$oldvote] = $message; 
</table>             } 
</form>~;             ToChars( $options[$oldvote] ); 
             $voted .= qq~$options[$oldvote]<br />~;
   $display_template =~ s/({|<)yabb home(}|>)/$template_home/g;         } 
   $display_template =~ s/({|<)yabb category(}|>)/$template_cat/g;  
   $display_template =~ s/({|<)yabb board(}|>)/$template_board/g;         my $lookupIP = 
   $display_template =~ s/({|<)yabb threadurl(}|>)/$curthreadurl/g;           ($ipLookup) 
           ? qq~<a href="$scripturl?action=iplookup;ip=$voters_ip">$voters_ip</a>~
           : qq~$voters_ip~;
         $vote_date = timeformat($vote_date);
         $my_IP .= $mypoll_IP;
         $my_IP =~ s/{yabb id}/$id/sm;
         $my_IP =~ s/{yabb voters_name}/$voters_name/sm;
         $my_IP =~ s/{yabb lookupIP}/$lookupIP/sm;
         $my_IP =~ s/{yabb vote_date}/$vote_date/sm;
         $my_IP =~ s/{yabb voted}/$voted/sm;
     }
   
     $yymain .= $mypoll_details;
     $yymain =~ s/{yabb pollnum}/$pollnum/sm;
     $yymain =~ s/{yabb start}/$start/sm;
     $yymain =~ s/{yabb poll_question}/$poll_question/sm;
     $yymain =~ s/{yabb my_IP}/$my_IP/sm;
   
     $display_template =~ s/{yabb home}/$template_home/gsm;
     $display_template =~ s/{yabb category}/$template_cat/gsm;
     $display_template =~ s/{yabb board}/$template_board/gsm;
     $display_template =~ s/{yabb threadurl}/$curthreadurl/gsm;
   
   &template;     template(); 
     return;
} }
   
sub display_poll { sub display_poll {
   $pollnum = @_[0];     ( $pollnum, $brdpoll ) = @_; 
   
     # showcase poll start
     $scp        = q{};
     $viewthread = q{};
     $boardpoll  = q{};
     if ($brdpoll) {
         $scp = q~;scp=1~;
         $viewthread =
  qq~<a href="$scripturl?num=$pollnum" class="altlink">$img{'viewthread'}</a>~;
         if ( $iamadmin || $iamgmod ) {
             $boardpoll =
  qq~&nbsp;/ <a href="$scripturl?action=scpolldel" class="altlink">$polltxt{'showcaserem'}</a>~;
         }
     }
     elsif ( -e "$datadir/showcase.poll" ) {
         fopen (FILE, "$datadir/showcase.poll");
         if ( $pollnum == <FILE> ) {
             $boardpoll = qq~&nbsp;/ $polltxt{'showcased'}~;
         }
         fclose (FILE);
         if ($iamadmin || $iamgmod) {
             $boardpoll =
               $boardpoll
               ? qq~&nbsp;/ <a href="$scripturl?action=scpolldel" class="altlink">$polltxt{'showcaserem'}</a>~
               : qq~&nbsp;/ <a href="javascript:Check=confirm('$polltxt{'confirm'}');if(Check==true){window.location.href='$scripturl?action=scpoll;num=$pollnum';}else{void Check;}" class="altlink">$polltxt{'setshowcased'}</a>~;
         }
     }
     else {
         if ( $iamadmin || $iamgmod ) {
             $boardpoll =
  qq~&nbsp;/ <a href="$scripturl?action=scpoll;num=$pollnum" class="altlink">$polltxt{'setshowcased'}</a>~;
         }
     }
   
     # showcase poll end
   
     LoadCensorList();
   
     fopen(FILE, "$datadir/$pollnum.poll");
     $poll_question = <FILE>;
     @poll_data = <FILE>;
     fclose(FILE);
     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 /\|/xsm, $poll_question;
   
     if ($poll_end && !$poll_locked && $poll_end < $date) {
         $poll_locked = 1;
         $poll_end    = q{};
         fopen(FILE, ">$datadir/$pollnum.poll");
         print {FILE}
  "$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" 
           or croak "$croak{'print'} POLL FILE";
         print {FILE} @poll_data or croak "$croak{'print'} POLL FILE";
         fclose(FILE);
     }
   
     $pie_radius ||= 100;
     $pie_legends ||= 0;
   
     $users_votetext = q{};
     $has_voted = 0;
     if (!$guest_vote && $iamguest) { $has_voted = 4; }
     else {
         fopen(FILE, "$datadir/$pollnum.polled");
         @polled = <FILE>;
         fclose(FILE);
         foreach my $tmpLine (@polled) {
             chomp $tmpline;
             ( $voters_ip, $voters_name, $voters_vote, $vote_date ) =
               split /\|/xsm, $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 /\,/xsm, $voters_vote;
                 my $users_votecount = @users_vote;
                 if ($users_votecount == 1) {
                     $users_votetext =
  qq~<br /><span style="font-weight: bold;">$polltxt{'64'}:</span> $users_votedate<br /><span style="font-weight: bold;">$polltxt{'65'}:</span> ~;
                 }
                 else {
                     $users_votetext =
  qq~<br /><span style="font-weight: bold;">$polltxt{'64'}:</span> $users_votedate<br /><span style="font-weight: bold;">$polltxt{'66'}:</span> ~;
                 }
                 last;
             }
         }
     }
   
     my @options;
     my @votes;
     my $totalvotes = 0;
     my $maxvote    = 0;
     $piearray = q~[~;
     for my $i ( 0 .. $#poll_data ) {
         chomp $poll_data[$i];
         ( $votes[$i], $options[$i], $slicecolor[$i], $split[$i] ) =
           split /\|/xsm, $poll_data[$i];
   
         # Censor the options.
         $options[$i] = Censor( $options[$i] );
         $options[$i] =~ s/[\n\r]//gxsm;
         if ($ubbcpolls) {
             enable_yabbc();
             $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/\, $//ism;
     $piearray .= q~]~;
   
     my ($endedtext, $displayvoters);
     if ( !$iamguest
         && ( $username eq $poll_uname || $staff ) )
     {
         if ($poll_locked) {
             $lockpoll =
  qq~<a href="$scripturl?action=lockpoll;num=$pollnum$scp" class="altlink">$img{'openpoll'}</a>~;
         }
         else {
             $lockpoll =
  qq~<a href="$scripturl?action=lockpoll;num=$pollnum$scp" class="altlink">$img{'closepoll'}</a>~;
         }
         $modifypoll =
  qq~$menusep<a href="$scripturl?board=$currentboard;action=modify;message=Poll;thread=$pollnum" class="altlink">$img{'modifypoll'}</a>~;
         $deletepoll =
  qq~$menusep<a href="javascript:document.removepoll.submit();" class="altlink" onclick="return confirm('$polltxt{'44'}')">$img{'deletepoll'}</a>~;
         if ($iamadmin) {
             if ($viewthread) { $displayvoters = $menusep; }
             $displayvoters .=
  qq~<a href="$scripturl?action=showvoters;num=$pollnum">$img{'viewvotes'}</a>~;
         }
         if ($hide_results) {
             $endedtext    = $mypoll_ended;
             $hide_results = 0;
         }
     }
   
     if ( $poll_modname ne q{} && $poll_mod ne q{} && $showmodify ) {
         $poll_mod = timeformat($poll_mod);
         LoadUser($poll_modname);
         if ( $iamguest ) {
             $displaydate =
  qq~<span class="small">&#171; $polltxt{'45a'}: $format_unbold{$poll_modname} $polltxt{'46'}: $poll_mod &#187;</span>~;
         }
         else {
             $displaydate =
  qq~<span class="small">&#171; $polltxt{'45a'}: <a href="$scripturl?action=viewprofile;username=$useraccount{$poll_modname}">$format_unbold{$poll_modname}</a> $polltxt{'46'}: $poll_mod &#187;</span>~;
         }
     }
     elsif ( $poll_uname ne q{} && $poll_date ne q{} ) {
         $poll_date = timeformat($poll_date);
         if ($poll_uname ne 'Guest' && -e "$memberdir/$poll_uname.vars") {
             LoadUser($poll_uname);
             if ( $iamguest ) {
                 $displaydate =
  qq~<span class="small">&#171; $polltxt{'45'}: $format_unbold{$poll_uname} $polltxt{'46'}: $poll_date &#187;</span>~;
             }
             else {
                 $displaydate =
  qq~<span class="small">&#171; $polltxt{'45'}: <a href="$scripturl?action=viewprofile;username=$useraccount{$poll_uname}">$format_unbold{$poll_uname}</a> $polltxt{'46'}: $poll_date &#187;</span>~;
             }
         }
         elsif ( $poll_name ne q{} ) {
             $displaydate =
  qq~<span class="small">&#171; $polltxt{'45'}: $poll_name $polltxt{'46'}: $poll_date &#187;</span>~;
         }
         else {
             $displaydate = q{};
         }
     }
     else {
         $displaydate = q{};
     }
   
     if ($poll_locked) {
         $endedtext = $mypoll_locked;
         $poll_icon = $img{'polliconclosed'};
         $has_voted = 5;
     }
     else {
         $poll_icon = $img{'pollicon'};
     }
   
     # Censor the question.
     $poll_question = Censor($poll_question);
     if ($ubbcpolls) {
         enable_yabbc();
         my $message = $poll_question;
         DoUBBC();
         $poll_question = $message;
     }
     ToChars($poll_question);
   
     $deletevote = q{};
     if ($has_voted) {
         if ($users_votetext) {
             if ( !$yyYaBBCloaded && $ubbcpolls ) {
                 require Sources::YaBBC;
             }
             $footer = $users_votetext;
             for my $i ( 0 .. $#users_vote ) {
                 $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//sm;
         $footer .= qq~<br /><br /><b>$polltxt{'17'}: $totalvotes</b>~;
         $width = q{};
         if ($viewthread) { $deletevote .= $menusep; }
         $deletevote .=
  qq~<a href="$scripturl?action=undovote;num=$pollnum$scp">$img{'deletevote'}</a>~;
         if ( !$viewthread && $displayvoters ) { $deletevote .= $menusep; }
     }
     else {
         $footer  =
           qq~<input type="submit" value="$polltxt{'18'}" class="button" />~;
         $width = q~ width="80%"~;
     }
     check_deletepoll();
     if ($iamguest || $poll_locked || $poll_nodelete{$username}) {
         $deletevote = q{};
     }
   
     if (!$yyUDLoaded{$username}) { LoadUser($username); }
     $scdivdisp = q~block~;
     $poll_coll = q{};
     if(!$INFO{'num'} && !$iamguest) {
         if(${$uid.$username}{'collapsescpoll'} == $pollnum) {
             $poll_coll .= qq~<img src="$imagesdir/$cat_exp" id="scpollcollapse" alt="$boardindex_exptxt{'1'}" title="$boardindex_exptxt{'1'}" class="cursor" onclick="collapseSCpoll('$pollnum');" />~;
             $scdivdisp = q~none~;
         }
         else {
             $poll_coll .= qq~<img src="$imagesdir/$cat_col" id="scpollcollapse" alt="$boardindex_exptxt{'2'}" title="$boardindex_exptxt{'2'}" class="cursor" onclick="collapseSCpoll('$pollnum');" />~;
         }
     }
     $pollmain = $mypoll_display;
     $pollmain =~ s/{yabb pollnum}/$pollnum/gsm;
     $pollmain =~ s/{yabb scp}/$scp/sm;
     $pollmain =~ s/{yabb poll_coll}/$poll_coll/gsm;
     $pollmain =~ s/{yabb scdivdisp}/$scdivdisp/gsm;
     $pollmain =~ s/{yabb poll_icon}/$poll_icon/gsm;
     $pollmain =~ s/{yabb boardpoll}/$boardpoll/gsm;
     $pollmain =~ s/{yabb lockpoll}/$lockpoll/gsm;
     $pollmain =~ s/{yabb modifypoll}/$modifypoll/gsm;
     $pollmain =~ s/{yabb deletepoll}/$deletepoll/gsm;
     $pollmain =~ s/{yabb poll_question}/$poll_question/gsm;
   
     if($has_voted) {
      if ( !$hide_results || $poll_locked ) {
         $poll_notlocked = qq~
            <div style="float: right; width: 55px; text-align: right; margin-right:4px">
                 <a href="$scripturl?num=$viewnum">$poll_bar</a> &nbsp;
                 <a href="$scripturl?num=$viewnum;view=pie">$poll_pie</a>
            </div>
     ~;
         }
     }
   
     if ($has_voted && $hide_results && !$poll_locked) {
   
         # Display Poll Hidden Message
         $poll_hidden .=
  qq~$polltxt{'47'}<br /><span class="small">($polltxt{'48'})</span><br />~;
     }
     else {
         if($has_voted) {
             if ( $INFO{'view'} eq 'pie' ) {
                 $poll_hasvoted = qq~
         <script src="$yyhtml_root/piechart.js" type="text/javascript"></script>
         <script type="text/javascript">
             if (document.getElementById('piestyle').currentStyle) {
                 pie_colorstyle = document.getElementById('piestyle').currentStyle['color'];
             } else if (window.getComputedStyle) {
                 var compStyle = window.getComputedStyle(document.getElementById('piestyle'), "");
                 pie_colorstyle = compStyle.getPropertyValue('color');
             }
             else pie_colorstyle = "#000000";
   
             var pie = new pieChart();
             pie.pie_array = $piearray;
             pie.radius = $pie_radius;
             pie.use_legends = $pie_legends;
             pie.color_style = pie_colorstyle;
             pie.sliceAdd();
         </script>~;
             }
             else {
                 for my $i ( 0 .. $#options ) {
                     if ( !$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);
                     }
                     $poll_hasvoted .= $mypoll_hasvoted;
                     $poll_hasvoted =~ s/{yabb optionsi}/$options[$i]/gsm;
                     $poll_hasvoted =~ s/{yabb pollbar}/$pollbar/gsm;
                     $poll_hasvoted =~ s/{yabb slicecolori}/$slicecolor[$i]/gsm;
                     $poll_hasvoted =~ s/{yabb votesi}/$votes[$i]/gsm;
                     $poll_hasvoted =~ s/{yabb pollpercent}/$pollpercent/gsm;
                 }
             }
         }
         else {
             for my $i ( 0 .. $#options ) {
                 if ( !$options[$i] ) { next; }
   
                 # Display Poll Options
                 if ($multi_vote) {
                     $input =
  qq~<input type="checkbox" name="option$i" id="option$i" value="$i" style="margin: 0; padding: 0; vertical-align: middle;" />~;
                 }
                 else {
                     $input =
  qq~<input type="radio" name="option" id="option$i" value="$i" style="margin: 0; padding: 0; vertical-align: middle;" />~;
                 }
                 $poll_hasvoted .= qq~
         <div class="clear">
         <div style="float: left; height: 22px; text-align: right;">$input <label for="option$i"><b>$options[$i]</b></label></div>
         </div>~;
             }
         }
     }
   
     if ($poll_comment ne q{}) {
         $poll_comment = Censor($poll_comment);
         $message = $poll_comment;
         if ($enable_ubbc) {
             enable_yabbc();
             DoUBBC();
         }
         $poll_comment = $message;
         ToChars($poll_comment);
         $my_pollcomment = qq~
     <div style="width: 100%;"><br />$poll_comment</div>~;
     }
     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'} ";
         if ($days) {
             $poll_end .= "$days $post_polltxt{'100a'}" 
               . ( $hours ? q{, } : " $post_polltxt{'100c'} " );
         }
         if ($hours) {
             $poll_end .= "$hours $post_polltxt{'100b'} $post_polltxt{'100c'} ";
         }
         $poll_end .= "$min $post_polltxt{'100d'}<br />";
     }
     else {
         $poll_end = q{};
     }
   
     $pollmain =~ s/{yabb pollnum}/$pollnum/gsm;
     $pollmain =~ s/{yabb scp}/$scp/sm;
     $pollmain =~ s/{yabb poll_coll}/$poll_coll/gsm;
     $pollmain =~ s/{yabb scdivdisp}/$scdivdisp/gsm;
     $pollmain =~ s/{yabb poll_icon}/$poll_icon/sm;
     $pollmain =~ s/{yabb boardpoll}/$boardpoll/sm;
     $pollmain =~ s/{yabb lockpoll}/$lockpoll/sm;
     $pollmain =~ s/{yabb modifypoll}/$modifypoll/sm;
     $pollmain =~ s/{yabb deletepoll}/$deletepoll/sm;
     $pollmain =~ s/{yabb poll_question}/$poll_question/sm;
     $pollmain =~ s/{yabb poll_notlocked}/$poll_notlocked/gsm;
     $pollmain =~ s/{yabb endedtext}/$endedtext/sm;
     $pollmain =~ s/{yabb pollhidden}/$poll_hidden/sm;
     $pollmain =~ s/{yabb poll_hasvoted}/$poll_hasvoted/sm;
     $pollmain =~ s/{yabb footer}/$footer/sm;
     $pollmain =~ s/{yabb my_pollcomment}/$my_pollcomment/sm;
     $pollmain =~ s/{yabb poll_end}/$poll_end/sm;
     $pollmain =~ s/{yabb displaydate}/$displaydate/sm;
     $pollmain =~ s/{yabb viewthread}/$viewthread/sm;
     $pollmain =~ s/{yabb deletevote}/$deletevote/sm;
     $pollmain =~ s/{yabb displayvoters}/$displayvoters/sm;
     $pollmain .= qq~<script type="text/javascript">
  function collapseSCpoll(pollnr) {
     if (document.getElementById("polldiv").style.display == 'none') linkpollnr = '0';
     else linkpollnr = pollnr;
     var doexpand = "$boardindex_exptxt{'1'}";
     var docollaps = "$boardindex_exptxt{'2'}";
     if (document.getElementById("polldiv").style.display == 'none') {
         document.getElementById("polldiv").style.display = 'block';
         document.getElementById('scpollcollapse').src = "$imagesdir/$cat_col";
         document.getElementById('scpollcollapse').alt = docollaps;
         document.getElementById('scpollcollapse').title = docollaps;
     }
     else {
         document.getElementById("polldiv").style.display = 'none';
         document.getElementById('scpollcollapse').src="$imagesdir/$cat_exp";
         document.getElementById('scpollcollapse').alt = doexpand;
         document.getElementById('scpollcollapse').title = doexpand;
     }
     var url = '$scripturl?action=scpollcoll&scpoll=' + linkpollnr;
     GetXmlHttpObject();
     if (xmlHttp === null) return;
     xmlHttp.open("GET",url,true);
     xmlHttp.send(null);
  }
  </script>
  ~;
     return $pollmain;
  }
   
   # showcase poll start  sub collapse_poll { 
   $brdpoll = @_[1];     ${$uid.$username}{'collapsescpoll'} = $INFO{'scpoll'}; 
   $scp = '';     UserAccount($username, 'update'); 
   $viewthread = '';     $elenable = 0; 
   $boardpoll = '';     croak q{}; 
   if ($brdpoll) {  
       $scp = qq~;scp=1~;  
       $viewthread = qq~<a href="$scripturl?num=$pollnum" class="altlink">$img{'viewthread'}</a>~;  
       $boardpoll = qq~&nbsp;/ <a href="$scripturl?action=scpolldel" class="altlink">$polltxt{'showcaserem'}</a>~ if ($iamadmin || $iamgmod);  
   } elsif (-e "$datadir/showcase.poll") {  
       fopen (FILE, "$datadir/showcase.poll");  
       $boardpoll = qq~&nbsp;/ $polltxt{'showcased'}~ if $pollnum == <FILE>;  
       fclose (FILE);  
       if ($iamadmin || $iamgmod) {  
           $boardpoll = $boardpoll ? qq~&nbsp;/ <a href="$scripturl?action=scpolldel" class="altlink">$polltxt{'showcaserem'}</a>~ : qq~&nbsp;/ <a href="javascript:Check=confirm('$polltxt{'confirm'}');if(Check==true){window.location.href='$scripturl?action=scpoll;num=$pollnum';}else{void Check;}" class="altlink">$polltxt{'setshowcased'}</a>~;  
       }  
   } else {  
       $boardpoll = qq~&nbsp;/ <a href="$scripturl?action=scpoll;num=$pollnum" class="altlink">$polltxt{'setshowcased'}</a>~ if ($iamadmin || $iamgmod);  
   }  
   # showcase poll end  
   
   &LoadCensorList;  
   
   fopen(FILE, "$datadir/$pollnum.poll");  
   $poll_question = <FILE>;  
   @poll_data = <FILE>;  
   fclose(FILE);  
   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 = '';  
       fopen(FILE, ">$datadir/$pollnum.poll");  
       print FILE "$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";  
       print FILE @poll_data;  
       fclose(FILE);  
   }  
   
   $pie_radius ||= 100;  
   $pie_legends ||= 0;  
   
   $users_votetext = '';  
   $has_voted = 0;  
   if (!$guest_vote && $iamguest) { $has_voted = 4; }  
   else {  
       fopen(FILE, "$datadir/$pollnum.polled");  
       @polled = <FILE>;  
       fclose(FILE);  
       foreach $tmpLine (@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~<br /><span style="font-weight: bold;">$polltxt{'64'}:</span> $users_votedate<br /><span style="font-weight: bold;">$polltxt{'65'}:</span> ~;  
               } else {  
                   $users_votetext = qq~<br /><span style="font-weight: bold;">$polltxt{'64'}:</span> $users_votedate<br /><span style="font-weight: bold;">$polltxt{'66'}:</span> ~;  
               }  
               last;  
           }  
       }  
   }  
   
   my @options;  
   my @votes;  
   my $totalvotes = 0;  
   my $maxvote    = 0;  
   $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 || $iamadmin || $iamgmod || $iammod)) {  
       if ($poll_locked) {  
           $lockpoll = qq~<a href="$scripturl?action=lockpoll;num=$pollnum$scp" class="altlink">$img{'openpoll'}</a>~;  
       } else {  
           $lockpoll = qq~<a href="$scripturl?action=lockpoll;num=$pollnum$scp" class="altlink">$img{'closepoll'}</a>~;  
       }  
       $modifypoll = qq~$menusep<a href="$scripturl?board=$currentboard;action=modify;message=Poll;thread=$pollnum" class="altlink">$img{'modifypoll'}</a>~;  
       $deletepoll = qq~$menusep<a href="javascript:document.removepoll.submit();" class="altlink" onclick="return confirm('$polltxt{'44'}')">$img{'deletepoll'}</a>~;  
       if ($iamadmin) {  
           $displayvoters = $menusep if $viewthread;  
           $displayvoters .= qq~<a href="$scripturl?action=showvoters;num=$pollnum">$img{'viewvotes'}</a>~;  
       }  
       if ($hide_results) {  
           $endedtext = qq~<span style="color: #FF0000;"><b>$polltxt{'53'}</b></span></td>  
               </tr>  
               <tr>  
                 <td colspan="2" align="center" class="windowbg2"><br />~;  
           $hide_results = 0;  
           $bgclass = 'windowbg2';  
       }  
   }  
   
   if ($poll_modname ne '' && $poll_mod ne '' && $showmodify) {  
       $poll_mod = &timeformat($poll_mod);  
       &LoadUser($poll_modname);  
       $displaydate = qq~<span class="small">&#171; $polltxt{'45a'}: <a href="$scripturl?action=viewprofile;username=$useraccount{$poll_modname}">${$uid.$poll_modname}{'realname'}</a> $polltxt{'46'}: $poll_mod &#187;</span>~;  
   } elsif ($poll_uname ne '' && $poll_date ne '') {  
       $poll_date = &timeformat($poll_date);  
       if ($poll_uname ne 'Guest' && -e "$memberdir/$poll_uname.vars") {  
           &LoadUser($poll_uname);  
           $displaydate = qq~<span class="small">&#171; $polltxt{'45'}: <a href="$scripturl?action=viewprofile;username=$useraccount{$poll_uname}">${$uid.$poll_uname}{'realname'}</a> $polltxt{'46'}: $poll_date &#187;</span>~;  
       } elsif ($poll_name ne '') {  
           $displaydate = qq~<span class="small">&#171; $polltxt{'45'}: $poll_name $polltxt{'46'}: $poll_date &#187;</span>~;  
       } else {  
           $displaydate = '';  
       }  
   } else {  
       $displaydate = '';  
   }  
   
   if ($poll_locked) {  
       $bgclass = 'windowbg2';  
       $endedtext = qq~<span style="color: #FF0000;"><b>$polltxt{'22'}</b></span></td>  
               </tr>  
               <tr>  
                 <td colspan="2" align="center" class="windowbg2"><br />~;  
       $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~<br /><br /><span style="font-weight: bold;">$polltxt{'17'}: $totalvotes</span>~;  
       $width = '';  
       $deletevote .= $menusep if $viewthread;  
       $deletevote .= qq~<a href="$scripturl?action=undovote;num=$pollnum$scp">$img{'deletevote'}</a>~;  
       $deletevote .= $menusep if !$viewthread && $displayvoters;  
   } else {  
       $footer  = qq~<input type="submit" value="$polltxt{'18'}" class="button" />~;  
       $width = qq~ width="80%"~;  
       $bgclass = 'windowbg2';  
   }  
   &check_deletepoll;  
   if ($iamguest || $poll_locked || $poll_nodelete{$username}) { $deletevote = ''; }  
   
   $pollmain = qq~  
<form name="removepoll" action="$scripturl?action=modify2;d=1" method="post" style="display: inline">  
   <input type="hidden" name="thread" value="$pollnum" />  
   <input type="hidden" name="id" value="Poll" />  
</form>  
   
<form name="poll" method="post" action="$scripturl?action=vote;num=$pollnum$scp" style="display: inline;">  
<table cellpadding="4" cellspacing="1" border="0" width="100%" class="bordercolor" align="center">  
<tr>  
<td class="titlebg" valign="middle" align="left">  
   <div style="float: left; width: 50%; text-align: left;">  
       <span class="text1">$poll_icon <b>$polltxt{'15'}</b>$boardpoll</span>  
   </div>  
   <div style="float: left; width: 50%; text-align: right;">  
       <span class="small">$lockpoll$modifypoll$deletepoll</span>  
   </div>  
</td>  
</tr>  
<tr>  
<td valign="top" class="catbg">  
   <div style="float: left; width: 80%;">  
       <b>$polltxt{'16'}:</b> $poll_question  
   </div>  
   ~;  
   if($has_voted) {  
       unless($hide_results && !$poll_locked) {  
           $pollmain .= qq~  
   <div style="float: left; width: 20%; text-align: right;">  
       <script language="JavaScript1.2" type="text/javascript">  
       <!--  
       document.write('<a href="$scripturl?num=$viewnum"><img src="$imagesdir/bars.gif" border="0" alt="" /></a>');  
       document.write('<a href="$scripturl?num=$viewnum;view=pie"><img src="$imagesdir/pie.gif" border="0" alt="" /></a>');  
       //-->  
       </script>  
   </div>  
   ~;  
       }  
   }  
   $pollmain .= qq~  
</td>  
</tr>  
<tr>  
<td colspan="2" align="center" class="$bgclass">  
   $endedtext  
   <div class="$bgclass" id="piestyle" style="width: 100%;"><br />~;  
   
   if ($has_voted && $hide_results && !$poll_locked) {  
   
       # Display Poll Hidden Message  
       $pollmain .= qq~$polltxt{'47'}<br /><span class="small">($polltxt{'48'})</span><br />~;  
   
   } else {  
       if($has_voted) {  
           if($INFO{'view'} eq "pie") {  
               $pollmain .= qq~  
       <script language="JavaScript1.2" src="$yyhtml_root/piechart.js" type="text/javascript"></script>  
       <script language="JavaScript1.2" type="text/javascript">  
       <!--  
           if (document.getElementById('piestyle').currentStyle) {  
               pie_colorstyle = document.getElementById('piestyle').currentStyle['color'];  
           } else if (window.getComputedStyle) {  
               var compStyle = window.getComputedStyle(document.getElementById('piestyle'), "");  
               pie_colorstyle = compStyle.getPropertyValue('color');  
           }  
           else pie_colorstyle = "#000000";  
   
           var pie = new pieChart();  
           pie.pie_array = $piearray;  
           pie.radius = $pie_radius;  
           pie.use_legends = $pie_legends;  
           pie.color_style = pie_colorstyle;  
           pie.sliceAdd();  
           //-->  
       </script>~;  
           }  
           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~  
       <div style="clear: both; height: 18px; vertical-align: middle;">  
       <div style="float: left; width: 50%; text-align: right;">$options[$i]&nbsp;&nbsp;&nbsp;&nbsp;</div>  
       <div style="float: left; text-align: left; width: $pollbar; height: 10px; background-color: $slicecolor[$i]; border: 1px outset $slicecolor[$i];"></div>  
       <div class="small" style="float: left; text-align: left;">&nbsp;&nbsp;$votes[$i] ($pollpercent%)</div>  
   </div>~;  
               }  
           }  
       }  
       else {  
           for ($i = 0; $i < @options; $i++) {  
               unless ($options[$i]) { next; }  
               # Display Poll Options  
               if ($multi_vote) { $input = qq~<input type="checkbox" name="option$i" id="option$i" value="$i" style="margin: 0; padding: 0; vertical-align: middle;" />~; }  
               else { $input = qq~<input type="radio" name="option" id="option$i" value="$i" style="margin: 0; padding: 0; vertical-align: middle;" />~; }  
               $pollmain .= qq~  
   <div style="clear: both;">  
       <div style="float: left; height: 22px; text-align: right;">$input <label for="option$i"><b>$options[$i]</b></label></div>  
       </div>~;  
           }  
       }  
   }  
   $pollmain .= qq~  
       <br />  
   </div>  
   <div style="width: 100%;">  
       <br />$footer  
   </div>~;  
   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~  
   <div style="width: 100%;"><br />$poll_comment</div>~;  
   }  
   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'}<br />";  
   } else {  
       $poll_end = '';  
   }  
   $pollmain .= qq~  
   <div style="float: left; width: 49%; text-align: left;">  
       <span class="small">$poll_end$displaydate</span>  
   </div>  
   <div style="float: left; width: 50%; text-align: right;">  
       <span class="small">$viewthread$deletevote$displayvoters</span>  
   </div>  
   </td>  
 </tr>  
</table>  
</form>~;  
} }
   
sub check_deletepoll { sub check_deletepoll {
   fopen(FILE, "$datadir/$pollnum.poll");    fopen(FILE, "$datadir/$pollnum.poll");
   $poll_chech = <FILE>;    $poll_chech = <FILE>;
   fclose(FILE);    fclose(FILE);
   chomp $poll_chech;    chomp $poll_chech;
   $vote_limit = (split /\|/, $poll_chech, 14)[12];     $vote_limit = ( split /\|/xsm, $poll_chech, 14 )[12]; 
   $poll_nodelete{$username} = 0;    $poll_nodelete{$username} = 0;
   if (!$vote_limit) {    if (!$vote_limit) {
       $poll_nodelete{$username} = 1;        $poll_nodelete{$username} = 1;
       return;        return;
   }    }
   if (-e "$datadir/$pollnum.polled") {    if (-e "$datadir/$pollnum.polled") {
       fopen(FILE, "$datadir/$pollnum.polled");        fopen(FILE, "$datadir/$pollnum.polled");
       @chpolled = <FILE>;        @chpolled = <FILE>;
       fclose(FILE);        fclose(FILE);
       foreach $chvoter (@chpolled) {        foreach my $chvoter (@chpolled) {
           (undef, $chvotersname, undef, $chvotedate) = split(/\|/, $chvoter);             ( undef, $chvotersname, undef, $chvotedate ) = split /\|/xsm, 
           if ($chvotersname eq $username) {               $chvoter; 
               $chdiff = $date - $chvotedate;             if ($chvotersname eq $username) { 
               if ($chdiff > ($vote_limit * 60)) {                 $chdiff = $date - $chvotedate; 
                   $poll_nodelete{$username} = 1;                 if ($chdiff > ($vote_limit * 60)) { 
                   last;                     $poll_nodelete{$username} = 1; 
               }                     last; 
           }                }
       }            }
   }        }
     }
     return;
} }
   
sub ShowcasePoll { sub ShowcasePoll {
   is_admin_or_gmod;     is_admin_or_gmod(); 
   my $thrdid = $INFO{'num'};    my $thrdid = $INFO{'num'};
   fopen (SCFILE, ">$datadir/showcase.poll");    fopen (SCFILE, ">$datadir/showcase.poll");
   print SCFILE $thrdid;     print {SCFILE} $thrdid or croak "$croak{'print'} SCFILE"; 
   fclose (SCFILE);    fclose (SCFILE);
   $yySetLocation = qq~$scripturl~;    $yySetLocation = qq~$scripturl~;
   &redirectexit;     redirectexit(); 
     return;
} }
   
sub DelShowcasePoll{ sub DelShowcasePoll{
   is_admin_or_gmod;     is_admin_or_gmod(); 
   if (-e "$datadir/showcase.poll") { unlink("$datadir/showcase.poll"); }    if ( -e "$datadir/showcase.poll" ) { unlink "$datadir/showcase.poll"; }
   $yySetLocation = qq~$scripturl~;    $yySetLocation = qq~$scripturl~;
   &redirectexit;     redirectexit(); 
     return;
} }
   
1; 1;