-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfunctions_main.php
155 lines (143 loc) · 5.9 KB
/
functions_main.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
<?php
require_once('coins.php');
$GLOBALS['cp']=$my_coins->coins_names_prefix;
$GLOBALS['cp_count']=count($my_coins->coins_names_prefix);
function getTradeId($i=0, $trade_account=true)
{
if($trade_account)
$i=0;
return $GLOBALS['cp'][0+$i]."_".$GLOBALS['cp'][1+$i]."_".$GLOBALS['cp'][2+$i];
}
function security($value) {
if(is_array($value)) {
$value = array_map('security', $value);
} else {
if(!get_magic_quotes_gpc()) {
$value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
} else {
$value = htmlspecialchars(stripslashes($value), ENT_QUOTES, 'UTF-8');
}
$value = str_replace("\\", "\\\\", $value);
}
return $value;
}
function apikeygen() {
$keygen_characters = "0011223344--__5566778899aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzAABBCCDDEEF--__FGGHHIIJJKKLLMMNNOOPPQQRRSSTUUVVWWXXYYZZ";
$keygen_key = "";
$keygen_length = rand(40, 60);
for($keygen_i = 0; $keygen_i < $keygen_length; $keygen_i++) {
$keygen_key .= $keygen_characters[rand(0, strlen($keygen_characters) - 1)];
}
return $keygen_key;
}
function satoshitize($satoshitize) {
return sprintf("%.8f", $satoshitize);
}
function satoshitrim($satoshitrim) {
return rtrim(rtrim($satoshitrim, "0"), ".");
}
function userbalance($function_user,$function_coin) {
for($i = 0; $i < $GLOBALS['cp_count']; $i+=3)
{
if($function_coin==$GLOBALS['cp'][0+$i]) {
$function_query = mysql_query("SELECT coin".($i+1)." FROM balances WHERE username='$function_user' AND trade_id = '".getTradeId($i)."'");
while($function_row = mysql_fetch_assoc($function_query)) { $function_return = $function_row['coin'.($i+1)]; }
break;
}
if($function_coin==$GLOBALS['cp'][2+$i]) {
$function_query = mysql_query("SELECT coin".($i+2)." FROM balances WHERE username='$function_user' AND trade_id = '".getTradeId($i)."'");
while($function_row = mysql_fetch_assoc($function_query)) { $function_return = $function_row['coin'.($i+2)]; }
break;
}
if($function_coin==$GLOBALS['cp'][1+$i]) {
$function_query = mysql_query("SELECT coin".($i+3)." FROM balances WHERE username='$function_user' AND trade_id = '".getTradeId($i)."'");
while($function_row = mysql_fetch_assoc($function_query)) { $function_return = $function_row['coin'.($i+3)]; }
break;
}
}
return $function_return;
}
function buyrate($function_coin, $function_coin2) {
$found_value=false;
for($i = 0; $i < $GLOBALS['cp_count']; $i+=3)
{
$function_query = mysql_query("SELECT rate FROM buy_orderbook WHERE want='$function_coin' and processed='1' and trade_id = '".getTradeId($i)."' AND trade_with = '$function_coin2' ORDER BY rate DESC LIMIT 1");
while($function_row = mysql_fetch_assoc($function_query)) {
$function_return = $function_row['rate'];
$found_value=true;
}
if($found_value)
break;
}
return $function_return;
}
function sellrate($function_coin,$function_coin2) {
$found_value=false;
for($i = 0; $i < $GLOBALS['cp_count']; $i+=3)
{
$function_query = mysql_query("SELECT rate FROM sell_orderbook WHERE want='$function_coin' and processed='1' and trade_id = '".getTradeId($i)."' AND trade_with = '$function_coin2' ORDER BY rate ASC LIMIT 1");
while($function_row = mysql_fetch_assoc($function_query)) {
$function_return = $function_row['rate'];
$found_value=true;
}
if($found_value)
break;
}
return $function_return;
}
function plusfunds($function_user,$function_coin,$function_amount) {
$found_value=false;
for($i = 0; $i < $GLOBALS['cp_count']; $i+=3)
{
$function_user_balance = userbalance($function_user,$function_coin);
$function_balance = $function_user_balance + $function_amount;
$function_balance = satoshitrim(satoshitize($function_balance));
if($function_coin==$GLOBALS['cp'][0+$i]) { $sql = "UPDATE balances SET coin".($i+1)."='$function_balance' WHERE username='$function_user' AND trade_id = '".getTradeId($i)."'"; $found_value=true;}
if($function_coin==$GLOBALS['cp'][2+$i]) { $sql = "UPDATE balances SET coin".($i+2)."='$function_balance' WHERE username='$function_user' AND trade_id = '".getTradeId($i)."'"; $found_value=true;}
if($function_coin==$GLOBALS['cp'][1+$i]) { $sql = "UPDATE balances SET coin".($i+3)."='$function_balance' WHERE username='$function_user' AND trade_id = '".getTradeId($i)."'"; $found_value=true;}
if(!$found_value)
continue;
$result = mysql_query($sql);
if($result) {
$function_return = "success";
} else {
$function_return = "error";
}
break;
}
return $function_return;
}
function minusfunds($function_user,$function_coin,$function_amount) {
$found_value=false;
for($i = 0; $i < $GLOBALS['cp_count']; $i+=3)
{
$function_user_balance = userbalance($function_user,$function_coin);
$function_balance = $function_user_balance - $function_amount;
$function_balance = satoshitrim(satoshitize($function_balance));
if($function_coin==$GLOBALS['cp'][0+$i]) { $sql = "UPDATE balances SET coin".($i+1)."='$function_balance' WHERE username='$function_user' AND trade_id = '".getTradeId($i)."'"; $found_value=true;}
if($function_coin==$GLOBALS['cp'][2+$i]) { $sql = "UPDATE balances SET coin".($i+2)."='$function_balance' WHERE username='$function_user' AND trade_id = '".getTradeId($i)."'"; $found_value=true;}
if($function_coin==$GLOBALS['cp'][1+$i]) { $sql = "UPDATE balances SET coin".($i+3)."='$function_balance' WHERE username='$function_user' AND trade_id = '".getTradeId($i)."'"; $found_value=true;}
if(!$found_value)
continue;
$result = mysql_query($sql);
if($result) {
$function_return = "success";
} else {
$function_return = "error";
}
break;
}
return $function_return;
}
function get_current_url()
{
return 'http'.(empty($_SERVER['HTTPS'])?'':'s').'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
}
function get_root_path($file)
{
$str = dirname(__FILE__);
$str = str_replace("ajax","",$str);
$str = $str . '/' . $file;
return $str;
}
?>