-
Notifications
You must be signed in to change notification settings - Fork 24
/
transaction_log.php
89 lines (66 loc) · 2.49 KB
/
transaction_log.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
<?php
require_once(__DIR__.'/global.php');
if (!UserConfig::$useSubscriptions) {
header('Location: '.UserConfig::$DEFAULTLOGOUTRETURN);
exit;
}
$user = User::require_login();
$account = Account::getCurrentAccount($user);
$template_info = StartupAPI::getTemplateInfo();
$template_info['account_name'] = $account->getName();
if ($account->getUserRole($user) !== Account::ROLE_ADMIN) {
header('Location: '.UserConfig::$DEFAULTLOGOUTRETURN);
exit;
}
# This view depends on request parameters
$date = array();
$date['from'] = isset($_REQUEST['from']) && $_REQUEST['from'] != '' ? $_REQUEST['from'] : NULL;
$date['to'] = isset($_REQUEST['to']) && $_REQUEST['to'] != '' ? $_REQUEST['to'] : NULL;
$message = array();
$tms = array();
foreach($date as $k => $v) {
if(is_null($v)) continue;
if(preg_match("/^(?:(\d{1,2})\/(\d{1,2})\/(\d{4})|(\d{4})-(\d{1,2})-(\d{1,2}))$/",$date[$k],$m)) {
foreach(array(1,2,5,6) as $i)
if(strlen($m[$i]) == 1 && $m[$i] < 10) $m[$i] = '0'.$m[$i];
$date[$k] = $m[1] != '' ? $m[3].'-'.$m[1].'-'.$m[2] : $m[4].'-'.$m[5].'-'.$m[6];
$tms[$k] = $m[1] != '' ? $m[3].$m[1].$m[2] : $m[4].$m[5].$m[6];
} else {
$message[] = "Can't parse '".$k."' date '".$date[$k]."'";
}
}
if(count($message)) {
$template_info['fatal'] = 1;
$template_info['message'] = $message;
return;
}
if(isset($tms['from'],$tms['to']) && $tms['from'] > $tms['to']) {
$d = $date['from'];
$date['from'] = $date['to'];
$date['to'] = $d;
}
$template_info['from'] = $date['from'];
$template_info['to'] = $date['to'];
$from_to = (is_null($date['from']) ? '' : '&from='.$date['from']).(is_null($date['to']) ? '' : '&to='.$date['to']);
$template_info['from_to'] = $from_to;
# Pagination
$perpage = 5;
$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 0;
$offset = $page * $perpage;
$template_info['perpage'] = $perpage;
$template_info['page'] = $page;
$log = TransactionLogger::getAccountTransactions($account->getID(),$date['from'],$date['to'], false, $perpage,$offset);
# Cheating on payment modules :)
$mods = array();
foreach(UserConfig::$payment_modules as $pm)
$mods[$pm->getID()] = $pm->getTitle();
foreach($log as $k => $l) {
if(array_key_exists($l['engine_slug'],$mods))
$log[$k]['engine_slug'] = $mods[$l['engine_slug']];
else
$log[$k]['engine_slug'] = '';
}
$template_info['log'] = $log;
// setting section value
$template_info['PAGE']['SECTION'] = 'transaction_log';
StartupAPI::$template->display('@startupapi/account/transaction_log.html.twig', $template_info);