Completed
Push — work-fleets ( 21e5a3...e0f70d )
by SuperNova.WS
05:07
created

overview.php (9 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * index.php - overview.php
4
 *
5
 * 2.4 - copyright (c) 2010 by Gorlum for http://supernova.ws
6
 *     [-] Removed News frame
7
 *     [-] Time & Usersonline moved to Top-Frame
8
 * 2.3 - copyright (c) 2010 by Gorlum for http://supernova.ws
9
 *     [*] Complying with PCG
10
 * 2.2 - copyright (c) 2010 by Gorlum for http://supernova.ws
11
 *     [+] Redo flying fleet list
12
 * 2.1 - copyright (c) 2010 by Gorlum for http://supernova.ws
13
 *     [+] Planets on planet list now have indication of planet fill
14
 *     [+] Planets on planet list now have indication when there is enemy fleet flying to planet
15
 * 2.0 - copyright (c) 2010 by Gorlum for http://supernova.ws
16
 *     [+] Now there is full planet list on right side of screen a-la oGame
17
 *     [+] Planet list now include icons for buildings/tech/fleet on progress
18
 * 1.5 - copyright (c) 2010 by Gorlum for http://supernova.ws
19
 *     [*] Subplanet timers now use sn_timer.js library
20
 * 1.4 - copyright (c) 2010 by Gorlum for http://supernova.ws
21
 *     [*] All mainplanet timers now use new sn_timer.js library
22
 * 1.3 - copyright (c) 2010 by Gorlum for http://supernova.ws
23
 *     [*] Adjusted layouts of player infos
24
 * 1.2 - copyright (c) 2010 by Gorlum for http://supernova.ws
25
 *     [*] Adjusted layouts of planet infos
26
 * 1.1 - Security checks by Gorlum for http://supernova.ws
27
 * @version 1
28
 * @copyright 2008 By Chlorel for XNova
29
 */
30
31
//define('SN_RENDER_NAVBAR_PLANET', false);
32
33
include('common.' . substr(strrchr(__FILE__, '.'), 1));
34
35
36
//$player = new Player();
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
37
//$player->db_load_by_id(2);
38
//$player->unitList->_dump();
39
//pvar_dump($player->player_bonus);
40
41
sn_db_transaction_start();
42
$fleet = new Fleet();
43
$fleet->dbLoad(103);
44
45
//$fleet_row = doquery("SELECT * FROM {{fleets}} WHERE fleet_id = 80;", true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
//$fleet_row = doquery("SELECT * FROM {{fleets}} WHERE fleet_id = 8;", true);
47
//pdump($fleet_row);
48
//$fleet->dbRowParse($fleet_row);
49
//pdie('disabled for debug purposes');
50
51
//$fleet->setDbId(0);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
52
//$fleet->unitList->unitZeroDbId();
53
//pvar_dump($fleet->unitList[1131268]);
54
//pdie('disabled for debug purposes');
55
56
57
58
pdump(property_exists($fleet->unitList[1131268], 'count'), 'count exists');
0 ignored issues
show
The property $unitList is declared protected in UnitContainer. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
59
pdump($fleet->unitList[1131268]->count);
0 ignored issues
show
The property $unitList is declared protected in UnitContainer. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
60
$fleet->unitList[1131268]->adjustCount(-1);
0 ignored issues
show
The property $unitList is declared protected in UnitContainer. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
61
pdump($fleet->unitList[1131268]->count);
0 ignored issues
show
The property $unitList is declared protected in UnitContainer. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
62
63
$fleet->dbSave();
64
65
pvar_dump($fleet->unitList);
0 ignored issues
show
The property $unitList is declared protected in UnitContainer. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
66
67
//$fleet->unitList->unitZeroCount();
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
68
//$fleet->dbSave();
69
70
sn_db_transaction_commit();
71
pdie('disabled for debug purposes');
72
73
74
75
76
77
lng_include('overview');
78
79
$result = array();
80
81
switch($mode = sys_get_param_str('mode')) {
82
  case 'manage':
83
    sn_sys_sector_buy('overview.php?mode=manage');
84
85
    $user_dark_matter = mrc_get_level($user, false, RES_DARK_MATTER);
86
    $result[] = sn_sys_planet_core_transmute($user, $planetrow);
87
88
    $template  = gettemplate('planet_manage', true);
89
    $planet_id = sys_get_param_id('planet_id');
90
91
    if(sys_get_param_str('rename') && $new_name = sys_get_param_str('new_name')) {
92
      $planetrow['name'] = $new_name;
93
//      $new_name = db_escape($new_name);
94
      db_planet_set_by_id($planetrow['id'], "`name` = '{$new_name}'");
95
    } elseif(sys_get_param_str('action') == 'make_capital') {
96
      try {
97
        sn_db_transaction_start();
98
        $user = db_user_by_id($user['id'], true, '*');
99
        $planetrow = db_planet_by_id($planetrow['id'], true, '*');
100
//        $global_data = sys_o_get_updated($user, $planetrow['id'], SN_TIME_NOW);
101
//        $user = $global_data['user'];
102
//        $planetrow = $global_data['planet'];
103
104 View Code Duplication
        if($planetrow['planet_type'] != PT_PLANET) {
105
          throw new exception(classLocale::$lang['ov_capital_err_not_a_planet'], ERR_ERROR);
106
        }
107
108
        if($planetrow['id'] == $user['id_planet']) {
109
          throw new exception(classLocale::$lang['ov_capital_err_capital_already'], ERR_ERROR);
110
        }
111
112
        if($user_dark_matter < $config->planet_capital_cost) {
113
          throw new exception(classLocale::$lang['ov_capital_err_no_dark_matter'], ERR_ERROR);
114
        }
115
116
        rpg_points_change($user['id'], RPG_CAPITAL, -$config->planet_capital_cost,
117
          array('Planet %s ID %d at coordinates %s now become Empire Capital', $planetrow['name'], $planetrow['id'], uni_render_coordinates($planetrow))
118
        );
119
120
        db_user_set_by_id($user['id'], "id_planet = {$planetrow['id']}, galaxy = {$planetrow['galaxy']}, system = {$planetrow['system']}, planet = {$planetrow['planet']}");
121
122
        $user['id_planet'] = $planetrow['id'];
123
        $result[] = array(
124
          'STATUS'  => ERR_NONE,
125
          'MESSAGE' => classLocale::$lang['ov_capital_err_none'],
126
        );
127
        sn_db_transaction_commit();
128
        sys_redirect('overview.php?mode=manage');
129
      } catch(exception $e) {
130
        sn_db_transaction_rollback();
131
        $result[] = array(
132
          'STATUS'  => $e->getCode(),
133
          'MESSAGE' => $e->getMessage(),
134
        );
135
      }
136
    } elseif(sys_get_param_str('action') == 'planet_teleport') {
137
      try {
138
        if(!uni_coordinates_valid($new_coordinates = array(
139
          'galaxy' => sys_get_param_int('new_galaxy'),
140
          'system' => sys_get_param_int('new_system'),
141
          'planet' => sys_get_param_int('new_planet')))
142
        ) {
143
          throw new exception(classLocale::$lang['ov_teleport_err_wrong_coordinates'], ERR_ERROR);
144
        }
145
146
        sn_db_transaction_start();
147
        // При телепорте обновлять данные не надо - просто получить текущие данные и залочить их
148
        $user = db_user_by_id($user['id'], true, '*');
149
        $planetrow = db_planet_by_id($planetrow['id'], true, '*');
150
//        $global_data = sys_o_get_updated($user, $planetrow['id'], SN_TIME_NOW);
151
//        $user = $global_data['user'];
152
//        $planetrow = $global_data['planet'];
153
154
        $can_teleport = uni_planet_teleport_check($user, $planetrow, $new_coordinates);
155
        if($can_teleport['result'] != ERR_NONE) {
156
          throw new exception($can_teleport['message'], $can_teleport['result']);
157
        }
158
159
        rpg_points_change($user['id'], RPG_TELEPORT, -$config->planet_teleport_cost,
160
          array(&classLocale::$lang['ov_teleport_log_record'], $planetrow['name'], $planetrow['id'], uni_render_coordinates($planetrow), uni_render_coordinates($new_coordinates))
161
        );
162
        $planet_teleport_next = SN_TIME_NOW + $config->planet_teleport_timeout;
163
        db_planet_set_by_gspt($planetrow['galaxy'], $planetrow['system'], $planetrow['planet'], PT_ALL,
164
          "galaxy = {$new_coordinates['galaxy']}, system = {$new_coordinates['system']}, planet = {$new_coordinates['planet']}, planet_teleport_next = {$planet_teleport_next}");
165
166
        if($planetrow['id'] == $user['id_planet']) {
167
          db_user_set_by_id($user['id'], "galaxy = {$new_coordinates['galaxy']}, system = {$new_coordinates['system']}, planet = {$new_coordinates['planet']}");
168
        }
169
170
        // $global_data = sys_o_get_updated($user, $planetrow['id'], SN_TIME_NOW);
171
        sn_db_transaction_commit();
172
        $user = db_user_by_id($user['id'], true, '*');
173
        $planetrow = db_planet_by_id($planetrow['id'], true, '*');
174
        $result[] = array(
175
          'STATUS'  => ERR_NONE,
176
          'MESSAGE' => classLocale::$lang['ov_teleport_err_none'],
177
        );
178
        sys_redirect('overview.php?mode=manage');
179
      } catch(exception $e) {
180
        sn_db_transaction_rollback();
181
        $result[] = array(
182
          'STATUS'  => $e->getCode(),
183
          'MESSAGE' => $e->getMessage(),
184
        );
185
      }
186
    } elseif(sys_get_param_str('action') == 'planet_abandon') {
187
      // if(sec_password_check($user['id'], sys_get_param('abandon_confirm'))) {
188
      if(classSupernova::$auth->password_check(sys_get_param('abandon_confirm'))) {
189
        if($user['id_planet'] != $user['current_planet'] && $user['current_planet'] == $planet_id) {
190
          $destroyed = SN_TIME_NOW + 60 * 60 * 24;
191
          db_planet_set_by_id($user['current_planet'], "`destruyed`='{$destroyed}', `id_owner`=0");
192
          db_planet_set_by_parent($user['current_planet'], "`destruyed`='{$destroyed}', `id_owner`=0");
193
          db_user_set_by_id($user['id'], '`current_planet` = `id_planet`');
194
          message(classLocale::$lang['ov_delete_ok'], classLocale::$lang['colony_abandon'], 'overview.php?mode=manage');
195
        } else {
196
          message(classLocale::$lang['ov_delete_wrong_planet'], classLocale::$lang['colony_abandon'], 'overview.php?mode=manage');
197
        }
198
      } else {
199
        message(classLocale::$lang['ov_delete_wrong_pass'] , classLocale::$lang['colony_abandon'], 'overview.php?mode=manage');
200
      }
201
    } elseif(
202
      ($hire = sys_get_param_int('hire')) && in_array($hire, sn_get_groups('governors'))
203
      && (
204
        !get_unit_param($hire, P_MAX_STACK) ||
205
        ($planetrow['PLANET_GOVERNOR_ID'] != $hire) ||
206
        (
207
          $planetrow['PLANET_GOVERNOR_ID'] == $hire &&
208
          $planetrow['PLANET_GOVERNOR_LEVEL'] < get_unit_param($hire, P_MAX_STACK)
209
        )
210
      )
211
    ) {
212
      sn_db_transaction_start();
213
      $user = db_user_by_id($user['id'], true);
214
      $planetrow = db_planet_by_id($planetrow['id'], true);
215
      $build_data = eco_get_build_data($user, $planetrow, $hire, $planetrow['PLANET_GOVERNOR_ID'] == $hire ? $planetrow['PLANET_GOVERNOR_LEVEL'] : 0);
216
      if($build_data['CAN'][BUILD_CREATE]) {
217
        if($planetrow['PLANET_GOVERNOR_ID'] == $hire) {
218
          $planetrow['PLANET_GOVERNOR_LEVEL']++;
219
          $query = '`PLANET_GOVERNOR_LEVEL` + 1';
220
        } else {
221
          $planetrow['PLANET_GOVERNOR_LEVEL'] = 1;
222
          $planetrow['PLANET_GOVERNOR_ID'] = $hire;
223
          $query = '1';
224
        }
225
        db_planet_set_by_id($planetrow['id'], "`PLANET_GOVERNOR_ID` = {$hire}, `PLANET_GOVERNOR_LEVEL` = {$query}");
226
        rpg_points_change(
227
          $user['id'],
228
          RPG_GOVERNOR,
229
          -$build_data[BUILD_CREATE][RES_DARK_MATTER],
230
          sprintf(classLocale::$lang['ov_governor_purchase'], classLocale::$lang['tech'][$hire], $hire, $planetrow['PLANET_GOVERNOR_LEVEL'], uni_render_planet_full($planetrow, '', false, true))
231
        );
232
233
        //  => 'Игрок купил Губернатора %1$s ID %2$d уровня %3$d на планету %4$s',
234
        // die();
235
      }
236
      sn_db_transaction_commit();
237
      sys_redirect('overview.php?mode=manage');
238
      die();
239
    }
240
241
    lng_include('mrc_mercenary');
242
    int_planet_pretemplate($planetrow, $template);
243
    foreach(sn_get_groups('governors') as $governor_id) {
244
      if($planetrow['planet_type'] == PT_MOON && $governor_id == MRC_TECHNOLOGIST) {
245
        continue;
246
      }
247
248
      $governor_level = $planetrow['PLANET_GOVERNOR_ID'] == $governor_id ? $planetrow['PLANET_GOVERNOR_LEVEL'] : 0;
249
      $build_data = eco_get_build_data($user, $planetrow, $governor_id, $governor_level);
250
      $template->assign_block_vars('governors', array(
251
        'ID'         => $governor_id,
252
        'NAME'       => classLocale::$lang['tech'][$governor_id],
253
        'COST'       => $build_data[BUILD_CREATE][RES_DARK_MATTER],
254
        'MAX'        => get_unit_param($governor_id, P_MAX_STACK),
255
        'LEVEL'      => $governor_level,
256
        'LEVEL_PLUS' => mrc_get_level($user, $planetrow, $governor_id) - $governor_level,
257
      ));
258
    }
259
260
    $user_dark_matter = mrc_get_level($user, false, RES_DARK_MATTER);
261
    $planet_density_index = $planetrow['density_index'];
262
    $density_price_chart = planet_density_price_chart($planetrow);
263
    tpl_planet_density_info($template, $density_price_chart, $user_dark_matter);
264
265
    $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true);
266
    $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER];
267
    $planet_fill = floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100);
268
    $planet_fill = $planet_fill > 100 ? 100 : $planet_fill;
269
    $can_teleport = uni_planet_teleport_check($user, $planetrow);
270
    $template->assign_vars(array(
271
      'DARK_MATTER'           => $user_dark_matter,
272
273
      'PLANET_FILL'           => floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100),
274
      'PLANET_FILL_BAR'       => $planet_fill,
275
      'SECTOR_CAN_BUY'        => $sector_cost <= $user_dark_matter,
276
      'SECTOR_COST'           => $sector_cost,
277
      'SECTOR_COST_TEXT'      => pretty_number($sector_cost),
278
      'planet_field_current'  => $planetrow['field_current'],
279
      'planet_field_max'      => eco_planet_fields_max($planetrow),
280
281
      'CAN_TELEPORT'          => $can_teleport['result'] == ERR_NONE,
282
      'CAN_NOT_TELEPORT_MSG'  => $can_teleport['message'],
283
      'TELEPORT_COST_TEXT'    => pretty_number($config->planet_teleport_cost, true, $user_dark_matter),
284
285
      'CAN_CAPITAL'           => $user_dark_matter >= $config->planet_capital_cost,
286
      'CAPITAL_COST_TEXT'     => pretty_number($config->planet_capital_cost, true, $user_dark_matter),
287
288
      'PLANET_DENSITY_INDEX'  => $planet_density_index,
289
      'PLANET_CORE_TEXT'      => classLocale::$lang['uni_planet_density_types'][$planet_density_index],
290
291
      'IS_CAPITAL'            => $planetrow['id'] == $user['id_planet'],
292
293
      'PAGE_HINT'   => classLocale::$lang['ov_manage_page_hint'],
294
    ));
295
296
    foreach($result as &$a_result) {
297
      $template->assign_block_vars('result', $a_result);
298
    }
299
300
    display($template, classLocale::$lang['rename_and_abandon_planet']);
301
  break;
302
303
  default:
304
    sn_sys_sector_buy();
305
306
    if(sys_get_param_str('rename') && $new_name = sys_get_param_str('new_name')) {
307
      $planetrow['name'] = $new_name;
308
      $new_name_safe = db_escape($new_name);
309
      db_planet_set_by_id($planetrow['id'], "`name` = '{$new_name_safe}'");
310
    }
311
312
    $result[] = sn_sys_planet_core_transmute($user, $planetrow);
313
314
    $template = gettemplate('planet_overview', true);
315
316
    $user_dark_matter = mrc_get_level($user, false, RES_DARK_MATTER);
317
318
    $planet_density_index = $planetrow['density_index'];
319
    $density_price_chart = planet_density_price_chart($planetrow);
320
    tpl_planet_density_info($template, $density_price_chart, $user_dark_matter);
321
322
    rpg_level_up($user, RPG_STRUCTURE);
323
    rpg_level_up($user, RPG_RAID);
324
    rpg_level_up($user, RPG_TECH);
325
    rpg_level_up($user, RPG_EXPLORE);
326
327
    $fleet_id = 1;
328
329
//    $fleet_and_missiles_list = FleetList::fleet_and_missiles_list_incoming($user['id']);
330
//    $fleets = flt_parse_fleets_to_events($fleet_and_missiles_list);
331
    $fleet_and_missiles_list = FleetList::dbGetFleetListAndMissileINCOMING($user['id']);
332
    $fleets = flt_parse_objFleetList_to_events($fleet_and_missiles_list);
333
334
    $planet_count = 0;
335
    $planets_query = db_planet_list_sorted($user, false, '*');
336
    foreach($planets_query as $an_id => $UserPlanet) {
337
      sn_db_transaction_start();
338
      $UserPlanet = sys_o_get_updated($user, $UserPlanet['id'], SN_TIME_NOW, false, true);
339
      sn_db_transaction_commit();
340
      $list_planet_que = $UserPlanet['que'];
341
      $UserPlanet = $UserPlanet['planet'];
342
343
      $template_planet = tpl_parse_planet($UserPlanet);
344
345
      $planet_fleet_id = 0;
346
      $fleet_list = $template_planet['fleet_list'];
347 View Code Duplication
      if($fleet_list['own']['count']) {
348
        $planet_fleet_id = "p{$UserPlanet['id']}";
349
        $fleets_to_planet[$UserPlanet['id']] = tpl_parse_fleet_sn($fleet_list['own']['total'], $planet_fleet_id);
350
//        $fleet_id++;tpl_parse_fleet_sn
351
      }
352
      if($UserPlanet['planet_type'] == PT_MOON) {
353
        continue;
354
      }
355
      $moon = db_planet_by_parent($UserPlanet['id']);
356
      if($moon) {
357
        $moon_fill = min(100, floor($moon['field_current'] / eco_planet_fields_max($moon) * 100));
358
      } else {
359
        $moon_fill = 0;
360
      }
361
362
//      $moon_fleets = flt_get_fleets_to_planet($moon);
363
      $moon_fleets = FleetList::EMULATE_flt_get_fleets_to_planet($moon);
364
//      $moon_fleets = array();
365
//      $fleet_db_list = FleetList::dbGetFleetListAndMissileByCoordinates($moon);
366
//      /**
367
//       * @var Fleet[] $array_of_Fleet
368
//       */
369
//      $array_of_Fleet = array();
370
//      if(!empty($fleet_db_list) && $fleet_db_list->count()) {
371
//        foreach($fleet_db_list->_container as $fleet_id => $objFleet) {
372
//          $array_of_Fleet[$fleet_id] = $objFleet;
373
//        }
374
//        $moon_fleets = flt_get_fleets_to_planet_by_array_of_Fleet($array_of_Fleet);
375
//      }
376
377
      $template->assign_block_vars('planet', array_merge($template_planet, array(
378
        'PLANET_FLEET_ID'  => $planet_fleet_id,
379
380
        'MOON_ID'      => $moon['id'],
381
        'MOON_NAME'    => $moon['name'],
382
        'MOON_IMG'     => $moon['image'],
383
        'MOON_FILL'    => min(100, $moon_fill),
384
        'MOON_ENEMY'   => !empty($moon_fleets['enemy']['count']) ? $moon_fleets['enemy']['count'] : 0,
385
386
        'MOON_PLANET'  => $moon['parent_planet'],
387
      )));
388
389
      $planet_count++;
390
    }
391
392
    tpl_assign_fleet($template, $fleets_to_planet);
393
    tpl_assign_fleet($template, $fleets);
394
395
    $lune = $planetrow['planet_type'] == PT_PLANET ? db_planet_by_parent($planetrow['id']) : db_planet_by_id($planetrow['parent_planet']);
396
    if($lune) {
397
      $template->assign_vars(array(
398
        'MOON_ID' => $lune['id'],
399
        'MOON_IMG' => $lune['image'],
400
        'MOON_NAME' => $lune['name'],
401
      ));
402
    }
403
404
    $planet_fill = floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100);
405
    $planet_fill = $planet_fill > 100 ? 100 : $planet_fill;
406
407
    $planet_recyclers_orbiting = 0;
408
    foreach(sn_get_groups('flt_recyclers') as $recycler_id) {
409
      $planet_recyclers_orbiting += mrc_get_level($user, $planetrow, $recycler_id);
410
    }
411
412
    int_planet_pretemplate($planetrow, $template);
413
414
    $sn_group_ques = sn_get_groups('ques');
415
    if(!defined('GAME_STRUCTURES_DISABLED') || !GAME_STRUCTURES_DISABLED) {
416
      foreach(array(QUE_STRUCTURES => $sn_group_ques[QUE_STRUCTURES]) as $que_id => $que_type_data) {
417
        $this_que = $que['ques'][$que_id][$user['id']][$planetrow['id']];
418
        $template->assign_block_vars('ques', array(
419
          'ID'     => $que_id,
420
          'NAME'   => classLocale::$lang['sys_ques'][$que_id],
421
          'LENGTH' => empty($this_que) ? 0 : count($this_que),
422
        ));
423
424
        if(!empty($this_que)) {
425
          foreach($this_que as $que_item) {
426
            $template->assign_block_vars('que', que_tpl_parse_element($que_item));
427
          }
428
        }
429
      }
430
    }
431
432
    $que_hangar_length = tpl_assign_hangar($template, $planetrow, SUBQUE_FLEET);
433
    $template->assign_block_vars('ques', array(
434
      'ID'     => QUE_HANGAR,
435
      'NAME'   => classLocale::$lang['sys_ques'][QUE_HANGAR],
436
      'LENGTH' => $que_hangar_length,
437
    ));
438
439
    if(!defined('GAME_DEFENSE_DISABLED') || !GAME_DEFENSE_DISABLED) {
440
      $que_hangar_length = tpl_assign_hangar($template, $planetrow, SUBQUE_DEFENSE);
441
      $template->assign_block_vars('ques', array(
442
        'ID'     => SUBQUE_DEFENSE,
443
        'NAME'   => classLocale::$lang['sys_ques'][SUBQUE_DEFENSE],
444
        'LENGTH' => $que_hangar_length,
445
      ));
446
    }
447
448
    $overview_planet_rows = $user['opt_int_overview_planet_rows'];
449
    $overview_planet_columns = $user['opt_int_overview_planet_columns'];
450
451
    if($overview_planet_rows <= 0 && $overview_planet_columns <= 0) {
452
      $overview_planet_rows = $user_option_list[OPT_INTERFACE]['opt_int_overview_planet_rows'];
453
      $overview_planet_columns = $user_option_list[OPT_INTERFACE]['opt_int_overview_planet_columns'];
454
    }
455
456
    if($overview_planet_rows > 0 && $overview_planet_columns <= 0) {
457
      $overview_planet_columns = ceil($planet_count / $overview_planet_rows);
458
    }
459
460
    $sector_cost = eco_get_build_data($user, $planetrow, UNIT_SECTOR, mrc_get_level($user, $planetrow, UNIT_SECTOR), true);
461
    $sector_cost = $sector_cost[BUILD_CREATE][RES_DARK_MATTER];
462
    $governor_level = $planetrow['PLANET_GOVERNOR_ID'] ? mrc_get_level($user, $planetrow, $planetrow['PLANET_GOVERNOR_ID'], false, true) : 0;
463
    $template->assign_vars(array(
464
      'USER_ID'               => $user['id'],
465
      'user_username'         => $user['username'],
466
      'USER_AUTHLEVEL'        => $user['authlevel'],
467
468
      'NEW_MESSAGES'          => $user['new_message'],
469
      'NEW_LEVEL_MINER'       => $level_miner,
470
      'NEW_LEVEL_RAID'        => $level_raid,
471
472
      'planet_diameter'       => pretty_number($planetrow['diameter']),
473
      'planet_field_current'  => $planetrow['field_current'],
474
      'planet_field_max'      => eco_planet_fields_max($planetrow),
475
      'PLANET_FILL'           => floor($planetrow['field_current'] / eco_planet_fields_max($planetrow) * 100),
476
      'PLANET_FILL_BAR'       => $planet_fill,
477
      'metal_debris'          => pretty_number($planetrow['debris_metal']),
478
      'crystal_debris'        => pretty_number($planetrow['debris_crystal']),
479
      'PLANET_RECYCLERS'      => $planet_recyclers_orbiting,
480
      'planet_image'          => $planetrow['image'],
481
      'planet_temp_min'       => $planetrow['temp_min'],
482
      'planet_temp_avg'       => round(($planetrow['temp_min'] + $planetrow['temp_max']) / 2),
483
      'planet_temp_max'       => $planetrow['temp_max'],
484
      'planet_density'        => $planetrow['density'],
485
      'planet_density_index'  => $planetrow['density_index'],
486
      'planet_density_text'   => classLocale::$lang['uni_planet_density_types'][$planetrow['density_index']],
487
488
      'GATE_LEVEL'            => mrc_get_level($user, $planetrow, STRUC_MOON_GATE),
489
      'GATE_JUMP_REST_TIME'   => uni_get_time_to_jump($planetrow),
490
491
      'ADMIN_EMAIL'           => $config->game_adminEmail,
492
493
      'PLANET_GOVERNOR_ID'    => $planetrow['PLANET_GOVERNOR_ID'],
494
//      'PLANET_GOVERNOR_LEVEL' => $planetrow['PLANET_GOVERNOR_LEVEL'] mrc_get_level($user, $planetrow,),
495
      'PLANET_GOVERNOR_LEVEL' => $governor_level,
496
      'PLANET_GOVERNOR_LEVEL_PLUS' => mrc_get_level($user, $planetrow, $planetrow['PLANET_GOVERNOR_ID']) - $governor_level,
497
      'PLANET_GOVERNOR_NAME'  => classLocale::$lang['tech'][$planetrow['PLANET_GOVERNOR_ID']],
498
499
      'LIST_ROW_COUNT'        => $overview_planet_rows,
500
      'LIST_COLUMN_COUNT'     => $overview_planet_columns,
501
502
      'DARK_MATTER'           => $user_dark_matter,
503
504
      'PLANET_DENSITY_INDEX'  => $planet_density_index,
505
      'PLANET_CORE_TEXT'      => classLocale::$lang['uni_planet_density_types'][$planet_density_index],
506
507
      'SECTOR_CAN_BUY'        => $sector_cost <= mrc_get_level($user, null, RES_DARK_MATTER),
508
      'SECTOR_COST'           => $sector_cost,
509
      'SECTOR_COST_TEXT'      => pretty_number($sector_cost),
510
    ));
511
    tpl_set_resource_info($template, $planetrow, $fleets_to_planet, 2);
512
513
    foreach($result as &$a_result) {
514
      $template->assign_block_vars('result', $a_result);
515
    }
516
517
    $classLocale = classLocale::$lang;
518
    display($template, "{$classLocale['ov_overview']} - {$classLocale['sys_planet_type'][$planetrow['planet_type']]} {$planetrow['name']} [{$planetrow['galaxy']}:{$planetrow['system']}:{$planetrow['planet']}]");
519
  break;
520
}
521