1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* adm_meta_matter.php |
5
|
|
|
* |
6
|
|
|
* Adjust Meta Matter quantity |
7
|
|
|
* |
8
|
|
|
* @version 2.0 (c) copyright 2013-2017 by Gorlum for http://supernova.ws |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
use Common\Exceptions\ExceptionSnLocalized; |
13
|
|
|
|
14
|
|
|
define('INSIDE', true); |
15
|
|
|
define('INSTALL', false); |
16
|
|
|
define('IN_ADMIN', true); |
17
|
|
|
|
18
|
|
|
require('../common.' . substr(strrchr(__FILE__, '.'), 1)); |
19
|
|
|
|
20
|
|
|
if(!SN::$gc->modules->countModulesInGroup('payment')) { |
21
|
|
|
sys_redirect(SN_ROOT_VIRTUAL . 'admin/overview.php'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
SnTemplate::messageBoxAdminAccessDenied(AUTH_LEVEL_ADMINISTRATOR); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param classLocale $lang |
28
|
|
|
* @param array $user |
29
|
|
|
* @param string $accountIdOrName_unsafe |
30
|
|
|
* @param string $playerIdOrName_unsafe |
31
|
|
|
* @param float $points |
32
|
|
|
* @param string $reason_unsafe |
33
|
|
|
* @param bool $confirmed |
34
|
|
|
* |
35
|
|
|
* @throws ExceptionSnLocalized |
36
|
|
|
*/ |
37
|
|
|
function admin_meta_matter_model($lang, $user, $accountIdOrName_unsafe, $playerIdOrName_unsafe, $points, $reason_unsafe, $confirmed) { |
38
|
|
|
// If no points and no username - nothing to do |
39
|
|
|
if (!$points && !$playerIdOrName_unsafe && !$accountIdOrName_unsafe) { |
40
|
|
|
return; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if (!$points) { |
44
|
|
|
throw new ExceptionSnLocalized('adm_mm_err_points_empty', ERR_ERROR); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$account = new Account(SN::$auth->account->db); |
48
|
|
|
|
49
|
|
|
if (!empty($accountIdOrName_unsafe)) { |
50
|
|
|
if ( |
51
|
|
|
!$account->db_get_by_id($accountIdOrName_unsafe) |
52
|
|
|
&& |
53
|
|
|
!$account->db_get_by_name($accountIdOrName_unsafe) |
54
|
|
|
&& |
55
|
|
|
!$account->db_get_by_email($accountIdOrName_unsafe) |
56
|
|
|
) { |
57
|
|
|
throw new ExceptionSnLocalized('adm_mm_err_account_not_found', ERR_ERROR); |
58
|
|
|
} |
59
|
|
|
} elseif (!empty($playerIdOrName_unsafe)) { |
60
|
|
|
$row = dbPlayerByIdOrName($playerIdOrName_unsafe); |
|
|
|
|
61
|
|
|
if (empty($row['id'])) { |
62
|
|
|
throw new ExceptionSnLocalized('adm_mm_err_player_not_found', ERR_ERROR, null, array($playerIdOrName_unsafe)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (!$account->dbGetByPlayerId($row['id'])) { |
66
|
|
|
throw new ExceptionSnLocalized('adm_mm_err_player_no_account', ERR_ERROR, null, array($playerIdOrName_unsafe)); |
67
|
|
|
} |
68
|
|
|
} else { |
69
|
|
|
throw new ExceptionSnLocalized('adm_mm_err_account_and_player_empty', ERR_ERROR); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$sprintfPayload = array( |
73
|
|
|
$account->account_name, |
74
|
|
|
$account->account_id, |
75
|
|
|
HelperString::numberFloorAndFormat($points), |
76
|
|
|
!empty($row['id']) ? $row['id'] : 0, |
77
|
|
|
!empty($row['username']) ? $row['username'] : '' |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
if ($confirmed) { |
81
|
|
|
if (empty($account->metamatter_change( |
82
|
|
|
RPG_ADMIN, |
83
|
|
|
$points, |
84
|
|
|
sprintf( |
85
|
|
|
$lang['adm_mm_msg_change_mm_log_record'], |
86
|
|
|
$account->account_id, |
87
|
|
|
$account->account_name, |
88
|
|
|
$user['id'], |
89
|
|
|
$user['username'], |
90
|
|
|
$reason_unsafe, |
91
|
|
|
core_auth::$main_provider->account->account_id, |
92
|
|
|
core_auth::$main_provider->account->account_name, |
93
|
|
|
!empty($row['id']) ? $row['id'] : 0, |
94
|
|
|
!empty($row['username']) ? $row['username'] : '' |
95
|
|
|
) |
96
|
|
|
))) { |
97
|
|
|
throw new ExceptionSnLocalized($lang['adm_mm_err_mm_change_failed'], ERR_ERROR); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
throw new ExceptionSnLocalized('adm_mm_msg_mm_changed', ERR_NONE, null, $sprintfPayload); |
101
|
|
|
} else { |
102
|
|
|
throw new ExceptionSnLocalized('adm_mm_msg_confirm_mm_change', ERR_WARNING, null, $sprintfPayload); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param array $user |
110
|
|
|
* @param classLocale $lang |
111
|
|
|
*/ |
112
|
|
|
function admin_meta_matter_view($user, $lang) { |
113
|
|
|
$accountIdOrName_unsafe = sys_get_param_str_unsafe('accountId'); |
114
|
|
|
$playerIdOrName_unsafe = sys_get_param_str_unsafe('playerId'); |
115
|
|
|
$points = sys_get_param_float('points'); |
116
|
|
|
$reason_unsafe = sys_get_param_str_unsafe('reason'); |
117
|
|
|
$confirmed = sys_get_param('confirm_mm_change'); |
118
|
|
|
$confirmed = !empty($confirmed); // can't use empty() or isset() with function result in PHP 5.3 |
119
|
|
|
|
120
|
|
|
$template = SnTemplate::gettemplate("admin/adm_metamatter", true); |
|
|
|
|
121
|
|
|
|
122
|
|
|
try { |
123
|
|
|
admin_meta_matter_model($lang, $user, $accountIdOrName_unsafe, $playerIdOrName_unsafe, $points, $reason_unsafe, $confirmed); |
124
|
|
|
} catch (ExceptionSnLocalized $e) { |
125
|
|
|
$template->assign_block_vars('result', array( |
126
|
|
|
'MESSAGE' => $e->getMessageLocalized(), |
127
|
|
|
'STATUS' => $e->getCode() ? $e->getCode() : ERR_NONE, |
128
|
|
|
)); |
129
|
|
|
|
130
|
|
|
if ($e->getCode() != ERR_NONE) { |
131
|
|
|
$template->assign_vars(array( |
132
|
|
|
'ACCOUNT_ID' => sys_safe_output($accountIdOrName_unsafe), |
133
|
|
|
'PLAYER_ID' => sys_safe_output($playerIdOrName_unsafe), |
134
|
|
|
'POINTS' => $points, |
135
|
|
|
'REASON' => sys_safe_output($reason_unsafe), |
136
|
|
|
)); |
137
|
|
|
}; |
138
|
|
|
|
139
|
|
|
if ($e->getCode() == ERR_WARNING) { |
140
|
|
|
$template->assign_vars(array( |
141
|
|
|
'NEED_CONFIRMATION' => 1, |
142
|
|
|
)); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
SnTemplate::display($template, $lang['adm_dm_title']); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
global $user, $lang; |
150
|
|
|
|
151
|
|
|
admin_meta_matter_view($user, $lang); |
152
|
|
|
|