-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvote.php
233 lines (209 loc) · 5.78 KB
/
vote.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
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
<?php
define("INCLUDED", true); //This is for returning a die message if INCLUDED is not defined on any of the template
$AJAX_PAGE = false;
//################ Required Resources ################
$REQUIRED_RESOURCES = array(
'WoW' => true,
'Realm' => true,
);
//################ Required Files ################
require_once("init.php");
//################ PAGE ACCESS ################
$cms->BannedAccess(true);
if(empty($_GET['act']))
{
eval($cms->SetPageAccess(ACCESS_ALL));
}
else
{
eval($cms->SetPageAccess(ACCESS_REGISTERED));
}
//################ General Variables ################
$page_name[] = array("Vote"=>"vote.php");
WoW::getZonesArray();
//################ Constants ################
define("RPPV", $cms->config['rppv']);
//################ Page Functions ################
//VOTE SPEND PAGE
function ModifyVotePoints($id, $amount)
{
global $DB;
if($amount < 1)
{
$times = 0;
}
else
{
$times = 1;
}
$query = new Query();
$query->Update("`account_mm_extend`")->Where("`id` = '%s'", $id)
->Columns(array("`votepoints`" => "`votepoints` + '%s'", "`voted`" => "`voted` + '{$times}'"), $amount)->Build();
$DB->query($query, DBNAME);
return $DB->affected_rows;
}
function FetchVoteRewards($rid)
{
global $DB;
$query = new Query();
$query->Select("`rewards_voting`")->Columns("*")->Where("`realm` = '%s' AND `disabled` = '0'", $rid)->Build();
$return = MySQLiFetch($DB->query($query, DBNAME));
return $return;
}
//VOTE FORM PAGE
function FetchVoteLogs()
{
global $DB, $USER;
//Logged in or not
$query = new Query();
$query->Select("`log_votes`")->Columns("*");
if($USER['loggedin'])
{
$query->Where("`ip` = '%s' OR `id` = '%s'", GetIp(), $USER['id']);
}
else
{
$query->Where("`ip` = '%s'", GetIp());
}
$query->Build();
$votes = MySQLiFetch($DB->query($query, DBNAME));
//Gateway ID to array key
$return = array();
foreach($votes as $vote)
{
$return[$vote['gateway']] = $vote;
}
return $return;
}
function TallyVote()
{
global $DB, $USER;
//Check if gateway exists
$query = new Query();
$query->Select("`vote_gateways`")->Columns("*")->Where("`id` = '%s'", $_POST['gateway'])->Build();
$result = $DB->query($query, DBNAME);
if($result->num_rows == 0)
{
return false;
}
$gateway = MySQLiFetch($result, "onerow: 1");
//If already voted in last 12 hour
$query = new Query();
$query->Select("`log_votes`")->Columns(array("COUNT(*)"=>"numrows"));
if($USER['loggedin'])
{
$query->Where("(`id` = '%s' OR `ip` = '%s') AND `gateway` = '%s'", $USER['id'], GetIp(), $_POST['gateway']);
}
else
{
$query->Where("`ip` = '%s' AND `gateway` = '%s'", GetIp(), $_POST['gateway']);
}
$query->Build();
$result = MySQLiFetch($DB->query($query, DBNAME), "onerow: 1");
if((int)$result['numrows'] == 0)
{
//Add vote to logs
$id = $USER['loggedin'] ? $USER['id'] : '0';
$query = new Query();
$query->Insert("`log_votes`")->Columns(array("`gateway`"=>"'%s'", "`ip`"=>"'%s'", "`id`"=>"'%s'", "`time`"=>"'%s'"), $_POST['gateway'], GetIp(), $id, time())->Build();
$DB->query($query, DBNAME);
//Modify Vote Points
if($USER['loggedin'])
{
ModifyVotePoints($USER['id'], RPPV);
}
}
return $gateway['url'];
}
//################ Template's Output ################
$action = $_GET['act'];
switch($action)
{
case "spend":
if(empty($_GET['rid']) || empty($REALM[$_GET['rid']]))
{
$page_name[] = array("Select Realm");
$tplname = "realm_selection";
}
else
{
$page_name[] = array("Buy Vote Rewards"=>"vote.php?act=spend");
$page_name[] = array($REALM[$_GET['rid']]['NAME']=>$_SERVER['REQUEST_URI']);
$rclass = new Realm($_GET['rid']);
//If Submitted ... Check for erros
if(isset($_POST['submit']))
{
if(empty($_POST['character_selected']))
{
$cms->ErrorPopulate("You did not select a character.");
}
if(empty($_POST['reward_selected']))
{
$cms->ErrorPopulate("You did not select a reward.");
}
}
//Prepare page variables
$CHARACTERLIST_RID = $_GET['rid'];
$CHARACTERLIST_SHOW_TOOLS = false;
$CHARACTERLIST_MUSTBEONLINE = false;
$CHARACTERLIST_MUSTBEOFFLINE = false;
$CHARACTERLIST_SELECTION = true;
$characters = $rclass->FetchCharactersByAccountID("", $USER['id']);
$rewards = FetchVoteRewards($_GET['rid']);
$itemnames = FetchItemsData($rewards, $_GET['rid']);
//If there is an error
if($cms->ErrorExists())
{
$tplname = "vote_spend";
}
else //Or else we'll continue on sending the items
{
if(isset($_POST['submit']))
{
$result = $rclass->SendReward($_POST['reward_selected'], $_POST['character_selected'], REWARD_VOTE);
if($result['bool'])
{
$successmessage = $result['message'];
}
else
{
$cms->ErrorPopulate($result['message']);
}
}
$tplname = "vote_spend";
}
}
break;
default:
if(isset($_POST['submit']))
{
$url = TallyVote();
$REDIRECT_TYPE = "success"; //Can be "success", "error", and "notification"
if($url == false)
{
$message = "You've voted on an invalid gateway, please try again or vote on another gateway. If this problem persists, please contact an administrator.";
$url = "vote.php";
$REDIRECT_TYPE = "error"; //Can be "success", "error", and "notification"
}
else
{
$message = "You're being redirected to the vote page. You will receive your vote points after the vote have been successfuly counted and only if you are logged in.";
}
$REDIRECT_MESSAGE = $message;
$REDIRECT_LOCATION = $url;
$REDIRECT_INTERVAL = 3000; //Interval in milliseconds(Default 2000 ie 2seconds)
eval($templates->Redirect()); //This is called after the 4 variables have been set
}
else
{
$previousvotes = FetchVoteLogs();
$gateways = FetchVoteGateways();
$tplname = "vote_info";
}
break;
}
if($tplname)
{
eval($templates->Output($tplname));
}
?>