-
Notifications
You must be signed in to change notification settings - Fork 38
/
join.php
352 lines (296 loc) · 11 KB
/
join.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?php
include('php-includes/connect.php');
include('php-includes/check-login.php');
$userid = $_SESSION['userid'];
$capping = 500;
?>
<?php
//User cliced on join
if(isset($_GET['join_user'])){
$side='';
$pin = mysqli_real_escape_string($con,$_GET['pin']);
$email = mysqli_real_escape_string($con,$_GET['email']);
$mobile = mysqli_real_escape_string($con,$_GET['mobile']);
$address = mysqli_real_escape_string($con,$_GET['address']);
$account = mysqli_real_escape_string($con,$_GET['account']);
$under_userid = mysqli_real_escape_string($con,$_GET['under_userid']);
$side = mysqli_real_escape_string($con,$_GET['side']);
$password = "123456";
$flag = 0;
if($pin!='' && $email!='' && $mobile!='' && $address!='' && $account!='' && $under_userid!='' && $side!=''){
//User filled all the fields.
if(pin_check($pin)){
//Pin is ok
if(email_check($email)){
//Email is ok
if(!email_check($under_userid)){
//Under userid is ok
if(side_check($under_userid,$side)){
//Side check
$flag=1;
}
else{
echo '<script>alert("The side you selected is not available.");</script>';
}
}
else{
//check under userid
echo '<script>alert("Invalid Under userid.");</script>';
}
}
else{
//check email
echo '<script>alert("This user id already availble.");</script>';
}
}
else{
//check pin
echo '<script>alert("Invalid pin");</script>';
}
}
else{
//check all fields are fill
echo '<script>alert("Please fill all the fields.");</script>';
}
//Now we are heree
//It means all the information is correct
//Now we will save all the information
if($flag==1){
//Insert into User profile
$query = mysqli_query($con,"insert into user(`email`,`password`,`mobile`,`address`,`account`,`under_userid`,`side`) values('$email','$password','$mobile','$address','$account','$under_userid','$side')");
//Insert into Tree
//So that later on we can view tree.
$query = mysqli_query($con,"insert into tree(`userid`) values('$email')");
//Insert to side
$query = mysqli_query($con,"update tree set `$side`='$email' where userid='$under_userid'");
//Update pin status to close
$query = mysqli_query($con,"update pin_list set status='close' where pin='$pin'");
//Inset into Icome
$query = mysqli_query($con,"insert into income (`userid`) values('$email')");
echo mysqli_error($con);
//This is the main part to join a user\
//If you will do any mistake here. Then the site will not work.
//Update count and Income.
$temp_under_userid = $under_userid;
$temp_side_count = $side.'count'; //leftcount or rightcount
$temp_side = $side;
$total_count=1;
$i=1;
while($total_count>0){
$i;
$q = mysqli_query($con,"select * from tree where userid='$temp_under_userid'");
$r = mysqli_fetch_array($q);
$current_temp_side_count = $r[$temp_side_count]+1;
$temp_under_userid;
$temp_side_count;
mysqli_query($con,"update tree set `$temp_side_count`=$current_temp_side_count where userid='$temp_under_userid'");
//income
if($temp_under_userid!=""){
$income_data = income($temp_under_userid);
//check capping
//$income_data['day_bal'];
if($income_data['day_bal']<$capping){
$tree_data = tree($temp_under_userid);
//check leftplusright
//$tree_data['leftcount'];
//$tree_data['rightcount'];
//$leftplusright;
$temp_left_count = $tree_data['leftcount'];
$temp_right_count = $tree_data['rightcount'];
//Both left and right side should at least 1 user
if($temp_left_count>0 && $temp_right_count>0){
if($temp_side=='left'){
$temp_left_count;
$temp_right_count;
if($temp_left_count<=$temp_right_count){
$new_day_bal = $income_data['day_bal']+100;
$new_current_bal = $income_data['current_bal']+100;
$new_total_bal = $income_data['total_bal']+100;
//update income
mysqli_query($con,"update income set day_bal='$new_day_bal', current_bal='$new_current_bal', total_bal='$new_total_bal' where userid='$temp_under_userid' limit 1");
}
}
else{
if($temp_right_count<=$temp_left_count){
$new_day_bal = $income_data['day_bal']+100;
$new_current_bal = $income_data['current_bal']+100;
$new_total_bal = $income_data['total_bal']+100;
$temp_under_userid;
//update income
if(mysqli_query($con,"update income set day_bal='$new_day_bal', current_bal='$new_current_bal', total_bal='$new_total_bal' where userid='$temp_under_userid'")){
}
}
}
}//Both left and right side should at least 1 user
}
//change under_userid
$next_under_userid = getUnderId($temp_under_userid);
$temp_side = getUnderIdPlace($temp_under_userid);
$temp_side_count = $temp_side.'count';
$temp_under_userid = $next_under_userid;
$i++;
}
//Chaeck for the last user
if($temp_under_userid==""){
$total_count=0;
}
}//Loop
echo mysqli_error($con);
echo '<script>alert("Testing success.");</script>';
}
}
?><!--/join user-->
<?php
//functions
function pin_check($pin){
global $con,$userid;
$query =mysqli_query($con,"select * from pin_list where pin='$pin' and userid='$userid' and status='open'");
if(mysqli_num_rows($query)>0){
return true;
}
else{
return false;
}
}
function email_check($email){
global $con;
$query =mysqli_query($con,"select * from user where email='$email'");
if(mysqli_num_rows($query)>0){
return false;
}
else{
return true;
}
}
function side_check($email,$side){
global $con;
$query =mysqli_query($con,"select * from tree where userid='$email'");
$result = mysqli_fetch_array($query);
$side_value = $result[$side];
if($side_value==''){
return true;
}
else{
return false;
}
}
function income($userid){
global $con;
$data = array();
$query = mysqli_query($con,"select * from income where userid='$userid'");
$result = mysqli_fetch_array($query);
$data['day_bal'] = $result['day_bal'];
$data['current_bal'] = $result['current_bal'];
$data['total_bal'] = $result['total_bal'];
return $data;
}
function tree($userid){
global $con;
$data = array();
$query = mysqli_query($con,"select * from tree where userid='$userid'");
$result = mysqli_fetch_array($query);
$data['left'] = $result['left'];
$data['right'] = $result['right'];
$data['leftcount'] = $result['leftcount'];
$data['rightcount'] = $result['rightcount'];
return $data;
}
function getUnderId($userid){
global $con;
$query = mysqli_query($con,"select * from user where email='$userid'");
$result = mysqli_fetch_array($query);
return $result['under_userid'];
}
function getUnderIdPlace($userid){
global $con;
$query = mysqli_query($con,"select * from user where email='$userid'");
$result = mysqli_fetch_array($query);
return $result['side'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Mlml Website - Join</title>
<!-- Bootstrap Core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- MetisMenu CSS -->
<link href="vendor/metisMenu/metisMenu.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="dist/css/sb-admin-2.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<!-- Navigation -->
<?php include('php-includes/menu.php'); ?>
<!-- Page Content -->
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Join</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-4">
<form method="get">
<div class="form-group">
<label>Pin</label>
<input type="text" name="pin" class="form-control" required>
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="email" class="form-control" required>
</div>
<div class="form-group">
<label>Mobile</label>
<input type="text" name="mobile" class="form-control" required>
</div>
<div class="form-group">
<label>Address</label>
<input type="text" name="address" class="form-control" required>
</div>
<div class="form-group">
<label>Account</label>
<input type="text" name="account" class="form-control" required>
</div>
<div class="form-group">
<label>Under Userid</label>
<input type="text" name="under_userid" class="form-control" required>
</div>
<div class="form-group">
<label>Side</label><br>
<input type="radio" name="side" value="left"> Left
<input type="radio" name="side" value="right"> Right
</div>
<div class="form-group">
<input type="submit" name="join_user" class="btn btn-primary" value="Join">
</div>
</form>
</div>
</div><!--/.row-->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<!-- jQuery -->
<script src="vendor/jquery/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="vendor/metisMenu/metisMenu.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="dist/js/sb-admin-2.js"></script>
</body>
</html>