-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter.php
97 lines (88 loc) · 2.44 KB
/
counter.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
<?php
global $url, $connection;
if (empty($url['params'][0])) {
redirect('404');
}
$query = $connection->prepare("SELECT `rowid`, * FROM `polls` WHERE `slug` = :slug LIMIT 1;");
if (!$query) {
redirect("error/database");
}
$params = array(
':slug' => $url['params'][0]
);
if (!$query->execute($params)) {
redirect("error/database");
}
$poll = $query->fetchObject();
$expired = $poll->expires && (strtotime($poll->expires) - strtotime() <= 0);
if (!$poll->enabled || $expired) {
$msg = $expired ? 'expired' : 'off';
redirect("error/$msg");
}
function format_question($question) {
echo "<span class=\"question\">$question->question</span>";
$votes = str_split($question->votes);
echo '<span class="votes">';
foreach ($votes as $v) {
echo "<span title=\"$v\" class=\"number\">$v</span>";
}
echo '</span>';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>RH Vote!</title>
<link rel="stylesheet" href="<?php echo $url['base']; ?>/css/fonts.css" />
<link rel="stylesheet" href="<?php echo $url['base']; ?>/css/styles.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<?php if (config('refresh')): ?>
<script>
function refresh() {
console.log(window.location);
$('#page').load(window.location.href+' #counts');
setTimeout(refresh, <?php echo config('refresh')*1000; ?>);
}
$(document).ready(function() {
setTimeout(refresh, <?php echo config('refresh')*1000; ?>);
});
</script>
<?php endif; ?>
</head>
<body>
<section>
<header class="page-header">
<img src="<?php echo $url['base']; ?>/img/header.jpg" />
</header>
<div id="page">
<table id="counts" class="table table-striped">
<tbody>
<?php
$query = $connection->prepare("SELECT `rowid`, * FROM `questions` WHERE `poll_id` = :poll_id ORDER BY `order` ASC;");
if ($query->execute(array(':poll_id' => $poll->rowid))):
$questions = $query->fetchAll(PDO::FETCH_CLASS);
$questions = array_chunk($questions, ceil(count($questions)/2));
foreach ($questions[0] as $row => $obj): ?>
<tr>
<td>
<?php
echo format_question($questions[0][$row]);
?>
</td>
<td>
<?php
if (isset($questions[1][$row])) {
echo format_question($questions[1][$row]);
}
?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</section>
</body>
</html>