|
1
|
|
|
<?php |
|
2
|
|
|
/************************************************************************/ |
|
3
|
|
|
/* Donations - Paypal financial management module for Xoops 2 */ |
|
4
|
|
|
/* Copyright (c) 2016 XOOPS Project */ |
|
5
|
|
|
/* http://dev.xoops.org/modules/xfmod/project/?group_id=1060 */ |
|
6
|
|
|
/* |
|
7
|
|
|
/************************************************************************/ |
|
8
|
|
|
/* */ |
|
9
|
|
|
/* Based on NukeTreasury for PHP-Nuke - by Dave Lawrence AKA Thrash */ |
|
10
|
|
|
/* NukeTreasury - Financial management for PHP-Nuke */ |
|
11
|
|
|
/* Copyright (c) 2004 by Dave Lawrence AKA Thrash */ |
|
12
|
|
|
/* [email protected] */ |
|
13
|
|
|
/* [email protected] */ |
|
14
|
|
|
/* */ |
|
15
|
|
|
/************************************************************************/ |
|
16
|
|
|
/* */ |
|
17
|
|
|
/* This program is free software; you can redistribute it and/or modify */ |
|
18
|
|
|
/* it under the terms of the GNU General Public License as published by */ |
|
19
|
|
|
/* the Free Software Foundation; either version 2 of the License. */ |
|
20
|
|
|
/* */ |
|
21
|
|
|
/* This program is distributed in the hope that it will be useful, but */ |
|
22
|
|
|
/* WITHOUT ANY WARRANTY; without even the implied warranty of */ |
|
23
|
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ |
|
24
|
|
|
/* General Public License for more details. */ |
|
25
|
|
|
/* */ |
|
26
|
|
|
/* You should have received a copy of the GNU General Public License */ |
|
27
|
|
|
/* along with this program; if not, write to the Free Software */ |
|
28
|
|
|
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 */ |
|
29
|
|
|
/* USA */ |
|
30
|
|
|
/************************************************************************/ |
|
31
|
|
|
|
|
32
|
|
|
use XoopsModules\Xdonations; |
|
33
|
|
|
|
|
34
|
|
|
// defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
35
|
|
|
|
|
36
|
|
|
$xdBlockDir = basename(dirname(__DIR__)); |
|
37
|
|
|
xoops_loadLanguage('main', $xdBlockDir); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param $options |
|
41
|
|
|
* @return array |
|
42
|
|
|
*/ |
|
43
|
|
|
function b_donations_donatometer_show($options) |
|
44
|
|
|
{ |
|
45
|
|
|
global $xoopsDB; |
|
46
|
|
|
$xdBlockDir = basename(dirname(__DIR__)); |
|
47
|
|
|
$utility = new Xdonations\Utility(); |
|
48
|
|
|
$tr_config = $utility::getConfigInfo(); |
|
49
|
|
|
//determine the currency |
|
50
|
|
|
$PP_CURR_CODE = explode('|', $tr_config['pp_curr_code']); // [USD,GBP,JPY,CAD,EUR] |
|
51
|
|
|
$PP_CURR_CODE = $PP_CURR_CODE[0]; |
|
52
|
|
|
$currencySign = $utility::defineCurrency($PP_CURR_CODE); |
|
53
|
|
|
|
|
54
|
|
|
$block = []; |
|
55
|
|
|
|
|
56
|
|
|
$swingd = $tr_config['swing_day']; |
|
57
|
|
|
if (($swingd < 0) || ($swingd > 31)) { |
|
58
|
|
|
$swingd = 6; |
|
59
|
|
|
} |
|
60
|
|
|
$dmshowdate = $options[1]; |
|
61
|
|
|
$dmshowamt = $options[2]; |
|
62
|
|
|
|
|
63
|
|
|
if (is_numeric($options[0]) && $options[0] > 0) { |
|
64
|
|
|
$dmlen = $options[0]; |
|
65
|
|
|
} elseif (is_numeric($dmlen) && 0 == $dmlen) { |
|
|
|
|
|
|
66
|
|
|
$dmlen = -1; |
|
67
|
|
|
} else { |
|
68
|
|
|
$dmlen = 10; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// Check the current day against the swing day to execute the proper query |
|
72
|
|
|
if (date('d') >= $swingd) { |
|
73
|
|
|
$query_Recordset1 = 'SELECT count(mc_gross) AS count, sum(mc_gross) AS gross, sum(' |
|
74
|
|
|
. "mc_gross-mc_fee) AS net, date_format( now(),'%M') AS mon, date_format( subdate( date_format( adddate(" |
|
75
|
|
|
. "now(), INTERVAL 1 MONTH),'%Y-%c-1'), INTERVAL 1 DAY), '%b %e') AS due_by, date_format(now(),'%b') AS " |
|
76
|
|
|
. 'mon_short FROM ' |
|
77
|
|
|
. $xoopsDB->prefix('donations_transactions') |
|
78
|
|
|
. ' WHERE (payment_date >= date_format(' |
|
79
|
|
|
. "now(),'%Y-%m-" |
|
80
|
|
|
. $swingd |
|
81
|
|
|
. "'))"; |
|
82
|
|
|
|
|
83
|
|
|
$query_Recordset3 = 'select custom as muser_id, option_selection1 as showname, ' |
|
84
|
|
|
. "date_format( payment_date, '%b-%e') as date, concat('" |
|
85
|
|
|
. $currencySign |
|
86
|
|
|
. "',sum(mc_gross)) as amt " |
|
87
|
|
|
. 'from ' |
|
88
|
|
|
. $xoopsDB->prefix('donations_transactions') |
|
89
|
|
|
. ' where (payment_date >= date_format( ' |
|
90
|
|
|
. "now(), '%Y-%m-" |
|
91
|
|
|
. $swingd |
|
92
|
|
|
. "')) group by txn_id order by payment_date desc"; |
|
93
|
|
|
} else { |
|
94
|
|
|
$query_Recordset1 = 'select count(mc_gross) as count, sum(mc_gross) as gross, sum(mc_gross -' |
|
95
|
|
|
. ' mc_fee) as net, date_format( subdate( now(), interval ' |
|
96
|
|
|
. $swingd |
|
97
|
|
|
. " day), '%M') as mon," |
|
98
|
|
|
. " 'Now!' as due_by, date_format( subdate( now(), interval " |
|
99
|
|
|
. $swingd |
|
100
|
|
|
. " day), '%b') as mon_short" |
|
101
|
|
|
. ' from ' |
|
102
|
|
|
. $xoopsDB->prefix('donations_transactions') |
|
103
|
|
|
. " where (payment_date < date_format( now(), '%Y-%m-" |
|
104
|
|
|
. $swingd |
|
105
|
|
|
. "')" |
|
106
|
|
|
. ') and payment_date > date_format( subdate( now(), interval ' |
|
107
|
|
|
. $swingd |
|
108
|
|
|
. " day), '%Y-%m-" |
|
109
|
|
|
. $swingd |
|
110
|
|
|
. "')"; |
|
111
|
|
|
|
|
112
|
|
|
$query_Recordset3 = 'select custom as muser_id, option_selection1 as showname, ' |
|
113
|
|
|
. "date_format( payment_date, '%b-%e') as date, concat('" |
|
114
|
|
|
. $currencySign |
|
115
|
|
|
. "', sum(mc_gross)) as amt " |
|
116
|
|
|
. 'from ' |
|
117
|
|
|
. $xoopsDB->prefix('donations_transactions') |
|
118
|
|
|
. ' where (payment_date < date_format(now(),' |
|
119
|
|
|
. " '%Y-%m-" |
|
120
|
|
|
. $swingd |
|
121
|
|
|
. "')) and payment_date > date_format( subdate( now(),interval " |
|
122
|
|
|
. $swingd |
|
123
|
|
|
. ' ' |
|
124
|
|
|
. "day), '%Y-%m-" |
|
125
|
|
|
. $swingd |
|
126
|
|
|
. "') group by txn_id order by payment_date desc"; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
// Get the donation totals |
|
130
|
|
|
$Recordset1 = $xoopsDB->query($query_Recordset1); |
|
131
|
|
|
$row_Recordset1 = $xoopsDB->fetchArray($Recordset1); |
|
132
|
|
|
//If there are not records, then get "null" data |
|
133
|
|
|
if (!$row_Recordset1) { |
|
134
|
|
|
$query_Recordset1 = "select '0' as count, '0' as gross, '0' as net, date_format( now()," |
|
135
|
|
|
. "'%M') as mon, date_format( subdate( date_format( adddate( now(), interval 1 month), '%Y-%c-1')," |
|
136
|
|
|
. " interval 1 day), '%b %e') as due_by, date_format( now(), '%b') as mon_short from " |
|
137
|
|
|
. ' ' |
|
138
|
|
|
. $xoopsDB->prefix('donations_transactions') |
|
139
|
|
|
. ''; |
|
140
|
|
|
$Recordset1 = $xoopsDB->query($query_Recordset1); |
|
141
|
|
|
$row_Recordset1 = $xoopsDB->fetchArray($Recordset1); |
|
142
|
|
|
} |
|
143
|
|
|
// Get the goal |
|
144
|
|
|
$query_Recordset2 = 'SELECT * FROM ' . $xoopsDB->prefix('donations_config') . " WHERE name='month_goal' AND subtype='" . $row_Recordset1['mon_short'] . "'"; |
|
145
|
|
|
$Recordset2 = $xoopsDB->query($query_Recordset2); |
|
146
|
|
|
$row_Recordset2 = $xoopsDB->fetchArray($Recordset2); |
|
147
|
|
|
|
|
148
|
|
|
// Set our remaining template vars |
|
149
|
|
|
if (!$row_Recordset1['mon']) { |
|
150
|
|
|
$DM_MON = date('F'); |
|
151
|
|
|
} else { |
|
152
|
|
|
$DM_MON = $row_Recordset1['mon']; |
|
153
|
|
|
} |
|
154
|
|
|
$difference = $row_Recordset1['net'] - $row_Recordset2['value']; |
|
155
|
|
|
$DM_GOAL = sprintf($currencySign . '%.02f', $row_Recordset2['value']); |
|
156
|
|
|
$DM_DUE = $row_Recordset1['due_by']; |
|
157
|
|
|
$DM_NUM = $row_Recordset1['count']; |
|
|
|
|
|
|
158
|
|
|
$DM_GROSS = sprintf($currencySign . '%.02f', $row_Recordset1['gross']); |
|
159
|
|
|
$DM_NET = sprintf($currencySign . '%.02f', $row_Recordset1['net']); |
|
160
|
|
|
$DM_LEFT = sprintf($currencySign . '%.02f', $row_Recordset2['value'] - $row_Recordset1['net']); |
|
161
|
|
|
$DM_BUTTON = $options[3]; |
|
162
|
|
|
$DM_BUTT_DIMS = ''; |
|
163
|
|
|
if (is_numeric($options[4])) { |
|
164
|
|
|
$DM_BUTT_DIMS .= 'width=' . $options[4] . ' '; |
|
165
|
|
|
} |
|
166
|
|
|
if (is_numeric($options[5])) { |
|
167
|
|
|
$DM_BUTT_DIMS .= 'height=' . $options[5] . ' '; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
// Load the template |
|
171
|
|
|
$block['DM_BUTTON'] = $DM_BUTTON; |
|
172
|
|
|
$block['DM_BUTT_DIMS'] = $DM_BUTT_DIMS; |
|
173
|
|
|
$block['DM_MON'] = $DM_MON; |
|
174
|
|
|
$block['DM_GOAL'] = $DM_GOAL; |
|
175
|
|
|
$block['DM_DUE'] = $DM_DUE; |
|
176
|
|
|
$block['DM_GROSS'] = $DM_GROSS; |
|
177
|
|
|
$block['DM_NET'] = $DM_NET; |
|
178
|
|
|
$block['DON_URL'] = XOOPS_URL . '/modules/' . $xdBlockDir . '/index.php'; |
|
|
|
|
|
|
179
|
|
|
$show_don = 0; |
|
180
|
|
|
// Do we want to display the donators? |
|
181
|
|
|
if (is_numeric($dmlen) && $dmlen >= 0) { |
|
182
|
|
|
$show_don = 1; |
|
183
|
|
|
// Get the list of donators |
|
184
|
|
|
$Recordset3 = $xoopsDB->query($query_Recordset3); |
|
185
|
|
|
|
|
186
|
|
|
// List all the donators |
|
187
|
|
|
$i = 0; |
|
188
|
|
|
$var = ''; |
|
189
|
|
|
while (($row_Recordset3 = $xoopsDB->fetchArray($Recordset3)) && ($i != $options[0])) { |
|
190
|
|
|
// Refunded transactions will show up with $0 amount |
|
191
|
|
|
if ($row_Recordset3['amt'] > '$0') { |
|
192
|
|
|
$dmalign = 'center'; |
|
193
|
|
|
$var .= "<tr><td style=\"width: 100%; text-align: {$dmalign};\" colspan=\"2\">\n"; |
|
194
|
|
|
// Observe the user's wish regarding revealing their name |
|
195
|
|
|
$muser_id = $row_Recordset3['muser_id']; |
|
196
|
|
|
/** @var \XoopsUser $userfoin */ |
|
197
|
|
|
if (0 == strcmp($row_Recordset3['showname'], 'Yes') && ($userfoin = $utility::getUserInfo($muser_id))) { |
|
198
|
|
|
$var .= "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $userfoin->getVar('uid') . "'>" . $userfoin->getVar('uname') . "</a>\n"; |
|
199
|
|
|
} else { |
|
200
|
|
|
$var .= _MB_XDONATION_ANONYMOUS_SHORT; |
|
201
|
|
|
} |
|
202
|
|
|
$var .= ' '; |
|
203
|
|
|
if ($dmshowamt) { |
|
204
|
|
|
$var .= '(' . $row_Recordset3['amt'] . ')'; |
|
205
|
|
|
} |
|
206
|
|
|
if ($dmshowdate) { |
|
207
|
|
|
$var .= $row_Recordset3['date']; |
|
208
|
|
|
} |
|
209
|
|
|
$var .= "</td></tr>\n"; |
|
210
|
|
|
} |
|
211
|
|
|
++$i; |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
if ($difference >= 0) { |
|
216
|
|
|
$DM_OVERAGE = sprintf($currencySign . '%.02f', $difference); |
|
217
|
|
|
$block['DM_REMAIN'] = _MB_XDONATION_SURPLUS; |
|
218
|
|
|
$block['DM_BALANCE'] = $DM_OVERAGE; |
|
219
|
|
|
} else { |
|
220
|
|
|
$block['DM_REMAIN'] = _MB_XDONATION_LEFT2GO; |
|
221
|
|
|
$block['DM_BALANCE'] = "<span style=\"color: #CC0000;\">{$DM_LEFT}</span>"; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
// Define language constants |
|
225
|
|
|
$block['DM_STAT'] = _MB_XDONATION_STAT; |
|
226
|
|
|
$block['DM_MONGOAL'] = _MB_XDONATION_MONGOAL; |
|
227
|
|
|
$block['DM_DUEDATE'] = _MB_XDONATION_DUEDATE; |
|
228
|
|
|
$block['DM_GROSSAMT'] = _MB_XDONATION_GROSSAMT; |
|
229
|
|
|
$block['DM_NETBAL'] = _MB_XDONATION_NETBAL; |
|
230
|
|
|
$block['DM_DONATIONS'] = _MB_XDONATION_DONATIONS; |
|
231
|
|
|
$block['DM_MAKEDON'] = _MB_XDONATION_MAKEDON; |
|
232
|
|
|
|
|
233
|
|
|
// Display block |
|
234
|
|
|
$block['show_don'] = $show_don; |
|
235
|
|
|
$block['content'] = $var; |
|
|
|
|
|
|
236
|
|
|
|
|
237
|
|
|
return $block; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* @param $options |
|
242
|
|
|
* @return string |
|
243
|
|
|
*/ |
|
244
|
|
|
function b_donations_donatometer_edit($options) |
|
245
|
|
|
{ |
|
246
|
|
|
$form = _MB_XDONATION_NUM_DONORS . ": <input type='text' name='options[0]' value='" . $options[0] . "' size='4'>"; |
|
247
|
|
|
$form .= '<br>' . _MB_XDONATION_REVEAL_DATES . ": <select size='1' name='options[1]'><option value='1'"; |
|
248
|
|
|
if (1 == $options[1]) { |
|
249
|
|
|
$form .= ' selected'; |
|
250
|
|
|
} |
|
251
|
|
|
$form .= '>' . _YES . "</option><option value='0'"; |
|
|
|
|
|
|
252
|
|
|
if (0 == $options[1]) { |
|
253
|
|
|
$form .= ' selected'; |
|
254
|
|
|
} |
|
255
|
|
|
$form .= '>' . _NO . '</option></select>'; |
|
|
|
|
|
|
256
|
|
|
$form .= '<br>' . _MB_XDONATION_REVEAL_AMOUNTS . ": <select size='1' name='options[2]'><option value='1'"; |
|
257
|
|
|
if (1 == $options[2]) { |
|
258
|
|
|
$form .= ' selected'; |
|
259
|
|
|
} |
|
260
|
|
|
$form .= '>' . _YES . "</option><option value='0'"; |
|
261
|
|
|
if (0 == $options[2]) { |
|
262
|
|
|
$form .= ' selected'; |
|
263
|
|
|
} |
|
264
|
|
|
$form .= '>' . _NO . '</option></select>'; |
|
265
|
|
|
$form .= '<br>' . _MB_XDONATION_BUTTON_URL . ': '; |
|
266
|
|
|
$form .= "<input size='70' name='options[3]' type='text' value='" . $options[3] . "'>"; |
|
267
|
|
|
$form .= '<br>' . _MB_XDONATION_BUTTON_DIMS . ': '; |
|
268
|
|
|
$form .= _MB_XDONATION_WIDTH . " <input size='4' name='options[4]' type='text' value='" . $options[4] . "'>"; |
|
269
|
|
|
$form .= ' ' . _MB_XDONATION_WIDTH . " <input size='4' name='options[5]' type='text' value='" . $options[5] . "'>"; |
|
270
|
|
|
|
|
271
|
|
|
return $form; |
|
272
|
|
|
} |
|
273
|
|
|
|