|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Planet\DBStaticPlanet; |
|
4
|
|
|
use Player\RecordPlayer; |
|
5
|
|
|
use Unit\DBStaticUnit; |
|
6
|
|
|
|
|
7
|
|
|
define('INSIDE', true); |
|
8
|
|
|
define('INSTALL', false); |
|
9
|
|
|
define('IN_ADMIN', true); |
|
10
|
|
|
|
|
11
|
|
|
require('../common.' . substr(strrchr(__FILE__, '.'), 1)); |
|
12
|
|
|
|
|
13
|
|
|
global $lang, $user; |
|
14
|
|
|
|
|
15
|
|
|
SnTemplate::messageBoxAdminAccessDenied(AUTH_LEVEL_ADMINISTRATOR); |
|
16
|
|
|
|
|
17
|
|
|
//messageBoxAdmin('Временно не работает'); |
|
18
|
|
|
|
|
19
|
|
|
require("includes/admin_planet_edit.inc" . DOT_PHP_EX); |
|
20
|
|
|
|
|
21
|
|
|
$template = SnTemplate::gettemplate('admin/admin_planet_edit', true); |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
$mode = admin_planet_edit_mode($template, $admin_planet_edit_mode_list); |
|
24
|
|
|
$planet_id = sys_get_param_id('planet_id'); |
|
25
|
|
|
|
|
26
|
|
|
$unit_list = sys_get_param('unit_list'); |
|
27
|
|
|
if (sys_get_param('change_data') && !empty($unit_list)) { |
|
28
|
|
|
planet_edit_model($planet_id, $unit_list, $mode); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
if ($planet_id) { |
|
32
|
|
|
$edit_planet_row = DBStaticPlanet::db_planet_by_id($planet_id); |
|
|
|
|
|
|
33
|
|
|
admin_planet_edit_template($template, $edit_planet_row, $mode); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
foreach ($admin_planet_edit_mode_list as $page_mode => $mode_locale) { |
|
37
|
|
|
$template->assign_block_vars('page_menu', array( |
|
38
|
|
|
'ID' => $page_mode, |
|
39
|
|
|
'TEXT' => $mode_locale, |
|
40
|
|
|
)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$template->assign_vars(array( |
|
44
|
|
|
'MODE' => $mode, |
|
45
|
|
|
'PLANET_ID' => $planet_id, |
|
46
|
|
|
'PLANET_NAME' => empty($edit_planet_row) ? '' : $lang['sys_planet_type'][$edit_planet_row['planet_type']] . ' ' . uni_render_planet($edit_planet_row), |
|
47
|
|
|
'PAGE_HINT' => $lang['adm_planet_edit_hint'], |
|
48
|
|
|
)); |
|
49
|
|
|
|
|
50
|
|
|
SnTemplate::display($template, $lang['adm_am_ttle']); |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param $planet_id |
|
55
|
|
|
* @param array $unit_list |
|
56
|
|
|
* @param $mode |
|
57
|
|
|
*/ |
|
58
|
|
|
function planet_edit_model($planet_id, array $unit_list, $mode) { |
|
59
|
|
|
$thePlanet = DBStaticPlanet::db_planet_by_id($planet_id); |
|
60
|
|
|
$theUserId = $thePlanet['id_owner']; |
|
61
|
|
|
$thePlayer = RecordPlayer::findRecordById($theUserId); |
|
62
|
|
|
|
|
63
|
|
|
$query_string = []; |
|
64
|
|
|
foreach ($unit_list as $unit_id => $unit_amount) { |
|
65
|
|
|
if ($mode === 'resources_loot') { |
|
66
|
|
|
if (!floatval($unit_amount)) { |
|
67
|
|
|
continue; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if ($unit_query_string = admin_planet_edit_query_string($unit_id, $unit_amount, $mode)) { |
|
71
|
|
|
$query_string[] = $unit_query_string; |
|
72
|
|
|
} |
|
73
|
|
|
} elseif (in_array($mode, [UNIT_SHIPS_STR, UNIT_STRUCTURES_STR, UNIT_DEFENCE_STR,]) ) { |
|
74
|
|
|
if (!floatval($unit_amount)) { |
|
75
|
|
|
continue; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$currentAmount = mrc_get_level($thePlayer, $thePlanet, $unit_id); |
|
79
|
|
|
|
|
80
|
|
|
$newAmount = $currentAmount + $unit_amount; |
|
81
|
|
|
|
|
82
|
|
|
if ($newAmount <= 0) { |
|
83
|
|
|
DBStaticUnit::db_unit_list_delete($theUserId, LOC_PLANET, $planet_id, $unit_id); |
|
84
|
|
|
} else { |
|
85
|
|
|
DBStaticUnit::dbChangeUnit($theUserId, $planet_id, $unit_id, $unit_amount); |
|
86
|
|
|
|
|
87
|
|
|
DBStaticUnit::cache_clear(); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
if (!empty($query_string)) { |
|
94
|
|
|
DBStaticPlanet::db_planet_set_by_id($planet_id, implode(', ', $query_string)); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|