smart-poll-071
Code (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
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
<?
# Filename : admin.php
# Author : Mitch Vroege
# Projectname : SMART PoLL
# Projectversion : 0.7.1
# Releasedate : 16-08-2004
# Include database classfile
include("database.php");
# Class new_poll
class new_poll
{
function showAdmin()
{
$admin .= "<form method=\"POST\" ation=\"" . $_SERVER['PHP_SELF'] . "\">";
$admin .= "Vraag :<br />";
$admin .= "<input type=\"text\" name=\"q\" maxlength=\"255\" /><br />";
$admin .= "Antwoorden : (gescheiden door een komma en zonder spaties)<br />";
$admin .= "<input type=\"text\" name=\"a\" /><br />";
$admin .= "<input type=\"submit\" name=\"add\" value=\"Voeg toe!\" />";
$admin .= "</form>";
return $admin;
}
function makeScores($num)
{
for($i=1;$i<=$num;$i++)
{
if($i == $num)
{
$scores .= "0";
}
else
{
$scores .= "0,";
}
}
return $scores;
}
}
# Check if user is Admin
# Hier kun je je eigen log systeem in verwerken
$admin = 1;
if($admin)
{
# Show options
$np = new new_poll;
$db = new database;
# Check if form is submitted
if(!$_POST['add'])
{
# Show admin
echo $np->showAdmin();
}
else
{
# Set some vars
$a = $_POST['a'];
$total = count(explode(",", $a));
$q = htmlentities($_POST['q']);
$a = $_POST['a'];
# calc null values
$null = $np->makeScores($total);
# Insert new poll
$sql1 = "INSERT INTO `poll` SET `poll_stelling` = '" . $q . "', `poll_keuzes` = '" . $a . "', `poll_scores` = '" . $null . "', `poll_datum` = '" . time() . "'";
# Reset votes
$sql2 = "DELETE FROM `votes`";
$res1 = $db->execute($sql1);
$res2 = $db->execute($sql2);
echo "Nieuwe poll toegevoegd!";
}
}
else
{
# User isnt an admin
die("INVALID ACCESLEVEL!");
}
?>
# Filename : admin.php
# Author : Mitch Vroege
# Projectname : SMART PoLL
# Projectversion : 0.7.1
# Releasedate : 16-08-2004
# Include database classfile
include("database.php");
# Class new_poll
class new_poll
{
function showAdmin()
{
$admin .= "<form method=\"POST\" ation=\"" . $_SERVER['PHP_SELF'] . "\">";
$admin .= "Vraag :<br />";
$admin .= "<input type=\"text\" name=\"q\" maxlength=\"255\" /><br />";
$admin .= "Antwoorden : (gescheiden door een komma en zonder spaties)<br />";
$admin .= "<input type=\"text\" name=\"a\" /><br />";
$admin .= "<input type=\"submit\" name=\"add\" value=\"Voeg toe!\" />";
$admin .= "</form>";
return $admin;
}
function makeScores($num)
{
for($i=1;$i<=$num;$i++)
{
if($i == $num)
{
$scores .= "0";
}
else
{
$scores .= "0,";
}
}
return $scores;
}
}
# Check if user is Admin
# Hier kun je je eigen log systeem in verwerken
$admin = 1;
if($admin)
{
# Show options
$np = new new_poll;
$db = new database;
# Check if form is submitted
if(!$_POST['add'])
{
# Show admin
echo $np->showAdmin();
}
else
{
# Set some vars
$a = $_POST['a'];
$total = count(explode(",", $a));
$q = htmlentities($_POST['q']);
$a = $_POST['a'];
# calc null values
$null = $np->makeScores($total);
# Insert new poll
$sql1 = "INSERT INTO `poll` SET `poll_stelling` = '" . $q . "', `poll_keuzes` = '" . $a . "', `poll_scores` = '" . $null . "', `poll_datum` = '" . time() . "'";
# Reset votes
$sql2 = "DELETE FROM `votes`";
$res1 = $db->execute($sql1);
$res2 = $db->execute($sql2);
echo "Nieuwe poll toegevoegd!";
}
}
else
{
# User isnt an admin
die("INVALID ACCESLEVEL!");
}
?>
----------------------------------------------------------------------------------------------------
Code (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
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
<?
# Filename : archives.php
# Author : Mitch Vroege
# Projectname : SMART PoLL
# Projectversion : 0.7.1
# Releasedate : 16-08-2004
# Include database classfile
include("database.php");
# Include poll classfile
include("poll.php");
# Archives class
class archive
{
function showAll()
{
# Run database class
$db = new database;
# Get the number of rows
$sql = "SELECT * FROM `poll` ORDER BY `poll_id` DESC";
$aantal = $db->num_rows($sql);
$archives .= "<b>Er zijn " . $aantal . " polls in het archief!</b><br />";
# Get all rowvalues
$data = $db->get_array($sql);
# Set paragraph start
$archives .= "<p>";
# Loop to make the URLs
for($i=0; $i<$aantal; $i++)
$archives .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?ArchID=" . $data[$i]['poll_id'] . "\">" . date("j-n-Y", $data[$i]['poll_datum']) . "</a><br />";
# End paragraph
$archives .= "</p>";
# Link back to mainpage
$archives .= "<p><a href=\"index.php\">Terug</a>";
return $archives;
}
function showSingle($id)
{
# Run poll class
$poll = new poll;
# Get the results
$single = $poll->archResults($id);
return $single;
}
}
# Run archive class
$ac = new archive;
# Check for $_GET data
if($_GET['ArchID'] && is_numeric($_GET['ArchID']))
echo $ac->showSingle($_GET['ArchID']);
else
echo $ac->showAll();
?>
# Filename : archives.php
# Author : Mitch Vroege
# Projectname : SMART PoLL
# Projectversion : 0.7.1
# Releasedate : 16-08-2004
# Include database classfile
include("database.php");
# Include poll classfile
include("poll.php");
# Archives class
class archive
{
function showAll()
{
# Run database class
$db = new database;
# Get the number of rows
$sql = "SELECT * FROM `poll` ORDER BY `poll_id` DESC";
$aantal = $db->num_rows($sql);
$archives .= "<b>Er zijn " . $aantal . " polls in het archief!</b><br />";
# Get all rowvalues
$data = $db->get_array($sql);
# Set paragraph start
$archives .= "<p>";
# Loop to make the URLs
for($i=0; $i<$aantal; $i++)
$archives .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?ArchID=" . $data[$i]['poll_id'] . "\">" . date("j-n-Y", $data[$i]['poll_datum']) . "</a><br />";
# End paragraph
$archives .= "</p>";
# Link back to mainpage
$archives .= "<p><a href=\"index.php\">Terug</a>";
return $archives;
}
function showSingle($id)
{
# Run poll class
$poll = new poll;
# Get the results
$single = $poll->archResults($id);
return $single;
}
}
# Run archive class
$ac = new archive;
# Check for $_GET data
if($_GET['ArchID'] && is_numeric($_GET['ArchID']))
echo $ac->showSingle($_GET['ArchID']);
else
echo $ac->showAll();
?>
----------------------------------------------------------------------------------------------------
Code (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
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
<?
# Filename : database.php
# Author : Mitch Vroege
# Projectname : SMART PoLL
# Projectversion : 0.7.1
# Releasedate : 16-08-2004
class database
{
# Database vars
var $user = "User";
var $pass = "Pass";
var $host = "localhost";
var $name = "DBname";
# Functie die mysql_num_rows teruggeeft
function num_rows($sql)
{
$this->connect();
$res = mysql_query($sql);
$aantal = mysql_num_rows($res);
mysql_close();
return $aantal;
}
# Functie de mysql_fetch_array teruggeeft
function get_array($sql)
{
$this->connect();
$res = mysql_query($sql);
while($data = mysql_fetch_array($res))
$row[] = $data;
mysql_close();
return $row;
}
# Zelfde als hierboven maar dan 1 row
function get_single($sql)
{
$this->connect();
$res = mysql_query($sql);
$data = mysql_fetch_array($res);
mysql_close();
return $data;
}
# Functie die een normale query runt
function execute($sql)
{
$this->connect();
$res = mysql_query($sql);
mysql_close();
return $res;
}
# Functie die de database connectie maakt
function connect()
{
return mysql_select_db($this->name, mysql_connect($this->host, $this->user, $this->pass));
}
}
?>
# Filename : database.php
# Author : Mitch Vroege
# Projectname : SMART PoLL
# Projectversion : 0.7.1
# Releasedate : 16-08-2004
class database
{
# Database vars
var $user = "User";
var $pass = "Pass";
var $host = "localhost";
var $name = "DBname";
# Functie die mysql_num_rows teruggeeft
function num_rows($sql)
{
$this->connect();
$res = mysql_query($sql);
$aantal = mysql_num_rows($res);
mysql_close();
return $aantal;
}
# Functie de mysql_fetch_array teruggeeft
function get_array($sql)
{
$this->connect();
$res = mysql_query($sql);
while($data = mysql_fetch_array($res))
$row[] = $data;
mysql_close();
return $row;
}
# Zelfde als hierboven maar dan 1 row
function get_single($sql)
{
$this->connect();
$res = mysql_query($sql);
$data = mysql_fetch_array($res);
mysql_close();
return $data;
}
# Functie die een normale query runt
function execute($sql)
{
$this->connect();
$res = mysql_query($sql);
mysql_close();
return $res;
}
# Functie die de database connectie maakt
function connect()
{
return mysql_select_db($this->name, mysql_connect($this->host, $this->user, $this->pass));
}
}
?>
----------------------------------------------------------------------------------------------------
Code (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
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
<?
# Filename : index.php
# Author : Mitch Vroege
# Projectname : SMART PoLL
# Projectversion : 0.7.1
# Releasedate : 16-08-2004
# Include database classfile
include("database.php");
# Include poll classfile
include("poll.php");
# Run database class
$db = new database;
# Set query to see if voted already
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "SELECT * FROM `votes` WHERE `vote_ip` = '" . $ip . "'";
# Run poll class
$poll = new poll;
# If a match is found show results only
if($db->num_rows($sql) == 1)
{
# Show results
echo $poll->showResults();
}
else
{
# Check if form submitted
if(!$_POST['vote'])
{
# Show form
echo $poll->showOptions();
}
else
{
# Add data to database
# Check for a value
if(!$_POST['poll'])
{
# No option selected
# Show poll again
echo $poll->showOptions();
}
else
{
# A radio is checked
# Update votes
$poll->updateVotes($_POST['poll']);
# Show results
echo $poll->showResults();
}
}
}
?>
# Filename : index.php
# Author : Mitch Vroege
# Projectname : SMART PoLL
# Projectversion : 0.7.1
# Releasedate : 16-08-2004
# Include database classfile
include("database.php");
# Include poll classfile
include("poll.php");
# Run database class
$db = new database;
# Set query to see if voted already
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "SELECT * FROM `votes` WHERE `vote_ip` = '" . $ip . "'";
# Run poll class
$poll = new poll;
# If a match is found show results only
if($db->num_rows($sql) == 1)
{
# Show results
echo $poll->showResults();
}
else
{
# Check if form submitted
if(!$_POST['vote'])
{
# Show form
echo $poll->showOptions();
}
else
{
# Add data to database
# Check for a value
if(!$_POST['poll'])
{
# No option selected
# Show poll again
echo $poll->showOptions();
}
else
{
# A radio is checked
# Update votes
$poll->updateVotes($_POST['poll']);
# Show results
echo $poll->showResults();
}
}
}
?>
-----------------------------------------------------------------------------------------------------
Code (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
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
<?
# Filename : install.php
# Author : Mitch Vroege
# Projectname : SMART PoLL
# Projectversion : 0.7.1
# Releasedate : 16-08-2004
# Include database classfile
include("database.php");
# Instal class
class install
{
# Instal function
function insPoll()
{
$sql1 .= "DROP TABLE IF EXISTS `poll`;";
$sql2 .= "CREATE TABLE `poll` (";
$sql2 .= "`poll_id` int(11) primary key auto_increment,";
$sql2 .= "`poll_stelling` varchar(255) not null default '',";
$sql2 .= "`poll_keuzes` longtext not null default '',";
$sql2 .= "`poll_scores` longtext not null default '',";
$sql2 .= "`poll_datum` int(20) not null default '0'";
$sql2 .= ") TYPE=MyISAM;";
$sql3 .= "DROP TABLE IF EXISTS `votes`;";
$sql4 .= "CREATE TABLE `votes` (";
$sql4 .= "`vote_id` int(11) primary key auto_increment,";
$sql4 .= "`vote_ip` varchar(16) not null default '',";
$sql4 .= "`vote_datum` int(20) not null default '0'";
$sql4 .= ") TYPE=MyISAM;";
# Run db class
$db = new database;
# Execute
$res1 = $db->execute($sql1);
$res2 = $db->execute($sql2);
$res3 = $db->execute($sql3);
$res4 = $db->execute($sql4);
if($res2 && $res4)
{
$install .= "<b>Succesvol geinstalleerd!</b><br />";
$install .= "<a href=\"admin.php\">Klik hier om een vraag in te stellen!</a>";
}
else
{
$install .= "<b>Er is iets fout gegegaan probeer het opnieuw!</b><br />";
$install .= $this->insMenu();
$install .= "<p><b>Is dit al de zoveelste keer dat het mislukt?</b><br />";
$install .= "Voer dan handmatig deze code in in je db:<br />";
$install .= $sql2 . $sql4;
}
return $install;
}
# Show menu
function insMenu()
{
$menu .= "<p><b>SMART PoLL 0.7 INSTALLER</b><br />";
$menu .= "<u>LeT oP!</u> zodra je op <i>install</i> klikt zullen de tabellen genaamd<br />";
$menu .= "<i>'poll'</i> en <i>'votes'</i>, mits ze al bestaan, overschreven worden!<br />";
$menu .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?ins=1\">INSTALL SMART PoLL 0.7 NOW!</a></p>";
return $menu;
}
}
# Run install class
$ins = new install;
# Check for $_GET data
if($_GET['ins'] && is_numeric($_GET['ins']))
echo $ins->insPoll();
else
echo $ins->insMenu();
?>
# Filename : install.php
# Author : Mitch Vroege
# Projectname : SMART PoLL
# Projectversion : 0.7.1
# Releasedate : 16-08-2004
# Include database classfile
include("database.php");
# Instal class
class install
{
# Instal function
function insPoll()
{
$sql1 .= "DROP TABLE IF EXISTS `poll`;";
$sql2 .= "CREATE TABLE `poll` (";
$sql2 .= "`poll_id` int(11) primary key auto_increment,";
$sql2 .= "`poll_stelling` varchar(255) not null default '',";
$sql2 .= "`poll_keuzes` longtext not null default '',";
$sql2 .= "`poll_scores` longtext not null default '',";
$sql2 .= "`poll_datum` int(20) not null default '0'";
$sql2 .= ") TYPE=MyISAM;";
$sql3 .= "DROP TABLE IF EXISTS `votes`;";
$sql4 .= "CREATE TABLE `votes` (";
$sql4 .= "`vote_id` int(11) primary key auto_increment,";
$sql4 .= "`vote_ip` varchar(16) not null default '',";
$sql4 .= "`vote_datum` int(20) not null default '0'";
$sql4 .= ") TYPE=MyISAM;";
# Run db class
$db = new database;
# Execute
$res1 = $db->execute($sql1);
$res2 = $db->execute($sql2);
$res3 = $db->execute($sql3);
$res4 = $db->execute($sql4);
if($res2 && $res4)
{
$install .= "<b>Succesvol geinstalleerd!</b><br />";
$install .= "<a href=\"admin.php\">Klik hier om een vraag in te stellen!</a>";
}
else
{
$install .= "<b>Er is iets fout gegegaan probeer het opnieuw!</b><br />";
$install .= $this->insMenu();
$install .= "<p><b>Is dit al de zoveelste keer dat het mislukt?</b><br />";
$install .= "Voer dan handmatig deze code in in je db:<br />";
$install .= $sql2 . $sql4;
}
return $install;
}
# Show menu
function insMenu()
{
$menu .= "<p><b>SMART PoLL 0.7 INSTALLER</b><br />";
$menu .= "<u>LeT oP!</u> zodra je op <i>install</i> klikt zullen de tabellen genaamd<br />";
$menu .= "<i>'poll'</i> en <i>'votes'</i>, mits ze al bestaan, overschreven worden!<br />";
$menu .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?ins=1\">INSTALL SMART PoLL 0.7 NOW!</a></p>";
return $menu;
}
}
# Run install class
$ins = new install;
# Check for $_GET data
if($_GET['ins'] && is_numeric($_GET['ins']))
echo $ins->insPoll();
else
echo $ins->insMenu();
?>
----------------------------------------------------------------------------------------------------
Code (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
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
<?
# Filename : poll.php
# Author : Mitch Vroege
# Projectname : SMART PoLL
# Projectversion : 0.7.1
# Releasedate : 16-08-2004
class poll
{
# Show options function
function showOptions()
{
# Get newest poll
$data = $this->getPoll();
# Split options
$options = explode(",", $data['poll_keuzes']);
# Count options for loop
$aant = count($options)-1;
$poll .= "<b>" . $data['poll_stelling'] . "</b><br />";
$poll .= "<form method=\"POST\" action=\"" . $_SERVER['PHP_SELF'] . "\">";
# Loop and make input radios
for($i = 0; $i <= $aant; $i++)
{
$j = $i+1;
$poll .= "<input type=\"radio\" value=\"" . $j . "\" name=\"poll\" />" . $options[$i] . "<br />";
}
# End form
$poll .= "<input type=\"submit\" name=\"vote\" value=\"Stem!\" />";
$poll .= "</form>";
# Show pollid no. and poll date
$poll .= "<p>PollID: " . $data['poll_id'] . " - PollDatum: " . date("j-n-Y", $data['poll_datum']);
# Show link to archives
$poll .= "<p><a href=\"archives.php\">Bekijk archief!</a>";
return $poll;
}
function updateVotes($vote)
{
# Get newest poll
$data = $this->getPoll();
# Split the vote scores
$stemmen = explode(",", $data['poll_scores']);
# add one to the selected option
$vote--;
(int) $stemmen[$vote]++;
# Remake the data
$stem = implode(",", $stemmen);
# Add to database
$sql1 = "UPDATE `poll` SET `poll_scores` = '" . $stem . "' WHERE `poll_id` = '" . $data['poll_id'] . "'";
$ip = $_SERVER['REMOTE_ADDR'];
$sql2 = "INSERT INTO `votes` SET `vote_ip` = '" . $ip . "', `vote_datum` = '" . time() . "'";
# Run db class
$db = new database;
$res1 = $db->execute($sql1);
$res2 = $db->execute($sql2);
}
function getPoll()
{
# Select the newest poll
$sql = "SELECT * FROM `poll` ORDER BY `poll_id` DESC LIMIT 1";
# Run db class
$db = new database;
# Get array
$data = $db->get_single($sql);
return $data;
}
function showResults()
{
# Get data
$data = $this->getPoll();
# Split options and scores
$options = explode(",", $data['poll_keuzes']);
$scores = explode(",", $data['poll_scores']);
$option = count($options)-1;
# Count the votes
$votes = array_sum($scores);
# Show total votes
$results .= "<b>" . $data['poll_stelling'] . "</b><br />";
$results .= "Totaal aantal stemmen: " . $votes . "<br />";
$results .= "<p>";
# Loop through results
for($i = 0;$i <= $option; $i++)
{
$results .= $options[$i] . "<br />";
$results .= "<img src=\"indicator.png\" width=\"" . $this->imgPXL($votes, $scores[$i]) . "\" height=\"15\" />" . $this->imgPXL($votes, $scores[$i]) . "%";
$results .= "<br />";
}
$results .= "</p>";
# Show pollid no. and poll date
$results .= "<p>PollID: " . $data['poll_id'] . " - PollDatum: " . date("j-n-Y", $data['poll_datum']);
# Show link to archives
$results .= "<p><a href=\"archives.php\">Bekijk archief!</a>";
return $results;
}
function archResults($id)
{
# Get data
$data = $this->archPoll($id);
# Split options and scores
$options = explode(",", $data['poll_keuzes']);
$scores = explode(",", $data['poll_scores']);
$option = count($options)-1;
# Count the votes
$votes = array_sum($scores);
# Show total votes
$results .= "<b>" . $data['poll_stelling'] . "</b><br />";
$results .= "Totaal aantal stemmen: " . $votes . "<br />";
$results .= "<p>";
# Loop through results
for($i = 0;$i <= $option; $i++)
{
$results .= $options[$i] . "<br />";
$results .= "<img src=\"indicator.png\" width=\"" . $this->imgPXL($votes, $scores[$i]) . "\" height=\"15\" />" . $this->imgPXL($votes, $scores[$i]) . "%";
$results .= "<br />";
}
$results .= "</p>";
# Show pollid no. and poll date
$results .= "<p>PollID: " . $data['poll_id'] . " - PollDatum: " . date("j-n-Y", $data['poll_datum']);
# Show link to archives
$results .= "<p><a href=\"archives.php\">Terug!</a>";
return $results;
}
function archPoll($id)
{
# Select the newest poll
$sql = "SELECT * FROM `poll` WHERE `poll_id` = '" . $id . "' ORDER BY `poll_id` DESC LIMIT 1";
# Run db class
$db = new database;
# Get array
$data = $db->get_single($sql);
return $data;
}
# Calculate indicator size
function imgPXL($tot, $opt)
{
$pro = $tot / 100;
$num = $opt / $pro;
return (int) $num;
}
}
?>
# Filename : poll.php
# Author : Mitch Vroege
# Projectname : SMART PoLL
# Projectversion : 0.7.1
# Releasedate : 16-08-2004
class poll
{
# Show options function
function showOptions()
{
# Get newest poll
$data = $this->getPoll();
# Split options
$options = explode(",", $data['poll_keuzes']);
# Count options for loop
$aant = count($options)-1;
$poll .= "<b>" . $data['poll_stelling'] . "</b><br />";
$poll .= "<form method=\"POST\" action=\"" . $_SERVER['PHP_SELF'] . "\">";
# Loop and make input radios
for($i = 0; $i <= $aant; $i++)
{
$j = $i+1;
$poll .= "<input type=\"radio\" value=\"" . $j . "\" name=\"poll\" />" . $options[$i] . "<br />";
}
# End form
$poll .= "<input type=\"submit\" name=\"vote\" value=\"Stem!\" />";
$poll .= "</form>";
# Show pollid no. and poll date
$poll .= "<p>PollID: " . $data['poll_id'] . " - PollDatum: " . date("j-n-Y", $data['poll_datum']);
# Show link to archives
$poll .= "<p><a href=\"archives.php\">Bekijk archief!</a>";
return $poll;
}
function updateVotes($vote)
{
# Get newest poll
$data = $this->getPoll();
# Split the vote scores
$stemmen = explode(",", $data['poll_scores']);
# add one to the selected option
$vote--;
(int) $stemmen[$vote]++;
# Remake the data
$stem = implode(",", $stemmen);
# Add to database
$sql1 = "UPDATE `poll` SET `poll_scores` = '" . $stem . "' WHERE `poll_id` = '" . $data['poll_id'] . "'";
$ip = $_SERVER['REMOTE_ADDR'];
$sql2 = "INSERT INTO `votes` SET `vote_ip` = '" . $ip . "', `vote_datum` = '" . time() . "'";
# Run db class
$db = new database;
$res1 = $db->execute($sql1);
$res2 = $db->execute($sql2);
}
function getPoll()
{
# Select the newest poll
$sql = "SELECT * FROM `poll` ORDER BY `poll_id` DESC LIMIT 1";
# Run db class
$db = new database;
# Get array
$data = $db->get_single($sql);
return $data;
}
function showResults()
{
# Get data
$data = $this->getPoll();
# Split options and scores
$options = explode(",", $data['poll_keuzes']);
$scores = explode(",", $data['poll_scores']);
$option = count($options)-1;
# Count the votes
$votes = array_sum($scores);
# Show total votes
$results .= "<b>" . $data['poll_stelling'] . "</b><br />";
$results .= "Totaal aantal stemmen: " . $votes . "<br />";
$results .= "<p>";
# Loop through results
for($i = 0;$i <= $option; $i++)
{
$results .= $options[$i] . "<br />";
$results .= "<img src=\"indicator.png\" width=\"" . $this->imgPXL($votes, $scores[$i]) . "\" height=\"15\" />" . $this->imgPXL($votes, $scores[$i]) . "%";
$results .= "<br />";
}
$results .= "</p>";
# Show pollid no. and poll date
$results .= "<p>PollID: " . $data['poll_id'] . " - PollDatum: " . date("j-n-Y", $data['poll_datum']);
# Show link to archives
$results .= "<p><a href=\"archives.php\">Bekijk archief!</a>";
return $results;
}
function archResults($id)
{
# Get data
$data = $this->archPoll($id);
# Split options and scores
$options = explode(",", $data['poll_keuzes']);
$scores = explode(",", $data['poll_scores']);
$option = count($options)-1;
# Count the votes
$votes = array_sum($scores);
# Show total votes
$results .= "<b>" . $data['poll_stelling'] . "</b><br />";
$results .= "Totaal aantal stemmen: " . $votes . "<br />";
$results .= "<p>";
# Loop through results
for($i = 0;$i <= $option; $i++)
{
$results .= $options[$i] . "<br />";
$results .= "<img src=\"indicator.png\" width=\"" . $this->imgPXL($votes, $scores[$i]) . "\" height=\"15\" />" . $this->imgPXL($votes, $scores[$i]) . "%";
$results .= "<br />";
}
$results .= "</p>";
# Show pollid no. and poll date
$results .= "<p>PollID: " . $data['poll_id'] . " - PollDatum: " . date("j-n-Y", $data['poll_datum']);
# Show link to archives
$results .= "<p><a href=\"archives.php\">Terug!</a>";
return $results;
}
function archPoll($id)
{
# Select the newest poll
$sql = "SELECT * FROM `poll` WHERE `poll_id` = '" . $id . "' ORDER BY `poll_id` DESC LIMIT 1";
# Run db class
$db = new database;
# Get array
$data = $db->get_single($sql);
return $data;
}
# Calculate indicator size
function imgPXL($tot, $opt)
{
$pro = $tot / 100;
$num = $opt / $pro;
return (int) $num;
}
}
?>
-----------------------------------------------------------------------------------------------------
En dat was het :)