-
Notifications
You must be signed in to change notification settings - Fork 1
/
ajax_manage_custom_currency.php
129 lines (109 loc) · 3.33 KB
/
ajax_manage_custom_currency.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
<?php
$require_petload = 'no';
$invisible = 'yes';
$AJAX = true;
// confirm the session...
require_once 'commons/dbconnect.php';
require_once 'commons/sessions.php';
require_once 'commons/grouplib.php';
require_once 'commons/userlib.php';
$resident = $_POST['resident'];
$currency_id = (int)$_POST['currency'];
$action = $_POST['action'];
$amount = (int)$_POST['amount'];
$field_id = (int)$_POST['fieldid'];
if($amount == 0 || ($action != 'give' && $action != 'take'))
die('Err0');
$command = '
SELECT groupid,name
FROM psypets_group_currencies
WHERE
idnum=' . $currency_id . '
AND `type`=\'resident\'
LIMIT 1
';
$currency_data = $database->FetchSingle($command, 'fetching currency data');
if($currency_data === false)
die('Err1');
$target_user = get_user_bydisplay($resident, 'idnum,display');
if($target_user === false)
die('Err2');
$groupid = $currency_data['groupid'];
$group = get_group_byid($groupid);
if($group === false)
die('Err3');
$ranks = get_group_ranks($groupid);
/*$members = explode(',', $group['members']);
$organizer = get_user_byid($group['leaderid'], 'idnum,display,graphic');*/
$a_member = is_a_member($group, $user['idnum']);
if($a_member)
{
// $invites = get_invites_bygroup($groupid);
$rankid = get_member_rank($group, $user['idnum']);
$can_manage_money = (rank_has_right($ranks, $rankid, 'treasurer') || $group['leaderid'] == $user['idnum']);
}
else
$can_manage_money = false;
if(!$can_manage_money)
die('Err4');
if($action == 'give')
{
$command = '
UPDATE psypets_group_player_currencies
SET amount=amount+' . $amount . '
WHERE
userid=' . $target_user['idnum'] . '
AND currencyid=' . $currency_id . '
LIMIT 1
';
$database->FetchNone($command, 'updating player currency');
if($database->AffectedRows() == 0)
{
$command = '
INSERT INTO psypets_group_player_currencies
(userid, currencyid, amount)
VALUES
(
' . $target_user['idnum'] . ',
' . $currency_id . ',
' . $amount . '
)
';
$database->FetchNone($command, 'adding player currency');
}
}
else if($action == 'take')
{
$command = '
UPDATE psypets_group_player_currencies
SET amount=amount-' . $amount . '
WHERE
userid=' . $target_user['idnum'] . '
AND currencyid=' . $currency_id . '
LIMIT 1
';
$database->FetchNone($command, 'updating player currency');
if($database->AffectedRows() == 0)
{
$command = '
INSERT INTO psypets_group_player_currencies
(userid, currencyid, amount)
VALUES
(
' . $target_user['idnum'] . ',
' . $currency_id . ',
-' . $amount . '
)
';
$database->FetchNone($command, 'adding player currency');
}
}
else
die('Log!');
$command = 'SELECT amount FROM psypets_group_player_currencies WHERE userid=' . $target_user['idnum'] . ' AND currencyid=' . $currency_id . ' LIMIT 1';
$new_value = $database->FetchSingle($command, 'fetching new currency value');
if($new_value === false)
die('Err5');
$wealth_amount = $wealth_table_display = $new_value['amount'];
echo '<a href="#" onclick="add_remove_currency_for_resident(this, ' . $field_id . ', \'' . addslashes($target_user['display']) . '\', \'' . addslashes($currency_data['name']) . '\', ' . $currency_id . ', ' . $wealth_amount . '); return false;">' . $wealth_table_display . '</a>';
?>