1###############################################################################
2# Poll.pm                                                                     #
3# $Date: 12.02.14 $                                                           #
4###############################################################################
5# YaBB: Yet another Bulletin Board                                            #
6# Open-Source Community Software for Webmasters                               #
7# Version:        YaBB 2.6.11                                                 #
8# Packaged:       December 2, 2014                                            #
9# Distributed by: http://www.yabbforum.com                                    #
10# =========================================================================== #
11# Copyright (c) 2000-2014 YaBB (www.yabbforum.com) - All Rights Reserved.     #
12# Software by:  The YaBB Development Team                                     #
13#               with assistance from the YaBB community.                      #
14###############################################################################
15use CGI::Carp qw(fatalsToBrowser);
16our $VERSION = '2.6.11';
17
18$pollpmver = 'YaBB 2.6.11 $Revision: 1611 $';
19if ($action eq 'detailedversion') { return 1; }
20
21LoadLanguage('Poll');
22get_micon();
23get_template('Poll');
24
25sub DoVote {
26    $pollnum = $INFO{'num'};
27    $start   = $INFO{'start'};
28    if ( !-e "$datadir/$pollnum.poll" ) {
29        fatal_error( 'poll_not_found', $pollnum );
30    }
31
32    $novote = 0;
33    $vote   = q{};
34    fopen(FILE, "$datadir/$pollnum.poll");
35    $poll_question = <FILE>;
36    @poll_data     = <FILE>;
37    fclose(FILE);
38    chomp $poll_question;
39    (
40        undef, $poll_locked, undef,       undef,       undef,
41        undef, $guest_vote,  undef,       $multi_vote, undef,
42        undef, undef,        $vote_limit, undef
43    ) = split /\|/xsm, $poll_question, 14;
44
45    for my $i ( 0 .. ( @poll_data - 1 ) ) {
46        chomp $poll_data[$i];
47        ( $votes[$i], $options[$i], $slicecols[$i], $split[$i] ) =
48          split /\|/xsm, $poll_data[$i];
49        $tmp_vote = qq~$FORM{"option$i"}~;
50        if ( $multi_vote && $tmp_vote ne q{} ) {
51            $votes[$i]++;
52            $novote = 1;
53            if ( $vote ne q{} ) { $vote .= q{,}; }
54            $vote .= $tmp_vote;
55        }
56    }
57    $tmp_vote = $FORM{'option'};
58    if ( !$multi_vote && $tmp_vote ne q{} ) {
59        $vote = $tmp_vote;
60        $votes[$tmp_vote]++;
61        $novote = 1;
62    }
63
64    if ( $novote == 0 || $vote eq q{} ) { fatal_error('no_vote_option'); }
65    if ( $iamguest && !$guest_vote ) { fatal_error('members_only'); }
66    if ($poll_locked) { fatal_error('locked_poll_no_count'); }
67
68    fopen(FILE, "$datadir/$pollnum.polled");
69    @polled = <FILE>;
70    fclose(FILE);
71
72    for my $i ( 0 .. ( @polled - 1 ) ) {
73        ( $voters_ip, $voters_name, $voters_vote, $vote_time ) = split /\|/xsm,
74          $polled[$i];
75        chomp $voters_vote;
76        if (   $iamguest
77            && $voters_name  eq 'Guest'
78            && lc $voters_ip eq lc $user_ip )
79        {
80            fatal_error('ip_guest_used');
81        }
82        elsif ($iamguest
83            && $voters_name ne 'Guest'
84            && lc $voters_ip eq lc $user_ip )
85        {
86            fatal_error('ip_member_used');
87        }
88        elsif ( !$iamguest
89            && $voters_name ne 'Guest'
90            && lc $username eq lc $voters_name )
91        {
92            fatal_error('voted_already');
93        }
94        elsif ( !$iamguest
95            && $voters_name  eq 'Guest'
96            && lc $voters_ip eq lc $user_ip )
97        {
98            foreach my $oldvote ( split /\,/xsm, $voters_vote ) {
99                $votes[$oldvote]--;
100            }
101            $polled[$i] = q{};
102            last;
103        }
104    }
105
106    fopen(FILE, ">$datadir/$pollnum.poll");
107    print {FILE} "$poll_question\n" or croak "$croak{'print'} POLL FILE";
108    for my $i ( 0 .. ( @poll_data - 1 ) ) {
109        print {FILE} "$votes[$i]|$options[$i]|$slicecols[$i]|$split[$i]\n"
110          or croak "$croak{'print'} POLL FILE";
111    }
112    fclose(FILE);
113
114    fopen(FILE, ">$datadir/$pollnum.polled");
115    print {FILE} "$user_ip|$username|$vote|$date\n"
116      or croak "$croak{'print'} POLL FILE";
117    print {FILE} @polled or croak "$croak{'print'} POLL FILE";
118    fclose(FILE);
119
120    if ($start) { $start = "/$start"; }
121    if ($INFO{'scp'}) {
122        $yySetLocation = qq~$scripturl~;
123    }
124    else {
125        $yySetLocation = qq~$scripturl?num=$pollnum$start~;
126    }
127    redirectexit();
128    return;
129}
130
131sub UndoVote {
132    $pollnum = $INFO{'num'};
133    if ( !-e "$datadir/$pollnum.poll" ) {
134        fatal_error( 'poll_not_found', $pollnum );
135    }
136
137    check_deletepoll();
138    if ( !$iamadmin && $poll_nodelete{$username} ) { fatal_error('no_access'); }
139
140    fopen(FILE, "$datadir/$pollnum.poll");
141    $poll_question = <FILE>;
142    @poll_data     = <FILE>;
143    fclose(FILE);
144    $poll_locked = ( split /\|/xsm, $poll_question, 2 )[1];
145    my @options;
146    my @votes;
147
148    for my $i ( 0 .. ( @poll_data - 1 ) ) {
149        chomp $poll_data[$i];
150        ( $votes[$i], $options[$i], $slicecols[$i], $split[$i] ) =
151          split /\|/xsm, $poll_data[$i];
152    }
153
154    fopen(FILE, "$datadir/$pollnum.polled");
155    @polled = <FILE>;
156    fclose(FILE);
157
158    if ( $FORM{'multidel'} == 1 ) {
159        is_admin();
160        for my $i ( 0 .. ( @polled - 1 ) ) {
161            ( $voters_ip, $voters_name, $voters_vote, $vote_date ) =
162              split /\|/xsm, $polled[$i];
163            chomp $voters_vote;
164            $id = $FORM{"$voters_ip-$voters_name"};
165            if ( $id == 1 ) {
166                foreach my $oldvote ( split /\,/xsm, $voters_vote ) {
167                    $votes[$oldvote]--;
168                }
169                $polled[$i] = q{};
170            }
171            }
172        }
173     else {
174        if ($iamguest)  { fatal_error('not_allowed'); }
175        if ($poll_lock) { fatal_error('locked_poll_no_delete'); }
176        $found = 0;
177        for my $i ( 0 .. ( @polled - 1 ) ) {
178            ( $voters_ip, $voters_name, $voters_vote, $vote_date ) =
179              split /\|/xsm, $polled[$i];
180            chomp $voters_vote;
181            if ($voters_name eq $username) {
182                $found = 1;
183                for my $oldvote ( split /\,/xsm, $voters_vote ) {
184                    $votes[$oldvote]--;
185                }
186                $polled[$i] = q{};
187                last;
188            }
189        }
190        if ( !$found ) { fatal_error('not_completed'); }
191    }
192
193    fopen(FILE, ">$datadir/$pollnum.poll");
194    print {FILE} $poll_question or croak "$croak{'print'} POLL FILE";
195    for my $i ( 0 .. ( @poll_data - 1 ) ) {
196        print {FILE} "$votes[$i]|$options[$i]|$slicecols[$i]|$split[$i]\n"
197          or croak "$croak{'print'} POLL FILE";
198    }
199    fclose(FILE);
200
201    fopen(FILE, ">$datadir/$pollnum.polled");
202    print {FILE} @polled or croak "$croak{'print'} POLL FILE";
203    fclose(FILE);
204
205    if ($start) { $start = "/$start"; }
206    if ($INFO{'scp'}) {
207        $yySetLocation = qq~$scripturl~;
208    }
209    else {
210        $yySetLocation = qq~$scripturl?num=$pollnum$start~;
211    }
212    redirectexit();
213    return;
214}
215
216sub LockPoll {
217    $pollnum = $INFO{'num'};
218    if ( !-e "$datadir/$pollnum.poll" ) {
219        fatal_error( 'poll_not_found', $pollnum );
220    }
221
222    fopen(FILE, "$datadir/$pollnum.poll");
223    $poll_question = <FILE>;
224    @poll_data     = <FILE>;
225    fclose(FILE);
226    chomp $poll_question;
227    ( $poll_question, $poll_locked, $poll_uname, $poll_stuff ) = split /\|/xsm,
228      $poll_question, 4;
229    if ( $username ne $poll_uname && !$staff ) { fatal_error('not_allowed'); }
230
231    if ($poll_locked) { $poll_locked = 0; }
232    else { $poll_locked = 1; }
233
234    fopen(FILE, ">$datadir/$pollnum.poll");
235    print {FILE} "$poll_question|$poll_locked|$poll_uname|$poll_stuff\n"
236      or croak "$croak{'print'} POLL FILE";
237    print {FILE} @poll_data or croak "$croak{'print'} POLL FILE";
238    fclose(FILE);
239
240    if ($start) { $start = "/$start"; }
241    if ($INFO{'scp'}){
242        $yySetLocation = qq~$scripturl~;
243    }
244    else {
245        $yySetLocation = qq~$scripturl?num=$pollnum$start~;
246    }
247    redirectexit();
248    return;
249}
250
251sub votedetails {
252    is_admin();
253
254    $pollnum = $INFO{'num'};
255    if ( !-e "$datadir/$pollnum.poll" ) {
256        fatal_error( 'poll_not_found', $pollnum );
257    }
258    if ($start) { $start = "/$start"; }
259
260    LoadCensorList();
261
262    # Figure out the name of the category
263    get_forum_master();
264    ( $curcat, $catperms ) = split /\|/xsm, $catinfo{"$cat"};
265
266    fopen(FILE, "$datadir/$pollnum.poll");
267    $poll_question = <FILE>;
268    @poll_data     = <FILE>;
269    fclose(FILE);
270    chomp $poll_question;
271    (
272        $poll_question, $poll_locked, $poll_uname, $poll_name,
273        $poll_email, $poll_date, $guest_vote, $hide_results,
274        $multi_vote, $poll_mod, $poll_modname, $poll_comment,
275        undef
276    ) = split /\|/xsm, $poll_question, 13;
277
278    if ( !ref $thread_arrayref{$pollnum} ) {
279        fopen(POLLTP, "$datadir/$pollnum.txt");
280        @{$thread_arrayref{$pollnum}} = <POLLTP>;
281        fclose(POLLTP);
282    }
283    $psub = ( split /\|/xsm, ${ $thread_arrayref{$pollnum} }[0], 2 )[0];
284    ToChars($psub);
285
286    # Censor the options.
287    $poll_question = Censor($poll_question);
288    if ($ubbcpolls) {
289        enable_yabbc();
290        $message = $poll_question;
291        DoUBBC();
292        $poll_question = $message;
293    }
294    ToChars($poll_question);
295
296    my @options;
297    my @votes;
298    my $totalvotes = 0;
299    my $maxvote    = 0;
300    for my $i ( 0 .. ( @poll_data - 1 ) ) {
301        chomp $poll_data[$i];
302        ( $votes[$i], $options[$i] ) = split /\|/xsm, $poll_data[$i];
303        $totalvotes += int $votes[$i];
304        if ( int( $votes[$i] ) >= $maxvote ) { $maxvote = int $votes[$i]; }
305        $options[$i] = Censor( $options[$i] );
306        if ($ubbcpolls) {
307            $message = $options[$i];
308            DoUBBC();
309            $options[$i] = $message;
310        }
311        ToChars( $options[$i] );
312    }
313
314    fopen(FILE, "$datadir/$pollnum.polled");
315    @polled = <FILE>;
316    fclose(FILE);
317
318    if ( $poll_modname ne q{} && $poll_mod ne q{} ) {
319        $poll_mod = timeformat($poll_mod);
320        LoadUser($poll_modname);
321        if ( $iamguest ) {
322            $displaydate =
323qq~<span class="small">&#171; $polltxt{'45a'}: $format_unbold{$poll_modname} $polltxt{'46'}: $poll_mod &#187;</span>~;
324        }
325        else {
326            $displaydate =
327qq~<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>~;
328        }
329    }
330    if ( $poll_uname ne q{} && $poll_date ne q{} ) {
331        $poll_date = timeformat($poll_date);
332        if ($poll_uname ne 'Guest' && -e "$memberdir/$poll_uname.vars") {
333            LoadUser($poll_uname);
334            if ( $iamguest ) {
335                $displaydate =
336qq~<span class="small">&#171; $polltxt{'45a'}: $format_unbold{$poll_uname} $polltxt{'46'}: $poll_mod &#187;</span>~;
337            }
338            else {
339                $displaydate =
340qq~<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>~;
341            }
342        }
343        else {
344            $displaydate =
345qq~<span class="small">&#171; $polltxt{'45'}: $poll_name $polltxt{'46'}: $poll_date &#187;</span>~;
346        }
347    }
348    ToChars($boardname);
349    $yytitle = $polltxt{'42'};
350
351    $template_home = qq~<a href="$scripturl" class="nav">$mbname</a>~;
352    $template_cat =
353      qq~<a href="$scripturl?catselect=$curcat" class="nav">$cat</a>~;
354    $template_board =
355      qq~<a href="$scripturl?board=$currentboard" class="nav">$boardname</a>~;
356    $curthreadurl =
357qq~<a href="$scripturl?num=$pollnum" class="nav">$psub</a> &rsaquo; $polltxt{'42'}~;
358
359    $yynavigation =
360qq~&rsaquo; $template_cat &rsaquo; $template_board &rsaquo; $curthreadurl~;
361
362    foreach my $entry (@polled) {
363        chomp $entry;
364        $voted = q{};
365        ( $voters_ip, $voters_name, $voters_vote, $vote_date ) = split /\|/xsm,
366          $entry;
367        $id = qq~$voters_ip-$voters_name~;
368        if ($voters_name ne 'Guest' && -e "$memberdir/$voters_name.vars") {
369            LoadUser($voters_name);
370            if ( $iamguest ) {
371                $voters_name = qq~$format_unbold{$voters_name}~;
372            }
373            else {
374                $voters_name =
375qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$voters_name}">$format_unbold{$voters_name}</a>~;
376            }
377        }
378        foreach my $oldvote ( split /\,/xsm, $voters_vote ) {
379            if ($ubbcpolls) {
380                $message = $options[$oldvote];
381                DoUBBC();
382                $options[$oldvote] = $message;
383            }
384            ToChars( $options[$oldvote] );
385            $voted .= qq~$options[$oldvote]<br />~;
386        }
387
388        my $lookupIP =
389          ($ipLookup)
390          ? qq~<a href="$scripturl?action=iplookup;ip=$voters_ip">$voters_ip</a>~
391          : qq~$voters_ip~;
392        $vote_date = timeformat($vote_date);
393        $my_IP .= $mypoll_IP;
394        $my_IP =~ s/{yabb id}/$id/sm;
395        $my_IP =~ s/{yabb voters_name}/$voters_name/sm;
396        $my_IP =~ s/{yabb lookupIP}/$lookupIP/sm;
397        $my_IP =~ s/{yabb vote_date}/$vote_date/sm;
398        $my_IP =~ s/{yabb voted}/$voted/sm;
399    }
400
401    $yymain .= $mypoll_details;
402    $yymain =~ s/{yabb pollnum}/$pollnum/sm;
403    $yymain =~ s/{yabb start}/$start/sm;
404    $yymain =~ s/{yabb poll_question}/$poll_question/sm;
405    $yymain =~ s/{yabb my_IP}/$my_IP/sm;
406
407    $display_template =~ s/{yabb home}/$template_home/gsm;
408    $display_template =~ s/{yabb category}/$template_cat/gsm;
409    $display_template =~ s/{yabb board}/$template_board/gsm;
410    $display_template =~ s/{yabb threadurl}/$curthreadurl/gsm;
411
412    template();
413    return;
414}
415
416sub display_poll {
417    ( $pollnum, $brdpoll ) = @_;
418
419    # showcase poll start
420    $scp        = q{};
421    $viewthread = q{};
422    $boardpoll  = q{};
423    if ($brdpoll) {
424        $scp = q~;scp=1~;
425        $viewthread =
426qq~<a href="$scripturl?num=$pollnum" class="altlink">$img{'viewthread'}</a>~;
427        if ( $iamadmin || $iamgmod ) {
428            $boardpoll =
429qq~&nbsp;/ <a href="$scripturl?action=scpolldel" class="altlink">$polltxt{'showcaserem'}</a>~;
430        }
431    }
432    elsif ( -e "$datadir/showcase.poll" ) {
433        fopen (FILE, "$datadir/showcase.poll");
434        if ( $pollnum == <FILE> ) {
435            $boardpoll = qq~&nbsp;/ $polltxt{'showcased'}~;
436        }
437        fclose (FILE);
438        if ($iamadmin || $iamgmod) {
439            $boardpoll =
440              $boardpoll
441              ? qq~&nbsp;/ <a href="$scripturl?action=scpolldel" class="altlink">$polltxt{'showcaserem'}</a>~
442              : 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>~;
443        }
444    }
445    else {
446        if ( $iamadmin || $iamgmod ) {
447            $boardpoll =
448qq~&nbsp;/ <a href="$scripturl?action=scpoll;num=$pollnum" class="altlink">$polltxt{'setshowcased'}</a>~;
449        }
450    }
451
452    # showcase poll end
453
454    LoadCensorList();
455
456    fopen(FILE, "$datadir/$pollnum.poll");
457    $poll_question = <FILE>;
458    @poll_data = <FILE>;
459    fclose(FILE);
460    chomp $poll_question;
461    (
462        $poll_question, $poll_locked, $poll_uname,   $poll_name,
463        $poll_email,    $poll_date,   $guest_vote,   $hide_results,
464        $multi_vote,    $poll_mod,    $poll_modname, $poll_comment,
465        $vote_limit,    $pie_radius,  $pie_legends,  $poll_end
466    ) = split /\|/xsm, $poll_question;
467
468    if ($poll_end && !$poll_locked && $poll_end < $date) {
469        $poll_locked = 1;
470        $poll_end    = q{};
471        fopen(FILE, ">$datadir/$pollnum.poll");
472        print {FILE}
473"$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"
474          or croak "$croak{'print'} POLL FILE";
475        print {FILE} @poll_data or croak "$croak{'print'} POLL FILE";
476        fclose(FILE);
477    }
478
479    $pie_radius ||= 100;
480    $pie_legends ||= 0;
481
482    $users_votetext = q{};
483    $has_voted = 0;
484    if (!$guest_vote && $iamguest) { $has_voted = 4; }
485    else {
486        fopen(FILE, "$datadir/$pollnum.polled");
487        @polled = <FILE>;
488        fclose(FILE);
489        foreach my $tmpLine (@polled) {
490            chomp $tmpline;
491            ( $voters_ip, $voters_name, $voters_vote, $vote_date ) =
492              split /\|/xsm, $tmpLine;
493            if (   $iamguest
494                && $voters_name  eq 'Guest'
495                && lc $voters_ip eq lc $user_ip )
496            {
497                $has_voted = 1;
498                last;
499            }
500            elsif ($iamguest
501                && $voters_name ne 'Guest'
502                && lc $voters_ip eq lc $user_ip )
503            {
504                $has_voted = 2;
505                last;
506            }
507            elsif (!$iamguest && lc $username eq lc $voters_name) {
508                $has_voted = 3;
509                $users_votedate = timeformat($vote_date);
510                @users_vote     = split /\,/xsm, $voters_vote;
511                my $users_votecount = @users_vote;
512                if ($users_votecount == 1) {
513                    $users_votetext =
514qq~<br /><span style="font-weight: bold;">$polltxt{'64'}:</span> $users_votedate<br /><span style="font-weight: bold;">$polltxt{'65'}:</span> ~;
515                }
516                else {
517                    $users_votetext =
518qq~<br /><span style="font-weight: bold;">$polltxt{'64'}:</span> $users_votedate<br /><span style="font-weight: bold;">$polltxt{'66'}:</span> ~;
519                }
520                last;
521            }
522        }
523    }
524
525    my @options;
526    my @votes;
527    my $totalvotes = 0;
528    my $maxvote    = 0;
529    $piearray = q~[~;
530    for my $i ( 0 .. ( @poll_data - 1 ) ) {
531        chomp $poll_data[$i];
532        ( $votes[$i], $options[$i], $slicecolor[$i], $split[$i] ) =
533          split /\|/xsm, $poll_data[$i];
534
535        # Censor the options.
536        $options[$i] = Censor( $options[$i] );
537        $options[$i] =~ s/[\n\r]//gxsm;
538        if ($ubbcpolls) {
539            enable_yabbc();
540            $message = $options[$i];
541            DoUBBC();
542            $options[$i] = $message;
543        }
544        ToChars( $options[$i] );
545        $piearray .= qq~"$votes[$i]|$options[$i]|$slicecolor[$i]|$split[$i]", ~;
546        $totalvotes += int $votes[$i];
547        if ( int( $votes[$i] ) >= $maxvote ) { $maxvote = int $votes[$i]; }
548    }
549    $piearray =~ s/\, $//ism;
550    $piearray .= q~]~;
551
552    my ($endedtext, $displayvoters);
553    if ( !$iamguest
554        && ( $username eq $poll_uname || $staff ) )
555    {
556        if ($poll_locked) {
557            $lockpoll =
558qq~<a href="$scripturl?action=lockpoll;num=$pollnum$scp" class="altlink">$img{'openpoll'}</a>~;
559        }
560        else {
561            $lockpoll =
562qq~<a href="$scripturl?action=lockpoll;num=$pollnum$scp" class="altlink">$img{'closepoll'}</a>~;
563        }
564        $modifypoll =
565qq~$menusep<a href="$scripturl?board=$currentboard;action=modify;message=Poll;thread=$pollnum" class="altlink">$img{'modifypoll'}</a>~;
566        $deletepoll =
567qq~$menusep<a href="javascript:document.removepoll.submit();" class="altlink" onclick="return confirm('$polltxt{'44'}')">$img{'deletepoll'}</a>~;
568        if ($iamadmin) {
569            if ($viewthread) { $displayvoters = $menusep; }
570            $displayvoters .=
571qq~<a href="$scripturl?action=showvoters;num=$pollnum">$img{'viewvotes'}</a>~;
572        }
573        if ($hide_results) {
574            $endedtext    = $mypoll_ended;
575            $hide_results = 0;
576        }
577    }
578
579    if ( $poll_modname ne q{} && $poll_mod ne q{} && $showmodify ) {
580        $poll_mod = timeformat($poll_mod);
581        LoadUser($poll_modname);
582        if ( $iamguest ) {
583            $displaydate =
584qq~<span class="small">&#171; $polltxt{'45a'}: $format_unbold{$poll_modname} $polltxt{'46'}: $poll_mod &#187;</span>~;
585        }
586        else {
587            $displaydate =
588qq~<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>~;
589        }
590    }
591    elsif ( $poll_uname ne q{} && $poll_date ne q{} ) {
592        $poll_date = timeformat($poll_date);
593        if ($poll_uname ne 'Guest' && -e "$memberdir/$poll_uname.vars") {
594            LoadUser($poll_uname);
595            if ( $iamguest ) {
596                $displaydate =
597qq~<span class="small">&#171; $polltxt{'45'}: $format_unbold{$poll_uname} $polltxt{'46'}: $poll_date &#187;</span>~;
598            }
599            else {
600                $displaydate =
601qq~<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>~;
602            }
603        }
604        elsif ( $poll_name ne q{} ) {
605            $displaydate =
606qq~<span class="small">&#171; $polltxt{'45'}: $poll_name $polltxt{'46'}: $poll_date &#187;</span>~;
607        }
608        else {
609            $displaydate = q{};
610        }
611    }
612    else {
613        $displaydate = q{};
614    }
615
616    if ($poll_locked) {
617        $endedtext = $mypoll_locked;
618        $poll_icon = $img{'polliconclosed'};
619        $has_voted = 5;
620    }
621    else {
622        $poll_icon = $img{'pollicon'};
623    }
624
625    # Censor the question.
626    $poll_question = Censor($poll_question);
627    if ($ubbcpolls) {
628        enable_yabbc();
629        my $message = $poll_question;
630        DoUBBC();
631        $poll_question = $message;
632    }
633    ToChars($poll_question);
634
635    $deletevote = q{};
636    if ($has_voted) {
637        if ($users_votetext) {
638            if ( !$yyYaBBCloaded && $ubbcpolls ) {
639                require Sources::YaBBC;
640            }
641            $footer = $users_votetext;
642            for my $i ( 0 .. ( @users_vote - 1 ) ) {
643                $optnum = $users_vote[$i];
644
645                # Censor the user answer.
646                $options[$optnum] = Censor( $options[$optnum] );
647                if ($ubbcpolls) {
648                    $message = $options[$optnum];
649                    DoUBBC();
650                    $options[$optnum] = $message;
651                }
652                ToChars( $options[$optnum] );
653                $footer .= qq~$options[$optnum], ~;
654            }
655        }
656        $footer =~ s/, \Z//sm;
657        $footer .= qq~<br /><br /><b>$polltxt{'17'}: $totalvotes</b>~;
658        $width = q{};
659        if ($viewthread) { $deletevote .= $menusep; }
660        $deletevote .=
661qq~<a href="$scripturl?action=undovote;num=$pollnum$scp">$img{'deletevote'}</a>~;
662        if ( !$viewthread && $displayvoters ) { $deletevote .= $menusep; }
663    }
664    else {
665        $footer  =
666          qq~<input type="submit" value="$polltxt{'18'}" class="button" />~;
667        $width = q~ width="80%"~;
668    }
669    check_deletepoll();
670    if ($iamguest || $poll_locked || $poll_nodelete{$username}) {
671        $deletevote = q{};
672    }
673
674    if (!$yyUDLoaded{$username}) { LoadUser($username); }
675    $scdivdisp = q~block~;
676    $poll_coll = q{};
677    if(!$INFO{'num'} && !$iamguest) {
678        if(${$uid.$username}{'collapsescpoll'} == $pollnum) {
679            $poll_coll .= qq~<img src="$imagesdir/$cat_exp" id="scpollcollapse" alt="$boardindex_exptxt{'1'}" title="$boardindex_exptxt{'1'}" class="cursor" onclick="collapseSCpoll('$pollnum');" />~;
680            $scdivdisp = q~none~;
681        }
682        else {
683            $poll_coll .= qq~<img src="$imagesdir/$cat_col" id="scpollcollapse" alt="$boardindex_exptxt{'2'}" title="$boardindex_exptxt{'2'}" class="cursor" onclick="collapseSCpoll('$pollnum');" />~;
684        }
685    }
686    $pollmain = $mypoll_display;
687    $pollmain =~ s/{yabb pollnum}/$pollnum/gsm;
688    $pollmain =~ s/{yabb scp}/$scp/sm;
689    $pollmain =~ s/{yabb poll_coll}/$poll_coll/gsm;
690    $pollmain =~ s/{yabb scdivdisp}/$scdivdisp/gsm;
691    $pollmain =~ s/{yabb poll_icon}/$poll_icon/gsm;
692    $pollmain =~ s/{yabb boardpoll}/$boardpoll/gsm;
693    $pollmain =~ s/{yabb lockpoll}/$lockpoll/gsm;
694    $pollmain =~ s/{yabb modifypoll}/$modifypoll/gsm;
695    $pollmain =~ s/{yabb deletepoll}/$deletepoll/gsm;
696    $pollmain =~ s/{yabb poll_question}/$poll_question/gsm;
697
698    if($has_voted) {
699     if ( !$hide_results || $poll_locked ) {
700        $poll_notlocked = qq~
701           <div style="float: right; width: 55px; text-align: right; margin-right:4px">
702                <a href="$scripturl?num=$viewnum">$poll_bar</a> &nbsp;
703                <a href="$scripturl?num=$viewnum;view=pie">$poll_pie</a>
704           </div>
705    ~;
706        }
707    }
708
709    if ($has_voted && $hide_results && !$poll_locked) {
710
711        # Display Poll Hidden Message
712        $poll_hidden .=
713qq~$polltxt{'47'}<br /><span class="small">($polltxt{'48'})</span><br />~;
714    }
715    else {
716        if($has_voted) {
717            if ( $INFO{'view'} eq 'pie' ) {
718                $poll_hasvoted = qq~
719        <script src="$yyhtml_root/piechart.js" type="text/javascript"></script>
720        <script type="text/javascript">
721            if (document.getElementById('piestyle').currentStyle) {
722                pie_colorstyle = document.getElementById('piestyle').currentStyle['color'];
723            } else if (window.getComputedStyle) {
724                var compStyle = window.getComputedStyle(document.getElementById('piestyle'), "");
725                pie_colorstyle = compStyle.getPropertyValue('color');
726            }
727            else pie_colorstyle = "#000000";
728
729            var pie = new pieChart();
730            pie.pie_array = $piearray;
731            pie.radius = $pie_radius;
732            pie.use_legends = $pie_legends;
733            pie.color_style = pie_colorstyle;
734            pie.sliceAdd();
735        </script>~;
736            }
737            else {
738                for my $i ( 0 .. $#options ) {
739                    if ( !$options[$i] ) { next; }
740
741                    # Display Poll Results
742                    $pollpercent = 0;
743                    $pollbar     = 0;
744                    if ($totalvotes > 0 && $maxvote > 0) {
745                        $pollpercent = (100 * $votes[$i]) / $totalvotes;
746                        $pollpercent = sprintf '%.1f', $pollpercent;
747                        $pollbar = int(150 * $votes[$i] / $maxvote);
748                    }
749                    $poll_hasvoted .= $mypoll_hasvoted;
750                    $poll_hasvoted =~ s/{yabb optionsi}/$options[$i]/gsm;
751                    $poll_hasvoted =~ s/{yabb pollbar}/$pollbar/gsm;
752                    $poll_hasvoted =~ s/{yabb slicecolori}/$slicecolor[$i]/gsm;
753                    $poll_hasvoted =~ s/{yabb votesi}/$votes[$i]/gsm;
754                    $poll_hasvoted =~ s/{yabb pollpercent}/$pollpercent/gsm;
755                }
756            }
757        }
758        else {
759            for my $i ( 0 .. ( @options - 1 ) ) {
760                if ( !$options[$i] ) { next; }
761
762                # Display Poll Options
763                if ($multi_vote) {
764                    $input =
765qq~<input type="checkbox" name="option$i" id="option$i" value="$i" style="margin: 0; padding: 0; vertical-align: middle;" />~;
766                }
767                else {
768                    $input =
769qq~<input type="radio" name="option" id="option$i" value="$i" style="margin: 0; padding: 0; vertical-align: middle;" />~;
770                }
771                $poll_hasvoted .= qq~
772        <div class="clear">
773        <div style="float: left; height: 22px; text-align: right;">$input <label for="option$i"><b>$options[$i]</b></label></div>
774        </div>~;
775            }
776        }
777    }
778
779    if ($poll_comment ne q{}) {
780        $poll_comment = Censor($poll_comment);
781        $message = $poll_comment;
782        if ($enable_ubbc) {
783            enable_yabbc();
784            DoUBBC();
785        }
786        $poll_comment = $message;
787        ToChars($poll_comment);
788        $my_pollcomment = qq~
789    <div style="width: 100%;"><br />$poll_comment</div>~;
790    }
791    if (!$poll_locked && $poll_end) {
792        my $x = $poll_end - $date;
793        my $days  = int( $x / 86400 );
794        my $hours = int( ( $x - ( $days * 86400 ) ) / 3600 );
795        my $min   = int( ( $x - ( $days * 86400 ) - ( $hours * 3600 ) ) / 60 );
796        $poll_end = "$post_polltxt{'100'} ";
797        if ($days) {
798            $poll_end .= "$days $post_polltxt{'100a'}"
799              . ( $hours ? q{, } : " $post_polltxt{'100c'} " );
800        }
801        if ($hours) {
802            $poll_end .= "$hours $post_polltxt{'100b'} $post_polltxt{'100c'} ";
803        }
804        $poll_end .= "$min $post_polltxt{'100d'}<br />";
805    }
806    else {
807        $poll_end = q{};
808    }
809
810    $pollmain =~ s/{yabb pollnum}/$pollnum/gsm;
811    $pollmain =~ s/{yabb scp}/$scp/sm;
812    $pollmain =~ s/{yabb poll_coll}/$poll_coll/gsm;
813    $pollmain =~ s/{yabb scdivdisp}/$scdivdisp/gsm;
814    $pollmain =~ s/{yabb poll_icon}/$poll_icon/sm;
815    $pollmain =~ s/{yabb boardpoll}/$boardpoll/sm;
816    $pollmain =~ s/{yabb lockpoll}/$lockpoll/sm;
817    $pollmain =~ s/{yabb modifypoll}/$modifypoll/sm;
818    $pollmain =~ s/{yabb deletepoll}/$deletepoll/sm;
819    $pollmain =~ s/{yabb poll_question}/$poll_question/sm;
820    $pollmain =~ s/{yabb poll_notlocked}/$poll_notlocked/gsm;
821    $pollmain =~ s/{yabb endedtext}/$endedtext/sm;
822    $pollmain =~ s/{yabb pollhidden}/$poll_hidden/sm;
823    $pollmain =~ s/{yabb poll_hasvoted}/$poll_hasvoted/sm;
824    $pollmain =~ s/{yabb footer}/$footer/sm;
825    $pollmain =~ s/{yabb my_pollcomment}/$my_pollcomment/sm;
826    $pollmain =~ s/{yabb poll_end}/$poll_end/sm;
827    $pollmain =~ s/{yabb displaydate}/$displaydate/sm;
828    $pollmain =~ s/{yabb viewthread}/$viewthread/sm;
829    $pollmain =~ s/{yabb deletevote}/$deletevote/sm;
830    $pollmain =~ s/{yabb displayvoters}/$displayvoters/sm;
831    $pollmain .= qq~<script type="text/javascript">
832function collapseSCpoll(pollnr) {
833    if (document.getElementById("polldiv").style.display == 'none') linkpollnr = '0';
834    else linkpollnr = pollnr;
835    var doexpand = "$boardindex_exptxt{'1'}";
836    var docollaps = "$boardindex_exptxt{'2'}";
837    if (document.getElementById("polldiv").style.display == 'none') {
838        document.getElementById("polldiv").style.display = 'block';
839        document.getElementById('scpollcollapse').src = "$imagesdir/$cat_col";
840        document.getElementById('scpollcollapse').alt = docollaps;
841        document.getElementById('scpollcollapse').title = docollaps;
842    }
843    else {
844        document.getElementById("polldiv").style.display = 'none';
845        document.getElementById('scpollcollapse').src="$imagesdir/$cat_exp";
846        document.getElementById('scpollcollapse').alt = doexpand;
847        document.getElementById('scpollcollapse').title = doexpand;
848    }
849    var url = '$scripturl?action=scpollcoll&scpoll=' + linkpollnr;
850    GetXmlHttpObject();
851    if (xmlHttp === null) return;
852    xmlHttp.open("GET",url,true);
853    xmlHttp.send(null);
854}
855</script>
856~;
857    return $pollmain;
858}
859
860sub collapse_poll {
861    ${$uid.$username}{'collapsescpoll'} = $INFO{'scpoll'};
862    UserAccount($username, 'update');
863    $elenable = 0;
864    croak q{};
865}
866
867sub check_deletepoll {
868    fopen(FILE, "$datadir/$pollnum.poll");
869    $poll_chech = <FILE>;
870    fclose(FILE);
871    chomp $poll_chech;
872    $vote_limit = ( split /\|/xsm, $poll_chech, 14 )[12];
873    $poll_nodelete{$username} = 0;
874    if (!$vote_limit) {
875        $poll_nodelete{$username} = 1;
876        return;
877    }
878    if (-e "$datadir/$pollnum.polled") {
879        fopen(FILE, "$datadir/$pollnum.polled");
880        @chpolled = <FILE>;
881        fclose(FILE);
882        foreach my $chvoter (@chpolled) {
883            ( undef, $chvotersname, undef, $chvotedate ) = split /\|/xsm,
884              $chvoter;
885            if ($chvotersname eq $username) {
886                $chdiff = $date - $chvotedate;
887                if ($chdiff > ($vote_limit * 60)) {
888                    $poll_nodelete{$username} = 1;
889                    last;
890                }
891            }
892        }
893    }
894    return;
895}
896
897sub ShowcasePoll {
898    is_admin_or_gmod();
899    my $thrdid = $INFO{'num'};
900    fopen (SCFILE, ">$datadir/showcase.poll");
901    print {SCFILE} $thrdid or croak "$croak{'print'} SCFILE";
902    fclose (SCFILE);
903    $yySetLocation = qq~$scripturl~;
904    redirectexit();
905    return;
906}
907
908sub DelShowcasePoll{
909    is_admin_or_gmod();
910    if ( -e "$datadir/showcase.poll" ) { unlink "$datadir/showcase.poll"; }
911    $yySetLocation = qq~$scripturl~;
912    redirectexit();
913    return;
914}
915
9161;
917