-
Notifications
You must be signed in to change notification settings - Fork 3
/
voting.php
120 lines (110 loc) · 3.33 KB
/
voting.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
<script src="js/jquery.textfill.min.js"></script>
<script type="text/javascript" src="js/scripts.js"></script>
<?php
echo '<div class="voting">';
if ((!isset($_POST["voting_code"])) AND (!isset($_SESSION["voting_code"])))
{
// Somebody tried to load file directly, die in pain!
die();
}
// Set SESSION to count questions
if (!isset($_SESSION["question"]))
{
$_SESSION["question"] = 1;
}
// Set SESSION variable to hold username
if (!isset($_SESSION["voting_user"]))
{
if ((isset($_COOKIE["computer_id"])) AND (is_numeric($_COOKIE["computer_id"])))
{
$_SESSION["voting_user"] = $_COOKIE["computer_id"];
}
elseif (isset($_POST["voting_user"]))
{
$_SESSION["voting_user"] = $_POST["voting_user"];
}
}
// Set SESSION variable to hold voting code
if (!isset($_SESSION["voting_code"]))
{
$_SESSION["voting_code"] = $_POST["voting_code"];
}
// Whoops, bad code
if ((isset($_SESSION["voting_code"])) AND ($voting->voting_exists($_SESSION["voting_code"]) != 1))
{
$die = 1;
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php?page=password">';
die();
}
// Load voting info file, just in case something gonna need this
$more = $voting->get_more($_SESSION["voting_code"]);
// Check if somebody actually voted
if (isset($_GET["vote"]))
{
$voting->write_vote($_SESSION["voting_user"], $_SESSION["voting_code"], $_SESSION["question"] , $_GET["vote"]);
if ($_SESSION["question"] == $voting->question_count($_SESSION["voting_code"]))
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php?page=finish">';
die();
}
$_SESSION["question"] = $_SESSION["question"] + 1;
}
// Whoops, too late
if ($more[3] == 0)
{
$die = 1;
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php?page=timeout">';
die();
}
// Check just for the first question and only once in one SESSION if user voted already
if (!isset($_SESSION["user_passed"]))
{
$voters = $voting->voters($_SESSION["voting_code"]);
if (empty($voters))
{
$voters[] = -1; // Silence warning
}
if (in_array($_SESSION["voting_user"], $voters))
{
$die = 1;
// User voted already here, kick him out
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php?page=voted">';
}
else
{
// So, user didn't voted here yet, let him go
$_SESSION["user_passed"] = 1;
}
}
$header = $voting->view_voting($_SESSION["voting_code"]);
if (!isset($_SESSION["decrease"]))
{
$_SESSION["decrease"] = 0;
}
// Check if question exists so we don't need to renumber questions
while (!$voting->question_exists($_SESSION["voting_code"], $_SESSION["question"]))
{
$_SESSION["question"] = $_SESSION["question"] + 1;
$_SESSION["decrease"] = $_SESSION["decrease"] + 1;
}
echo " <div class='mezera'></div>";
if (isset($die))
{
die();
}
echo "<h10>" . $header . " - " . $voting->question_header($_SESSION["voting_code"], $_SESSION["question"]) . "</h10>";
echo "<p>" . ($_SESSION["question"] - $_SESSION["decrease"]) . "/" . $voting->question_count($_SESSION["voting_code"]) . "</p>";
echo "<br>";
$i = 1;
echo '<div class="hlasovani">';
foreach ($voting->get_possibilities($_SESSION["voting_code"], $_SESSION["question"]) as $pos)
{
echo '
<a href="index.php?page=voting&vote=' . $i . '"><div value="' . $pos . '" id="Poll_'.$i.'">
<span>' . $pos . '</span>
</div></a>';
$i=$i+1;
}
echo '</div>';
?>
</div>