-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreferalcoderedemption.php
More file actions
221 lines (187 loc) · 6.23 KB
/
referalcoderedemption.php
File metadata and controls
221 lines (187 loc) · 6.23 KB
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
<?php
session_start();
require_once "pdo.php";
$phone = $_SESSION['phone'];
if (isset($_POST["cancel"])) {
header('Location: user.php');
return;
}
if (isset($_POST['referalcode'])) {
$stmt1 = $pdo->prepare('SELECT * FROM referal WHERE referalcode= :referalcode');
$stmt1->execute(array(
':referalcode' => htmlentities($_POST['referalcode']),
));
$rows2 = $stmt1->fetchAll(PDO::FETCH_ASSOC);
$count1 = $stmt1->rowCount();
$stmt2 = $pdo->prepare('SELECT * FROM users WHERE phone= :phone'); //own user
$stmt2->execute(array(
':phone' => $phone,
));
$rows3 = $stmt2->fetchAll(PDO::FETCH_ASSOC);
foreach($rows3 as $row3){
if (strlen($_POST['referalcode']) < 1) {
$_SESSION["error"] = "Referal code missing";
header("Location: referalcoderedemption.php");
return;
} elseif ($count1>0){
$_SESSION["error"] = "Referal code already claimed";
header("Location: referalcoderedemption.php");
return;
} elseif($_POST['referalcode'] === $row3['referalcode']){
$_SESSION["error"] = "Own referal code cannot be claimed";
header("Location: referalcoderedemption.php");
return;
}else {
$stmt = $pdo->prepare('SELECT * FROM users WHERE referalcode= :referalcode'); //the owner of the referal code user
$stmt->execute(array(
':referalcode' => htmlentities($_POST['referalcode']),
));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$count = $stmt->rowCount();
foreach($rows as $row){
$refertypeacc = $row3['refertype'];
$coinreward = 0;
$coinmultiplier = 1;
if($row['refertype']== "first"){
$refertypeacc = "second";
$coinreward = 50;
} elseif($row['refertype']== "second"){
$refertypeacc = "third";
$coinreward = 20;
} elseif ($row['refertype']== "third"){
$refertypeacc = "third";
$coinreward = 10;
} else{
$refertypeacc = "first";
}
if($row['category']== "king"){
$coinmultiplier = 1.5;
} elseif($row['category']== "duke"){
$coinmultiplier = 1.2;
} elseif ($row['category']== "peasant"){
$coinmultiplier = 1;
} else{
$coinmultiplier = 1;
}
$phonereferer = $row['phone'];
//adding coins award to the referal code owner
$precoinamount = ($row['coinamount'] + $coinreward) * $coinmultiplier;
//print($precoinamount);
$referalcounter = $row['referalcounter'] + 1;
$channel = "website";
$sql = "UPDATE users SET coinamount = :coinamount, referalcounter = :referalcounter WHERE phone = :phone";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(
':coinamount' => $precoinamount,
':referalcounter' => $referalcounter,
':phone' => $phonereferer,
));
//adding coinsaward to the account owner
$oricoinamount = $row3['coinamount'] + 25;
$phonereferee = $_SESSION['phone'];
$sql3 = "UPDATE users SET coinamount = :coinamount, refertype = :refertype WHERE phone = :phone;";
$stmt3 = $pdo->prepare($sql3);
$stmt3->execute(array(
':coinamount' => $oricoinamount,
':refertype' => $refertypeacc,
':phone' => $phonereferee,
));
$stmt4 = $pdo->prepare('INSERT INTO referal (channel, ipadd, phone, referalcode) VALUES (:channel, :ipadd ,:phone, :referalcode);');
$stmt4->execute(array(
':channel' => $channel,
':ipadd' => $_SERVER['REMOTE_ADDR'],
':phone' => $phone,
':referalcode' => htmlentities($_POST['referalcode']),
));
if($count > 0){
$_SESSION['referalcode'] = $_POST['referalcode'];
header("location: user.php");
}
else{
$_SESSION['error'] = "Wrong data";
header("location: referalcoderedemption.php");
return;
}
$_SESSION['success'] = "Code claimed";
header("Location: referalcoderedemption.php");
return;
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Muhammad Qayim bin Norizan</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">
</script>
<style>
.container-sm{
text-align: center;
padding: 10px;
width:550px;
}
.logo{
font-family: "Trebuchet MS", sans-serif;
padding-top: 70px;
padding-bottom: 30px;
}
#referalcode{
padding:10px;
height:53px;
width:355px;
font-size:14pt;
}
.btn{
height:53px;
width:355px;
}
.fa{
padding: 10px;
}
</style>
</head>
<body>
<p> </p>
<div class="container-sm p-1 border">
<div class="logo">
<a href="deal.php">
<h1>Ringgit%</h1>
</a>
<?php
if ( isset($_SESSION['success']) ) {
echo('<p style="color: red;">'.htmlentities($_SESSION['success'])."</p>\n");
unset($_SESSION['success']);
}
?>
<?php
//error message
if ( isset($_SESSION['error']) ) {
echo('<p style="color: red;">'.htmlentities($_SESSION['error'])."</p>\n");
unset($_SESSION['error']);
}
?>
</div>
<form method="POST">
<input type="text" placeholder="Referal code" name="referalcode" id="referalcode">
<p> </p>
<input type="submit" class="btn btn-info btn-lg" value="Claim">
<p> </p>
</form>
</div>
<p> </p>
</body>
</html>