Passed
Pull Request — develop-3.2.x (#66)
by
unknown
02:09
created

admin_transactions_controller::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 21
nc 1
nop 16
dl 0
loc 23
rs 9.584
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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) ? '&amp;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 . '&amp;' . $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 . '&amp;' . $u_sort_param . $keywords_param . '&amp;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
						$this->ppde_actions->log_to_db($data_ary);
337
338
						$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_PPDE_MT_ADDED', array($transaction_data['MT_USERNAME']));
339
						trigger_error($this->language->lang('PPDE_MT_ADDED') . adm_back_link($this->u_action));
340
					}
341
					catch (transaction_exception $e)
342
					{
343
						$errors = $e->get_errors();
344
					}
345
				}
346
347
				$this->ppde_actions_currency->build_currency_select_menu($this->config['ppde_default_currency']);
0 ignored issues
show
Bug introduced by
$this->config['ppde_default_currency'] of type string is incompatible with the type integer expected by parameter $config_value of skouat\ppde\actions\curr..._currency_select_menu(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

347
				$this->ppde_actions_currency->build_currency_select_menu(/** @scrutinizer ignore-type */ $this->config['ppde_default_currency']);
Loading history...
348
349
				$this->s_error_assign_template_vars($errors);
350
351
				$this->template->assign_vars($transaction_data);
352
353
				$this->template->assign_vars(array(
354
					'U_ACTION'           => $this->u_action,
355
					'U_BACK'             => $this->u_action,
356
					'S_ADD'              => true,
357
					'ANONYMOUS_USER_ID'  => ANONYMOUS,
358
					'U_FIND_USERNAME'    => append_sid($this->phpbb_root_path . 'memberlist.' . $this->php_ext, 'mode=searchuser&amp;form=manual_transaction&amp;field=username&amp;select_single=true'),
359
				));
360
			break;
361
		}
362
363
		return $action;
364
	}
365
366
	/**
367
	 * View log
368
	 *
369
	 * @param array  &$log         The result array with the logs
370
	 * @param mixed  &$log_count   If $log_count is set to false, we will skip counting all entries in the
371
	 *                             database. Otherwise an integer with the number of total matching entries is returned.
372
	 * @param int     $limit       Limit the number of entries that are returned
373
	 * @param int     $offset      Offset when fetching the log entries, f.e. when paginating
374
	 * @param int     $limit_days
375
	 * @param string  $sort_by     SQL order option, e.g. 'l.log_time DESC'
376
	 * @param string  $keywords    Will only return log entries that have the keywords in log_operation or log_data
377
	 *
378
	 * @return int Returns the offset of the last valid page, if the specified offset was invalid (too high)
379
	 * @access private
380
	 */
381
	private function view_txn_log(&$log, &$log_count, $limit = 0, $offset = 0, $limit_days = 0, $sort_by = 'txn.payment_date DESC', $keywords = '')
382
	{
383
		$count_logs = ($log_count !== false);
384
385
		$log = $this->get_logs($count_logs, $limit, $offset, $limit_days, $sort_by, $keywords);
386
		$log_count = $this->get_log_count();
387
388
		return $this->get_valid_offset();
389
	}
390
391
	/**
392
	 * @param bool   $count_logs
393
	 * @param int    $limit
394
	 * @param int    $offset
395
	 * @param int    $log_time
396
	 * @param string $sort_by
397
	 * @param string $keywords
398
	 *
399
	 * @return array $log
400
	 * @access private
401
	 */
402
	private function get_logs($count_logs = true, $limit = 0, $offset = 0, $log_time = 0, $sort_by = 'txn.payment_date DESC', $keywords = '')
403
	{
404
		$this->entry_count = 0;
405
		$this->last_page_offset = $offset;
406
		$url_ary = array();
407
408
		if ($this->get_container_entity()->is_in_admin() && $this->phpbb_admin_path)
409
		{
410
			$url_ary['profile_url'] = append_sid($this->phpbb_admin_path . 'index.' . $this->php_ext, 'i=users&amp;mode=overview');
411
			$url_ary['txn_url'] = append_sid($this->phpbb_admin_path . 'index.' . $this->php_ext, 'i=-skouat-ppde-acp-ppde_module&amp;mode=transactions');
412
413
		}
414
		else
415
		{
416
			$url_ary['profile_url'] = append_sid($this->phpbb_root_path . 'memberlist.' . $this->php_ext, 'mode=viewprofile');
417
			$url_ary['txn_url'] = '';
418
		}
419
420
		$get_logs_sql_ary = $this->ppde_operator->get_logs_sql_ary($keywords, $sort_by, $log_time);
421
422
		if ($count_logs)
423
		{
424
			$this->entry_count = $this->ppde_operator->query_sql_count($get_logs_sql_ary, 'txn.transaction_id');
425
426
			if ($this->entry_count == 0)
427
			{
428
				// Save the queries, because there are no logs to display
429
				$this->last_page_offset = 0;
430
431
				return array();
432
			}
433
434
			// Return the user to the last page that is valid
435
			while ($this->last_page_offset >= $this->entry_count)
436
			{
437
				$this->last_page_offset = max(0, $this->last_page_offset - $limit);
438
			}
439
		}
440
441
		return $this->ppde_operator->build_log_ary($get_logs_sql_ary, $url_ary, $limit, $this->last_page_offset);
442
	}
443
444
	/**
445
	 * @return integer
446
	 */
447
	public function get_log_count()
448
	{
449
		return ($this->entry_count) ? (int) $this->entry_count : 0;
450
	}
451
452
	/**
453
	 * @return integer
454
	 */
455
	public function get_valid_offset()
456
	{
457
		return ($this->last_page_offset) ? (int) $this->last_page_offset : 0;
458
	}
459
460
	/**
461
	 * Prepare data array() before send it to $entity
462
	 *
463
	 * @param array $transaction_data
464
	 *
465
	 * @return array
466
	 * @throws transaction_exception
467
	 */
468
	private function build_data_ary($transaction_data)
469
	{
470
		$errors = array();
471
472
		if ($this->request->is_set('u' && $transaction_data['MT_USERNAME'] === ''))
473
		{
474
			$user_id = ANONYMOUS;
475
		}
476
		else
477
		{
478
			$user_ary = $this->ppde_operator->query_donor_user_data('username', $transaction_data['MT_USERNAME']);
479
480
			if (!$user_ary)
481
			{
482
				$errors[] = $this->language->lang('PPDE_MT_DONOR_NOT_FOUND', $transaction_data['MT_USERNAME']);
483
			}
484
485
			$user_id = $user_ary['user_id'];
486
		}
487
488
		$payment_date = implode('-', [
489
			$transaction_data['MT_PAYMENT_DATE_YEAR'],
490
			$transaction_data['MT_PAYMENT_DATE_MONTH'],
491
			$transaction_data['MT_PAYMENT_DATE_DAY'],
492
		]);
493
494
		$payment_date_timestamp_at_midnight = $this->user->get_timestamp_from_format('Y-m-d H:i:s', $payment_date . ' 00:00:00');
495
496
		if ($payment_date_timestamp_at_midnight === false)
0 ignored issues
show
introduced by
The condition $payment_date_timestamp_at_midnight === false is always false.
Loading history...
497
		{
498
			$errors[] = $this->language->lang('PPDE_MT_PAYMENT_DATE_ERROR', $payment_date);
499
		}
500
501
		$payment_time = $transaction_data['MT_PAYMENT_TIME'];
502
		$payment_time_timestamp = strtotime($payment_time);
503
504
		if ($payment_time_timestamp === false)
505
		{
506
			$errors[] = $this->language->lang('PPDE_MT_PAYMENT_TIME_ERROR', $payment_time);
507
		}
508
509
		// Normalize payment time to start from today at midnight
510
		$payment_time_timestamp_from_midnight = $payment_time_timestamp - strtotime('00:00:00');
511
512
		if ($errors)
513
		{
514
			throw (new transaction_exception())->set_errors($errors);
515
		}
516
517
		return array(
518
			'business'          => $this->config['ppde_account_id'],
519
			'confirmed'         => true,
520
			'exchange_rate'     => '',
521
			'first_name'        => $transaction_data['MT_FIRST_NAME'],
522
			'item_name'         => '',
523
			'item_number'       => implode('_', ['uid', $user_id, time()]),
524
			'last_name'         => $transaction_data['MT_LAST_NAME'],
525
			'mc_currency'       => $transaction_data['MT_MC_CURRENCY'],
526
			'mc_gross'          => $transaction_data['MT_MC_GROSS'],
527
			'mc_fee'            => $transaction_data['MT_MC_FEE'],
528
			'net_amount'        => (float) 0, // This value is calculated in core_actions:log_to_db()
529
			'parent_txn_id'     => '',
530
			'payer_email'       => $transaction_data['MT_PAYER_EMAIL'],
531
			'payer_id'          => '',
532
			'payer_status'      => '',
533
			'payment_date'      => $payment_date_timestamp_at_midnight + $payment_time_timestamp_from_midnight,
534
			'payment_status'    => 'Completed',
535
			'payment_type'      => '',
536
			'memo'              => $transaction_data['MT_MEMO'],
537
			'receiver_id'       => '',
538
			'receiver_email'    => '',
539
			'residence_country' => $transaction_data['MT_RESIDENCE_COUNTRY'],
540
			'settle_amount'     => (float) 0,
541
			'settle_currency'   => '',
542
			'test_ipn'          => false,
543
			'txn_errors'        => '',
544
			'txn_id'            => 'PPDE' . gen_rand_string(13),
545
			'txn_type'          => '',
546
			'user_id'           => $user_id,
547
		);
548
	}
549
550
	/**
551
	 * Set log output vars for display in the template
552
	 *
553
	 * @param array $row
554
	 *
555
	 * @return void
556
	 * @access protected
557
	 */
558
	protected function display_log_assign_template_vars($row)
559
	{
560
		$this->template->assign_block_vars('log', array(
561
			'CONFIRMED'        => ($row['confirmed']) ? $this->language->lang('PPDE_DT_VERIFIED') : $this->language->lang('PPDE_DT_UNVERIFIED'),
562
			'DATE'             => $this->user->format_date($row['payment_date']),
563
			'ID'               => $row['transaction_id'],
564
			'PAYMENT_STATUS'   => $this->language->lang(array('PPDE_DT_PAYMENT_STATUS_VALUES', strtolower($row['payment_status']))),
565
			'TNX_ID'           => $row['txn_id'],
566
			'USERNAME'         => $row['username_full'],
567
			'S_CONFIRMED'      => (bool) $row['confirmed'],
568
			'S_PAYMENT_STATUS' => (strtolower($row['payment_status']) === 'completed') ? true : false,
569
			'S_TXN_ERRORS'     => !empty($row['txn_errors']),
570
			'S_TEST_IPN'       => (bool) $row['test_ipn'],
571
		));
572
	}
573
574
	/**
575
	 * Set output vars for display in the template
576
	 *
577
	 * @param array $data
578
	 *
579
	 * @return void
580
	 * @access protected
581
	 */
582
	protected function action_assign_template_vars($data)
583
	{
584
		$s_hidden_fields = build_hidden_fields(array(
585
			'id'                  => $data['transaction_id'],
586
			'txn_errors_approved' => $data['txn_errors_approved'],
587
		));
588
589
		$this->template->assign_vars(array(
590
			'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&amp;mode=overview')),
591
			'EXCHANGE_RATE'  => '1 ' . $data['mc_currency'] . ' = ' . $data['exchange_rate'] . ' ' . $data['settle_currency'],
592
			'ITEM_NAME'      => $data['item_name'],
593
			'ITEM_NUMBER'    => $data['item_number'],
594
			'MC_CURRENCY'    => $data['net_amount'] . ' ' . $data['mc_currency'],
595
			'MC_GROSS'       => $data['mc_gross'] . ' ' . $data['mc_currency'],
596
			'MC_FEE'         => $data['mc_fee'] . ' ' . $data['mc_currency'],
597
			'MC_NET'         => $data['net_amount'] . ' ' . $data['mc_currency'],
598
			'MEMO'           => $data['memo'],
599
			'NAME'           => $data['first_name'] . ' ' . $data['last_name'],
600
			'PAYER_EMAIL'    => $data['payer_email'],
601
			'PAYER_ID'       => $data['payer_id'],
602
			'PAYER_STATUS'   => $data['payer_status'] ? $this->language->lang('PPDE_DT_VERIFIED') : $this->language->lang('PPDE_DT_UNVERIFIED'),
603
			'PAYMENT_DATE'   => $this->user->format_date($data['payment_date']),
604
			'PAYMENT_STATUS' => $this->language->lang(array('PPDE_DT_PAYMENT_STATUS_VALUES', strtolower($data['payment_status']))),
605
			'RECEIVER_EMAIL' => $data['receiver_email'],
606
			'RECEIVER_ID'    => $data['receiver_id'],
607
			'SETTLE_AMOUNT'  => $data['settle_amount'] . ' ' . $data['settle_currency'],
608
			'TXN_ID'         => $data['txn_id'],
609
610
			'L_PPDE_DT_SETTLE_AMOUNT'         => $this->language->lang('PPDE_DT_SETTLE_AMOUNT', $data['settle_currency']),
611
			'L_PPDE_DT_EXCHANGE_RATE_EXPLAIN' => $this->language->lang('PPDE_DT_EXCHANGE_RATE_EXPLAIN', $this->user->format_date($data['payment_date'])),
612
			'S_CONVERT'                       => ($data['settle_amount'] == 0 && empty($data['exchange_rate'])) ? false : true,
613
			'S_ERROR'                         => !empty($data['txn_errors']),
614
			'S_ERROR_APPROVED'                => !empty($data['txn_errors_approved']),
615
			'S_HIDDEN_FIELDS'                 => $s_hidden_fields,
616
			'ERROR_MSG'                       => (!empty($data['txn_errors'])) ? $data['txn_errors'] : '',
617
		));
618
	}
619
}
620