1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * admin_darkmatter.php |
||||
5 | * |
||||
6 | * Adjust Dark Matter quantity |
||||
7 | * |
||||
8 | * @version 2.0 (c) copyright 2010-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 | SnTemplate::messageBoxAdminAccessDenied(AUTH_LEVEL_ADMINISTRATOR); |
||||
21 | |||||
22 | /** |
||||
23 | * @param $lang |
||||
24 | * @param $user |
||||
25 | * |
||||
26 | * @throws ExceptionSnLocalized |
||||
27 | * |
||||
28 | */ |
||||
29 | function admin_dark_matter_model($lang, $user) { |
||||
30 | $points = sys_get_param_float('points'); |
||||
31 | $reason_unsafe = sys_get_param_str_unsafe('reason'); |
||||
32 | $playerIdOrName_unsafe = sys_get_param_str_unsafe('playerId'); |
||||
33 | |||||
34 | // If no points and no username - nothing to do |
||||
35 | if (!$points && !$playerIdOrName_unsafe) { |
||||
36 | return; |
||||
37 | } |
||||
38 | |||||
39 | if (!$points) { |
||||
40 | throw new ExceptionSnLocalized('adm_dm_no_quant', ERR_ERROR); |
||||
41 | } |
||||
42 | if (empty($playerIdOrName_unsafe)) { |
||||
43 | throw new ExceptionSnLocalized('adm_dm_no_dest', ERR_ERROR); |
||||
44 | } |
||||
45 | |||||
46 | $row = dbPlayerByIdOrName($playerIdOrName_unsafe); |
||||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||||
47 | if (empty($row['id'])) { |
||||
48 | throw new ExceptionSnLocalized('adm_dm_user_none', ERR_ERROR, null, array($playerIdOrName_unsafe)); |
||||
49 | } |
||||
50 | |||||
51 | // Does anything post to DB? |
||||
52 | if (!rpg_points_change( |
||||
53 | $row['id'], |
||||
54 | RPG_ADMIN, |
||||
55 | $points, |
||||
56 | sprintf($lang['adm_matter_change_log_record'], $row['id'], $row['username'], $user['id'], $user['username'], $reason_unsafe) |
||||
57 | ) |
||||
58 | ) { |
||||
59 | // No? We will say it to user... |
||||
60 | throw new ExceptionSnLocalized('adm_dm_add_err', ERR_ERROR); |
||||
61 | } |
||||
62 | |||||
63 | throw new ExceptionSnLocalized( |
||||
64 | 'adm_dm_user_added', |
||||
65 | ERR_NONE, |
||||
66 | null, |
||||
67 | array($row['username'], $row['id'], HelperString::numberFloorAndFormat($points)) |
||||
68 | ); |
||||
69 | } |
||||
70 | |||||
71 | |||||
72 | /** |
||||
73 | * @param $template |null $template |
||||
0 ignored issues
–
show
|
|||||
74 | */ |
||||
75 | function admin_dark_matter_view($template = null) { |
||||
0 ignored issues
–
show
The parameter
$template is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
76 | global $user, $lang; |
||||
77 | |||||
78 | $playerIdOrName_unsafe = sys_get_param_str_unsafe('playerId'); |
||||
79 | $points = sys_get_param_float('points'); |
||||
80 | $reason_unsafe = sys_get_param_str_unsafe('reason'); |
||||
81 | |||||
82 | $template = SnTemplate::gettemplate("admin/admin_darkmatter", true); |
||||
0 ignored issues
–
show
true of type true is incompatible with the type null|template expected by parameter $template of SnTemplate::gettemplate() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
83 | |||||
84 | try { |
||||
85 | admin_dark_matter_model($lang, $user); |
||||
86 | } catch (ExceptionSnLocalized $e) { |
||||
87 | $template->assign_block_vars('result', array( |
||||
88 | 'MESSAGE' => $e->getMessageLocalized(), |
||||
89 | 'STATUS' => $e->getCode() ? $e->getCode() : ERR_NONE, |
||||
90 | )); |
||||
91 | |||||
92 | if ($e->getCode() != ERR_NONE) { |
||||
93 | $template->assign_vars(array( |
||||
94 | 'PLAYER_ID' => sys_safe_output($playerIdOrName_unsafe), |
||||
95 | 'POINTS' => $points, |
||||
96 | 'REASON' => sys_safe_output($reason_unsafe), |
||||
97 | )); |
||||
98 | }; |
||||
99 | |||||
100 | } |
||||
101 | |||||
102 | SnTemplate::display($template, $lang['adm_dm_title']); |
||||
103 | |||||
104 | return $template; |
||||
105 | } |
||||
106 | |||||
107 | admin_dark_matter_view(); |
||||
108 |