-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoting.php
More file actions
431 lines (410 loc) · 16.6 KB
/
voting.php
File metadata and controls
431 lines (410 loc) · 16.6 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
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
<?php
session_start();
if(empty($_SESSION['user_id'])){
header('location: index.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Main Dashboard</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600"
rel="stylesheet">
<link href="css/font-awesome.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link href="css/pages/dashboard.css" rel="stylesheet">
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<?php
$userid=$_SESSION['user_id'];
?>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container"> <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"><span
class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span> </a><a class="brand" href="index.php">Tanyard Springs Board Portal</a>
<!--/.nav-collapse -->
</div>
<!-- /container -->
</div>
<!-- /navbar-inner -->
</div>
<!-- /navbar -->
<div class="subnavbar">
<div class="subnavbar-inner">
<div class="container">
<ul class="mainnav">
<li><a href="dashboard.php"><em class="icon-dashboard"></em><span>Dashboard</span> </a> </li>
<li> <a href ="add.php"><em class ="icon-dashboard"></em><span>Add Motion</span></a></li>
<li class="active"><a href="vote.php"><em class ="icon-dashboard"></em><span>Vote</span></a></li>
<li><a href="discussions.php"><em class ="icon-dashboard"></em><span>Discussions</span></a></li>
<li><a href="userprefs.php"><em class ="icon-dashboard"></em><span>Prefences</span></a></li>
<li><a href="logout.php"><em class="icon-dashboard"></em><span>Logout</span></a> </li>
</ul>
</div>
<!-- /container -->
</div>
<!-- /subnavbar-inner -->
</div>
<!-- /subnavbar -->
<div class="main">
<div class="main-inner">
<div class="container">
<div class="row">
<?php
include_once ('include/db-config.php');
function mailing($motionid,$boardEmail,$managementEmail)
{
global $db_con;
$motionArray = array($motionid);
foreach ($motionArray as $motion)
{
$motion=$db_con->prepare ("SELECT * from motions where motion_id = :motionid");
$motion->bindParam(':motionid',$motionid);
$motion->execute();
$body="<html>
<head>
<title>Status of Motion</title>
</head>
<body>";
while ($row=$motion->fetch(PDO::FETCH_ASSOC))
{
$motionid=$row['motion_id'];
$motionname=$row['motion_name'];
$session=$row['Session'];
$dateadded=$row['dateadded'];
$motiondesc=$row['motion_description'];
$disposition=$row['motion_disposition'];
$body .= "<h1>" . $motionname . "</h1>
<h2>Date Added:</h2>" . $dateadded . "<br />
<h2>Motion Text</h2>" .
$motiondesc .
"<br /> <h2>Session</h2>" .
$session .
"<h2>Disposition:</h2>" .
$disposition;
}//End of while
$body .= "<br /><br />
<h2>Current Votes</h2>
<table border=\"1\" width=\"100%\">
<tr>
<th>User</th>
<th>Date</th>
<th>Vote</th>
</tr>";
$votes=$db_con->prepare(
"SELECT u.first_name, u.last_name, v.time, v.vote from votes v
inner join motions m on m.motion_id=v.motions_id INNER join users u on
u.users_id=v.users_id where m.motion_id=:motionid ORDER BY v.time ASC;");
$votes->bindParam(':motionid',$motionid);
$votes->execute();
while ($row=$votes->fetch(PDO::FETCH_ASSOC))
{
$firstname=$row['first_name'];
$lastname=$row['last_name'];
$votetime=$row['time'];
$votecast=$row['vote'];
$body .= "<tr>
<td>" . $firstname . " " . $lastname . "</td>
<td>" . $votetime . "</td>
<td>" . $votecast . "</td>
</tr>";
}// while ($row=$votes->fetch(PDO::FETCH_ASSOC))
$body .= "</table>";
$body .= "<br /><br />
<h2>Discussions</h2>
<table border=\"1\" width=\"100%\">
<tr>
<th>User</th>
<th>Date</th>
<th>Comment</th>
</tr>";
$motiondiscussions=$db_con->prepare(
"SELECT u.first_name,u.last_name,d.dateadded,d.discussion_text
from users u inner join discussion d on d.user_id=u.users_id where d.motion_id=:motionid");
$motiondiscussions->bindParam(':motionid',$motionid);
$motiondiscussions->execute();
while ($row=$motiondiscussions->fetch(PDO::FETCH_ASSOC))
{
$firstname=$row['first_name'];
$lastname=$row['last_name'];
$discussiontime=$row['dateadded'];
$discussiontext=$row['discussion_text'];
$body .= "<tr>
<td>" . $firstname . " " . $lastname . "</td>
<td>" . $discussiontime . "</td>
<td>" . $discussiontext . "</td>
</tr>";
}//end of while
$body .= "</table>";
echo "<br />";
echo '<h2>Change Log</h2>
<table border=\"1\" width=\"100%\">
<tr>
<th>User</th>
<th>Date</th>
<th>Field</th>
<th>Old Value</th>
<th>New Value</th>
</tr>';
$changeLog=$db_con->prepare(
"SELECT u.first_name,u.last_name,mcl.date, mcl.field,mcl.oldValue,mcl.newValue
FROM users u
inner join motionChangeLog mcl on mcl.userid=u.users_id
WHERE mcl.motionid=:motionid;");
$changeLog->bindParam(':motionid',$motionid);
$changeLog->execute();
while ($row=$changeLog->fetch(PDO::FETCH_ASSOC))
{
$firstname=$row['first_name'];
$lastname=$row['last_name'];
$changeLogTime=$row['date'];
$field=$row['field'];
$oldValue=$row['oldValue'];
$newValue=$row['newValue'];
echo "<tr>";
echo "<td>" . $firstname . " " . $lastname . "</td>";
echo "<td>" . $changeLogTime . "</td>";
echo "<td>" . $field . "</td>";
echo "<td>" . $oldValue . "</td>";
echo "<td>" . $newValue . "</td>";
echo "</tr>";
}//end of while
echo "</table>";
$body .= "</body>
</html>";
}//end of foreach
$emailSearch=$db_con->prepare("SELECT email from users where enabled=1;");
$emailSearch->execute();
$subject = "<$session> Motion Summary for Motion:" . $motionname;
$message = $body;
$to=$managementEmail;
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = "Cc: $boardEmail";
$headers[]= 'From: Tanyard Springs Votes <noreply@tanyardspringshoa.com>';
if(mail($to,$subject,$message, implode("\r\n", $headers)))
{
print "<br />Email successfully sent";
}
else
{
print "<br />An error occured";
}
}//end of function
?>
<?php
$decision=htmlspecialchars($_POST['vote']);
$motionid=htmlspecialchars($_POST['motionid']);
echo "Motion ID: " . $motionid;
echo "<br />Decision: " . $decision;
if (isset($_POST['revote']))
{
//allready have userid
$revoteoption=$_POST['revote1'];
$vote=$_POST['vote'];
if ( $revoteoption == "Yes" )
{
$updateVote=$db_con->prepare(
"UPDATE votes set vote=:updatedvote where motions_id=:motionid AND users_id=:userid;");
$updateVote->execute(array(':updatedvote'=>$vote,':motionid' =>$motionid, ':userid' => $userid));
echo "Updated your vote";
}// if ( $revoteoption == "Yes"
else
{
echo "You decided not to revote";
}//end of else if ( $revoteoption == "Yes"
}// if (isset($_POST['revote']))
else
{
$addvote=$db_con->prepare(
"SELECT * FROM votes WHERE users_id=:userid AND motions_id=:motionsid;");
$addvote->execute(array(':userid' => $userid,':motionsid' => $motionid));
$row=$addvote->fetchAll(PDO::FETCH_ASSOC);
$vote=htmlspecialchars($_POST['vote']);
if (count($row) == 1)
{
echo '<form id="voting" name="voting" method="POST" action="voting.php">
<input type="hidden" name="motionid" value="' . $motionid . '">
<input type="hidden" name="revote" value="revote">
<input type="hidden" name="vote" value="' . $vote . '">
<input type="radio" name="revote1" value="Yes">Yes<br />
<input type="radio" name="revote1" value="No">No<br />
<input type="Submit" name="Submit" value="Submit">
<input type="Reset" name="Reset" value="Reset">
</form>';
}// if (count($row) == 1)
else
{
$secondedVote=$db_con->prepare(
"SELECT * FROM votes where motions_id=:motionid;");
$secondedVote->bindParam(':motionid',$motionid);
$secondedVote->execute();
$secondedCount=$secondedVote->rowCount();
if ($secondedCount == 1)
{
if ($decision == "NO")
{
$initialVote=$db_con->prepare(
"INSERT INTO votes (users_id,motions_id,vote) VALUE (:users_id, :motions_id, :vote)");
$initialVote->bindParam(':users_id',$userid);
$initialVote->bindParam(':motions_id',$motionid);
$initialVote->bindParam(':vote',$decision);
$initialVote->execute();
echo "Voted";
$disposition="FAILED";
$motiondep=$db_con->prepare(
"UPDATE motions set motion_disposition =:disposition WHERE motion_id=:motion_id");
$motiondep->bindParam(':disposition',$disposition);
$motiondep->bindParam(':motion_id',$motionid);
$motiondep->execute();
//grabbing email addresses for Board and management
$userSearch=$db_con->prepare("SELECT * from users where enabled=1;");
$userSearch->execute();
$boardEmail="";
while ($row=$userSearch->fetch(PDO::FETCH_ASSOC))
{
$boardEmail .= $row['email'] .",";
}
$managementSearch=$db_con->prepare("SELECT * FROM management where fenabled=1;");
$managementSearch->execute();
$managementEmail="";
while ($row=$managementSearch->fetch(PDO::FETCH_ASSOC))
{
$managementEmail .= $row['email'] .",";
}
mailing($motionid,$boardEmail,$managementEmail);
}
else
{
$decision="SECONDED";
$initialVote=$db_con->prepare(
"INSERT INTO votes (users_id,motions_id,vote) VALUE (:users_id, :motions_id, :vote)");
$initialVote->bindParam(':users_id',$userid);
$initialVote->bindParam(':motions_id',$motionid);
$initialVote->bindParam(':vote',$decision);
$initialVote->execute();
echo "Voted";
}
}
else
{
$initialVote=$db_con->prepare(
"INSERT INTO votes (users_id,motions_id,vote) VALUE (:users_id, :motions_id, :vote)");
$initialVote->bindParam(':users_id',$userid);
$initialVote->bindParam(':motions_id',$motionid);
$initialVote->bindParam(':vote',$decision);
$initialVote->execute();
echo "Voted";
}
$enabledCount=$db_con->prepare(
"SELECT * FROM users where enabled=1;");
$enabledCount->execute();
$enabledUserCount = $enabledCount->rowCount();
$votecount=$db_con->prepare(
"SELECT * FROM votes where motions_id=:motionid");
$votecount->bindParam(':motionid',$motionid);
$votecount->execute();
$votesCount= $votecount->rowCount();
if ($votesCount == $enabledUserCount)
{
$disposition="PASSED";
$motiondep=$db_con->prepare(
"UPDATE motions set motion_disposition =:disposition WHERE motion_id=:motion_id");
$motiondep->bindParam(':disposition',$disposition);
$motiondep->bindParam(':motion_id',$motionid);
$motiondep->execute();
echo "<br /> Updated the final disposition of the motion";
//grabbing email addresses for Board and management
$userSearch=$db_con->prepare("SELECT * from users where enabled=1;");
$userSearch->execute();
$boardEmail="";
while ($row=$userSearch->fetch(PDO::FETCH_ASSOC))
{
$boardEmail .= $row['email'] .",";
}
$managementSearch=$db_con->prepare("SELECT * FROM management where fenabled=1;");
$managementSearch->execute();
$managementEmail="";
while ($row=$managementSearch->fetch(PDO::FETCH_ASSOC))
{
$managementEmail .= $row['email'] .",";
}
mailing($motionid,$boardEmail,$managementEmail);
}
else
{
echo "";
}
if ($decision=="NO")
{
$disposition="FAILED";
$motiondep=$db_con->prepare(
"UPDATE motions set motion_disposition =:disposition WHERE motion_id=:motion_id");
$motiondep->bindParam(':disposition',$disposition);
$motiondep->bindParam(':motion_id',$motionid);
$motiondep->execute();
//grabbing email addresses for Board and management
$userSearch=$db_con->prepare("SELECT * from users where enabled=1;");
$userSearch->execute();
$boardEmail="";
while ($row=$userSearch->fetch(PDO::FETCH_ASSOC))
{
$boardEmail .= $row['email'] .",";
}
$managementSearch=$db_con->prepare("SELECT * FROM management where fenabled=1;");
$managementSearch->execute();
$managementEmail="";
while ($row=$managementSearch->fetch(PDO::FETCH_ASSOC))
{
$managementEmail .= $row['email'] .",";
}
mailing($motionid,$boardEmail,$managementEmail);
}
else
{
exit;
}
}//end of else if (count($row) == 1)
}//end of else if (isset($_POST['revote']))
?>
<!-- /span6 -->
<!-- /span6 -->
</div>
<!-- /row -->
</div>
<!-- /container -->
</div>
<!-- /main-inner -->
</div>
<!-- /main -->
<!-- /extra -->
<div class="footer">
<div class="footer-inner">
<div class="container">
<div class="row">
<div class="span12"> © 2013 <a href="http://www.egrappler.com/">Bootstrap Responsive Admin Template</a>. </div>
<!-- /span12 -->
</div>
<!-- /row -->
</div>
<!-- /container -->
</div>
<!-- /footer-inner -->
</div>
<!-- /footer -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>