-
Notifications
You must be signed in to change notification settings - Fork 0
/
votingPage.php
executable file
·117 lines (104 loc) · 3.96 KB
/
votingPage.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- default css -->
<link rel="stylesheet" media="all" type="text/css" href="css/style.css" />
<title>Meetrix "Meeting Management System"</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src='js/jquery-1.10.2.min.js'></script>
<script src='js/timer2.js'></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<?php
session_start();
function endDate($date, $duration){
$startSec = strtotime($date);
$durSec = explode(":", $duration);
$sec = (intval($durSec[0]) * 3600) + (intval($durSec[1]) * 60) + intval($durSec[2]);
$temp = intval($startSec) + $sec;
$date = new DateTime("@$temp");
$end = date('Y-m-d H:i:s', strval($temp));
return $date->format('Y-m-d H:i:s');
}
/*initial connection to database*/
$host="localhost"; // Host name
$username='root'; // Mysql username
$password='Menu6Rainy*guilt'; // Mysql password
$db_name='meetrix_database'; // Database name
$tbl_name='meeting'; // Table name
$pdo = new PDO("mysql: host=$host; dbname=$db_name", "$username", "$password");
$resultId = $_POST['answer'];
$votingId = $_GET['votingId'];
/*if answer is set coming in here*/
if(isset($_POST['answer'])){
/*check wether user have voted or not*/
$st1 = $pdo->query("SELECT EXISTS(SELECT *
FROM `vote_log`
WHERE `vote_log`.vote_id=". $_SESSION["votingId"] ." and `vote_log`.employee_id='" . $_SESSION["user_id"] . "')");
$posts = $st1->fetchAll();
/*if they have not*/
if($posts[0][0] == 0){
/*update result*/
$st1 = $pdo->query("UPDATE `result`
SET `data`=`data` + 1
WHERE result_id=".$resultId);
$st1 = $pdo->query("INSERT INTO `vote_log`(`vote_id`, `result_id`, `employee_id`) VALUES (". $_SESSION["votingId"] .", ". $resultId .", ". $_SESSION["user_id"] .")");
echo "you have successfully voted";
unset($_SESSION["votingId"]);
exit(0);
}else{
/*if they have do not update result*/
echo "You were already voted";
unset($_SESSION["votingId"]);
exit(1);
}
} else {
/*get all voting options that user have*/
$st1 = $pdo->query("SELECT *
FROM `vote_result`
INNER JOIN `result` ON `vote_result`.result_id=`result`.result_id
INNER JOIN `votes` ON `vote_result`.vote_id=`votes`.vote_id
WHERE `vote_result`.vote_id=". $votingId . ";");
$posts = $st1->fetchAll();
$end = endDate($posts[0]['startDate'], $posts[0]['duration']);
date_default_timezone_set('Australia/Brisbane');
/*set up remmaining voting time*/
$current = date('Y-m-d H:i:s');
$_SESSION["votingId"] = $votingId;
if(strtotime($current) > strtotime($end)){
$_SESSION["votingId"] = $votingId;
header("Location: viewVotingResult.php");
}
}
?>
<script>
$(document).ready(function(){
timer('<?php echo $current;?>', '<?php echo $end;?>');
})
</script>
</head>
<body>
<!--Main contents comes in side here please edit or enter contents in here-->
<div id="votingPopUp">
<!-- show time left for this voting-->
<p id="timeleft">Time Left: </p>
<!-- a form to left user vote -->
<form action="votingPage.php" id="edit" method="post">
<?php
echo "<p>". $posts[0]['question'] ."</p>";
foreach($posts as $post){
echo "<input type='radio' name='answer' value='". $post['result_id']."'>". $post['answer'];
echo "<br/>";
}
echo "<input type='submit' value='Submit'>";
?>
</form>
</div>
</body>
</html>