forked from cherian/xmec
/
polls.php
489 lines (469 loc) · 15.2 KB
/
polls.php
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<?php
$secure_page=1;
$this_page = "poll";
include_once 'header.php';
include_once 'xmec_poll.php';
reset($HTTP_POST_VARS);
$action=chop($HTTP_POST_VARS["action"]);
$poll_id=chop($HTTP_POST_VARS["pollID"]);
if ($REQUEST_METHOD == "GET") {
$action=chop($HTTP_GET_VARS["action"]);
$poll_id=chop($HTTP_GET_VARS["pollID"]);
}
if (!$action) {
$action="view_open";
}
$user =& XMEC::getUser();
if (($action == "del_poll") || ($action == "create_poll") || ($action == "poll_admin")) {
if (!$user->isAdmin()) {
echo "<CENTER><H1>You are not authorised...!<BR></H1></CENTER>";
include 'footer.php';
exit;
}
}
?>
<BR>
<CENTER><B class =head>XMEC Polls - Your Opinion Counts</B></CENTER><BR>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 ALIGN=CENTER WIDTH="85%">
<?php
echo '<TR><TD><TABLE BORDER=0 WIDTH=100%><TR><TD WIDTH=5%> </TD>';
if ($action != "view_open") {
echo '<TD ALIGN=CENTER><A class=flink HREF="polls.php?action=view_open">Active Polls</A></TD>';
}
if ($action != "view_results") {
echo '<TD ALIGN=CENTER><A class=flink HREF="polls.php?action=view_results">Results</A></TD>';
}
if ($user->isAdmin()) {
echo '<TD ALIGN=CENTER><A class=flink HREF="polls.php?action=poll_admin">Administer Polls</A></TD>';
}
echo '<TD WIDTH=5%> </TD></TR></TABLE></TD></TR>';
?>
<?php
if ($action == "view_open") {
$polls =& getOpenPolls();
for($i=0;$i<count($polls);$i++) {
$userResponse = $polls[$i]->hasUserVoted($user);
if ( ($polls[$i]->isAnonymous == 0) ||
($userResponse == 0) ) {
?>
<TR><TD>
<TABLE ALIGN=CENTER CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH="100%">
<TBODY>
<TR><TD>
<!-- Box start -->
<TABLE cellSpacing=0 cellPadding=0 border=0 width="100%">
<TBODY>
<TR>
<TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
<TD align=left background=images/tb_top.gif height=4><IMG height=4 src="images/tb_left_topt.gif" width=8></TD>
<TD align=right background=images/tb_top.gif height=4><IMG height=4 src="images/tb_right_topt.gif" width=8></TD>
<TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
</TR>
<TR>
<TD vAlign=top width=4 background=images/tb_left.gif height="50%"><IMG height=6 src="images/tb_left_topb.gif" width=3></TD>
<TD colSpan=2 rowSpan=2>
<!--Content Start -->
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0 WIDTH="100%"
ALIGN=CENTER>
<FORM METHOD=POST ACTION="polls.php">
<?php
if ($userResponse == 0) {
?>
<INPUT TYPE=hidden NAME=action VALUE=vote>
<?php
} else {
?>
<INPUT TYPE=HIDDEN NAME=action VALUE=revote>
<?php
}
echo '<INPUT TYPE=HIDDEN NAME=pollID VALUE="' . $polls[$i]->pollID . '">';
?>
<TR ALIGN=CENTER>
<TD BGCOLOR="#CFDDD1">
<B class=head>
<?php
echo $polls[$i]->title;
if ($polls[$i]->isAnonymous) {
echo "<SUP>*</SUP>";
}
?>
</B>
</TD>
</TR>
<TR ALIGN=RIGHT>
<TD BGCOLOR="#CFDDD1">
<B class=body>
<?php
echo "This Poll Closes ". $polls[$i]->endDatefmt;
?>
</B>
</TD>
</TR>
<TR>
<TD BGCOLOR="#FFFFFF" class=name>
<?php
echo $polls[$i]->pollQuestion;
?>
</TD>
</TR>
<TR>
<TD BGCOLOR="#FFFFFF" class=body>
<?php
for ($j = 0; $j < count($polls[$i]->answers); $j++) {
$ansSeq = $polls[$i]->answers[$j]->ansSeq;
$ansDesc = $polls[$i]->answers[$j]->ansDesc;
echo '<INPUT TYPE=radio NAME=answers VALUE=' . $ansSeq;
if ($ansSeq == $userResponse) {
echo " CHECKED";
}
echo '>' . $polls[$i]->answers[$j]->ansDesc . '</INPUT><BR>';
}
?>
</TD>
</TR>
<TR>
<TD ALIGN=CENTER>
<?php
if ($userResponse == 0) {
echo '<INPUT TYPE=submit VALUE="Vote"></INPUT>';
} else {
echo '<INPUT TYPE=submit VALUE="Revote"></INPUT>';
}
?>
</TD>
</TR>
<?php
if ($polls[$i]->isAnonymous == 1) {
?>
<TR>
<TD CLASS=head>
<CENTER><SUP>*</SUP>This is an anonymous poll. Vote once registered cannot be changed.</CENTER>
</TD>
</TR>
<?php
}
?>
</FORM>
</TABLE>
<!--Content Ends-->
</TD>
<TD vAlign=top width=4 background=images/tb_right.gif height="50%"><IMG height=6 src="images/tb_right_topb.gif" width=3></TD>
</TR>
<TR>
<TD vAlign=bottom width=4 background=images/tb_left.gif height="50%"><IMG height=6 src="images/tb_left_bottomb.gif" width=3></TD>
<TD vAlign=bottom width=4 background=images/tb_right.gif height="50%"><IMG height=6 src="images/tb_right_bottomb.gif" width=3></TD>
</TR>
<TR>
<TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
<TD align=left background=images/tb_bottom.gif height=4><IMG height=4 src="images/tb_left_bottomt.gif" width=8></TD>
<TD align=right background=images/tb_bottom.gif height=4><IMG height=4 src="images/tb_right_bottomt.gif" width=8></TD>
<TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
</TR>
</TBODY>
</TABLE>
<!--Box ends -->
</TD></TR>
</TBODY>
</TABLE><br>
</TD></TR>
<?php
} # if loop
} # for loop
}
?>
<?php
if ($action == "view_results") {
$titles = getTitles();
?>
<TR><TD><BR></TD></TR>
<?php if ($user->isAdmin()) {
echo '<tr><td>For Admins all the polls will be listed. not just the closed ones</td></tr>';
} ?>
<TR><TD colspan=2>
<!-- Box starts -->
<TABLE cellSpacing=0 cellPadding=0 border=0 width="100%">
<TBODY>
<TR>
<TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
<TD align=left background=images/tb_top.gif height=4><IMG height=4 src="images/tb_left_topt.gif" width=8></TD>
<TD align=right background=images/tb_top.gif height=4><IMG height=4 src="images/tb_right_topt.gif" width=8></TD>
<TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
</TR>
<TR>
<TD vAlign=top width=4 background=images/tb_left.gif height="50%"><IMG height=6 src="images/tb_left_topb.gif" width=3></TD>
<TD colSpan=2 rowSpan=2>
<!--Content start-->
<TABLE border=0 cellPadding=0 cellSpacing=3 WIDTH=100%>
<TR bgcolor="#CFDDD1">
<TD WIDTH="75%"><B class=head>Poll Title</B></TD>
<TD WIDTH="25%"><B class=head>Closed On</B></TD>
</TR>
<?php
for($i=0;$i<count($titles); $i++) {
$ttl = $titles[$i];
?>
<TR>
<TD class=body>
<?php
echo "<A class=link HREF=polls.php?action=view_poll&pollID=" . $ttl[0] . ">" . $ttl[1];
?>
</A>
</TD>
<TD class=body>
<?php
/* list($date,)=split(' ',$ttl[2]); echo descDate($date); */
echo $ttl[2];
?>
</TD>
</TR>
<?php
}
?>
</TABLE>
<!-- Content Ends -->
</TD>
<TD vAlign=top width=4 background=images/tb_right.gif height="50%"><IMG height=6 src="images/tb_right_topb.gif" width=3></TD>
</TR>
<TR>
<TD vAlign=bottom width=4 background=images/tb_left.gif height="50%"><IMG height=6 src="images/tb_left_bottomb.gif" width=3></TD>
<TD vAlign=bottom width=4 background=images/tb_right.gif height="50%"><IMG height=6 src="images/tb_right_bottomb.gif" width=3></TD>
</TR>
<TR>
<TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
<TD align=left background=images/tb_bottom.gif height=4><IMG height=4 src="images/tb_left_bottomt.gif" width=8></TD>
<TD align=right background=images/tb_bottom.gif height=4><IMG height=4 src="images/tb_right_bottomt.gif" width=8></TD>
<TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
</TR>
</TBODY>
</TABLE>
<!-- Box Ends-->
</TD></TR>
<?php
}
?>
<?php
if ($action == "view_poll") {
?>
<TR><TD><BR></TD></TR>
<TR><TD>
<!--Box Starts -->
<TABLE cellSpacing=0 cellPadding=0 border=0 width="100%">
<TBODY>
<TR>
<TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
<TD align=left background=images/tb_top.gif height=4><IMG height=4 src="images/tb_left_topt.gif" width=8></TD>
<TD align=right background=images/tb_top.gif height=4><IMG height=4 src="images/tb_right_topt.gif" width=8></TD>
<TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
</TR>
<TR>
<TD vAlign=top width=4 background=images/tb_left.gif height="50%"><IMG height=6 src="images/tb_left_topb.gif" width=3></TD>
<TD colSpan=2 rowSpan=2>
<!--Content Start -->
<?php
$poll = getPoll($poll_id);
$total_votes = 0;
for ($i=0;$i<count($poll->answers);$i++) {
$total_votes += $poll->answers[$i]->votes;
}
if (!$total_votes) $total_votes++;
?>
<TABLE border=0 cellPadding=0 cellSpacing=3 WIDTH=100%>
<TR bgcolor="#CFDDD1">
<TD WIDTH="75%" COLSPAN=3>
<B class=head>
<?php
echo $poll->title;
?>
</B>
</TD>
</TR>
<TR>
<TD class=name COLSPAN=3>
<?php
echo $poll->pollQuestion;
?>
</TD>
</TR>
<?php
for($i=0;$i<count($poll->answers);$i++) {
$percent = ($poll->answers[$i]->votes*100)/$total_votes;
?>
<TR>
<TD class=body WIDTH="60%">
<?php
echo $poll->answers[$i]->ansDesc;
?>
</TD>
<TD class=body WIDTH="5%">
<?php
echo $poll->answers[$i]->votes;
?>
</TD>
<TD class=body WIDTH="35%">
<?php
echo '<IMG SRC="images/pollBar.gif" HEIGHT=12 WIDTH=' .$percent . '>';
printf(" %.2f%s", $percent,"%") ;
?>
</TD>
</TR>
<?php
}
?>
</TABLE>
<!--Content End-->
</TD>
<TD vAlign=top width=4 background=images/tb_right.gif height="50%"><IMG height=6 src="images/tb_right_topb.gif" width=3></TD>
</TR>
<TR>
<TD vAlign=bottom width=4 background=images/tb_left.gif height="50%"><IMG height=6 src="images/tb_left_bottomb.gif" width=3></TD>
<TD vAlign=bottom width=4 background=images/tb_right.gif height="50%"><IMG height=6 src="images/tb_right_bottomb.gif" width=3></TD>
</TR>
<TR>
<TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
<TD align=left background=images/tb_bottom.gif height=4><IMG height=4 src="images/tb_left_bottomt.gif" width=8></TD>
<TD align=right background=images/tb_bottom.gif height=4><IMG height=4 src="images/tb_right_bottomt.gif" width=8></TD>
<TD width=4 height=4><IMG height=4 src="images/corner.gif" width=4></TD>
</TR>
</TBODY>
</TABLE>
<!--Box Ends-->
<CENTER>
<?php if ($user->isAdmin()) { ?>
<FORM NAME=delme ACTION=polls.php METHOD=GET>
<INPUT TYPE=HIDDEN NAME=pollID VALUE=<?php echo $poll_id; ?>>
<INPUT TYPE=SUBMIT NAME=action VALUE=del_poll>
</FORM>
<FONT color=#FF0000><B>Please note that I am not going to prompt you again if you hit that button above.</B></FONT>
<?php } ?>
</CENTER>
</TD></TR>
<?php
}
?>
<?php
if ($action == "del_poll") {
$retval = deletePoll($poll_id);
if ($retval == 0) {
echo "<CENTER>Poll Sucessfully Deleted<BR></CENTER>";
} else {
echo "<CENTER>There were some errors while deleting the poll<BR></CENTER>";
}
}
?>
<?php
if ($action == "revote") {
?>
<TR><TD><BR></TD></TR>
<TR><TD class=head style="color:#00FF00">
<?php
$ansSeq=chop($HTTP_POST_VARS["answers"]);
$poll_id = chop($HTTP_POST_VARS["pollID"]);
$userID = $user->id;
registerReVote($poll_id,$user, $ansSeq);
?>
<CENTER><B>Thank you for for using XMEC Polls . Your Vote has been updated. The results will be displayed after the poll is closed.</B> </CENTER>
</TD></TR>
<?php
}
?>
<?php
if ($action == "vote") {
?>
<TR><TD><BR></TD></TR>
<TR><TD>
<?php
$ansSeq=chop($HTTP_POST_VARS["answers"]);
$poll_id = chop($HTTP_POST_VARS["pollID"]);
$userID = $user->id;
registerVote($poll_id,$user, $ansSeq);
?>
<CENTER>Thanks For Voting. Your Vote has been registered.</CENTER>
</TD></TR>
<?php
}
?>
<?php
if ($action == "poll_admin") {
if ($user->isAdmin()) {
?>
<TR><TD>
<TABLE WIDTH="80%" border=1>
<FORM NAME=create_poll method=post action="polls.php">
<INPUT TYPE=hidden NAME=action value=create_poll>
<TR><TD COLSPAN=2 ALIGN=center>Create new poll</TD></TR>
<TR>
<TD>Title</TD>
<TD><INPUT TYPE=text NAME=poll_title Value="Replace this line by the title of the poll" size=35 maxlength=200></INPUT>
</TD>
</TR>
<TR>
<TD>
Poll Question
</TD>
<TD>
<TEXTAREA NAME=poll_q maxlength=2048 cols=35 rows=5>Replace this line by the poll question.</TEXTAREA>
</TD>
</TR>
<TR>
<TD>
Poll Answers
</TD>
<TD>
<TEXTAREA NAME=poll_ans cols=35 rows=5>Replace this line by the options for the poll oneeach on a line.</TEXTAREA>
</TD>
</TR>
<TR>
<TD><INPUT TYPE=checkbox NAME=poll_anonymous>Anonymous</TD>
<TD>Start Date
<INPUT TYPE=text NAME=poll_start_date></INPUT>yyyy/mm/dd
<BR>End Date
<INPUT TYPE=text NAME=poll_end_date></INPUT>yyyy/mm/dd
</TD>
</TR>
<TR>
<TD COLSPAN=2 ALIGN=center>
<INPUT TYPE=submit Value="Create Poll"></INPUT>
</TD>
</TR>
</FORM>
</TABLE>
</TD></TR>
<?php
} else {
echo "You need to be admin to access this page<BR>";
}
}
?>
<?php
if ($action == "create_poll") {
if ($user->isAdmin()) {
$poll_title = $HTTP_POST_VARS['poll_title'];
$poll_q = $HTTP_POST_VARS['poll_q'];
$poll_ans = $HTTP_POST_VARS['poll_ans'];
$poll_st = $HTTP_POST_VARS['poll_start_date'];
$poll_en = $HTTP_POST_VARS['poll_end_date'];
$poll_anon = $HTTP_POST_VARS['poll_anonymous'];
if ($poll_anon == 'on') {
$poll_anon = 1;
} else {
$poll_anon = 0;
}
if (!$poll_title || !$poll_q || !$poll_ans || !$poll_st || !$poll_en) {
echo "Enter all the values in the create FORM before creating\n";
} else {
$retval = createPoll($poll_title, $poll_q, $poll_ans, $poll_st, $poll_en, $poll_anon);
if ($retval != 0) {
echo "<CENTER>There were errors while creating the poll<BR></CENTER>";
} else {
echo "<CENTER>Sucessfully create the poll<BR></CENTER>";
}
}
} else {
echo "You need to be an Administrator to create a poll<br>";
}
}
?>
</TABLE>
<?php
include 'footer.php';
?>