forked from thedilab/Simple-OOP-poll-system
/
index.php
75 lines (68 loc) · 1.4 KB
/
index.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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
ul{
width:300px;
list-style-type: none;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 2em;
}
ul li{
margin-bottom:2px;
padding:2px;
}
ul li.result{
position: relative;
}
ul li.result span.bar{
background-color: #D8DFEA;
display: block;
left: 0;
position: absolute;
top: 0;
z-index: -1;
}
</style>
</head>
<body>
<?php
include 'vote.php';
$vote = new Vote();
$action='';
//get action
if(isset($_REQUEST['action'])){
$action = $_REQUEST['action'];
}
//vote and show results
if('vote'==$action){
//vote
$vote->vote($_REQUEST['id']);
//show results
$total=$vote->getTotal();
echo '<ul>';
foreach($vote->showResults() as $vote){
$percent = 0;
if(isset($vote['number'])&&!empty($vote['number'])){
$percent = $vote['number']/$total * 100;
}
echo '<li class="result">';
echo '<span class="bar" style="width:'.$percent.'%;"> </span>';
echo '<span class="label">'.$vote['name'].' (<strong>'.$percent.'%</strong>)</span>';
echo '</li>';
}
echo '</ul>';
//show options
}else{
echo '<ul>';
foreach($vote->getList() as $option){
echo '<li>';
echo '<a href="'.$_SERVER['PHP_SELF'].'?action=vote&&id='.$option['id'].'">'.$option['name'].'</a>';
echo '</li>';
}
echo '</ul>';
}
?>
</body>
</html>