-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
71 lines (62 loc) · 2.39 KB
/
Copy pathindex.php
File metadata and controls
71 lines (62 loc) · 2.39 KB
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
<?php
session_start();
if (!isset($_SESSION['loggedin'])) {
header('Location: login.php');
exit;
}
$msg = "";
if (isset($_SESSION['msg'])) {
$msg = $_SESSION['msg'];
$_SESSION['msg'] = "";
}
include 'functions.php';
$pdo = pdo_connect_mysql();
$stmt = $pdo->query('SELECT p.*, GROUP_CONCAT(pa.title ORDER BY pa.id) AS answers FROM polls p LEFT JOIN poll_answers pa ON pa.poll_id = p.id GROUP BY p.id');
$polls = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<?=template_header('Polls')?>
<div class="container-fluid content home">
<?php if ($msg): ?>
<div class="notif-warning"><p><i class="fas fa-exclamation-circle"></i> <?=$msg?></p></div>
<?php endif;?>
<h2><i class="fa fa-poll-h fa-lg" style="margin-right: 10px;"></i>Polls</h2>
<p>Hi <?=$_SESSION['name']?>, you can view the list of polls below. You also can create your own poll!</p>
<a href="create.php" class="create-poll">Create Poll</a>
<table class="table table-bordered">
<thead class="thead-dark">
<tr>
<td scope="col">#</td>
<td scope="col">Title</td>
<td scope="col">Answers</td>
<td scope="col">Creator</td>
<td scope="col">Action</td>
</tr>
</thead>
<tbody>
<?php $num = 1; ?>
<?php foreach ($polls as $poll): ?>
<?php
$stmt = $pdo->query('SELECT username FROM accounts WHERE id = ' . $poll['creator_id']);
$creator = $stmt->fetch(PDO::FETCH_ASSOC);
$creator_name = $creator['username'];
?>
<tr>
<th scope="row"><?=$num?></td>
<td><?=$poll['title']?></td>
<td><?=$poll['answers']?></td>
<td><?=$creator_name?></td>
<td class="actions">
<a href="vote.php?id=<?=$poll['id']?>" class="view" title="View Poll"><i class="fas fa-eye fa-xs"></i></a>
<?php
if ($_SESSION['id'] == $poll['creator_id'] || $_SESSION['su']) {
echo '<a href="delete.php?id=' . $poll['id'] . '" class="trash" title="Delete Poll"><i class="fas fa-trash fa-xs"></i></a>';
}
?>
</td>
</tr>
<?php $num++; ?>
<?php endforeach;?>
</tbody>
</table>
</div>
<?=template_footer()?>