/
function.php
284 lines (220 loc) · 6.56 KB
/
function.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
<?php
function getbaseme()
{
$q = mysql_query("SELECT * FROM tbl_core_config_data WHERE path='web/unsecure/base_url'");
$row = mysql_fetch_array($q);
return $row['value'];
}
function countfield($field,$value)
{
$query = mysql_query("SELECT * FROM tbl_accounts WHERE $field='$value'");
return mysql_num_rows($query);
}
function formquery($post)
{
$return = array();
foreach($post as $key=>$val)
{
$return[] = "$key='$val'";
}
return implode(",",$return);
}
function randid()
{
return rand().strtotime("now");
}
function totalaccount()
{
$query = "SELECT username,accounts_id as aid,(SELECT COUNT(id) FROM tbl_cycle WHERE account_link = aid AND cycle_count=1 AND cycle_link = 0) as totalacct,account_count FROM tbl_accounts as acct
JOIN tbl_package as pck WHERE pck.package_id = acct.package_id
HAVING totalacct < account_count LIMIt 1";
return mysql_query($query);
}
function autocreateaccount()
{
while($row=mysql_fetch_assoc(totalaccount()))
{
$limit = $row['account_count'] - $row['totalacct'];
$aid = $row['aid'];
for ($x = 1; $x <= $limit; $x++) {
$username = $row['username']."-".randid();
mysql_query("INSERT INTO tbl_cycle SET username='$username',account_link='$aid',cycle_count='1',cycle_link='0'");
}
return;
}
}
function autodetectparent()
{
$query ="SELECT username,account_link,cycle_count,id as alink,(SELECT COUNT(id) FROM tbl_relation WHERE parent = alink) as checkparent FROM tbl_cycle HAVING checkparent < 2 ORDER by id ASC LIMIT 1 ";
return mysql_query($query);
}
function autodetectchild($parentid)
{
$query = "SELECT username,account_link,cycle_count,id as alink,(SELECT COUNT(id) FROM tbl_relation WHERE child = alink) as checkchild FROM tbl_cycle WHERE id!=$parentid AND id > $parentid HAVING checkchild = 0 ORDER by id ASC LIMIT 1";
return mysql_query($query);
}
function loadcycle($id)
{
$q = mysql_query("SELECT * FROM tbl_cycle WHERE id='$id'");
$row = mysql_fetch_assoc($q);
return $row;
}
function getRate($id)
{
$q = mysql_query("SELECT cycle_earn FROM tbl_package WHERE package_id='$id'");
$row = mysql_fetch_assoc($q);
return $row['cycle_earn'];
}
function getUserPackage($id)
{
$q = mysql_query("SELECT package_id FROM tbl_accounts WHERE accounts_id='$id'");
$row = mysql_fetch_assoc($q);
return $row['package_id'];
}
function addmoney($uid,$rate)
{
mysql_query("UPDATE tbl_accounts SET balance = balance + $rate WHERE accounts_id=$uid");
}
function totalbalance($uid,$rate)
{
mysql_query("UPDATE tbl_accounts SET total_earnings = total_earnings + $rate WHERE accounts_id=$uid");
}
function exitlabel($id)
{
mysql_query("UPDATE tbl_cycle SET cycle_status = 1 WHERE id=$id");
}
function cycleinc($id)
{
$user = loadcycle($id);
$inc = $user['cycle_count'] + 1;
exitlabel($id);
$userpackage = getUserPackage($user['account_link']);
$rate = getRate($userpackage);
totalbalance($user['account_link'],$rate);
if($inc==4)
{
addmoney($account_link,($rate * 3));
$username = "adminbonus-".randid();
$account_link = 1;
$cycle_count = 1;
$cycle_link = 0;
mysql_query("INSERT INTO tbl_cycle SET username='$username',account_link='$account_link',cycle_count='$cycle_count',cycle_link='$cycle_link'");
}
else
{
$username = $user['username']."-".$inc;
$account_link = $user['account_link'];
$cycle_count = $inc;
if($user['cycle_link']==0)
{
$cycle_link =$id;
}
else{
$cycle_link = $user['cycle_link'];
}
$q = mysql_fetch_assoc(mysql_query("SELECT COUNT(id) as chet FROM tbl_cycle WHERE username='$username' AND account_link='$account_link' AND cycle_count='$cycle_count' AND cycle_link='$cycle_link'"));
if($q['chet']==0):
mysql_query("INSERT INTO tbl_cycle SET username='$username',account_link='$account_link',cycle_count='$cycle_count',cycle_link='$cycle_link'");
endif;
}
}
function cycleevent($row)
{
$rowx = mysql_fetch_assoc(autodetectchild($row['alink']));
$parent = $row['alink'];
$child = $rowx['alink'];
if($child!='')
{
mysql_query("INSERT INTO tbl_relation SET parent='$parent',child='$child'");
$q = mysql_fetch_assoc(mysql_query("SELECT COUNT(parent) as chet FROM tbl_relation WHERE parent='$parent'"));
if($q['chet']==2)
{
cycleinc($parent);
}
}
}
function mytimestamp()
{
return date('Y-m-d H:i:s');
}
function getrow($var)
{
$array['title'] = 'Monoline';
$array['image'] = 'https://placeholdit.imgix.net/~text?txtsize=19&txt=150%C3%97150&w=200&h=75';
return $array;
}
function countquery($query)
{
$q = mysql_query($query);
return mysql_num_rows($q);
}
function getpackagelist()
{
$packrowq = mysql_query("SELECT * FROM tbl_package");
while($packrow = mysql_fetch_assoc($packrowq))
{
$options[$packrow['package_id']] = $packrow['package_name'];
}
return $options;
}
function getwheresearch($field)
{
if($_GET['search']!='')
{
$search = $_GET['search'];
$where = "WHERE";
foreach($field as $f)
{
$where .= " $f LIKE '%$search%' OR";
}
$where .= " 1=1";
$where = str_replace("OR 1=1","",$where);
}
return $where;
}
function getlimit($limit,$page)
{
if($page=='')
{
$page = 0;
}
else
{
$page--;
}
$limitx = $limit * $page;
return "LIMIT $limitx,$limit";
}
function getpagecount($total,$limit)
{
return (ceil($total/$limit));
}
function csv()
{
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=payout-'.$_GET['r']."-".rand().'.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
if($_GET['r']=='bank')
{
$rows = mysql_query("SELECT b.accounts_id,b.username,transnum,email,amount,bank_name,bank_accountnumber,bank_accountname FROM tbl_withdraw_history as a JOIN tbl_accounts as b WHERE claim_status=0 AND a.accounts_id=b.accounts_id AND claimtype='".$_GET['r']."'
");
$array = explode(",","accounts_id,username,transnum,email,amount,bank_name,bank_accountnumber,bank_accountname");
}
if($_GET['r']=='pickup')
{
$rows = mysql_query("SELECT b.accounts_id,b.username,transnum,email,amount FROM tbl_withdraw_history as a JOIN tbl_accounts as b WHERE claim_status=0 AND a.accounts_id=b.accounts_id AND claimtype='".$_GET['r']."'");
$array = explode(",","accounts_id,username,transnum,email,amount");
}
fputcsv($output,$array);
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows))
{
foreach($row as $key=>$val)
{
$row[$key] = "\"".$val."\"";
}
fputcsv($output, $row);
}
}
?>