-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonline.php
267 lines (244 loc) · 9.26 KB
/
online.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
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<link href='https://fonts.googleapis.com/css?family=Abel' rel='stylesheet'>
<title>ONLINE VOTE</title>
<style type="text/css">
html {
background: url(bck.jpg) no-repeat center center fixed;
background-size: cover;
height: 100%;
overflow: hidden;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: rgba(0, 0, 0, 0.5);
color: white;
text-align: center;
}
body {
font-family: 'Abel';
font-size: 22px;
}
#container {
position: absolute;
top: 120px;
left: 100px;
width: 100%;
height: auto;
}
img {
position: fixed;
margin-left: 45%;
margin-top: 8%;
height: auto;
width: 700px;
}
.button {
background-color: #4CAF50;
/* Green */
border: none;
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s;
/* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
.button1 {
background-color: white;
color: black;
border: 2px solid #4CAF50;
}
.button1:hover {
background-color: #4CAF50;
color: white;
}
.button2 {
background-color: white;
color: black;
border: 2px solid #008CBA;
}
.button2:hover {
background-color: #008CBA;
color: white;
}
.button3 {
background-color: white;
color: black;
border: 2px solid #f44336;
}
.button3:hover {
background-color: #f44336;
color: white;
}
.button4 {
background-color: white;
color: black;
border: 2px solid #e7e7e7;
}
.button4:hover {
background-color: #e7e7e7;
}
.firstItem {
margin: 10px 0 10px 0;
}
.wyniki {
position: fixed;
margin-left: 45%;
margin-top: 8%;
display: flex;
flex-direction: column;
}
.wyniki>div {
margin: 10px;
}
</style>
</head>
<body>
<script src='script.js'> </script>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<ul class="navbar-nav">
<li class="nav-item active">
<?php
if (isset($_SESSION['logged']) && $_SESSION['logged'] == true) {
echo "<a class='nav-link' href='#'>" .$_SESSION['name']."</a>";
} else {
echo "<a class='nav-link' href='#'> Guest </a>";
}
?>
</li>
<li class="nav-item">
<a class="nav-link" href="index.php">Main page</a>
</li>
<li class="nav-item">
<a class="nav-link" href="documentation.php">Documentation</a>
</li>
<?php
if (isset($_SESSION['logged']) && $_SESSION['logged'] == true) {
echo "<a class='nav-link' href='logout.php'>Logout</a>";
}
?>
</ul>
</nav>
<div id='container'>
<?php
error_reporting(0);
if (!isset($_SESSION['logged']) && $_SESSION['logged'] == false) {
echo "<nav>";
echo "<h1>Sign in</h1>";
echo "<form action='login.php' method='post'>
<input type='text' name='login' value='login'><br/>
<input type='password' name='password' value='password'><br/>
<input type='submit' value='' style='visibility: hidden;'><button class='button button4' value='Zaloguj'>Log-in</button>
</nav>
</form>";
echo "<h1 style='margin: 250px 0px 0px 0px;'>Dont have an account?</h1>";
echo "<a href='reg_form.php'><button class='button button4'>Register</button></a></div>";
if (isset($_SESSION['error'])) {
echo $_SESSION['error'] . "<br>";
unset($_SESSION['error']);
}
if (isset($_SESSION['message'])) {
echo $_SESSION['message'] . "<br>";
unset($_SESSION['message']);
}
} else {
echo "
<fieldset>
<form action='online.php' method='post'>
<h1>Choose your president</h1>
<br><input type='radio' value='A' id='odpA' name='odp' checked> Donald Trump
<br><input type='radio' value='B' id='odpB' name='odp'> Elizabeth Warren
<br><input type='radio' value='C' id='odpC' name='odp'> Bernie Sanders
<br><input type='radio' value='D' id='odpD' name='odp'> Joe Biden
<br><input type='submit' value='' style='visibility: hidden; margin: 70px 0px 0px 0px;'><button class='button button4' value='addanswer' onclick='removeImg()'>Approve vote</button>
<input type='hidden' value='w' name='wynik'>
</form>
</fieldset>
<br>
</div>
";
if (isset($_POST['odp'])) {
$db = new SQLite3('baza.db');
$db->exec("UPDATE president SET answer='$_POST[odp]' WHERE login='$_SESSION[login]'");
}
if (isset($_POST['wynik'])) {
$db = new SQLite3('baza.db');
$result = $db->query("SELECT * from president WHERE answer IS NOT NULL");
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$tab[] = $row;
}
$i = 0;
$firstCount = 0;
$secondCount = 0;
$thirdCount = 0;
$fourthCount = 0;
$count = 0;
while (isset($tab[$i]['name'])) {
switch ($tab[$i]['answer']) {
case "A":
++$firstCount;
++$count;
break;
case "B":
++$secondCount;
++$count;
break;
case "C":
++$thirdCount;
++$count;
break;
case "D":
++$fourthCount;
++$count;
break;
}
$i = $i + 1;
}
$trumpPercentage = round((100 * $firstCount) / $count);
$warrenPercentage = round((100 * $secondCount) / $count);
$sandersPercentage = round((100 * $thirdCount) / $count);
$bidenPercentage = round((100 * $fourthCount) / $count);
$firstCount = $firstCount * 100;
$secondCount = $secondCount * 100;
$thirdCount = $thirdCount * 100;
$fourthCount = $fourthCount * 100;
echo "<div id='wyniki' class='wyniki'>";
echo "<div id='trump' class='trump'>Trump $trumpPercentage% <canvas id='myCanvas' width='$firstCount' height='100' style='border:1px solid #c3c3c3; background-color: #3D9970;'></canvas></div>";
echo "<div id='trump' class='trump'>Warren $warrenPercentage% <canvas id='myCanvas' width='$secondCount' height='100' style='border:1px solid #c3c3c3; background-color: #85144b;'></canvas></div>";
echo "<div id='trump' class='trump'>Sanders $sandersPercentage% <canvas id='myCanvas' width='$thirdCount' height='100' style='border:1px solid #c3c3c3; background-color: #FF851B;'></canvas></div>";
echo "<div id='trump' class='trump'>Biden $bidenPercentage% <canvas id='myCanvas' width='$fourthCount' height='100' style='border:1px solid #c3c3c3; background-color: #001f3f;'></canvas></div>";
echo "</div>";
}
}
?>
<?php
if (!isset($_SESSION['logged']) && $_SESSION['logged'] == false) {
echo "<img src='flag.png'>";
}
?>
<div class="footer">
<p>Techniki Internetowe 2019/2020 Michal Stefaniuk</p>
</div>
</body>
</html>