1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* PayPal Donation extension for the phpBB Forum Software package. |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2015 Skouat |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace skouat\ppde\controller; |
12
|
|
|
|
13
|
|
|
use phpbb\auth\auth; |
14
|
|
|
use phpbb\config\config; |
15
|
|
|
use phpbb\language\language; |
16
|
|
|
use phpbb\log\log; |
17
|
|
|
use phpbb\request\request; |
18
|
|
|
use phpbb\template\template; |
19
|
|
|
use phpbb\user; |
20
|
|
|
use skouat\ppde\actions\core; |
21
|
|
|
use skouat\ppde\actions\currency; |
22
|
|
|
use skouat\ppde\exception\transaction_exception; |
23
|
|
|
use skouat\ppde\operators\transactions; |
24
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @property config config Config object |
28
|
|
|
* @property ContainerInterface container Service container interface |
29
|
|
|
* @property string id_prefix_name Prefix name for identifier in the URL |
30
|
|
|
* @property string lang_key_prefix Prefix for the messages thrown by exceptions |
31
|
|
|
* @property language language Language user object |
32
|
|
|
* @property log log The phpBB log system. |
33
|
|
|
* @property string module_name Name of the module currently used |
34
|
|
|
* @property request request Request object. |
35
|
|
|
* @property bool submit State of submit $_POST variable |
36
|
|
|
* @property template template Template object |
37
|
|
|
* @property string u_action Action URL |
38
|
|
|
* @property user user User object. |
39
|
|
|
*/ |
40
|
|
|
class admin_transactions_controller extends admin_main |
41
|
|
|
{ |
42
|
|
|
public $ppde_operator; |
43
|
|
|
protected $adm_relative_path; |
44
|
|
|
protected $auth; |
45
|
|
|
protected $entry_count; |
46
|
|
|
protected $last_page_offset; |
47
|
|
|
protected $php_ext; |
48
|
|
|
protected $phpbb_admin_path; |
49
|
|
|
protected $phpbb_root_path; |
50
|
|
|
protected $ppde_actions; |
51
|
|
|
protected $ppde_actions_currency; |
52
|
|
|
protected $table_prefix; |
53
|
|
|
protected $table_ppde_transactions; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Constructor |
57
|
|
|
* |
58
|
|
|
* @param auth $auth Authentication object |
59
|
|
|
* @param config $config Config object |
60
|
|
|
* @param ContainerInterface $container Service container interface |
61
|
|
|
* @param language $language Language user object |
62
|
|
|
* @param log $log The phpBB log system |
63
|
|
|
* @param core $ppde_actions PPDE actions object |
64
|
|
|
* @param currency $ppde_actions_currency PPDE currency actions object |
65
|
|
|
* @param transactions $ppde_operator_transactions Operator object |
66
|
|
|
* @param request $request Request object |
67
|
|
|
* @param template $template Template object |
68
|
|
|
* @param user $user User object. |
69
|
|
|
* @param string $adm_relative_path phpBB admin relative path |
70
|
|
|
* @param string $phpbb_root_path phpBB root path |
71
|
|
|
* @param string $php_ext phpEx |
72
|
|
|
* @param string $table_prefix The table prefix |
73
|
|
|
* @param string $table_ppde_transactions Name of the table used to store data |
74
|
|
|
* |
75
|
|
|
* @access public |
76
|
|
|
*/ |
77
|
|
|
public function __construct(auth $auth, config $config, ContainerInterface $container, language $language, log $log, core $ppde_actions, currency $ppde_actions_currency, transactions $ppde_operator_transactions, request $request, template $template, user $user, $adm_relative_path, $phpbb_root_path, $php_ext, $table_prefix, $table_ppde_transactions) |
78
|
|
|
{ |
79
|
|
|
$this->auth = $auth; |
80
|
|
|
$this->config = $config; |
81
|
|
|
$this->container = $container; |
82
|
|
|
$this->language = $language; |
83
|
|
|
$this->log = $log; |
84
|
|
|
$this->ppde_actions = $ppde_actions; |
85
|
|
|
$this->ppde_actions_currency = $ppde_actions_currency; |
86
|
|
|
$this->ppde_operator = $ppde_operator_transactions; |
87
|
|
|
$this->request = $request; |
88
|
|
|
$this->template = $template; |
89
|
|
|
$this->user = $user; |
90
|
|
|
$this->adm_relative_path = $adm_relative_path; |
91
|
|
|
$this->phpbb_admin_path = $phpbb_root_path . $adm_relative_path; |
92
|
|
|
$this->phpbb_root_path = $phpbb_root_path; |
93
|
|
|
$this->php_ext = $php_ext; |
94
|
|
|
$this->table_prefix = $table_prefix; |
95
|
|
|
$this->table_ppde_transactions = $table_ppde_transactions; |
96
|
|
|
parent::__construct( |
97
|
|
|
'transactions', |
98
|
|
|
'PPDE_DT', |
99
|
|
|
'transaction' |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Display the transactions list |
105
|
|
|
* |
106
|
|
|
* @param string $id Module id |
107
|
|
|
* @param string $mode Module categorie |
108
|
|
|
* @param string $action Action name |
109
|
|
|
* |
110
|
|
|
* @return void |
111
|
|
|
* @access public |
112
|
|
|
*/ |
113
|
|
|
public function display_transactions($id, $mode, $action) |
114
|
|
|
{ |
115
|
|
|
// Set up general vars |
116
|
|
|
$args = array(); |
117
|
|
|
$start = $this->request->variable('start', 0); |
118
|
|
|
$deletemark = $this->request->is_set('delmarked') ? $this->request->variable('delmarked', false) : false; |
119
|
|
|
$deleteall = $this->request->is_set('delall') ? $this->request->variable('delall', false) : false; |
120
|
|
|
$marked = $this->request->variable('mark', array(0)); |
121
|
|
|
$txn_approve = $this->request->is_set('approve'); |
122
|
|
|
$txn_approved = $this->request->variable('txn_errors_approved', 0); |
123
|
|
|
$txn_add = $this->request->is_set('add'); |
124
|
|
|
// Sort keys |
125
|
|
|
$sort_days = $this->request->variable('st', 0); |
126
|
|
|
$sort_key = $this->request->variable('sk', 't'); |
127
|
|
|
$sort_dir = $this->request->variable('sd', 'd'); |
128
|
|
|
|
129
|
|
|
// Prepares args for entries deletion |
130
|
|
|
if (($deletemark || $deleteall) && $this->auth->acl_get('a_ppde_manage')) |
131
|
|
|
{ |
132
|
|
|
$action = 'delete'; |
133
|
|
|
$args = array( |
134
|
|
|
'hidden_fields' => array( |
135
|
|
|
'start' => $start, |
136
|
|
|
'delall' => $deleteall, |
137
|
|
|
'delmarked' => $deletemark, |
138
|
|
|
'mark' => $marked, |
139
|
|
|
'st' => $sort_days, |
140
|
|
|
'sk' => $sort_key, |
141
|
|
|
'sd' => $sort_dir, |
142
|
|
|
'i' => $id, |
143
|
|
|
'mode' => $mode, |
144
|
|
|
), |
145
|
|
|
); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
if ($txn_approve) |
149
|
|
|
{ |
150
|
|
|
$transaction_id = $this->request->variable('id', 0); |
151
|
|
|
$action = 'approve'; |
152
|
|
|
$args = array( |
153
|
|
|
'hidden_fields' => array( |
154
|
|
|
'approve' => true, |
155
|
|
|
'id' => $transaction_id, |
156
|
|
|
'txn_errors_approved' => $txn_approved, |
157
|
|
|
), |
158
|
|
|
); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
if ($txn_add) |
162
|
|
|
{ |
163
|
|
|
$action = 'add'; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
$action = $this->do_action($action, $args); |
167
|
|
|
|
168
|
|
|
if (!$action) |
169
|
|
|
{ |
170
|
|
|
/** @type \phpbb\pagination $pagination */ |
171
|
|
|
$pagination = $this->container->get('pagination'); |
172
|
|
|
|
173
|
|
|
// Sorting |
174
|
|
|
$limit_days = array(0 => $this->language->lang('ALL_ENTRIES'), 1 => $this->language->lang('1_DAY'), 7 => $this->language->lang('7_DAYS'), 14 => $this->language->lang('2_WEEKS'), 30 => $this->language->lang('1_MONTH'), 90 => $this->language->lang('3_MONTHS'), 180 => $this->language->lang('6_MONTHS'), 365 => $this->language->lang('1_YEAR')); |
175
|
|
|
$sort_by_text = array('txn' => $this->language->lang('PPDE_DT_SORT_TXN_ID'), 'u' => $this->language->lang('PPDE_DT_SORT_DONORS'), 'ipn' => $this->language->lang('PPDE_DT_SORT_IPN_STATUS'), 'ipn_test' => $this->language->lang('PPDE_DT_SORT_IPN_TYPE'), 'ps' => $this->language->lang('PPDE_DT_SORT_PAYMENT_STATUS'), 't' => $this->language->lang('SORT_DATE')); |
176
|
|
|
$sort_by_sql = array('txn' => 'txn.txn_id', 'u' => 'u.username_clean', 'ipn' => 'txn.confirmed', 'ipn_test' => 'txn.test_ipn', 'ps' => 'txn.payment_status', 't' => 'txn.payment_date'); |
177
|
|
|
|
178
|
|
|
$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; |
179
|
|
|
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param); |
180
|
|
|
|
181
|
|
|
// Define where and sort sql for use in displaying transactions |
182
|
|
|
$sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0; |
183
|
|
|
$sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC'); |
184
|
|
|
|
185
|
|
|
$keywords = $this->request->variable('keywords', '', true); |
186
|
|
|
$keywords_param = !empty($keywords) ? '&keywords=' . urlencode(htmlspecialchars_decode($keywords)) : ''; |
187
|
|
|
|
188
|
|
|
// Grab log data |
189
|
|
|
$log_data = array(); |
190
|
|
|
$log_count = 0; |
191
|
|
|
|
192
|
|
|
$this->view_txn_log($log_data, $log_count, (int) $this->config['topics_per_page'], $start, $sql_where, $sql_sort, $keywords); |
193
|
|
|
|
194
|
|
|
$base_url = $this->u_action . '&' . $u_sort_param . $keywords_param; |
195
|
|
|
$pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, (int) $this->config['topics_per_page'], $start); |
196
|
|
|
|
197
|
|
|
$this->template->assign_vars(array( |
198
|
|
|
'S_CLEARLOGS' => $this->auth->acl_get('a_ppde_manage'), |
199
|
|
|
'S_KEYWORDS' => $keywords, |
200
|
|
|
'S_LIMIT_DAYS' => $s_limit_days, |
201
|
|
|
'S_SORT_KEY' => $s_sort_key, |
202
|
|
|
'S_SORT_DIR' => $s_sort_dir, |
203
|
|
|
'S_TXN' => $mode, |
204
|
|
|
'U_ACTION' => $this->u_action . '&' . $u_sort_param . $keywords_param . '&start=' . $start, |
205
|
|
|
)); |
206
|
|
|
|
207
|
|
|
array_map(array($this, 'display_log_assign_template_vars'), $log_data); |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Do action regarding the value of $action |
213
|
|
|
* |
214
|
|
|
* @param string $action Requested action |
215
|
|
|
* @param array $args Arguments required for the action |
216
|
|
|
* |
217
|
|
|
* @return string |
218
|
|
|
* @access private |
219
|
|
|
*/ |
220
|
|
|
private function do_action($action, $args) |
221
|
|
|
{ |
222
|
|
|
// Initiate an entity |
223
|
|
|
/** @type \skouat\ppde\entity\transactions $entity */ |
224
|
|
|
$entity = $this->get_container_entity(); |
225
|
|
|
|
226
|
|
|
switch ($action) |
227
|
|
|
{ |
228
|
|
|
case 'view': |
229
|
|
|
// Request Identifier of the transaction |
230
|
|
|
$transaction_id = $this->request->variable('id', 0); |
231
|
|
|
|
232
|
|
|
// add field username to the table schema needed by entity->import() |
233
|
|
|
$additional_table_schema = array( |
234
|
|
|
'item_username' => array('name' => 'username', 'type' => 'string'), |
235
|
|
|
'item_user_colour' => array('name' => 'user_colour', 'type' => 'string'), |
236
|
|
|
); |
237
|
|
|
|
238
|
|
|
// Grab transaction data |
239
|
|
|
$data_ary = $entity->get_data($this->ppde_operator->build_sql_data($transaction_id), $additional_table_schema); |
240
|
|
|
|
241
|
|
|
array_map(array($this, 'action_assign_template_vars'), $data_ary); |
242
|
|
|
|
243
|
|
|
$this->template->assign_vars(array( |
244
|
|
|
'U_ACTION' => $this->u_action, |
245
|
|
|
'U_BACK' => $this->u_action, |
246
|
|
|
'S_VIEW' => true, |
247
|
|
|
)); |
248
|
|
|
break; |
249
|
|
|
case 'delete': |
250
|
|
|
if (confirm_box(true)) |
251
|
|
|
{ |
252
|
|
|
$where_sql = ''; |
253
|
|
|
|
254
|
|
|
if ($args['hidden_fields']['delmarked'] && count($args['hidden_fields']['mark'])) |
255
|
|
|
{ |
256
|
|
|
$where_sql = $this->ppde_operator->build_marked_where_sql($args['hidden_fields']['mark']); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
if ($where_sql || $args['hidden_fields']['delall']) |
260
|
|
|
{ |
261
|
|
|
$entity->delete(0, '', $where_sql, $args['hidden_fields']['delall']); |
262
|
|
|
$this->ppde_actions->set_ipn_test_properties(true); |
263
|
|
|
$this->ppde_actions->update_overview_stats(); |
264
|
|
|
$this->ppde_actions->set_ipn_test_properties(false); |
265
|
|
|
$this->ppde_actions->update_overview_stats(); |
266
|
|
|
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_' . $this->lang_key_prefix . '_PURGED', time()); |
267
|
|
|
} |
268
|
|
|
} |
269
|
|
|
else |
270
|
|
|
{ |
271
|
|
|
confirm_box(false, $this->language->lang('CONFIRM_OPERATION'), build_hidden_fields($args['hidden_fields'])); |
272
|
|
|
} |
273
|
|
|
// Clear $action status |
274
|
|
|
$action = ''; |
275
|
|
|
break; |
276
|
|
|
case 'approve': |
277
|
|
|
if (confirm_box(true)) |
278
|
|
|
{ |
279
|
|
|
$transaction_id = (int) $args['hidden_fields']['id']; |
280
|
|
|
$txn_approved = !empty($args['hidden_fields']['txn_errors_approved']) ? false : true; |
281
|
|
|
|
282
|
|
|
// Update DB record |
283
|
|
|
$entity->load($transaction_id); |
284
|
|
|
$entity->set_txn_errors_approved($txn_approved); |
285
|
|
|
$entity->save(false); |
286
|
|
|
|
287
|
|
|
// Prepare transaction settings before doing actions |
288
|
|
|
$this->ppde_actions->set_transaction_data($entity->get_data($this->ppde_operator->build_sql_data($transaction_id))); |
289
|
|
|
$this->ppde_actions->set_ipn_test_properties($entity->get_test_ipn()); |
290
|
|
|
$this->ppde_actions->is_donor_is_member(); |
291
|
|
|
|
292
|
|
|
// Do the actions related to the approval of the transaction |
293
|
|
|
$this->ppde_actions->update_overview_stats(); |
294
|
|
|
$this->ppde_actions->update_raised_amount(); |
295
|
|
|
if (!$this->ppde_actions->get_ipn_test() && $this->ppde_actions->get_donor_is_member()) |
296
|
|
|
{ |
297
|
|
|
$this->ppde_actions->update_donor_stats(); |
298
|
|
|
$this->ppde_actions->donors_group_user_add(); |
299
|
|
|
$this->ppde_actions->notification->notify_donor_donation_received(); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_' . $this->lang_key_prefix . '_UPDATED', time()); |
303
|
|
|
} |
304
|
|
|
else |
305
|
|
|
{ |
306
|
|
|
confirm_box(false, $this->language->lang('CONFIRM_OPERATION'), build_hidden_fields($args['hidden_fields'])); |
307
|
|
|
} |
308
|
|
|
// Clear $action status |
309
|
|
|
$action = ''; |
310
|
|
|
break; |
311
|
|
|
case 'add': |
312
|
|
|
$errors = array(); |
313
|
|
|
|
314
|
|
|
$transaction_data = array( |
315
|
|
|
'MT_ANONYMOUS' => $this->request->is_set('u'), |
316
|
|
|
'MT_USERNAME' => $this->request->variable('username', '', true), |
317
|
|
|
'MT_FIRST_NAME' => $this->request->variable('first_name', '', true), |
318
|
|
|
'MT_LAST_NAME' => $this->request->variable('last_name', '', true), |
319
|
|
|
'MT_PAYER_EMAIL' => $this->request->variable('payer_email', '', true), |
320
|
|
|
'MT_RESIDENCE_COUNTRY' => $this->request->variable('residence_country', ''), |
321
|
|
|
'MT_MC_GROSS' => $this->request->variable('mc_gross', (float) 0), |
322
|
|
|
'MT_MC_CURRENCY' => $this->request->variable('mc_currency', ''), |
323
|
|
|
'MT_MC_FEE' => $this->request->variable('mc_fee', (float) 0), |
324
|
|
|
'MT_PAYMENT_DATE_YEAR' => $this->request->variable('payment_date_year', (int) $this->user->format_date(time(), 'Y')), |
325
|
|
|
'MT_PAYMENT_DATE_MONTH' => $this->request->variable('payment_date_month', (int) $this->user->format_date(time(), 'n')), |
326
|
|
|
'MT_PAYMENT_DATE_DAY' => $this->request->variable('payment_date_day', (int) $this->user->format_date(time(), 'j')), |
327
|
|
|
'MT_PAYMENT_TIME' => $this->request->variable('payment_time', $this->user->format_date(time(), 'H:i:s')), |
328
|
|
|
'MT_MEMO' => $this->request->variable('memo', '', true), |
329
|
|
|
); |
330
|
|
|
|
331
|
|
|
if ($this->request->is_set_post('submit')) |
332
|
|
|
{ |
333
|
|
|
try |
334
|
|
|
{ |
335
|
|
|
$data_ary = $this->build_data_ary($transaction_data); |
336
|
|
|
|
337
|
|
|
$this->ppde_actions->log_to_db($data_ary); |
338
|
|
|
$this->ppde_actions->set_transaction_data($transaction_data); |
339
|
|
|
$this->ppde_actions->is_donor_is_member(); |
340
|
|
|
$this->ppde_actions->update_overview_stats(); |
341
|
|
|
$this->ppde_actions->update_raised_amount(); |
342
|
|
|
|
343
|
|
|
if ($this->ppde_actions->get_donor_is_member()) |
344
|
|
|
{ |
345
|
|
|
$this->ppde_actions->update_donor_stats(); |
346
|
|
|
$this->ppde_actions->donors_group_user_add(); |
347
|
|
|
$this->ppde_actions->notification->notify_donor_donation_received(); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_PPDE_MT_ADDED', time(), array($transaction_data['MT_USERNAME'])); |
351
|
|
|
trigger_error($this->language->lang('PPDE_MT_ADDED') . adm_back_link($this->u_action)); |
352
|
|
|
} |
353
|
|
|
catch (transaction_exception $e) |
354
|
|
|
{ |
355
|
|
|
$errors = $e->get_errors(); |
356
|
|
|
} |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
$this->ppde_actions_currency->build_currency_select_menu((int) $this->config['ppde_default_currency']); |
360
|
|
|
|
361
|
|
|
$this->s_error_assign_template_vars($errors); |
362
|
|
|
|
363
|
|
|
$this->template->assign_vars($transaction_data); |
364
|
|
|
|
365
|
|
|
$this->template->assign_vars(array( |
366
|
|
|
'U_ACTION' => $this->u_action, |
367
|
|
|
'U_BACK' => $this->u_action, |
368
|
|
|
'S_ADD' => true, |
369
|
|
|
'ANONYMOUS_USER_ID' => ANONYMOUS, |
370
|
|
|
'U_FIND_USERNAME' => append_sid($this->phpbb_root_path . 'memberlist.' . $this->php_ext, 'mode=searchuser&form=manual_transaction&field=username&select_single=true'), |
371
|
|
|
'PAYMENT_TIME_FORMATS' => $this->get_payment_time_examples(), |
372
|
|
|
)); |
373
|
|
|
break; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
return $action; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* Returns a list of valid times that the user can provide in the manual transaction form |
381
|
|
|
* |
382
|
|
|
* @return array Array of strings representing the current time, each in a different format |
383
|
|
|
* @access private |
384
|
|
|
*/ |
385
|
|
|
private function get_payment_time_examples() |
386
|
|
|
{ |
387
|
|
|
$formats = array( |
388
|
|
|
'H:i:s', |
389
|
|
|
'G:i', |
390
|
|
|
'h:i:s a', |
391
|
|
|
'g:i A', |
392
|
|
|
); |
393
|
|
|
|
394
|
|
|
$examples = array(); |
395
|
|
|
|
396
|
|
|
foreach ($formats as $format) |
397
|
|
|
{ |
398
|
|
|
$examples[] = $this->user->format_date(time(), $format); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
return $examples; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* View log |
406
|
|
|
* |
407
|
|
|
* @param array &$log The result array with the logs |
408
|
|
|
* @param mixed &$log_count If $log_count is set to false, we will skip counting all entries in the |
409
|
|
|
* database. Otherwise an integer with the number of total matching entries is returned. |
410
|
|
|
* @param int $limit Limit the number of entries that are returned |
411
|
|
|
* @param int $offset Offset when fetching the log entries, f.e. when paginating |
412
|
|
|
* @param int $limit_days |
413
|
|
|
* @param string $sort_by SQL order option, e.g. 'l.log_time DESC' |
414
|
|
|
* @param string $keywords Will only return log entries that have the keywords in log_operation or log_data |
415
|
|
|
* |
416
|
|
|
* @return int Returns the offset of the last valid page, if the specified offset was invalid (too high) |
417
|
|
|
* @access private |
418
|
|
|
*/ |
419
|
|
|
private function view_txn_log(&$log, &$log_count, $limit = 0, $offset = 0, $limit_days = 0, $sort_by = 'txn.payment_date DESC', $keywords = '') |
420
|
|
|
{ |
421
|
|
|
$count_logs = ($log_count !== false); |
422
|
|
|
|
423
|
|
|
$log = $this->get_logs($count_logs, $limit, $offset, $limit_days, $sort_by, $keywords); |
424
|
|
|
$log_count = $this->get_log_count(); |
425
|
|
|
|
426
|
|
|
return $this->get_valid_offset(); |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* @param bool $count_logs |
431
|
|
|
* @param int $limit |
432
|
|
|
* @param int $offset |
433
|
|
|
* @param int $log_time |
434
|
|
|
* @param string $sort_by |
435
|
|
|
* @param string $keywords |
436
|
|
|
* |
437
|
|
|
* @return array $log |
438
|
|
|
* @access private |
439
|
|
|
*/ |
440
|
|
|
private function get_logs($count_logs = true, $limit = 0, $offset = 0, $log_time = 0, $sort_by = 'txn.payment_date DESC', $keywords = '') |
441
|
|
|
{ |
442
|
|
|
$this->entry_count = 0; |
443
|
|
|
$this->last_page_offset = $offset; |
444
|
|
|
$url_ary = array(); |
445
|
|
|
|
446
|
|
|
if ($this->get_container_entity()->is_in_admin() && $this->phpbb_admin_path) |
447
|
|
|
{ |
448
|
|
|
$url_ary['profile_url'] = append_sid($this->phpbb_admin_path . 'index.' . $this->php_ext, 'i=users&mode=overview'); |
449
|
|
|
$url_ary['txn_url'] = append_sid($this->phpbb_admin_path . 'index.' . $this->php_ext, 'i=-skouat-ppde-acp-ppde_module&mode=transactions'); |
450
|
|
|
|
451
|
|
|
} |
452
|
|
|
else |
453
|
|
|
{ |
454
|
|
|
$url_ary['profile_url'] = append_sid($this->phpbb_root_path . 'memberlist.' . $this->php_ext, 'mode=viewprofile'); |
455
|
|
|
$url_ary['txn_url'] = ''; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
$get_logs_sql_ary = $this->ppde_operator->get_logs_sql_ary($keywords, $sort_by, $log_time); |
459
|
|
|
|
460
|
|
|
if ($count_logs) |
461
|
|
|
{ |
462
|
|
|
$this->entry_count = $this->ppde_operator->query_sql_count($get_logs_sql_ary, 'txn.transaction_id'); |
463
|
|
|
|
464
|
|
|
if ($this->entry_count == 0) |
465
|
|
|
{ |
466
|
|
|
// Save the queries, because there are no logs to display |
467
|
|
|
$this->last_page_offset = 0; |
468
|
|
|
|
469
|
|
|
return array(); |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
// Return the user to the last page that is valid |
473
|
|
|
while ($this->last_page_offset >= $this->entry_count) |
474
|
|
|
{ |
475
|
|
|
$this->last_page_offset = max(0, $this->last_page_offset - $limit); |
476
|
|
|
} |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
return $this->ppde_operator->build_log_ary($get_logs_sql_ary, $url_ary, $limit, $this->last_page_offset); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
/** |
483
|
|
|
* @return integer |
484
|
|
|
*/ |
485
|
|
|
public function get_log_count() |
486
|
|
|
{ |
487
|
|
|
return ($this->entry_count) ? (int) $this->entry_count : 0; |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* @return integer |
492
|
|
|
*/ |
493
|
|
|
public function get_valid_offset() |
494
|
|
|
{ |
495
|
|
|
return ($this->last_page_offset) ? (int) $this->last_page_offset : 0; |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* Prepare data array() before send it to $entity |
500
|
|
|
* |
501
|
|
|
* @param array $transaction_data |
502
|
|
|
* |
503
|
|
|
* @return array |
504
|
|
|
* @throws transaction_exception |
505
|
|
|
*/ |
506
|
|
|
private function build_data_ary($transaction_data) |
507
|
|
|
{ |
508
|
|
|
$errors = array(); |
509
|
|
|
|
510
|
|
|
if ($this->request->is_set('u') && $transaction_data['MT_USERNAME'] === '') |
511
|
|
|
{ |
512
|
|
|
$user_id = ANONYMOUS; |
513
|
|
|
} |
514
|
|
|
else |
515
|
|
|
{ |
516
|
|
|
$user_ary = $this->ppde_operator->query_donor_user_data('username', $transaction_data['MT_USERNAME']); |
517
|
|
|
|
518
|
|
|
if ($user_ary) |
519
|
|
|
{ |
520
|
|
|
$user_id = $user_ary['user_id']; |
521
|
|
|
} |
522
|
|
|
else |
523
|
|
|
{ |
524
|
|
|
$errors[] = $this->language->lang('PPDE_MT_DONOR_NOT_FOUND', $transaction_data['MT_USERNAME']); |
525
|
|
|
} |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
if ($transaction_data['MT_MC_GROSS'] <= 0) |
529
|
|
|
{ |
530
|
|
|
$errors[] = $this->language->lang('PPDE_MT_MC_GROSS_TOO_LOW'); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
if ($transaction_data['MT_MC_FEE'] < 0) |
534
|
|
|
{ |
535
|
|
|
$errors[] = $this->language->lang('PPDE_MT_MC_FEE_NEGATIVE'); |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
if ($transaction_data['MT_MC_FEE'] >= $transaction_data['MT_MC_GROSS']) |
539
|
|
|
{ |
540
|
|
|
$errors[] = $this->language->lang('PPDE_MT_MC_FEE_TOO_HIGH'); |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
$payment_date = implode('-', [ |
544
|
|
|
$transaction_data['MT_PAYMENT_DATE_YEAR'], |
545
|
|
|
$transaction_data['MT_PAYMENT_DATE_MONTH'], |
546
|
|
|
$transaction_data['MT_PAYMENT_DATE_DAY'], |
547
|
|
|
]); |
548
|
|
|
|
549
|
|
|
$payment_date_timestamp_at_midnight = $this->user->get_timestamp_from_format('Y-m-d H:i:s', $payment_date . ' 00:00:00'); |
550
|
|
|
|
551
|
|
|
if ($payment_date_timestamp_at_midnight === false) |
|
|
|
|
552
|
|
|
{ |
553
|
|
|
$errors[] = $this->language->lang('PPDE_MT_PAYMENT_DATE_ERROR', $payment_date); |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
$payment_time = $transaction_data['MT_PAYMENT_TIME']; |
557
|
|
|
$payment_time_timestamp = strtotime($payment_time); |
558
|
|
|
|
559
|
|
|
if ($payment_time_timestamp === false) |
560
|
|
|
{ |
561
|
|
|
$errors[] = $this->language->lang('PPDE_MT_PAYMENT_TIME_ERROR', $payment_time); |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
// Normalize payment time to start from today at midnight |
565
|
|
|
$payment_time_timestamp_from_midnight = $payment_time_timestamp - strtotime('00:00:00'); |
566
|
|
|
|
567
|
|
|
$payment_date_time = $payment_date_timestamp_at_midnight + $payment_time_timestamp_from_midnight; |
568
|
|
|
|
569
|
|
|
if ($payment_date_time > time()) |
570
|
|
|
{ |
571
|
|
|
$errors[] = $this->language->lang('PPDE_MT_PAYMENT_DATE_FUTURE', $this->user->format_date($payment_date_time)); |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
if ($errors) |
575
|
|
|
{ |
576
|
|
|
throw (new transaction_exception())->set_errors($errors); |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
return array( |
580
|
|
|
'business' => $this->config['ppde_account_id'], |
581
|
|
|
'confirmed' => true, |
582
|
|
|
'exchange_rate' => '', |
583
|
|
|
'first_name' => $transaction_data['MT_FIRST_NAME'], |
584
|
|
|
'item_name' => '', |
585
|
|
|
'item_number' => implode('_', ['uid', $user_id, time()]), |
|
|
|
|
586
|
|
|
'last_name' => $transaction_data['MT_LAST_NAME'], |
587
|
|
|
'mc_currency' => $transaction_data['MT_MC_CURRENCY'], |
588
|
|
|
'mc_gross' => $transaction_data['MT_MC_GROSS'], |
589
|
|
|
'mc_fee' => $transaction_data['MT_MC_FEE'], |
590
|
|
|
'net_amount' => (float) 0, // This value is calculated in core_actions:log_to_db() |
591
|
|
|
'parent_txn_id' => '', |
592
|
|
|
'payer_email' => $transaction_data['MT_PAYER_EMAIL'], |
593
|
|
|
'payer_id' => '', |
594
|
|
|
'payer_status' => '', |
595
|
|
|
'payment_date' => $payment_date_time, |
596
|
|
|
'payment_status' => 'Completed', |
597
|
|
|
'payment_type' => '', |
598
|
|
|
'memo' => $transaction_data['MT_MEMO'], |
599
|
|
|
'receiver_id' => '', |
600
|
|
|
'receiver_email' => '', |
601
|
|
|
'residence_country' => strtoupper($transaction_data['MT_RESIDENCE_COUNTRY']), |
602
|
|
|
'settle_amount' => (float) 0, |
603
|
|
|
'settle_currency' => '', |
604
|
|
|
'test_ipn' => false, |
605
|
|
|
'txn_errors' => '', |
606
|
|
|
'txn_id' => 'PPDE' . gen_rand_string(13), |
607
|
|
|
'txn_type' => 'ppde_manual_donation', |
608
|
|
|
'user_id' => $user_id, |
609
|
|
|
); |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
/** |
613
|
|
|
* Set log output vars for display in the template |
614
|
|
|
* |
615
|
|
|
* @param array $row |
616
|
|
|
* |
617
|
|
|
* @return void |
618
|
|
|
* @access protected |
619
|
|
|
*/ |
620
|
|
|
protected function display_log_assign_template_vars($row) |
621
|
|
|
{ |
622
|
|
|
$this->template->assign_block_vars('log', array( |
623
|
|
|
'CONFIRMED' => ($row['confirmed']) ? $this->language->lang('PPDE_DT_VERIFIED') : $this->language->lang('PPDE_DT_UNVERIFIED'), |
624
|
|
|
'DATE' => $this->user->format_date($row['payment_date']), |
625
|
|
|
'ID' => $row['transaction_id'], |
626
|
|
|
'PAYMENT_STATUS' => $this->language->lang(array('PPDE_DT_PAYMENT_STATUS_VALUES', strtolower($row['payment_status']))), |
627
|
|
|
'TNX_ID' => $row['txn_id'], |
628
|
|
|
'USERNAME' => $row['username_full'], |
629
|
|
|
'S_CONFIRMED' => (bool) $row['confirmed'], |
630
|
|
|
'S_PAYMENT_STATUS' => (strtolower($row['payment_status']) === 'completed') ? true : false, |
631
|
|
|
'S_TXN_ERRORS' => !empty($row['txn_errors']), |
632
|
|
|
'S_TEST_IPN' => (bool) $row['test_ipn'], |
633
|
|
|
)); |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
/** |
637
|
|
|
* Set output vars for display in the template |
638
|
|
|
* |
639
|
|
|
* @param array $data |
640
|
|
|
* |
641
|
|
|
* @return void |
642
|
|
|
* @access protected |
643
|
|
|
*/ |
644
|
|
|
protected function action_assign_template_vars($data) |
645
|
|
|
{ |
646
|
|
|
$s_hidden_fields = build_hidden_fields(array( |
647
|
|
|
'id' => $data['transaction_id'], |
648
|
|
|
'txn_errors_approved' => $data['txn_errors_approved'], |
649
|
|
|
)); |
650
|
|
|
|
651
|
|
|
$this->template->assign_vars(array( |
652
|
|
|
'BOARD_USERNAME' => get_username_string('full', $data['user_id'], $data['username'], $data['user_colour'], $this->language->lang('GUEST'), append_sid($this->phpbb_admin_path . 'index.' . $this->php_ext, 'i=users&mode=overview')), |
653
|
|
|
'EXCHANGE_RATE' => '1 ' . $data['mc_currency'] . ' = ' . $data['exchange_rate'] . ' ' . $data['settle_currency'], |
654
|
|
|
'ITEM_NAME' => $data['item_name'], |
655
|
|
|
'ITEM_NUMBER' => $data['item_number'], |
656
|
|
|
'MC_CURRENCY' => $data['net_amount'] . ' ' . $data['mc_currency'], |
657
|
|
|
'MC_GROSS' => $data['mc_gross'] . ' ' . $data['mc_currency'], |
658
|
|
|
'MC_FEE' => $data['mc_fee'] . ' ' . $data['mc_currency'], |
659
|
|
|
'MC_NET' => $data['net_amount'] . ' ' . $data['mc_currency'], |
660
|
|
|
'MEMO' => $data['memo'], |
661
|
|
|
'NAME' => $data['first_name'] . ' ' . $data['last_name'], |
662
|
|
|
'PAYER_EMAIL' => $data['payer_email'], |
663
|
|
|
'PAYER_ID' => $data['payer_id'], |
664
|
|
|
'PAYER_STATUS' => $data['payer_status'] ? $this->language->lang('PPDE_DT_VERIFIED') : $this->language->lang('PPDE_DT_UNVERIFIED'), |
665
|
|
|
'PAYMENT_DATE' => $this->user->format_date($data['payment_date']), |
666
|
|
|
'PAYMENT_STATUS' => $this->language->lang(array('PPDE_DT_PAYMENT_STATUS_VALUES', strtolower($data['payment_status']))), |
667
|
|
|
'RECEIVER_EMAIL' => $data['receiver_email'], |
668
|
|
|
'RECEIVER_ID' => $data['receiver_id'], |
669
|
|
|
'SETTLE_AMOUNT' => $data['settle_amount'] . ' ' . $data['settle_currency'], |
670
|
|
|
'TXN_ID' => $data['txn_id'], |
671
|
|
|
|
672
|
|
|
'L_PPDE_DT_SETTLE_AMOUNT' => $this->language->lang('PPDE_DT_SETTLE_AMOUNT', $data['settle_currency']), |
673
|
|
|
'L_PPDE_DT_EXCHANGE_RATE_EXPLAIN' => $this->language->lang('PPDE_DT_EXCHANGE_RATE_EXPLAIN', $this->user->format_date($data['payment_date'])), |
674
|
|
|
'S_CONVERT' => ($data['settle_amount'] == 0 && empty($data['exchange_rate'])) ? false : true, |
675
|
|
|
'S_ERROR' => !empty($data['txn_errors']), |
676
|
|
|
'S_ERROR_APPROVED' => !empty($data['txn_errors_approved']), |
677
|
|
|
'S_HIDDEN_FIELDS' => $s_hidden_fields, |
678
|
|
|
'ERROR_MSG' => (!empty($data['txn_errors'])) ? $data['txn_errors'] : '', |
679
|
|
|
)); |
680
|
|
|
} |
681
|
|
|
} |
682
|
|
|
|