-
Notifications
You must be signed in to change notification settings - Fork 0
/
page-betting.php
277 lines (248 loc) · 8.8 KB
/
page-betting.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
/*
* Template Name: Betting Page
*/
include('includes/php/ufc-api.php');
include('includes/php/ufc-betting.php');
get_header(); ?>
<?php
global $wpdb;
global $current_user;
$ufc_event_id = '';
$event_title = '';
if (isset($_GET['ufc_event_id'])) {
$ufc_event_id = $_GET['ufc_event_id'];
}
if (isset($_GET['title'])) {
$event_title = $_GET['title'];
}
$bets_update_success = false;
// verify this is a correct page
if ($ufc_event_id && $event_title) {
$ufcBetInstance = new UfcBetting();
$event = $ufcBetInstance->getEventByEventId($ufc_event_id);
if (!$event){ ?>
<div class="ufc-event">
<div class="row">
<div class="col-md-12">
<div id="event-title">
Error
</div>
<div id="event-tagline">
There has been an error.
</div>
</div>
</div>
</div>
<div id="ufc-bets">
<div class="row">
<div class="col-md-12">
<div class="bet-locked">
This event doesn't exist.
</div>
</div>
</div>
</div>
<?php
}
else {
$url = str_replace(" ", "-", $event_title);
$ufc_event = UfcAPI::getFightsForEvent($ufc_event_id);
// also use this if the user has previously submitted bets for this event
if (isset( $_POST['submit'] )) {
$fights = $ufcBetInstance->getFightsByEventId($ufc_event_id);
foreach ($fights as $fight){
$exists = $ufcBetInstance->doesBetExist($current_user->user_login, $fight->id);
$fighter_selected = $_POST[$fight->id];
// use this to confirm submissions
$fighter = '';
if ($fighter_selected === 'fighter1') {
$fighter = $fight->fighter1;
}
else if ($fighter_selected === 'fighter2') {
$fighter = $fight->fighter2;
}
else {
$fighter = 'empty';
}
// add bet with user name and other stuff
if ($fighter != 'empty'){
$bet = array(
'fight_id' => $fight->id,
'ufc_event_id' => $fight->ufc_event_id,
'ufc_fight_id' => $fight->ufc_fight_id,
'username' => $current_user->user_login,
'fighter_selected' => $fighter
);
if (!$exists){
$ufcBetInstance->addNewBet($bet);
}
else {
$bet_update = array(
'fighter_selected' => $fighter
);
if (is_user_logged_in()) {
$ufcBetInstance->updateBet($bet_update, $fight->id, $current_user->user_login);
}
}
}
}
$bets_update_success = true;
$bets_update_success_message = "Your bets have been submitted.";
}
$fights = $ufcBetInstance->getFightsByEventId($ufc_event_id);
$fights_order = array_reverse($fights);
$bets = $ufcBetInstance->getUserBetsForEvent($current_user->user_login, $ufc_event_id);
?>
<div class="ufc-event">
<div class="row">
<div class="col-md-12">
<div id="event-title">
<?php echo $event_title; ?>
</div>
<div id="event-tagline">
Select your picks
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 button-wrap">
<?php $event_url = str_replace(" ", "-", $event_title); ?>
<a href="<?php echo site_url() . '/' . $ufc_event_id . '-' . $event_url ?>">
<div class="dark-button">
Back to <?php echo $event_title ?> Event Page
</div>
</a>
</div>
</div>
</div>
<?php if ($bets_update_success) { ?>
<div id="ufc-bets-success">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="bets-success-message">
<div id="close-bet-success"></div>
<?php echo $bets_update_success_message; ?>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<div id="ufc-bets">
<div class="container">
<?php if (is_user_logged_in()) {
// will only be 1
foreach ($event as $ev) {
$event_lock_time = $ev->lock_time;
}
echo '<br />';
date_default_timezone_set('America/Los_Angeles');
$current_time = date('Y-m-d H:i:s');
if (strtotime($event_lock_time) > strtotime($current_time)) {
?>
<form action="?action=add-bets&ufc_event_id=<?php echo $ufc_event_id ?>&title=<?php echo $event_title ?>" method="POST" id="add-bets">
<div class="row">
<div class="col-md-12 bet-fights">
<?php foreach ($fights_order as $fight) { ?>
<div class="row">
<div class="col-md-12 bet-fight-title bet__header">
<?php echo $fight->weight_class ?>
</div>
</div>
<input type="hidden" name="<?php echo $fight->id; ?>" id="<?php echo $fight->id; ?>" value="<?php $betValue = 0;foreach($bets as $bet){if ($bet->fight_id == $fight->id){if ($bet->fighter_selected == $fight->fighter1){$betValue = 'fighter1';}else{$betValue = 'fighter2';}}}echo $betValue;?>">
<div class="row bet__padding-bottom">
<div class="col-xs-5 fight-<?php echo $fight->id ?> bet-fighter fighter-1<?php if ($betValue === 'fighter1'){echo ' bet-fighter-selected';}?>" id="<?php echo $fight->id ?>-fighter1">
<?php foreach ($ufc_event as $event_fight): ?>
<?php if ($fight->ufc_fight_id == $event_fight->id): ?>
<img src="<?php echo $event_fight->fighter1_profile_image; ?>" class="img-responsive center-stuff" />
<?php endif; ?>
<?php endforeach; ?>
<p class="bet__fighter-names">
<?php echo $fight->fighter1; ?>
</p>
</div>
<div class="col-xs-2 bet__vs">
vs.
</div>
<div class="col-xs-5 fight-<?php echo $fight->id ?> bet-fighter fighter-2<?php if ($betValue === 'fighter2'){echo ' bet-fighter-selected';}?>" id="<?php echo $fight->id ?>-fighter2">
<?php foreach ($ufc_event as $event_fight): ?>
<?php if ($fight->ufc_fight_id == $event_fight->id): ?>
<img src="<?php echo $event_fight->fighter2_profile_image; ?>" class="img-responsive center-stuff" />
<?php endif; ?>
<?php endforeach; ?>
<p class="bet__fighter-names">
<?php echo $fight->fighter2; ?>
</p>
</div>
</div>
<?php } ?>
</div>
</div>
<div class="row">
<?php if ($fights_order) : ?>
<div class="col-md-12 bet-fights-submit">
<input type="submit" name="submit" id="add-bets-submit" value="Confirm Picks" />
</div>
<?php else: ?>
<div class="col-md-12">
<div class="bet-locked">
There are currently <span style="font-weight: bold;">no fights</span> to select.
</div>
</div>
<?php endif ?>
</div>
</form>
<?php } else { ?>
<div class="row">
<div class="col-md-4">
<!-- nothing -->
</div>
<div class="col-md-4">
<div class="bet-locked">
Betting for this event has been <span style="font-weight: bold;">locked.</span>
</div>
</div>
<div class="col-md-4">
<!-- nothing -->
</div>
</div>
<?php } ?>
<?php } else { ?>
<div class="row">
<div class="col-md-12">
<div class="bet-login-text">
Please log in to select your picks.
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<?php
}
} else { ?>
<div class="ufc-event">
<div class="row">
<div class="col-md-12">
<div id="event-title">
Error
</div>
<div id="event-tagline">
There has been an error.
</div>
</div>
</div>
</div>
<div id="ufc-bets">
<div class="row">
<div class="col-md-12">
<div class="bet-locked">
This event doesn't exist.
</div>
</div>
</div>
</div>
<?php } ?>
<?php get_footer(); ?>