forked from gopi1410/FEAT-V
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresults.php
139 lines (127 loc) · 3.94 KB
/
results.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
<?php
//echo $_SERVER['REMOTE_ADDR'];
if($_SERVER['REMOTE_ADDR']!="::1") {
die("Invalid Access");
}
?>
<!doctype html>
<?php
$exec_arr=array("president", "sports", "cultural", "scitech", "fmc");
$disp_arr=array("President, Students' Gymkhana", "General Secretary, Games and Sports Council", "General Secretary, Cultural Council", "General Secretary, Science and Technology Council", "General Secretary, Films and Media Council");
function display_result($post) {
global $exec_arr;
if(in_array($post, $exec_arr)) {
$sql="SELECT * FROM ".$post;
$result=mysql_query($sql) or die(mysql_error());
echo "<table cellspacing='9'>";
while($row=mysql_fetch_assoc($result)) {
echo '<tr>';
echo '<td style="color:brown"><b>'.$row['candidates'].'</b></td>';
echo '<td>'.$row['votes'].'</td>';
echo '</tr>';
}
echo "</table>";
$sql="SELECT * FROM nopref WHERE post='".$post."'";
$result=mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_assoc($result);
echo "<b>No preference votes: </b>".$row['votes'];
echo "<br/><br/><hr/>";
//Sports Sec
/*if($post=="Sports Secretary") {
$sql="SELECT * FROM sports";
$result=mysql_query($sql) or die(mysql_error());
echo "<table cellspacing='9'>";
while($row=mysql_fetch_assoc($result)) {
echo '<tr>';
echo '<td style="color:brown"><b>'.$row['candidates'].'</b></td>';
echo '<td>'.$row['votes'].'</td>';
echo '</tr>';
}
echo "</table>";
$sql="SELECT * FROM nopref WHERE post='".$post."'";
$result=mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_assoc($result);
echo "<b>No preference votes: </b>".$row['votes'];
echo "<br/><br/><hr/>";
}*/
}
else {
$sql="SELECT * FROM candidates WHERE post='".$post."' ORDER BY Name";
$result=mysql_query($sql) or die(mysql_error());
echo "<table cellspacing='9'>";
echo "<tr>";
echo "<th><i>Name</i></th>";
echo "<th><i>1<sup>st</sup>preference votes</i></th>";
echo "<th><i>2<sup>nd</sup>preference votes</i></th>";
echo "<th><i>3<sup>rd</sup>preference votes</i></th>";
echo "</tr>";
while($row=mysql_fetch_assoc($result)) {
echo '<tr>';
echo '<td style="color:brown"><b>'.$row['Name'].'</b></td>';
echo '<td>'.$row['votes1'].'</td>';
echo '<td>'.$row['votes2'].'</td>';
echo '<td>'.$row['votes3'].'</td>';
echo '</tr>';
}
echo "</table>";
// $sql="SELECT * FROM nopref WHERE post='".$post."'";
// $result=mysql_query($sql) or die(mysql_error());
// $row=mysql_fetch_assoc($result);
// echo "<b>No preference votes: </b>".$row['votes'];
echo "<br/><hr/>";
}
}
?>
<html>
<head>
<title>Election Results</title>
<style type="text/css">
h1,h2,h3,h4 {
padding: 0;
margin: 0;
}
td {text-align: center;}
</style>
</head>
<body>
<?php
$form='<br/>
<form action="" method="POST">
Enter password: <input name="passwd" type="password" /><br/><br/>
<input type="submit" name="submit" value="Enter" />
</form>';
?>
<?php
if(isset($_POST['submit'])) {
include('config.php');
if(isset($_POST['passwd']) && $_POST['passwd']==$resultsPass) {
//valid password; proceed with showing results
include('dbconnect.php');
echo "<h1>Results:</h1><br/>";
$sql="SELECT votecount from votes";
$result=mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_assoc($result);
$count=$row['votecount'];
echo "Total number of votes: <b>".$count."</b><br/><br/>";
$sql="SELECT post FROM nopref ORDER BY id";
$result=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_assoc($result)) {
if(array_search($row['post'], $exec_arr)!==FALSE) {
echo "<h3><u>".$disp_arr[array_search($row['post'], $exec_arr)].":</u></h3>";
}
else {
echo "<h3><u>".$row['post'].":</u></h3>";
}
display_result($row['post']);
}
}
else {
echo "<b>Invalid Password!!</b><br/>".$form;
}
}
else {
echo $form;
}
?>
</body>
</html>