forked from changi67/tiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiki-admin_credits.php
189 lines (159 loc) · 5.55 KB
/
tiki-admin_credits.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
/**
* @package tikiwiki
*/
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
require_once 'tiki-setup.php';
require_once 'lib/credits/creditslib.php';
//get_strings tra('Admin credits')
if ($tiki_p_admin_users != 'y') {
$smarty->assign('msg', tra('You do not have permission to use this feature'));
$smarty->display('error.tpl');
die;
}
if ( isset( $_REQUEST['use_credit'] ) && $use_credit_userid = $tikilib->get_user_id($_POST['userfilter']) ) {
$creditslib->useCredits(
$use_credit_userid,
$_POST['use_credit_type'],
$_POST['use_credit_amount']
);
header('Location: tiki-admin_credits.php?userfilter=' . urlencode($_REQUEST['userfilter']));
exit;
}
if ( isset( $_REQUEST['restore_credit'] ) && $restore_credit_userid = $tikilib->get_user_id($_POST['userfilter']) ) {
$creditslib->restoreCredits(
$restore_credit_userid,
$_POST['restore_credit_type'],
$_POST['restore_credit_amount']
);
header('Location: tiki-admin_credits.php?userfilter=' . urlencode($_REQUEST['userfilter']));
exit;
}
if ( isset( $_REQUEST['purge_credits'] ) ) {
$creditslib->purgeCredits();
header('Location: tiki-admin_credits.php');
exit;
}
if ( isset( $_REQUEST['update_types'] ) ) {
foreach ( $_POST['credit_types'] as $key => $values ) {
$creditslib->updateCreditType(
$values['credit_type'],
$values['display_text'],
$values['unit_text'],
$values['is_static_level'],
$values['scaling_divisor']
);
}
if ( !empty($_POST['new_credit_type']) ) {
$creditslib->updateCreditType(
$_POST['new_credit_type'],
$_POST['display_text'],
$_POST['unit_text'],
$_POST['is_static_level'],
$_POST['scaling_divisor']
);
}
}
$creditTypes = $creditslib->getCreditTypes();
$staticCreditTypes = $creditslib->getCreditTypes(true);
$smarty->assign('credit_types', $creditTypes);
$smarty->assign('static_credit_types', $staticCreditTypes);
if ( isset($_REQUEST['userfilter']) ) {
$smarty->assign('userfilter', $_REQUEST['userfilter']);
$editing = $userlib->get_user_info($_REQUEST['userfilter']);
if ( $editing ) {
$userPlans = array();
foreach ($creditTypes as $ct => $v) {
$userPlans[$ct]['nextbegin'] = $creditslib->getNextPlanBegin($editing['userId'], $ct);
$userPlans[$ct]['currentbegin'] = $creditslib->getLatestPlanBegin($editing['userId'], $ct);
$userPlans[$ct]['expiry'] = $creditslib->getPlanExpiry($editing['userId'], $ct);
}
$smarty->assign('userPlans', $userPlans);
$credits = $creditslib->getRawCredits($editing['userId']);
$smarty->assign('credits', $credits);
$smarty->assign('editing', $editing);
// Get usage information
// date values
if (isset($_REQUEST['startDate_Year']) || isset($_REQUEST['endDate_Year'])) {
$smarty->assign(
'startDate',
$tikilib->make_time(0, 0, 0, $_REQUEST['startDate_Month'], $_REQUEST['startDate_Day'], $_REQUEST['startDate_Year'])
);
$smarty->assign(
'endDate',
$tikilib->make_time(23, 59, 59, $_REQUEST['endDate_Month'], $_REQUEST['endDate_Day'], $_REQUEST['endDate_Year'])
);
$start_date = $_REQUEST['startDate_Year'] . '-' . $_REQUEST['startDate_Month'] . '-' . $_REQUEST['startDate_Day'];
$end_date = $_REQUEST['endDate_Year'] . '-' . $_REQUEST['endDate_Month'] . '-' . $_REQUEST['endDate_Day'] . ' 23:59:59';
} else {
$start_date = $tikilib->now - 3600 * 24 * 30;
$smarty->assign('startDate', $start_date);
$end_date = date('Y-m-d 23:59:59');
}
$req_type = $_REQUEST['action_type'];
$smarty->assign('act_type', $req_type);
$consumption_data = $creditslib->getCreditsUsage($editing['userId'], $req_type, $start_date, $end_date);
$smarty->assign('consumption_data', $consumption_data);
if ( isset( $_POST['save'], $_POST['credits'] ) ) {
foreach ( $_POST['credits'] as $key => $values ) {
if ( ! isset( $credits[$key] ) )
die('Mismatch');
$same = true;
$current = $credits[$key];
foreach ( $current as $field => $value )
if ( $field != 'creditId' && $value != $values[$field] ) {
$same = false;
break;
}
if ( ! $same ) {
$creditslib->replaceCredit(
$key,
$values['credit_type'],
$values['used_amount'],
$values['total_amount'],
$values['creation_date'],
$values['expiration_date']
);
}
}
if ( !empty($_POST['credit_type'])
&& !empty( $_POST['total_amount'])
&& in_array($_POST['credit_type'], array_keys($creditTypes))
) {
$creditslib->addCredits(
$editing['userId'],
$_POST['credit_type'],
$_POST['total_amount'],
$_POST['expiration_date'],
$_POST['creation_date']
);
}
header('Location: tiki-admin_credits.php?userfilter=' . urlencode($_REQUEST['userfilter']));
exit;
}
if ( !empty($_POST['credit_type']) && !empty($_POST['total_amount']) ) {
$creditslib->addCredits(
$editing['userId'],
$_POST['credit_type'],
$_POST['total_amount'],
$_POST['expiration_date'],
$_POST['creation_date']
);
header('Location: tiki-admin_credits.php?userfilter=' . urlencode($_REQUEST['userfilter']));
exit;
}
if ( isset($_POST['confirm'], $_POST['delete']) ) {
foreach ( $_POST['delete'] as $creditId )
if ( isset($credits[$creditId]) )
$creditslib->removeCreditBlock($creditId);
header('Location: tiki-admin_credits.php?userfilter=' . urlencode($_REQUEST['userfilter']));
exit;
}
}
}
$smarty->assign('mid', 'tiki-admin_credits.tpl');
$smarty->display('tiki.tpl');