-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.php
250 lines (217 loc) · 9.02 KB
/
user.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
<?php
include_once('database/connection.php');
include_once('database/polls.php');
include_once('database/users.php');
include_once('database/answers.php');
include_once('database/poll_answers.php');
include('lock.php');
include('templates/header.php');
include('templates/navbar.php');
$title = $filter = '';
$params = array('db' => $db);
if(isset($_SESSION['guest'])) {
if(isset($_GET['query']) && (strlen($_GET['query']) > 0)) {
$params['query'] = explode(" ", $_GET['query']);
$title = 'Search Results';
$result = getPublicSearchResults($params);
}
else {
$title = 'Public Polls';
$result = getPublicPolls($db);
}
} else {
$params['user_id'] = $_SESSION['myid'];
if(isset($_GET['query']) && (strlen($_GET['query']) > 0)) {
$params['query'] = explode(" ", $_GET['query']);
$title = 'Search Results';
$result = getSearchResults($params);
}
else if(isset($_GET['filter'])) {
$filter = $_GET['filter'];
if($filter == 'personal') {
$title = 'My Polls';
$result = getUserPolls($params);
} else if($filter == 'answered') {
$title = 'Polls I Answered';
$result = getAnsweredPolls($params);
} else if($filter == 'public') {
$title = 'Public Polls';
$result = getPublicPolls($db);
}
else {
$title = 'All Polls';
$result = getAllPolls($params);
}
}
else {
$title = 'All Polls';
$result = getAllPolls($params);
}
}
?>
<!-- User polls -->
<div class="panel panel-primary">
<div class="panel-heading">
<div class="panel-title">
<div class="dropdown">
<button title="Filter polls" class="btn btn-default dropdown-toggle <?php if(isset($_SESSION['guest'])) echo 'disabled';?>" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
<?= $title ?>
<span class="caret"></span>
</button>
<?php if(!isset($_SESSION['guest'])) { ?>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="user.php?filter=all" <?php if($title == 'All Polls') echo 'style="color:green;"'; else echo 'style="color:grey;"'; ?> >All Polls</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="user.php?filter=public" <?php if($title == 'Public Polls') echo 'style="color:green;"'; else echo 'style="color:grey;"'; ?> >Public Polls</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="user.php?filter=answered" <?php if($title == 'Polls I Answered') echo 'style="color:green;"'; else echo 'style="color:grey;"'; ?> >Polls I Answered</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="user.php?filter=personal" <?php if($title == 'My Polls') echo 'style="color:green;"'; else echo 'style="color:grey;"'; ?> >My Polls</a></li>
</ul>
<?php } ?>
</div>
</div>
</div>
<div class="modal fade bs-token-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title token-title" id="tokenModal"><b>Poll Token</b></h4>
<p>Any registered user with access to this token can answer this poll <b>(even if the poll is private!)</b></p>
</div>
<div class="modal-body token-body">
</div>
<div class="modal-footer token-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Back</button>
</div>
</div>
</div>
</div>
<div class="modal fade bs-details-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title details-title" id="detailsModal"></h4>
</div>
<div class="modal-body details-body">
</div>
<div class="modal-footer details-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Back</button>
</div>
</div>
</div>
</div>
<div class="panel-body">
<?php if(sizeof($result) > 0) { ?>
<table class="table">
<tr>
<th>Title</th>
<th>Owner</th>
<th>Public</th>
<th>Answers</th>
<th colspan="10"></th>
</tr>
<tr><td colspan="10"></td></tr>
<?php foreach($result as $row) { ?>
<tr>
<!-- POLL TITLE -->
<td>
<?=$row['description']?>
</td>
<!-- POLL TITLE -->
<td>
<?php
$paramsUser = array('db' => $db, 'id' => $row['user_id']);
$username = getUsernameById($paramsUser);
if($username == $_SESSION['myusername']) {
echo '<b>' . $username . '</b>';
}
else {
echo $username;
}
?>
</td>
<td>
<?php if($row['public'] == 1) { ?>
<span style="color: green" class="glyphicon glyphicon-ok" aria-hidden="true"></span>
<?php } else { ?>
<span style="color: red" class="glyphicon glyphicon-remove" aria-hidden="true"></span>
<?php } ?>
</td>
<td>
<?=$row['number_of_answers']?>
</td>
<!-- SHARE POLL -->
<?php
if($username == $_SESSION['myusername'] || ($row['public'] == 1)) { ?>
<td><a href="javascript: getToken('<?=$row['token']?>')" title="Get Poll Token">
<span style="color: green" class="glyphicon glyphicon-share" aria-hidden="true" data-toggle="modal" data-target=".bs-token-modal-lg"></span>
</a></td>
<?php } else { ?>
<td>
<span style="color: black" title="Sharing is not available for the current user" class="glyphicon glyphicon-share" aria-hidden="true"></span>
</td>
<?php } ?>
<!-- ANSWER POLL -->
<?php if(isset($_SESSION['guest'])) { ?>
<td>
<span style="color: black" title="Guests cannot answer polls" class="glyphicon glyphicon-edit" aria-hidden="true"></span>
</td>
<?php } else {
if(($title == 'Polls I Answered') || checkIfUserAnswered(array('db' => $db, 'user_id' => $_SESSION['myid'], 'id' => $row['id']))) { ?>
<td>
<span style="color: black" title="You have already answered this poll" class="glyphicon glyphicon-edit" aria-hidden="true"></span>
</td>
<?php } else { ?>
<td><a href="answer_poll.php?id=<?=$row['id']?>" title="Answer this poll">
<span style="color: green" class="glyphicon glyphicon-edit" aria-hidden="true"></span>
</a></td>
<?php } } ?>
<!-- VIEW POLL DETAILS -->
<td><a href="javascript: getDetails(<?=$row['id']?>)" title="Short Info">
<span style="color: blue" class="glyphicon glyphicon-info-sign" aria-hidden="true" data-toggle="modal" data-target=".bs-details-modal-lg"></span>
</a></td>
<!-- VIEW POLL STATISTICS -->
<?php if($row['number_of_answers'] > 0) { ?>
<td>
<a href="view_poll_detailed.php?id=<?=$row['id']?>&filter=<?=$filter?>"><span style="color: blue" title="Detailed view" class="glyphicon glyphicon-stats" aria-hidden="true"></span></a>
</td>
<?php } else {?>
<td>
<span style="color: black" title="Detailed view is unavailable since there are no answers" class="glyphicon glyphicon-stats" aria-hidden="true"></span></a>
</td>
<?php } ?>
<!-- EDIT POLL -->
<?php
if($username == $_SESSION['myusername']) {
if($row['number_of_answers'] > 0) { ?>
<td>
<span style="color: black" title="This poll has answers and can no longer be edited" class="glyphicon glyphicon-cog disabled" aria-hidden="true"></span>
</td>
<?php } else { ?>
<td><a href="edit_poll.php?id=<?=$row['id']?>" title="Edit Poll">
<span style="color: blue" class="glyphicon glyphicon-cog" aria-hidden="true"></span>
</a></td>
<?php } ?>
<!-- DELETE POLL -->
<td><a href="javascript: confirmDelete(<?=$row['id']?>)" title="Delete Poll">
<span style="color: red" class="glyphicon glyphicon-trash" aria-hidden="true"></span>
</a></td>
<?php } else { ?>
<td>
<span style="color: black" title="Editing is not available for the current user" class="glyphicon glyphicon-cog disabled" aria-hidden="true"></span>
</td>
<td>
<span style="color: black" title="Deleting is not available for the current user" class="glyphicon glyphicon-trash disabled" aria-hidden="true"></span>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
<?php } else { ?>
<ul class="list-group">
<li class="list-group-item">There are no polls</li>
</ul>
<?php } ?>
</div>
</div>
<?php include('templates/footer.php'); ?>