forked from darkalchemy/Pu-239
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolls.php
More file actions
323 lines (300 loc) · 9.48 KB
/
polls.php
File metadata and controls
323 lines (300 loc) · 9.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<?php
/**
* @return string
*/
function parse_poll()
{
global $CURUSER, $site_config;
$htmlout = '';
$check = 0;
$poll_footer = '';
$GVARS = [
'allow_creator_vote' => 1,
'allow_result_view' => 1,
'allow_poll_tags' => 1,
];
$poll_data = get_poll();
if (empty($poll_data)) {
return false;
}
$member_voted = 0;
$total_votes = 0;
if ($poll_data['user_id']) {
$member_voted = 1;
}
if ($member_voted) {
$check = 1;
$poll_footer = 'You have already voted';
}
if (($poll_data['starter_id'] == $CURUSER['id']) && ($GVARS['allow_creator_vote'] != 1)) {
$check = 1;
$poll_footer = 'You created this poll and are not allowed to vote';
}
if ($GVARS['allow_result_view'] == 1) {
if (isset($_GET['mode']) && $_GET['mode'] == 'show') {
$check = 1;
$poll_footer = '';
}
}
if ($check === 1) {
$htmlout = poll_header($poll_data['pid'], htmlsafechars($poll_data['poll_question'], ENT_QUOTES));
$poll_answers = unserialize(stripslashes($poll_data['choices']));
reset($poll_answers);
$tv_poll = 0;
foreach ($poll_answers as $id => $data) {
//subtitle question
$question = htmlsafechars($data['question'], ENT_QUOTES);
$choice_html = '';
//get total votes for each choice
foreach ($poll_answers[$id]['votes'] as $number) {
$tv_poll += intval($number);
}
// Get the choises from the unserialised array
foreach ($data['choice'] as $choice_id => $text) {
$choice = htmlsafechars($text, ENT_QUOTES);
$votes = intval($data['votes'][$choice_id]);
if (strlen($choice) < 1) {
continue;
}
if ($GVARS['allow_poll_tags']) {
$choice = format_comment($choice);
}
$percent = $votes == 0 ? 0 : $votes / $tv_poll * 100;
$percent = sprintf('%.2f', $percent);
$width = $percent > 0 ? intval($percent * 4) : 0;
$choice_html .= poll_show_rendered_choice($choice_id, $votes, $id, $choice, $percent, $width);
}
$htmlout .= poll_show_rendered_question($question, $choice_html);
}
$htmlout .= show_total_votes($tv_poll);
} elseif ($check == 2) {
// only for guests when view before vote is off
$htmlout = poll_header($poll_data['pid'], htmlsafechars($poll_data['poll_question'], ENT_QUOTES));
//$htmlout .= poll_show_no_guest_view();
$htmlout .= show_total_votes($total_votes);
} else {
$poll_answers = unserialize(stripslashes($poll_data['choices']));
//output poll form
$htmlout = poll_header($poll_data['pid'], htmlsafechars($poll_data['poll_question'], ENT_QUOTES));
foreach ($poll_answers as $id => $data) {
foreach ($poll_answers[$id]['votes'] as $number) {
$total_votes += intval($number);
}
// get the question again!
$question = htmlsafechars($data['question'], ENT_QUOTES);
$choice_html = '';
// get choices for this question
foreach ($data['choice'] as $choice_id => $text) {
$choice = htmlsafechars($text, ENT_QUOTES);
$votes = intval($data['votes'][$choice_id]);
if (strlen($choice) < 1) {
continue;
}
//do we wanna allow URL's and if so convert them
if ($GVARS['allow_poll_tags']) {
$choice = format_comment($choice);
}
if (isset($data['multi']) && $data['multi'] == 1) {
$choice_html .= poll_show_form_choice_multi($choice_id, $votes, $id, $choice);
} else {
$choice_html .= poll_show_form_choice($choice_id, $votes, $id, $choice);
}
}
$choice_html = "<table>{$choice_html}</table>";
$htmlout .= poll_show_form_question($id, $question, $choice_html);
}
$htmlout .= show_total_votes($total_votes);
}
$htmlout .= poll_footer();
if ($poll_footer != '') {
$htmlout = str_replace('<!--VOTE-->', $poll_footer, $htmlout);
} else {
if ($GVARS['allow_result_view'] == 1) {
if (isset($_GET['mode']) && $_GET['mode'] == 'show') {
$htmlout = str_replace('<!--SHOW-->', button_show_voteable(), $htmlout);
} else {
$htmlout = str_replace('<!--SHOW-->', button_show_results(), $htmlout);
$htmlout = str_replace('<!--VOTE-->', button_vote(), $htmlout);
}
} else {
//this section not for reviewing votes!
$htmlout = str_replace('<!--VOTE-->', button_vote(), $htmlout);
$htmlout = str_replace('<!--SHOW-->', button_null_vote(), $htmlout);
}
}
return $htmlout;
}
/**
* @param string $pid
* @param string $poll_q
*
* @return string
*/
function poll_header($pid = '', $poll_q = '')
{
global $site_config;
$HTMLOUT = '';
$HTMLOUT .= "<script>
/*<![CDATA[*/
function go_gadget_show()
{
window.location = \"{$site_config['baseurl']}/index.php?pollid={$pid}&mode=show&st=main\";
}
function go_gadget_vote()
{
window.location = \"{$site_config['baseurl']}/index.php?pollid={$pid}&st=main\";
}
/*]]>*/
</script>
<a id='poll-hash'></a>
<div id='poll' class='box'>
<div class='bordered'>
<div class='alt_bordered bg-00'>
<form action='{$site_config['baseurl']}/polls_take_vote.php?pollid={$pid}&st=main&addpoll=1' method='post'>";
return $HTMLOUT;
}
/**
* @return string
*/
function poll_footer()
{
return '
<div class="has-text-centered"><!--VOTE--><!--SHOW--></div>
<div class="has-text-centered"><!-- no content --></div>
</form>
</div>
</div>
</div>';
}
/**
* @param string $choice_id
* @param string $votes
* @param string $id
* @param string $answer
* @param string $percentage
* @param string $width
*
* @return string
*/
function poll_show_rendered_choice($choice_id = '', $votes = '', $id = '', $answer = '', $percentage = '', $width = '')
{
global $site_config;
return "
<div class='bottom20 bg-02 round10 padding10'>
<div class='bg-02 round10 padding10'>
$answer
</div>
<div class='level-center-center'>
<img src='{$site_config['pic_baseurl']}polls/bar.gif' style='width: {$width}px; height: 11px;' align='middle' alt=''>
[$percentage%]
</div>
<span class='size_4'>Total Votes: $votes</span>
</div>";
}
/**
* @param string $question
* @param string $choice_html
*
* @return string
*/
function poll_show_rendered_question($question = '', $choice_html = '')
{
return "
<div class='has-text-centered'>
<div class='round10'>
<span class='size_5'>
$question
</span>
</div>
$choice_html
</div>";
}
/**
* @param string $total_votes
*
* @return string
*/
function show_total_votes($total_votes = 0)
{
return "
<div class='has-text-centered top10'>
Total Votes: $total_votes
</div>";
}
/**
* @param string $choice_id
* @param string $votes
* @param string $id
* @param string $answer
*
* @return string
*/
function poll_show_form_choice_multi($choice_id = '', $votes = '', $id = '', $answer = '')
{
return "
<tr>
<td colspan='3'><input type='checkbox' name='choice_{$id}_{$choice_id}' value='1'> $answer</td>
</tr>";
}
/**
* @param string $choice_id
* @param string $votes
* @param string $id
* @param string $answer
*
* @return string
*/
function poll_show_form_choice($choice_id = '', $votes = '', $id = '', $answer = '')
{
return "
<div class='padding10 level-left'>
<input type='radio' name='choice[{$id}]' value='$choice_id' class='right20'> $answer
</div>";
}
/**
* @param string $id
* @param string $question
* @param string $choice_html
*
* @return string
*/
function poll_show_form_question($id = '', $question = '', $choice_html = '')
{
return "
<div class='bg-02 round5 padding10'>
<div>
<div class='has-text-white size_6 padding10'>
{$question}
</div>
</div>
$choice_html
</div>";
}
/**
* @return string
*/
function button_show_voteable()
{
return "<input class='button is-small tooltipper margin10' type='button' name='viewresult' value='Show Votes' title='Goto poll voting' onclick=\"go_gadget_vote()\">";
}
/**
* @return string
*/
function button_show_results()
{
return "<input class='button is-small tooltipper margin10' type='button' value='Results' title='Show all poll results' onclick=\"go_gadget_show()\">";
}
/**
* @return string
*/
function button_vote()
{
return "<input class='button is-small tooltipper margin10' type='submit' name='submit' value='Vote' title='Cast Your Vote'>";
}
/**
* @return string
*/
function button_null_vote()
{
return "<input class='button is-small tooltipper margin10' type='submit' name='nullvote' value='View Results (Null Vote)' title='View results, but forfeit your vote in this poll'>";
}