Skip to content

Commit fc7b8d1

Browse files
author
Super-User
committed
bug fixed for voting
1 parent 055f9e3 commit fc7b8d1

File tree

3 files changed

+54
-8
lines changed

3 files changed

+54
-8
lines changed

meetingPage.php

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function redirect2(id){
5959
</style>
6060

6161
<?php
62+
session_start();
6263
function endDate($date, $duration){
6364
$startSec = strtotime($date);
6465
$durSec = explode(":", $duration);
@@ -77,6 +78,7 @@ function endDate($date, $duration){
7778
$tbl_name='meeting'; // Table name
7879
$pdo = new PDO("mysql: host=$host; dbname=$db_name", "$username", "$password");
7980
$meetingId = $_GET['meetingId'];
81+
8082
/*get all room name, group name and department name from database using corresponding id*/
8183
$st1 = $pdo->query("SELECT *
8284
FROM `meeting`

viewVotingResult.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<?php
4+
if(strpos($_SERVER['HTTP_USER_AGENT'], "iPhone") || strpos($_SERVER['HTTP_USER_AGENT'], "Android")){
5+
header( 'Location: sp/index.php' ) ;
6+
}
7+
session_start();
8+
if(!isset($_SESSION["user_id"])) {
9+
header("Location:login.php");
10+
}
11+
?>
12+
<head>
13+
<!--Load the AJAX API-->
14+
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
15+
<script type="text/javascript" src="js/google-chart.js"></script>
16+
<script type="text/javascript">
17+
// Load the Visualization API and the piechart package.
18+
google.load('visualization', '1.0', {'packages':['corechart']});
19+
20+
// Set a callback to run when the Google Visualization API is loaded.
21+
google.setOnLoadCallback(drawChart_at_home);
22+
</script>
23+
<meta charset="utf-8">
24+
<!-- default css -->
25+
<link rel="stylesheet" media="all" type="text/css" href="css/style.css" />
26+
<!-- tablest css -->
27+
<link rel="stylesheet" media="all" type="text/css" href="css/tablet.css" />
28+
<!-- smartphones css -->
29+
<link rel="stylesheet" media="all" type="text/css" href="css/smart.css" />
30+
<title>Meetrix "Meeting Management System"</title>
31+
<!-- Bootstrap -->
32+
<link href="css/bootstrap.min.css" rel="stylesheet">
33+
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
34+
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
35+
<!--[if lt IE 9]>
36+
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
37+
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
38+
<![endif]-->
39+
</head>
40+
<body onload="drawChart_at_home()">
41+
</body>
42+
</html>

votingPage.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ function endDate($date, $duration){
3636
$db_name='meetrix_database'; // Database name
3737
$tbl_name='meeting'; // Table name
3838
$pdo = new PDO("mysql: host=$host; dbname=$db_name", "$username", "$password");
39-
$votingId = $_POST['answer'];
39+
$resultId = $_POST['answer'];
40+
$votingId = $_GET['votingId'];
4041

4142
if(isset($_POST['answer'])){
42-
$st1 = $pdo->query("SELECT EXISTS(SELECT * FROM `vote_log` WHERE `vote_log`.vote_id=". $votingId ." and `vote_log`.employee_id='" . $_SESSION["user_id"] . "')");
43+
$st1 = $pdo->query("SELECT EXISTS(SELECT * FROM `vote_log` WHERE `vote_log`.vote_id=". $_SESSION["votingId"] ." and `vote_log`.employee_id='" . $_SESSION["user_id"] . "')");
4344
/*$st1 = $pdo->query("SELECT *
4445
FROM `vote_log`
4546
WHERE `vote_log`.vote_id=". $votingId . " and `vote_log`.employee_id=". $_SESSION["user_id"] .";");*/
@@ -48,19 +49,20 @@ function endDate($date, $duration){
4849
if($posts[0][0] == 0){
4950
$st1 = $pdo->query("UPDATE `result`
5051
SET `data`=`data` + 1
51-
WHERE result_id=".$votingId);
52+
WHERE result_id=".$resultId);
5253

53-
$st1 = $pdo->query("INSERT INTO `vote_log`(`vote_id`, `employee_id`) VALUES (". $votingId .", ". $_SESSION["user_id"] .")");
54+
$st1 = $pdo->query("INSERT INTO `vote_log`(`vote_id`, `result_id`, `employee_id`) VALUES (". $_SESSION["votingId"] .", ". $resultId .", ". $_SESSION["user_id"] .")");
5455

5556
echo "you have successfully voted";
57+
unset($_SESSION["votingId"]);
5658
exit(0);
5759
}else{
5860
echo "You were arleady voted";
61+
unset($_SESSION["votingId"]);
5962
exit(1);
6063
}
6164

6265
} else {
63-
$votingId = $_GET['votingId'];
6466

6567
/*get all room name, group name and department name from database using corresponding id*/
6668
$st1 = $pdo->query("SELECT *
@@ -74,11 +76,11 @@ function endDate($date, $duration){
7476
$end = endDate($posts[0]['startDate'], $posts[0]['duration']);
7577
date_default_timezone_set('Australia/Brisbane');
7678
$current = date('Y-m-d H:i:s');
77-
78-
if(strtotime($current) > strtotime($end)){
79+
$_SESSION["votingId"] = $votingId;
80+
/*if(strtotime($current) > strtotime($end)){
7981
$_SESSION["votingId"] = $votingId;
8082
header("Location: viewVotingResult.php");
81-
}
83+
}*/
8284
}
8385

8486
?>

0 commit comments

Comments
 (0)