-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoupon-details.php
247 lines (245 loc) · 9.33 KB
/
coupon-details.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
<?php
include("db-connection.php");
$sql_select_odds = "SELECT odds from choices LEFT JOIN users_choice ON users_choice.choices = choices.id_choices
WHERE users_choice.bet = '" . $couponid . "'";
$result_select_odds = mysqli_query($db, $sql_select_odds);
$select_odds = [];
while ($row = mysqli_fetch_row($result_select_odds)) {
$select_odds[] = $row;
}
$multiplier = 1;
foreach ($select_odds as $cols) {
foreach ($cols as $odds) {
$multiplier = $multiplier * $odds;
}
}
$sql_select_balance = "SELECT balance FROM user WHERE user.login ='". $_SESSION['username'] . "'";
$result_select_balance = mysqli_query($db, $sql_select_balance);
$balance = [];
while ($row = mysqli_fetch_row($result_select_balance)) {
$balance[] = $row;
}
$userbalance = $balance[0][0];
$sql_select_admin_balance = "SELECT balance FROM user WHERE user.login ='admin'";
$result_select_admin_balance = mysqli_query($db, $sql_select_admin_balance);
$admin_balance = [];
while ($row = mysqli_fetch_row($result_select_admin_balance)) {
$admin_balance[] = $row;
}
$adminbalance = $admin_balance[0][0];
$sql_count_bets = "SELECT COUNT(id_users_choice) FROM users_choice WHERE users_choice.bet='" . $couponid . "'";
$result_count_bets = mysqli_query($db, $sql_count_bets);
$count_bets = [];
while ($row = mysqli_fetch_row($result_count_bets)) {
$count_bets[] = $row;
}
$prize = $stake * $multiplier;
if ($count_bets[0][0] < 4) {
$additional_prize = 0;
} else {
switch ($count_bets[0][0]) {
case 4:
$additional_prize = 7.5;
break;
case 5:
$additional_prize = 10;
break;
case 6:
$additional_prize = 15;
break;
case 7:
$additional_prize = 20;
break;
default:
$additional_prize = 25;
}
}
$prize += (($prize * $additional_prize)/100);
$prize_format_francais = number_format($prize, 2, ',', ' ');
$sql_status = "SELECT bet.status FROM bet WHERE id_bet='" . $couponid . "'";
$result_status = mysqli_query($db, $sql_status);
$status = [];
while ($row = mysqli_fetch_row($result_status)) {
$status[] = $row;
}
$flag = true;
$counter = $count_bets[0][0];
if ($status[0][0] == 0) {
echo "<table class='table'>
<thead class='thead-dark'>
<tr>
<th scope='col'>KUPON #" . $couponid . "</th>
<th scope='col'></th>
<th scope='col'></th>
<th scope='col'></th>
</tr>";
foreach ($select_odds as $odd) {
foreach ($odd as $value) {
$sql_select_names = "SELECT name, choices.choice, choices.has_won, bet_entity.status FROM bet_entity LEFT JOIN choices ON
choices.bet_entity = bet_entity.id_bet_entity LEFT JOIN users_choice ON users_choice.choices =
choices.id_choices WHERE choices.odds LIKE '" . $value . "' AND users_choice.bet = '" . $couponid . "'";
$result_select_names = mysqli_query($db, $sql_select_names);
$select_names = [];
while ($row = mysqli_fetch_row($result_select_names)) {
$select_names[] = $row;
}
echo "<tr>
<th scope='row'>" . $select_names[0][0] . "</th>
<th scope='row'>" . $select_names[0][1] . "</th>
<th scope='row'>" . $value . "</th>
<th scope='row'>";
if ($select_names[0][3] == 0) {
echo "🔮";
} else {
if ($select_names[0][2] == 0) {
echo "❌";
$flag = false;
} else {
echo "✔";
$counter--;
}
}
echo "</th>
</tr>";
}
}
echo "<tr>
<th scope='col'>STAWKA 💸 " . $stake . "zł</th>
<th scope='col'>POTENCJALNA WYGRANA 💰 ". $prize_format_francais . "zł</th>
<th scope='col'>" . round($multiplier, 2);
if ($additional_prize != 0) {
echo " + " . $additional_prize . "%";
}
echo "</th>
<th scope='col'>";
$userinfo = "SELECT name, email FROM user WHERE user.login='". $_SESSION['username'] . "'";
$resultinfo = mysqli_query($db, $userinfo);
$userinfos = [];
while ($row = mysqli_fetch_row($resultinfo)) {
$userinfos[] = $row;
}
if ($flag) {
if ($counter == 0) {
$sql_set_status = "UPDATE bet SET status = '1' WHERE bet.id_bet = '". $couponid . "'";
if ($db->query($sql_set_status) === TRUE) {
$reader = file_get_contents('highest-win.txt');
$reader = explode("\n", $reader);
$help = 1;
$record = "";
foreach ($reader as $row) {
if ($help = 1) {
$help++;
} else {
$record = $row;
}
}
if (round($prize) > $record) {
$txt = $_SESSION['username']."\n".$prize_format_francais;
file_put_contents('highest-win.txt', $txt);
}
$userbalance += round($prize, 2);
$sql_add_prize = "UPDATE user SET balance = '". $userbalance ."'
WHERE user.login = '". $_SESSION['username'] . "'";
if ($db->query($sql_add_prize) === TRUE) {
echo "🏆";
$to_email = $userinfos[0][0] . " <" . $userinfos[0][1] . ">";
$subject = "Wygrany kupon #" . $couponid . "! Gratulacje!";
$message = "Gratulujemy, właśnie dodaliśmy do twojego konta " . $prize_format_francais . "zł,
ponieważ twój kupon o numerze " . $couponid . " został oznaczony jako wygrany!\nTwój stan konta: ". $userbalance ." zł. \nDziękujemy za
korzystanie z naszej strony.\nPozdrawiamy, zespół MXBET";
$headers = "From: [email protected]";
mail($to_email, $subject, $message, $headers);
}
}
} else {
echo "🔮";
}
} else {
$sql_set_status = "UPDATE bet SET bet.status = '1' WHERE id_bet = '". $couponid . "'";
if ($db->query($sql_set_status) === TRUE) {
$adminbalance += $stake;
$sql_add_admin = "UPDATE user SET balance = '". $adminbalance ."'
WHERE user.login = 'admin'";
if ($db->query($sql_add_admin) === TRUE) {
echo "❌";
$to_email = $userinfos[0][0] . " <" . $userinfos[0][1] . ">";
$subject = "Przegrany kupon #" . $couponid . "!";
$message = "Przykro nam, ale właśnie oznaczyliśmy twój kupon o numerze " . $couponid . " jako przegrany.\n
Twój stan konta: ". $balance[0][0] ." zł. \nŻyczymy powodzenia w następnych zakładach! \nDziękujemy za korzystanie z naszej strony.\nPozdrawiamy, zespół MXBET";
$headers = "From: [email protected]";
mail($to_email, $subject, $message, $headers);
}
}
}
echo "</th>
</tr>
</thead>
</table>";
} else {
echo "<table class='table'>
<thead class='thead-dark'>
<tr>
<th scope='col'>KUPON #" . $couponid . "</th>
<th scope='col'></th>
<th scope='col'></th>
<th scope='col'></th>
</tr>";
foreach ($select_odds as $odd) {
foreach ($odd as $value) {
$sql_select_names = "SELECT name, choices.choice, choices.has_won, bet_entity.status FROM bet_entity LEFT JOIN choices ON
choices.bet_entity = bet_entity.id_bet_entity LEFT JOIN users_choice ON users_choice.choices =
choices.id_choices WHERE choices.odds LIKE '" . $value . "' AND users_choice.bet = '" . $couponid . "'";
$result_select_names = mysqli_query($db, $sql_select_names);
$select_names = [];
while ($row = mysqli_fetch_row($result_select_names)) {
$select_names[] = $row;
}
echo "<tr>
<th scope='row'>" . $select_names[0][0] . "</th>
<th scope='row'>" . $select_names[0][1] . "</th>
<th scope='row'>" . $value . "</th>
<th scope='row'>";
if ($select_names[0][3] == 0) {
echo "🔮";
} else {
if ($select_names[0][2] == 0) {
echo "❌";
$flag = false;
} else {
echo "✔";
$counter--;
}
}
echo "</th>
</tr>";
}
}
echo "<tr>
<th scope='col'>STAWKA 💸 " . $stake . "zł</th>";
if ($flag) {
if ($counter == 0) {
echo "<th scope='col'>WYGRANA 💰 ". $prize_format_francais . "zł</th>
<th scope='col'>" . round($multiplier, 2);
if ($additional_prize != 0) {
echo " + " . $additional_prize . "%";
}
echo "</th>
<th scope='col'>";
}
} else {
echo "<th scope='col'>PRZEGRANA</th>
<th scope='col'></th>
<th scope='col'>";
}
if ($flag) {
if ($counter == 0) {
echo "🏆";
}
} else {
echo "❌";
}
echo "</th>
</tr>
</thead>
</table>";
}