-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathadd_cash.php
169 lines (147 loc) · 6.59 KB
/
add_cash.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
<script type="text/javascript">
function ObjById(id)
{
if (document.getElementById)
var returnVar = document.getElementById(id);
else if (document.all)
var returnVar = document.all[id];
else if (document.layers)
var returnVar = document.layers[id];
return returnVar;
}
</script>
<?php
function show_similar_codes($reference)
{
$reference = strtolower($reference);
$result = do_query("
SELECT deposref, uid FROM users WHERE uid > 1
UNION
SELECT deposref, uid FROM old_deposrefs
ORDER BY deposref
");
while ($row = mysql_fetch_assoc($result)) {
$deposref = strtolower($row['deposref']);
$scores[$deposref] = round((9 + similar_text($reference, $deposref) - levenshtein($reference, $deposref))*100/18);
$uid[$deposref] = $row['uid'];
}
arsort($scores);
$first = true;
foreach ($scores as $deposref => $score) {
if ($score >= 50) {
if ($first) {
$first = false;
echo "<p>" . _("Did you mean one of these? Higher percentage = closer match.") . "</p>\n";
echo "<p>" . _("Click an entry to copy it to the form below, then click 'Deposit' again.") . "</p>\n";
echo "<table class='display_data'>\n";
echo "<tr><th>Reference</th><th>Match</th><th>UID</th></tr>\n";
}
$formatted = format_deposref($deposref);
echo "<tr",
" class=\"me\"",
" onmouseover=\"style.backgroundColor='#8ae3bf';\"",
" onmouseout=\"style.backgroundColor='#7ad3af';\"",
" onclick=\"ObjById('reference').value = '$deposref';\">";
echo "<td>$formatted</td><td>$score%</td><td>{$uid[$deposref]}</td></tr>\n";
}
}
if (!$first) echo "</table>\n";
}
if (isset($_POST['make_deposit'])) {
if (isset($_POST['csrf_token'])) {
if ($_SESSION['csrf_token'] != $_POST['csrf_token'])
throw new Error("csrf", "csrf token mismatch!");
} else
throw new Error("csrf", "csrf token missing!");
}
echo "<div class='content_box'>\n";
echo "<h3>" . _("Deposit cash") . "</h3>\n";
if (!$is_admin) throw new Error("GTFO", "How did you get here?");
if (isset($_POST['deposit_cash'])) {
$reference = post('reference');
$user = post('user');
$amount = post('amount');
$amount_internal = numstr_to_internal($amount);
if ($reference && $user)
throw new Error("Error", "Only specify one of 'Reference' and 'User ID'");
if ($reference) {
$ref_without_spaces = str_replace(' ', '', $reference);
$query = "
SELECT uid FROM users WHERE deposref='$ref_without_spaces'
UNION
SELECT uid FROM old_deposrefs WHERE deposref='$ref_without_spaces'
";
$result = do_query($query);
if (has_results($result)) {
$row = get_row($result);
$user = $row['uid'];
if (is_numeric($amount) && $amount != 0) {
$query = "
INSERT INTO requests (req_type, curr_type, uid, amount )
VALUES ('DEPOS', '" . CURRENCY . "', $user, $amount_internal)
";
do_query($query);
printf("<p><span style='font-weight: bold;'>" . _("added request to deposit %s to user %s's purse (reference %s)") . "</span></p>\n",
($amount . " " . CURRENCY), $user, $reference);
echo "<p>" . _("deposit should show up in their account") . " <string>" . _("in a minute or two") . "</strong></p>\n";
echo "<p>" . _("make another deposit?") . "</p>\n";
} else {
echo "<p>$reference is the code for user $user</p>\n";
if (get_verified_for_user($user))
echo "<p>user $user is verified</p>\n";
else
echo "<p>user $user is not verified</p>\n";
}
$amount = $reference = $user = '';
} else {
printf("<p>" . _("'%s' isn't a valid reference code") . "</p>\n",
$reference);
show_similar_codes($reference);
echo "<p>" . _("try again?") . "</p>\n";
}
} else {
$query = "SELECT deposref FROM users WHERE uid='$user'";
$result = do_query($query);
if (has_results($result)) {
$row = get_row($result);
$reference = $row['deposref'];
if (is_numeric($amount) && $amount != 0) {
$query = "
INSERT INTO requests (req_type, curr_type, uid, amount )
VALUES ('DEPOS', '" . CURRENCY . "', $user, $amount_internal)
";
do_query($query);
printf("<p><span style='font-weight: bold;'>" . _("added request to deposit %s to user %s's purse (reference %s)") . "</span></p>\n",
($amount . " " . CURRENCY), $user, $reference);
echo "<p>" . _("deposit should show up in their account") . " <string>" . _("in a minute or two") . "</strong></p>\n";
echo "<p>" . _("make another deposit?") . "</p>\n";
} else {
echo "<p>$reference is the code for user $user</p>\n";
if (get_verified_for_user($user))
echo "<p>user $user is verified</p>\n";
else
echo "<p>user $user is not verified</p>\n";
}
$amount = $reference = $user = '';
} else {
printf("<p>" . _("'%s' isn't a valid userid") . "</p>\n",
$user);
echo "<p>" . _("try again?") . "</p>\n";
}
}
} else
$amount = $reference = $user = '';
echo " <p>" . _("Specify either 'Reference' or 'User ID', but not both.") . "</p>\n";
?>
<form action='' class='indent_form' method='post'>
<input type='hidden' name='csrf_token' value="<?php echo $_SESSION['csrf_token']; ?>" />
<input type='hidden' name='deposit_cash' value='true' />
<label for='reference'><?php echo _("Reference"); ?></label>
<input id='reference' type='text' name='reference' value='<?php echo $reference; ?>'/>
<label for='user'><?php echo _("User ID"); ?></label>
<input id='user' type='text' name='user' value='<?php echo $user; ?>'/>
<label for='amount'><?php echo _("Amount"); ?></label>
<input id='amount' type='text' name='amount' value='<?php echo $amount; ?>' />
<input type='submit' value='Deposit' />
</form>
</div>