Completed
Push — work-fleets ( 9e446e...674b8a )
by SuperNova.WS
12:48 queued 05:50
created
includes/functions/eco_queue.php 1 patch
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
 
8 8
 function que_get_unit_que($unit_id) {
9 9
   $que_type = false;
10
-  foreach(sn_get_groups('ques') as $que_id => $que_data) {
11
-    if(in_array($unit_id, $que_data['unit_list'])) {
10
+  foreach (sn_get_groups('ques') as $que_id => $que_data) {
11
+    if (in_array($unit_id, $que_data['unit_list'])) {
12 12
       $que_type = $que_id;
13 13
       break;
14 14
     }
@@ -19,14 +19,14 @@  discard block
 block discarded – undo
19 19
 
20 20
 
21 21
 function que_get_max_que_length($user, $planet, $que_id, $que_data = null) {
22
-  if(empty($que_data)) {
22
+  if (empty($que_data)) {
23 23
     $que_data = sn_get_groups('ques');
24 24
     $que_data = $que_data[$que_id];
25 25
   }
26 26
 
27 27
 
28 28
   $que_length = 1;
29
-  switch($que_id) {
29
+  switch ($que_id) {
30 30
     case QUE_RESEARCH:
31 31
       $que_length = classSupernova::$config->server_que_length_research + mrc_get_level($user, null, UNIT_PREMIUM); // TODO - вынести в модуль
32 32
     break;
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 
41 41
 function eco_que_str2arr($que_str) {
42 42
   $que_arr = explode(';', $que_str);
43
-  foreach($que_arr as $que_index => &$que_item) {
44
-    if($que_item) {
43
+  foreach ($que_arr as $que_index => &$que_item) {
44
+    if ($que_item) {
45 45
       $que_item = explode(',', $que_item);
46 46
     } else {
47 47
       unset($que_arr[$que_index]);
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 }
53 53
 
54 54
 function eco_que_arr2str($que_arr) {
55
-  foreach($que_arr as &$que_item) {
55
+  foreach ($que_arr as &$que_item) {
56 56
     $que_item = implode(',', $que_item);
57 57
   }
58 58
 
@@ -64,28 +64,28 @@  discard block
 block discarded – undo
64 64
   $classLocale = classLocale::$lang;
65 65
 
66 66
   $is_autoconvert = false;
67
-  if($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) {
67
+  if ($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) {
68 68
     $build_mode = BUILD_CREATE;
69 69
     $is_autoconvert = true;
70 70
   }
71 71
 
72 72
   $unit_amount_qued = 0;
73 73
   try {
74
-    if(!$user['id']) {
74
+    if (!$user['id']) {
75 75
       throw new exception('{Нет идентификатора пользователя - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
76 76
     }
77 77
 
78 78
     $unit_id = sys_get_param_int('unit_id');
79
-    if(!$unit_id) {
79
+    if (!$unit_id) {
80 80
       throw new exception('{Нет идентификатора юнита - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
81 81
     }
82 82
 
83 83
     $que_id = que_get_unit_que($unit_id);
84
-    if(!$que_id) {
84
+    if (!$que_id) {
85 85
       throw new exception('{Неправильный тип очереди - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
86 86
     }
87 87
 
88
-    if($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) {
88
+    if ($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) {
89 89
       throw new exception('{Уничтожать можно только здания на планете}', ERR_ERROR); // TODO EXCEPTION
90 90
     }
91 91
 
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
     $que_data = $que_data[$que_id];
94 94
 
95 95
     // TODO Переделать под подочереди
96
-    if($que_id == QUE_STRUCTURES) {
96
+    if ($que_id == QUE_STRUCTURES) {
97 97
       $sn_groups_build_allow = sn_get_groups('build_allow');
98 98
       $que_data['unit_list'] = $sn_groups_build_allow[$planet['planet_type']];
99 99
 
100
-      if(!isset($que_data['unit_list'][$unit_id])) {
100
+      if (!isset($que_data['unit_list'][$unit_id])) {
101 101
         throw new exception('{Это здание нельзя строить на ' . ($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION
102 102
       }
103 103
     }
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
     // Это нужно, что бы заблокировать пользователя и работу с очередями
109 109
     $user = DBStaticUser::db_user_by_id($user['id']);
110 110
     // Это нужно, что бы заблокировать планету от списания ресурсов
111
-    if(isset($planet['id']) && $planet['id']) {
111
+    if (isset($planet['id']) && $planet['id']) {
112 112
       $planet = DBStaticPlanet::db_planet_by_id($planet['id'], true);
113 113
     } else {
114 114
       $planet['id'] = 0;
@@ -120,12 +120,12 @@  discard block
 block discarded – undo
120 120
     $in_que = &$que['in_que'][$que_id][$user['id']][$planet_id];
121 121
     $que_max_length = que_get_max_que_length($user, $planet, $que_id, $que_data);
122 122
     // TODO Добавить вызовы функций проверок текущей и максимальной длин очередей
123
-    if(count($in_que) >= $que_max_length) {
123
+    if (count($in_que) >= $que_max_length) {
124 124
       throw new exception('{Все слоты очереди заняты}', ERR_ERROR); // TODO EXCEPTION
125 125
     }
126 126
 
127 127
     // TODO Отдельно посмотреть на уничтожение зданий - что бы можно было уничтожать их без планов
128
-    switch(eco_can_build_unit($user, $planet, $unit_id)) {
128
+    switch (eco_can_build_unit($user, $planet, $unit_id)) {
129 129
       case BUILD_ALLOWED:
130 130
       break;
131 131
       case BUILD_UNIT_BUSY:
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
       break; // TODO EXCEPTION eco_bld_msg_err_laboratory_upgrading
134 134
       // case BUILD_REQUIRE_NOT_MEET:
135 135
       default:
136
-        if($build_mode == BUILD_CREATE) {
136
+        if ($build_mode == BUILD_CREATE) {
137 137
           throw new exception('{Требования не удовлетворены}', ERR_ERROR);
138 138
         }
139 139
       break; // TODO EXCEPTION eco_bld_msg_err_requirements_not_meet
@@ -143,33 +143,33 @@  discard block
 block discarded – undo
143 143
     $unit_amount_qued = $unit_amount;
144 144
     $units_qued = isset($in_que[$unit_id]) ? $in_que[$unit_id] : 0;
145 145
     $unit_level = mrc_get_level($user, $planet, $unit_id, true, true) + $units_qued;
146
-    if($unit_max = get_unit_param($unit_id, P_MAX_STACK)) {
147
-      if($unit_level >= $unit_max) {
146
+    if ($unit_max = get_unit_param($unit_id, P_MAX_STACK)) {
147
+      if ($unit_level >= $unit_max) {
148 148
         throw new exception('{Максимальное количество юнитов данного типа уже достигнуто или будет достигнуто по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION
149 149
       }
150 150
       $unit_amount = max(0, min($unit_amount, $unit_max - $unit_level));
151 151
     }
152 152
 
153
-    if($unit_amount < 1) {
153
+    if ($unit_amount < 1) {
154 154
       throw new exception('{Неправильное количество юнитов - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION
155 155
     }
156 156
 
157 157
     // TODO Переделать eco_unit_busy для всех типов зданий
158
-    if(get_unit_param($unit_id, P_STACKABLE)) {
158
+    if (get_unit_param($unit_id, P_STACKABLE)) {
159 159
       // TODO Поле 'max_Lot_size' для ограничения размера стэка в очереди - то ли в юниты, то ли в очередь
160
-      if(in_array($unit_id, $group_missile = sn_get_groups(GROUP_STR_MISSILES))) {
160
+      if (in_array($unit_id, $group_missile = sn_get_groups(GROUP_STR_MISSILES))) {
161 161
         // TODO Поле 'container' - указывает на родительску структуру, в которой хранится данный юнит и по вместительности которой нужно применять размер юнита
162 162
         $used_silo = 0;
163
-        foreach($group_missile as $missile_id) {
163
+        foreach ($group_missile as $missile_id) {
164 164
           $missile_qued = isset($in_que[$missile_id]) ? $in_que[$missile_id] : 0;
165 165
           $used_silo += (mrc_get_level($user, $planet, $missile_id, true, true) + $missile_qued) * get_unit_param($missile_id, P_UNIT_SIZE);
166 166
         }
167 167
         $free_silo = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY) - $used_silo;
168
-        if($free_silo <= 0) {
168
+        if ($free_silo <= 0) {
169 169
           throw new exception('{Ракетная шахта уже заполнена или будет заполнена по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION
170 170
         }
171 171
         $unit_size = get_unit_param($unit_id, P_UNIT_SIZE);
172
-        if($free_silo < $unit_size) {
172
+        if ($free_silo < $unit_size) {
173 173
           throw new exception("{В ракетной шахте нет места для {$classLocale['tech'][$unit_id]}}", ERR_ERROR); // TODO EXCEPTION
174 174
         }
175 175
         $unit_amount = max(0, min($unit_amount, floor($free_silo / $unit_size)));
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
       $unit_level = $new_unit_level = 0;
178 178
     } else {
179 179
       $unit_amount = 1;
180
-      if($que_id == QUE_STRUCTURES) {
180
+      if ($que_id == QUE_STRUCTURES) {
181 181
         $sectors_qued = is_array($in_que) ? array_sum($in_que) : 0;
182
-        if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) {
182
+        if ($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) {
183 183
           throw new exception('{Не хватает секторов на планете}', ERR_ERROR); // TODO EXCEPTION
184 184
         }
185 185
       }
@@ -191,9 +191,9 @@  discard block
 block discarded – undo
191 191
 
192 192
     $exchange = array();
193 193
     $market_get_autoconvert_cost = market_get_autoconvert_cost();
194
-    if($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) {
194
+    if ($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) {
195 195
       $dark_matter = mrc_get_level($user, null, RES_DARK_MATTER);
196
-      if(mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) {
196
+      if (mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) {
197 197
         throw new exception("{Нет хватает " . ($market_get_autoconvert_cost - $dark_matter) . "ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION
198 198
       }
199 199
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
       $resource_exchange_rates = array();
204 204
       $resource_diff = array();
205 205
       $all_positive = true;
206
-      foreach($resources_loot as $resource_id) {
206
+      foreach ($resources_loot as $resource_id) {
207 207
         $resource_db_name = pname_resource_name($resource_id);
208 208
         $resource_got[$resource_id] = floor(mrc_get_level($user, $planet, $resource_id));
209 209
         $resource_exchange_rates[$resource_id] = classSupernova::$config->__get("rpg_exchange_{$resource_db_name}");
@@ -211,15 +211,15 @@  discard block
 block discarded – undo
211 211
         $all_positive = $all_positive && ($resource_diff[$resource_id] > 0);
212 212
       }
213 213
       // Нужна автоконвертация
214
-      if($all_positive) {
214
+      if ($all_positive) {
215 215
         $is_autoconvert = false;
216 216
       } else {
217
-        foreach($resource_diff as $resource_diff_id => &$resource_diff_amount) {
218
-          if($resource_diff_amount >= 0) {
217
+        foreach ($resource_diff as $resource_diff_id => &$resource_diff_amount) {
218
+          if ($resource_diff_amount >= 0) {
219 219
             continue;
220 220
           }
221
-          foreach($resource_diff as $resource_got_id => &$resource_got_amount) {
222
-            if($resource_got_amount <= 0) {
221
+          foreach ($resource_diff as $resource_got_id => &$resource_got_amount) {
222
+            if ($resource_got_amount <= 0) {
223 223
               continue;
224 224
             }
225 225
             $current_exchange = $resource_exchange_rates[$resource_got_id] / $resource_exchange_rates[$resource_diff_id];
@@ -235,14 +235,14 @@  discard block
 block discarded – undo
235 235
         }
236 236
 
237 237
         $is_autoconvert_ok = true;
238
-        foreach($resource_diff as $resource_diff_amount2) {
239
-          if($resource_diff_amount2 < 0) {
238
+        foreach ($resource_diff as $resource_diff_amount2) {
239
+          if ($resource_diff_amount2 < 0) {
240 240
             $is_autoconvert_ok = false;
241 241
             break;
242 242
           }
243 243
         }
244 244
 
245
-        if($is_autoconvert_ok) {
245
+        if ($is_autoconvert_ok) {
246 246
           $build_data['RESULT'][$build_mode] = BUILD_ALLOWED;
247 247
           $build_data['CAN'][$build_mode] = $unit_amount;
248 248
         } else {
@@ -251,19 +251,19 @@  discard block
 block discarded – undo
251 251
       }
252 252
     }
253 253
     $unit_amount = min($build_data['CAN'][$build_mode], $unit_amount);
254
-    if($unit_amount <= 0) {
254
+    if ($unit_amount <= 0) {
255 255
       throw new exception('{Не хватает ресурсов}', ERR_ERROR); // TODO EXCEPTION
256 256
     }
257 257
 
258
-    if($new_unit_level < 0) {
258
+    if ($new_unit_level < 0) {
259 259
       throw new exception('{Нельзя уничтожить больше юнитов, чем есть}', ERR_ERROR); // TODO EXCEPTION
260 260
     }
261 261
 
262
-    if($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) {
262
+    if ($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) {
263 263
       throw new exception('{Строительство блокировано}', ERR_ERROR); // TODO EXCEPTION
264 264
     }
265 265
 
266
-    if($is_autoconvert) {
266
+    if ($is_autoconvert) {
267 267
       ksort($exchange);
268 268
       ksort($resource_got);
269 269
       db_change_resources(
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
     }
283 283
 
284 284
     $unit_amount_qued = 0;
285
-    while($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) {
285
+    while ($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) {
286 286
       $place = min($unit_amount, MAX_FLEET_OR_DEFS_PER_ROW);
287 287
       que_add_unit($unit_id, $user, $planet, $build_data, $new_unit_level, $place, $build_mode);
288 288
       $unit_amount -= $place;
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 
293 293
     sn_db_transaction_commit();
294 294
 
295
-    if($redirect) {
295
+    if ($redirect) {
296 296
       sys_redirect("{$_SERVER['PHP_SELF']}?mode=" . sys_get_param_str('mode') . "&ally_id=" . sys_get_param_id('ally_id'));
297 297
       die();
298 298
     }
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
       'STATUS'  => ERR_NONE,
302 302
       'MESSAGE' => '{Строительство начато}',
303 303
     );
304
-  } catch(Exception $e) {
304
+  } catch (Exception $e) {
305 305
     sn_db_transaction_rollback();
306 306
     $operation_result = array(
307 307
       'STATUS'  => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR,
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
     );
310 310
   }
311 311
 
312
-  if(!empty($operation_result['MESSAGE'])) {
312
+  if (!empty($operation_result['MESSAGE'])) {
313 313
     $operation_result['MESSAGE'] .= ' ' . ($unit_amount_qued ? $unit_amount_qued : $unit_amount) . 'x[' . classLocale::$lang['tech'][$unit_id] . ']';
314 314
   }
315 315
 
@@ -320,11 +320,11 @@  discard block
 block discarded – undo
320 320
 function que_recalculate($old_que) {
321 321
   $new_que = array();
322 322
 
323
-  if(!is_array($old_que['items'])) {
323
+  if (!is_array($old_que['items'])) {
324 324
     return $new_que;
325 325
   }
326
-  foreach($old_que['items'] as $row) {
327
-    if(!isset($row) || !$row || $row['que_unit_amount'] <= 0) {
326
+  foreach ($old_que['items'] as $row) {
327
+    if (!isset($row) || !$row || $row['que_unit_amount'] <= 0) {
328 328
       continue;
329 329
     }
330 330
 
@@ -335,9 +335,9 @@  discard block
 block discarded – undo
335 335
 
336 336
     $last_id = count($new_que['items']) - 1;
337 337
 
338
-    if($row['que_planet_id']) {
338
+    if ($row['que_planet_id']) {
339 339
       $new_que['planets'][$row['que_planet_id']][$row['que_type']][] = &$new_que['items'][$last_id];
340
-    } elseif($row['que_type'] == QUE_RESEARCH) {
340
+    } elseif ($row['que_type'] == QUE_RESEARCH) {
341 341
       $new_que['players'][$row['que_player_id']][$row['que_type']][] = &$new_que['items'][$last_id];
342 342
     }
343 343
     $new_que['ques'][$row['que_type']][$row['que_player_id']][intval($row['que_planet_id'])][] = &$new_que['items'][$last_id];
@@ -375,14 +375,14 @@  discard block
 block discarded – undo
375 375
   $que_type = que_get_unit_que($unit_id);
376 376
   $planet_id_origin = $planet['id'] ? $planet['id'] : 'NULL';
377 377
   $planet_id = $que_type == QUE_RESEARCH ? 'NULL' : $planet_id_origin;
378
-  if(is_numeric($planet_id)) {
378
+  if (is_numeric($planet_id)) {
379 379
     DBStaticPlanet::db_planet_update_set_by_id(
380 380
       $planet_id,
381 381
       array(
382 382
         'que_processed' => SN_TIME_NOW,
383 383
       )
384 384
     );
385
-  } elseif(is_numeric($user['id'])) {
385
+  } elseif (is_numeric($user['id'])) {
386 386
     DBStaticUser::db_user_set_by_id(
387 387
       $user['id'],
388 388
       array(
@@ -417,17 +417,17 @@  discard block
 block discarded – undo
417 417
   $planet['id'] = $planet['id'] && $que_type !== QUE_RESEARCH ? $planet['id'] : 0;
418 418
   $global_que = que_get($user['id'], $planet['id'], $que_type, true);
419 419
 
420
-  if(!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) {
420
+  if (!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) {
421 421
     $que = array_reverse($global_que['ques'][$que_type][$user['id']][$planet['id']]);
422 422
 
423
-    foreach($que as $que_item) {
423
+    foreach ($que as $que_item) {
424 424
       DBStaticQue::db_que_delete_by_id($que_item['que_id']);
425 425
 
426
-      if($que_item['que_planet_id_origin']) {
426
+      if ($que_item['que_planet_id_origin']) {
427 427
         $planet['id'] = $que_item['que_planet_id_origin'];
428 428
       }
429 429
 
430
-      if(!isset($planets_locked[$planet['id']])) {
430
+      if (!isset($planets_locked[$planet['id']])) {
431 431
         $planets_locked[$planet['id']] = $planet['id'] ? DBStaticPlanet::db_planet_by_id($planet['id'], true) : $planet;
432 432
       }
433 433
 
@@ -443,19 +443,19 @@  discard block
 block discarded – undo
443 443
         )
444 444
       );
445 445
 
446
-      if(!$clear) {
446
+      if (!$clear) {
447 447
         break;
448 448
       }
449 449
     }
450 450
 
451
-    if(is_numeric($planet['id'])) {
451
+    if (is_numeric($planet['id'])) {
452 452
       DBStaticPlanet::db_planet_update_set_by_id(
453 453
         $planet['id'],
454 454
         array(
455 455
           'que_processed' => SN_TIME_SQL,
456 456
         )
457 457
       );
458
-    } elseif(is_numeric($user['id'])) {
458
+    } elseif (is_numeric($user['id'])) {
459 459
       DBStaticUser::db_user_set_by_id(
460 460
         $user['id'],
461 461
         array(
@@ -507,21 +507,21 @@  discard block
 block discarded – undo
507 507
   // TODO: Переделать для $que_type === false
508 508
   $planet['id'] = $planet['id'] ? $planet['id'] : 0;
509 509
 
510
-  if(!is_array($que)) {
510
+  if (!is_array($que)) {
511 511
     $que = que_get($user['id'], $planet['id'], $que_type);
512 512
   }
513 513
 
514
-  if(is_array($que) && isset($que['items'])) {
514
+  if (is_array($que) && isset($que['items'])) {
515 515
     $que = $que['ques'][$que_type][$user['id']][$planet['id']];
516 516
   }
517 517
 
518
-  if($que) {
519
-    foreach($que as $que_element) {
518
+  if ($que) {
519
+    foreach ($que as $que_element) {
520 520
       $template->assign_block_vars('que', que_tpl_parse_element($que_element, $short_names));
521 521
     }
522 522
   }
523 523
 
524
-  if($que_type == QUE_RESEARCH) {
524
+  if ($que_type == QUE_RESEARCH) {
525 525
   }
526 526
 }
527 527
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
   $user = DBStaticUser::db_user_by_id($user['id'], true);
546 546
 
547 547
   $time_left[$user['id']][0] = max(0, $on_time - $user['que_processed']);
548
-  if($planet === null && !$time_left[$user['id']][0]) {
548
+  if ($planet === null && !$time_left[$user['id']][0]) {
549 549
     return $que;
550 550
   }
551 551
 
@@ -553,12 +553,12 @@  discard block
 block discarded – undo
553 553
   $que_type_id = $planet === null ? QUE_RESEARCH : false;
554 554
   $planet = intval(is_array($planet) ? $planet['id'] : $planet); // В $planet у нас теперь только её ID или шаблон null/0/false
555 555
   $que = que_get($user['id'], $planet, $que_type_id, true);
556
-  if(empty($que['items'])) {
556
+  if (empty($que['items'])) {
557 557
     return $que;
558 558
   }
559 559
 
560 560
   $planet_list = array();
561
-  if($planet !== null) {
561
+  if ($planet !== null) {
562 562
     // Если нужно изменять данные на планетах - блокируем планеты и получаем данные о них
563 563
     // TODO - от них не надо ничего, кроме ID и que_processed
564 564
     $planet_row = DBStaticPlanet::db_planet_list_by_user_or_planet($user['id'], $planet);
@@ -567,20 +567,20 @@  discard block
 block discarded – undo
567 567
   }
568 568
 
569 569
   // Теперь в $time_left лежит время обсчета всех очередей по каждой из планеты
570
-  if(array_sum($time_left[$user['id']]) == 0) {
570
+  if (array_sum($time_left[$user['id']]) == 0) {
571 571
     return $que;
572 572
   }
573 573
 
574 574
   $unit_changes = array();
575
-  foreach($que['items'] as &$que_item) {
575
+  foreach ($que['items'] as &$que_item) {
576 576
     $que_player_id = &$que_item['que_player_id'];
577 577
     $que_planet_id = intval($que_item['que_planet_id']);
578 578
 
579 579
     $que_time_left = &$que['time_left'][$que_player_id][$que_planet_id][$que_item['que_type']];
580
-    if(!isset($que_time_left)) {
580
+    if (!isset($que_time_left)) {
581 581
       $que_time_left = $time_left[$que_player_id][$que_planet_id];
582 582
     }
583
-    if($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) {
583
+    if ($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) {
584 584
       continue;
585 585
     }
586 586
     // Дальше мы идем, если только осталось время в очереди И юниты к постройке
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
     // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля
594 594
 
595 595
     // Если времени в очереди осталось не меньше, чем время текущего юнита - значит мы достроили юнит
596
-    if($que_time_left >= $que_item['que_time_left']) {
596
+    if ($que_time_left >= $que_item['que_time_left']) {
597 597
       // Увеличиваем количество отстроенных юнитов
598 598
       $unit_processed++;
599 599
       // Вычитаем из времени очереди потраченное на постройку время
@@ -606,12 +606,12 @@  discard block
 block discarded – undo
606 606
     $que_item['que_unit_amount'] -= $unit_processed;
607 607
 
608 608
     // Если еще остались юниты - значит ВСЁ оставшееся время приходится на достройку следующего юнита
609
-    if($que_item['que_unit_amount'] > 0) {
609
+    if ($que_item['que_unit_amount'] > 0) {
610 610
       $que_item['que_time_left'] = $que_item['que_time_left'] - $que_time_left;
611 611
       $que_time_left = 0;
612 612
     }
613 613
 
614
-    if($que_item['que_unit_amount'] <= 0) {
614
+    if ($que_item['que_unit_amount'] <= 0) {
615 615
       DBStaticQue::db_que_delete_by_id($que_item['que_id']);
616 616
     } else {
617 617
       classSupernova::$gc->cacheOperator->db_upd_record_by_id(
@@ -626,15 +626,15 @@  discard block
 block discarded – undo
626 626
       );
627 627
     }
628 628
 
629
-    if($unit_processed) {
629
+    if ($unit_processed) {
630 630
       $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1);
631 631
       $unit_changes[$que_player_id][$que_planet_id][$que_item['que_unit_id']] += $unit_processed_delta;
632 632
     }
633 633
   }
634 634
 
635
-  foreach($time_left as $player_id => $planet_data) {
636
-    foreach($planet_data as $planet_id => $time_on_planet) {
637
-      if($planet_id) {
635
+  foreach ($time_left as $player_id => $planet_data) {
636
+    foreach ($planet_data as $planet_id => $time_on_planet) {
637
+      if ($planet_id) {
638 638
         // update planet
639 639
         classSupernova::$gc->cacheOperator->db_upd_record_by_id(
640 640
           LOC_PLANET,
@@ -656,8 +656,8 @@  discard block
 block discarded – undo
656 656
         );
657 657
       }
658 658
 
659
-      if(is_array($unit_changes[$player_id][$planet_id])) {
660
-        foreach($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) {
659
+      if (is_array($unit_changes[$player_id][$planet_id])) {
660
+        foreach ($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) {
661 661
           DBStaticUnit::dbUpdateOrInsertUnit($unit_id, $unit_amount, $user, $planet_id ? $planet_id : null);
662 662
         }
663 663
       }
@@ -667,38 +667,38 @@  discard block
 block discarded – undo
667 667
   $que = que_recalculate($que);
668 668
 
669 669
   // TODO: Re-enable quests for Alliances
670
-  if(!empty($unit_changes) && !$user['user_as_ally']) {
670
+  if (!empty($unit_changes) && !$user['user_as_ally']) {
671 671
     $quest_list = qst_get_quests($user['id']);
672 672
     $quest_triggers = qst_active_triggers($quest_list);
673 673
     $quest_rewards = array();
674 674
 
675 675
 
676 676
     $xp_incoming = array();
677
-    foreach($unit_changes as $user_id => $planet_changes) {
678
-      foreach($planet_changes as $planet_id => $changes) {
677
+    foreach ($unit_changes as $user_id => $planet_changes) {
678
+      foreach ($planet_changes as $planet_id => $changes) {
679 679
         $planet_this = $planet_id ? classSupernova::$gc->cacheOperator->db_get_record_by_id(LOC_PLANET, $planet_id) : array();
680
-        foreach($changes as $unit_id => $unit_value) {
680
+        foreach ($changes as $unit_id => $unit_value) {
681 681
           $que_id = que_get_unit_que($unit_id);
682 682
           $unit_level_new = mrc_get_level($user, $planet_this, $unit_id, false, true) + $unit_value;
683
-          if($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) {
683
+          if ($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) {
684 684
             $build_data = eco_get_build_data($user, $planet_this, $unit_id, $unit_level_new - 1);
685 685
             $build_data = $build_data[BUILD_CREATE];
686
-            foreach(sn_get_groups('resources_loot') as $resource_id) {
686
+            foreach (sn_get_groups('resources_loot') as $resource_id) {
687 687
               $xp_incoming[$que_id] += $build_data[$resource_id]; // TODO - добавить конверсию рейтов обмена
688 688
             }
689 689
           }
690 690
 
691
-          if(is_array($quest_triggers)) {
691
+          if (is_array($quest_triggers)) {
692 692
             // TODO: Check mutiply condition quests
693 693
             $quest_trigger_list = array_keys($quest_triggers, $unit_id);
694
-            if(is_array($quest_trigger_list)) {
695
-              foreach($quest_trigger_list as $quest_id) {
694
+            if (is_array($quest_trigger_list)) {
695
+              foreach ($quest_trigger_list as $quest_id) {
696 696
                 $quest_unit_level = $unit_level_new;
697
-                if(get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) {
697
+                if (get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) {
698 698
                   $quest_unit_level = DBStaticUnit::db_unit_count_by_user_and_type_and_snid($user_id, 0, $unit_id);
699 699
                   $quest_unit_level = $quest_unit_level[$unit_id]['qty'];
700 700
                 }
701
-                if($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) {
701
+                if ($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) {
702 702
                   $quest_rewards[$quest_id][$user_id][$planet_id] = $quest_list[$quest_id]['quest_rewards_list'];
703 703
                   $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE;
704 704
                 }
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
     // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч
712 712
     qst_reward($user, $quest_rewards, $quest_list);
713 713
 
714
-    foreach($xp_incoming as $que_id => $xp) {
714
+    foreach ($xp_incoming as $que_id => $xp) {
715 715
       rpg_level_up($user, $que_id == QUE_RESEARCH ? RPG_TECH : RPG_STRUCTURE, $xp / 1000);
716 716
     }
717 717
   }
Please login to merge, or discard this patch.
includes/functions/sys_bbcode.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -103,23 +103,23 @@
 block discarded – undo
103 103
 
104 104
   !empty(classSupernova::$config->url_faq) ? $msg = str_replace('faq://', classSupernova::$config->url_faq, $msg) : false;
105 105
 
106
-  foreach(classSupernova::$design['bbcodes'] as $auth_level => $replaces) {
107
-    if($auth_level > $author_auth) {
106
+  foreach (classSupernova::$design['bbcodes'] as $auth_level => $replaces) {
107
+    if ($auth_level > $author_auth) {
108 108
       continue;
109 109
     }
110 110
 
111
-    foreach($replaces as $key => $html) {
112
-      $msg = preg_replace(''.$key.'', $html, $msg);
111
+    foreach ($replaces as $key => $html) {
112
+      $msg = preg_replace('' . $key . '', $html, $msg);
113 113
     }
114 114
   }
115 115
 
116
-  foreach(classSupernova::$design['smiles'] as $auth_level => $replaces) {
117
-    if($auth_level > $author_auth) {
116
+  foreach (classSupernova::$design['smiles'] as $auth_level => $replaces) {
117
+    if ($auth_level > $author_auth) {
118 118
       continue;
119 119
     }
120 120
 
121
-    foreach($replaces as $key => $imgName) {
122
-      $msg = preg_replace("#" . addcslashes($key, '()[]{}') . "#isU","<img src=\"design/images/smileys/".$imgName.".gif\" align=\"absmiddle\" title=\"".$key."\" alt=\"".$key."\">",$msg);
121
+    foreach ($replaces as $key => $imgName) {
122
+      $msg = preg_replace("#" . addcslashes($key, '()[]{}') . "#isU", "<img src=\"design/images/smileys/" . $imgName . ".gif\" align=\"absmiddle\" title=\"" . $key . "\" alt=\"" . $key . "\">", $msg);
123 123
     }
124 124
   }
125 125
 
Please login to merge, or discard this patch.
includes/functions/rpg_points.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -61,10 +61,10 @@
 block discarded – undo
61 61
     } else {
62 62
       $changeset['dark_matter_total'] = +$dark_matter;
63 63
     }
64
-    if($dark_matter) {
64
+    if ($dark_matter) {
65 65
       $changeset[$sn_data_dark_matter_db_name] = +$dark_matter;
66 66
     }
67
-    if(!empty($changeset)) {
67
+    if (!empty($changeset)) {
68 68
       DBStaticUser::db_user_adjust_by_id($user_id, $changeset);
69 69
     }
70 70
     $rows_affected = classSupernova::$db->db_affected_rows();
Please login to merge, or discard this patch.
galaxy.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 $uni_system = sys_get_param_int('system', $planetrow['system']);
22 22
 $planet = sys_get_param_int('planet', $planetrow['planet']);
23 23
 
24
-if($mode == 'name') {
24
+if ($mode == 'name') {
25 25
   require_once('includes/includes/uni_rename.php');
26 26
 }
27 27
 
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 
43 43
 $flying_fleet_count = FleetList::fleet_count_flying($user['id']);
44 44
 
45
-if($mode == 1) {
46
-} elseif($mode == 2 || $mode == 3) {
45
+if ($mode == 1) {
46
+} elseif ($mode == 2 || $mode == 3) {
47 47
   $planet = $planetrow['planet'];
48 48
 } else {
49 49
   $uni_galaxy = $planetrow['galaxy'];
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
   $planet = $planetrow['planet'];
52 52
 }
53 53
 
54
-$uni_galaxy = $uni_galaxy < 1 ? 1 : ($uni_galaxy > Vector::$knownGalaxies? Vector::$knownGalaxies: $uni_galaxy);
54
+$uni_galaxy = $uni_galaxy < 1 ? 1 : ($uni_galaxy > Vector::$knownGalaxies ? Vector::$knownGalaxies : $uni_galaxy);
55 55
 $uni_system = $uni_system < 1 ? 1 : ($uni_system > Vector::$knownSystems ? Vector::$knownSystems : $uni_system);
56 56
 $planet = $planet < 1 ? 1 : ($planet > Vector::$knownPlanets + 1 ? Vector::$knownPlanets + 1 : $planet);
57 57
 
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
 $PhalanxRange = GetPhalanxRange($HavePhalanx);
70 70
 
71 71
 $planet_precache_query = DBStaticPlanet::db_planet_list_in_system($uni_galaxy, $uni_system);
72
-if(!empty($planet_precache_query)) {
73
-  foreach($planet_precache_query as $planet_row) {
72
+if (!empty($planet_precache_query)) {
73
+  foreach ($planet_precache_query as $planet_row) {
74 74
     $planet_list[$planet_row['planet']][$planet_row['planet_type']] = $planet_row;
75 75
   }
76 76
 }
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
  * @var Fleet[][][] $fleet_list
89 89
  */
90 90
 $fleet_list = array();
91
-foreach($system_fleet_list->_container as $objFleetSystem) {
92
-  if(!$objFleetSystem->isReturning()) {
91
+foreach ($system_fleet_list->_container as $objFleetSystem) {
92
+  if (!$objFleetSystem->isReturning()) {
93 93
     $fleet_planet = $objFleetSystem->fleet_end_planet;
94 94
     $fleet_type = $objFleetSystem->fleet_end_type;
95 95
   } else {
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 $recycler_info = array();
105 105
 $planet_recyclers_orbiting = 0;
106 106
 $recyclers_fleet = array();
107
-foreach(classSupernova::$gc->groupRecyclers as $recycler_id) {
107
+foreach (classSupernova::$gc->groupRecyclers as $recycler_id) {
108 108
   $recycler_info[$recycler_id] = get_ship_data($recycler_id, $user);
109 109
   $recyclers_fleet[$recycler_id] = mrc_get_level($user, $planetrow, $recycler_id);
110 110
   $planet_recyclers_orbiting += $recyclers_fleet[$recycler_id];
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 $fleet_id = 1;
115 115
 $fleets = array();
116 116
 $config_game_max_planet = Vector::$knownPlanets + 1;
117
-for($Planet = 1; $Planet < $config_game_max_planet; $Planet++) {
117
+for ($Planet = 1; $Planet < $config_game_max_planet; $Planet++) {
118 118
   unset($uni_galaxyRowPlanet);
119 119
   unset($uni_galaxyRowMoon);
120 120
   unset($uni_galaxyRowUser);
@@ -124,17 +124,17 @@  discard block
 block discarded – undo
124 124
   $uni_galaxyRowPlanet = $planet_list[$Planet][PT_PLANET];
125 125
 
126 126
   $planet_fleet_id = 0;
127
-  if($uni_galaxyRowPlanet['destruyed']) {
127
+  if ($uni_galaxyRowPlanet['destruyed']) {
128 128
     CheckAbandonPlanetState($uni_galaxyRowPlanet);
129
-  } elseif($uni_galaxyRowPlanet['id']) {
130
-    if($cached['users'][$uni_galaxyRowPlanet['id_owner']]) {
129
+  } elseif ($uni_galaxyRowPlanet['id']) {
130
+    if ($cached['users'][$uni_galaxyRowPlanet['id_owner']]) {
131 131
       $uni_galaxyRowUser = $cached['users'][$uni_galaxyRowPlanet['id_owner']];
132 132
     } else {
133 133
       $uni_galaxyRowUser = DBStaticUser::db_user_by_id($uni_galaxyRowPlanet['id_owner']);
134 134
       $cached['users'][$uni_galaxyRowUser['id']] = $uni_galaxyRowUser;
135 135
     }
136 136
 
137
-    if(!$uni_galaxyRowUser['id']) {
137
+    if (!$uni_galaxyRowUser['id']) {
138 138
       classSupernova::$debug->warning("Planet '{$uni_galaxyRowPlanet['name']}' [{$uni_galaxy}:{$uni_system}:{$Planet}] has no owner!", 'Userless planet', 503);
139 139
       $uni_galaxyRowPlanet['destruyed'] = SN_TIME_NOW + 60 * 60 * 24;
140 140
       $uni_galaxyRowPlanet['id_owner'] = 0;
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
       );
148 148
     }
149 149
 
150
-    if($uni_galaxyRowUser['id']) {
150
+    if ($uni_galaxyRowUser['id']) {
151 151
       $planetcount++;
152
-      if($uni_galaxyRowUser['ally_id']) {
153
-        if($cached['allies'][$uni_galaxyRowUser['ally_id']]) {
152
+      if ($uni_galaxyRowUser['ally_id']) {
153
+        if ($cached['allies'][$uni_galaxyRowUser['ally_id']]) {
154 154
           $allyquery = $cached['allies'][$uni_galaxyRowUser['ally_id']];
155 155
         } else {
156 156
           $allyquery = DBStaticAlly::db_ally_get_by_id($uni_galaxyRowUser['ally_id']);
@@ -159,19 +159,19 @@  discard block
 block discarded – undo
159 159
       }
160 160
 
161 161
       $fleets_to_planet = flt_get_fleets_to_planet_by_array_of_Fleet($fleet_list[$Planet][PT_PLANET]);
162
-      if(!empty($fleets_to_planet['own']['count'])) {
162
+      if (!empty($fleets_to_planet['own']['count'])) {
163 163
         $planet_fleet_id = $fleet_id;
164 164
         $fleets[] = tpl_parse_fleet_sn($fleets_to_planet['own']['total'], $fleet_id);
165 165
         $fleet_id++;
166 166
       }
167 167
 
168 168
       $uni_galaxyRowMoon = $planet_list[$Planet][PT_MOON];
169
-      if($uni_galaxyRowMoon['destruyed']) {
169
+      if ($uni_galaxyRowMoon['destruyed']) {
170 170
         CheckAbandonPlanetState($uni_galaxyRowMoon);
171 171
       } else {
172 172
         $moon_fleet_id = 0;
173 173
         $fleets_to_planet = flt_get_fleets_to_planet_by_array_of_Fleet($fleet_list[$Planet][PT_MOON]);
174
-        if(!empty($fleets_to_planet['own']['count'])) {
174
+        if (!empty($fleets_to_planet['own']['count'])) {
175 175
           $moon_fleet_id = $fleet_id;
176 176
           $fleets[] = tpl_parse_fleet_sn($fleets_to_planet['own']['total'], $fleet_id);
177 177
           $fleet_id++;
@@ -182,10 +182,10 @@  discard block
 block discarded – undo
182 182
 
183 183
   $recyclers_incoming_capacity = 0;
184 184
   $uni_galaxyRowPlanet['debris'] = $uni_galaxyRowPlanet['debris_metal'] + $uni_galaxyRowPlanet['debris_crystal'];
185
-  if($uni_galaxyRowPlanet['debris']) {
186
-    if(!empty($fleet_list[$Planet][PT_DEBRIS])) {
187
-      foreach($fleet_list[$Planet][PT_DEBRIS] as $objFleetToDebris) {
188
-        if($objFleetToDebris->playerOwnerId == $user['id']) {
185
+  if ($uni_galaxyRowPlanet['debris']) {
186
+    if (!empty($fleet_list[$Planet][PT_DEBRIS])) {
187
+      foreach ($fleet_list[$Planet][PT_DEBRIS] as $objFleetToDebris) {
188
+        if ($objFleetToDebris->playerOwnerId == $user['id']) {
189 189
           $recyclers_incoming_capacity += $objFleetToDebris->shipsGetCapacityRecyclers($recycler_info);
190 190
         }
191 191
       }
@@ -262,21 +262,21 @@  discard block
 block discarded – undo
262 262
 
263 263
 tpl_assign_fleet($template, $fleets);
264 264
 
265
-foreach(sn_get_groups('defense_active') as $unit_id) {
265
+foreach (sn_get_groups('defense_active') as $unit_id) {
266 266
   $template->assign_block_vars('defense_active', array(
267 267
     'ID'   => $unit_id,
268 268
     'NAME' => classLocale::$lang['tech'][$unit_id],
269 269
   ));
270 270
 }
271 271
 
272
-foreach($cached['users'] as $PlanetUser) {
273
-  if(!$PlanetUser) {
272
+foreach ($cached['users'] as $PlanetUser) {
273
+  if (!$PlanetUser) {
274 274
     continue;
275 275
   }
276 276
 
277 277
   $user_ally = $cached['allies'][$PlanetUser['ally_id']];
278
-  if(isset($user_ally)) {
279
-    if($PlanetUser['id'] == $user_ally['ally_owner']) {
278
+  if (isset($user_ally)) {
279
+    if ($PlanetUser['id'] == $user_ally['ally_owner']) {
280 280
       $user_rank_title = $user_ally['ally_owner_range'];
281 281
     } else {
282 282
       $ally_ranks = explode(';', $user_ally['ranklist']);
@@ -299,8 +299,8 @@  discard block
 block discarded – undo
299 299
   ));
300 300
 }
301 301
 
302
-foreach($cached['allies'] as $PlanetAlly) {
303
-  if($PlanetAlly) {
302
+foreach ($cached['allies'] as $PlanetAlly) {
303
+  if ($PlanetAlly) {
304 304
     $template->assign_block_vars('alliances', array(
305 305
       'ID'      => $PlanetAlly['id'],
306 306
       'NAME_JS' => js_safe_string($PlanetAlly['ally_name']),
Please login to merge, or discard this patch.
announce.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -28,40 +28,40 @@  discard block
 block discarded – undo
28 28
 $mode = sys_get_param_str('mode');
29 29
 
30 30
 $announce = array();
31
-if($user['authlevel'] >= 3) {
32
-  if(!empty($text)) {
31
+if ($user['authlevel'] >= 3) {
32
+  if (!empty($text)) {
33 33
     $announce_time = strtotime($announce_time, SN_TIME_NOW);
34 34
     $announce_time = $announce_time ? $announce_time : SN_TIME_NOW;
35 35
 
36
-    if($mode == 'edit') {
36
+    if ($mode == 'edit') {
37 37
       DBStaticNews::db_news_update_set($announce_time, $text_unsafe, $detail_url_unsafe, $announce_id);
38 38
       DBStaticSurvey::db_survey_delete_by_id($announce_id);
39 39
     } else {
40 40
       DBStaticNews::db_news_insert_set($announce_time, $text_unsafe, $detail_url_unsafe, $user['id'], $user['username']);
41 41
       $announce_id = classSupernova::$db->db_insert_id();
42 42
     }
43
-    if(($survey_question = sys_get_param_str('survey_question')) && ($survey_answers = sys_get_param('survey_answers'))) {
43
+    if (($survey_question = sys_get_param_str('survey_question')) && ($survey_answers = sys_get_param('survey_answers'))) {
44 44
       $survey_answers = explode("\r\n", $survey_answers);
45 45
       $survey_until = strtotime($survey_until = sys_get_param_str('survey_until'), SN_TIME_NOW);
46 46
       $survey_until = date(FMT_DATE_TIME_SQL, $survey_until ? $survey_until : SN_TIME_NOW + PERIOD_DAY * 1);
47 47
       $survey_question_unsafe = sys_get_param_str_unsafe('survey_question');
48 48
       DBStaticSurvey::db_survey_insert($announce_id, $survey_question_unsafe, $survey_until);
49 49
       $survey_id = classSupernova::$db->db_insert_id();
50
-      foreach($survey_answers as $survey_answer) {
50
+      foreach ($survey_answers as $survey_answer) {
51 51
         $survey_answer_unsafe = trim($survey_answer);
52
-        if(empty($survey_answer_unsafe)) {
52
+        if (empty($survey_answer_unsafe)) {
53 53
           continue;
54 54
         }
55 55
         DBStaticSurveyAnswer::db_survey_answer_insert($survey_id, $survey_answer_unsafe);
56 56
       }
57 57
     }
58 58
 
59
-    if($announce_time <= SN_TIME_NOW) {
60
-      if($announce_time > classSupernova::$config->var_news_last && $announce_time == SN_TIME_NOW) {
59
+    if ($announce_time <= SN_TIME_NOW) {
60
+      if ($announce_time > classSupernova::$config->var_news_last && $announce_time == SN_TIME_NOW) {
61 61
         classSupernova::$config->db_saveItem('var_news_last', $announce_time);
62 62
       }
63 63
 
64
-      if(sys_get_param_int('news_mass_mail')) {
64
+      if (sys_get_param_int('news_mass_mail')) {
65 65
         $lang_news_more = classLocale::$lang['news_more'];
66 66
         $text = sys_get_param('text') . ($detail_url ? " <a href=\"{$detail_url}\"><span class=\"positive\">{$lang_news_more}</span></a>" : '');
67 67
         DBStaticMessages::msgSendFromAdmin('*', classLocale::$lang['news_title'], $text);
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
   }
74 74
 
75 75
   $survey_answers = '';
76
-  switch($mode) {
76
+  switch ($mode) {
77 77
     case 'del':
78 78
       DBStaticNews::db_news_delete_by_id($announce_id);
79 79
       $mode = '';
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
       $template->assign_var('ID', $announce_id);
85 85
     case 'copy':
86 86
       $announce = DBStaticNews::db_news_with_survey_select_by_id($announce_id);
87
-      if($announce['survey_id']) {
87
+      if ($announce['survey_id']) {
88 88
         $query = DBStaticSurveyAnswer::db_survey_answer_text_select_by_news($announce);
89
-        while($row = db_fetch($query)) {
89
+        while ($row = db_fetch($query)) {
90 90
           $survey_answers[] = $row['survey_answer_text'];
91 91
         }
92 92
         $survey_answers = implode("\r\n", $survey_answers);
Please login to merge, or discard this patch.
notes.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -19,17 +19,17 @@  discard block
 block discarded – undo
19 19
 $template = gettemplate('notes', true);
20 20
 
21 21
 $result = array();
22
-if(($result_message = sys_get_param_str('MESSAGE')) && isset(classLocale::$lang[$result_message])) {
22
+if (($result_message = sys_get_param_str('MESSAGE')) && isset(classLocale::$lang[$result_message])) {
23 23
   $result[] = array('STATUS' => sys_get_param_int('STATUS'), 'MESSAGE' => classLocale::$lang[$result_message]);
24 24
 }
25 25
 
26 26
 $note_id_edit = sys_get_param_id('note_id_edit');
27 27
 $note_title_unsafe = sys_get_param_str_unsafe('note_title');
28 28
 $note_text_unsafe = sys_get_param_str_unsafe('note_text');
29
-if(sys_get_param('note_delete')) {
29
+if (sys_get_param('note_delete')) {
30 30
   try {
31 31
     DBStaticNote::processDelete($user, $note_id_edit);
32
-  } catch(Exception $e) {
32
+  } catch (Exception $e) {
33 33
     $note_id_edit = 0;
34 34
     sn_db_transaction_rollback();
35 35
     $result[] = array(
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
       'MESSAGE' => classLocale::$lang[$e->getMessage()],
38 38
     );
39 39
   }
40
-} elseif(($note_title_unsafe = sys_get_param_str_unsafe('note_title')) || ($note_text_unsafe = sys_get_param_str('note_text'))) {
40
+} elseif (($note_title_unsafe = sys_get_param_str_unsafe('note_title')) || ($note_text_unsafe = sys_get_param_str('note_text'))) {
41 41
   $note_title_unsafe == classLocale::$lang['note_new_title'] ? $note_title_unsafe = '' : false;
42 42
   $note_text_unsafe == classLocale::$lang['note_new_text'] ? $note_text_unsafe = '' : false;
43 43
   try {
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     $note_system = max(0, min(sys_get_param_id('note_system'), Vector::$knownSystems));
46 46
     $note_planet = max(0, min(sys_get_param_id('note_planet'), Vector::$knownPlanets + 1));
47 47
 
48
-    if(!$note_text_unsafe && !$note_title_unsafe && !$note_galaxy && !$note_system && !$note_planet) {
48
+    if (!$note_text_unsafe && !$note_title_unsafe && !$note_galaxy && !$note_system && !$note_planet) {
49 49
       throw new Exception('note_err_note_empty', ERR_WARNING);
50 50
     }
51 51
 
@@ -54,15 +54,15 @@  discard block
 block discarded – undo
54 54
     $note_sticky = intval(sys_get_param_id('note_sticky')) ? 1 : 0;
55 55
 
56 56
     sn_db_transaction_start();
57
-    if($note_id_edit) {
57
+    if ($note_id_edit) {
58 58
       $check_note_id = DBStaticNote::db_note_get_id_and_owner($note_id_edit);
59
-      if(!$check_note_id) {
59
+      if (!$check_note_id) {
60 60
         throw new Exception('note_err_note_not_found', ERR_ERROR);
61 61
       }
62 62
     }
63 63
 
64
-    if($note_id_edit) {
65
-      if($check_note_id['owner'] != $user['id']) {
64
+    if ($note_id_edit) {
65
+      if ($check_note_id['owner'] != $user['id']) {
66 66
         throw new Exception('note_err_owner_wrong', ERR_ERROR);
67 67
       }
68 68
 
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     sn_db_transaction_commit();
75 75
     sys_redirect('notes.php?STATUS=' . ERR_NONE . '&MESSAGE=' . ($note_id_edit ? 'note_err_none_changed' : 'note_err_none_added'));
76 76
 //    throw new exception($note_id_edit ? 'note_err_none_changed' : 'note_err_none_added', ERR_NONE);
77
-  } catch(Exception $e) {
77
+  } catch (Exception $e) {
78 78
     $note_id_edit = 0;
79 79
     sn_db_transaction_rollback();
80 80
     $result[] = array(
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
   }
85 85
 }
86 86
 
87
-if(!$note_id_edit) {
87
+if (!$note_id_edit) {
88 88
   note_assign($template, array(
89 89
     'id'          => 0,
90 90
     'time'        => SN_TIME_NOW,
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
 
98 98
 $note_exist = false;
99 99
 $notes_query = DBStaticNote::db_note_list_by_owner($user['id']);
100
-while($note_row = db_fetch($notes_query)) {
100
+while ($note_row = db_fetch($notes_query)) {
101 101
   note_assign($template, $note_row);
102 102
   $note_exist = $note_exist || $note_row['id'] == $note_id_edit;
103 103
 }
104 104
 $note_id_edit = $note_exist ? $note_id_edit : 0;
105 105
 
106
-foreach($note_priority_classes as $note_priority_id => $note_priority_class) {
106
+foreach ($note_priority_classes as $note_priority_id => $note_priority_class) {
107 107
   $template->assign_block_vars('note_priority', array(
108 108
     'ID'    => $note_priority_id,
109 109
     'CLASS' => $note_priority_classes[$note_priority_id],
@@ -111,14 +111,14 @@  discard block
 block discarded – undo
111 111
   ));
112 112
 }
113 113
 
114
-foreach(classLocale::$lang['sys_planet_type'] as $planet_type_id => $planet_type_string) {
114
+foreach (classLocale::$lang['sys_planet_type'] as $planet_type_id => $planet_type_string) {
115 115
   $template->assign_block_vars('planet_type', array(
116 116
     'ID'   => $planet_type_id,
117 117
     'TEXT' => $planet_type_string,
118 118
   ));
119 119
 }
120 120
 
121
-foreach($result as $result_data) {
121
+foreach ($result as $result_data) {
122 122
   $template->assign_block_vars('result', $result_data);
123 123
 }
124 124
 
Please login to merge, or discard this patch.
admin/statbuilder.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -9,18 +9,18 @@
 block discarded – undo
9 9
  * @copyright 2008 by Chlorel for XNova
10 10
  */
11 11
 
12
-define('INSIDE'  , true);
13
-define('INSTALL' , false);
12
+define('INSIDE', true);
13
+define('INSTALL', false);
14 14
 define('IN_ADMIN', true);
15 15
 require_once('../common.' . substr(strrchr(__FILE__, '.'), 1));
16 16
 
17 17
 // if($user['authlevel'] < 1)
18
-if($user['authlevel'] < 3)
18
+if ($user['authlevel'] < 3)
19 19
 {
20 20
   AdminMessage(classLocale::$lang['adm_err_denied']);
21 21
 }
22 22
 
23
-if(SN_TIME_NOW >= classSupernova::$config->db_loadItem('var_stat_update_admin_forced') && SN_TIME_NOW >= classSupernova::$config->db_loadItem('var_stat_update_end'))
23
+if (SN_TIME_NOW >= classSupernova::$config->db_loadItem('var_stat_update_admin_forced') && SN_TIME_NOW >= classSupernova::$config->db_loadItem('var_stat_update_end'))
24 24
 {
25 25
   classSupernova::$config->db_saveItem('var_stat_update_admin_forced', SN_TIME_NOW + 120);
26 26
 
Please login to merge, or discard this patch.
admin/adm_message_list.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 
15 15
 require('../common.' . substr(strrchr(__FILE__, '.'), 1));
16 16
 
17
-if($user['authlevel'] < 3) {
17
+if ($user['authlevel'] < 3) {
18 18
   AdminMessage(classLocale::$lang['adm_err_denied']);
19 19
 }
20 20
 
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
   ),
29 29
 );
30 30
 $template->assign_block_vars('int_type_selected', $allowed_types[-1]);
31
-foreach(DBStaticMessages::$snMessageClassList as $key => $value) {
32
-  if($key == MSG_TYPE_NEW || $key == MSG_TYPE_OUTBOX) {
31
+foreach (DBStaticMessages::$snMessageClassList as $key => $value) {
32
+  if ($key == MSG_TYPE_NEW || $key == MSG_TYPE_OUTBOX) {
33 33
     continue;
34 34
   }
35 35
 
@@ -41,21 +41,21 @@  discard block
 block discarded – undo
41 41
 
42 42
 
43 43
 $deletedMessages = '';
44
-if($idMessageDelete = sys_get_param_id('msg_del')) {
44
+if ($idMessageDelete = sys_get_param_id('msg_del')) {
45 45
   DBStaticMessages::db_message_delete_by_id($idMessageDelete);
46 46
   $deletedMessages = $idMessageDelete;
47
-} elseif(sys_get_param('str_delete_selected') && is_array($message_delete = sys_get_param('selected')) && !empty($message_delete)) {
47
+} elseif (sys_get_param('str_delete_selected') && is_array($message_delete = sys_get_param('selected')) && !empty($message_delete)) {
48 48
   $message_delete = implode(', ', $message_delete);
49 49
   DBStaticMessages::db_message_list_delete_set($message_delete);
50 50
   $deletedMessages = $message_delete;
51 51
 }
52 52
 
53
-if($deletedMessages) {
53
+if ($deletedMessages) {
54 54
   $template->assign_block_vars('result', array('MESSAGE' => sprintf(classLocale::$lang['mlst_messages_deleted'], $deletedMessages)));
55 55
 }
56 56
 
57 57
 
58
-if(sys_get_param('str_delete_date') && checkdate($month = sys_get_param_id('delete_month'), $day = sys_get_param_id('delete_day'), $year = sys_get_param_id('delete_year'))) {
58
+if (sys_get_param('str_delete_date') && checkdate($month = sys_get_param_id('delete_month'), $day = sys_get_param_id('delete_day'), $year = sys_get_param_id('delete_year'))) {
59 59
   $delete_date = "{$year}-{$month}-{$day}";
60 60
   DBStaticMessages::db_message_list_delete_by_date($delete_date, $int_type_selected);
61 61
   $template->assign_block_vars('result', array('MESSAGE' => sprintf(classLocale::$lang['mlst_messages_deleted_date'], $allowed_types[$int_type_selected]['TEXT'], $delete_date)));
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
 
68 68
 $int_page_current = min(sys_get_param_id('int_page_current', 1), $page_max);
69 69
 
70
-if(sys_get_param('page_prev') && $int_page_current > 1) {
70
+if (sys_get_param('page_prev') && $int_page_current > 1) {
71 71
   $int_page_current--;
72
-} elseif(sys_get_param('page_next') && $int_page_current < $page_max) {
72
+} elseif (sys_get_param('page_next') && $int_page_current < $page_max) {
73 73
   $int_page_current++;
74 74
 }
75 75
 
76
-for($i = 1; $i <= $page_max; $i++) {
76
+for ($i = 1; $i <= $page_max; $i++) {
77 77
   $template->assign_block_vars('page', array('NUMBER' => $i));
78 78
 }
79 79
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 $StartRec = ($int_page_current - 1) * 25;
82 82
 
83 83
 $Messages = DBStaticMessages::db_message_list_admin_by_type($int_type_selected, $StartRec);
84
-while($row = db_fetch($Messages)) {
84
+while ($row = db_fetch($Messages)) {
85 85
   $row['FROM'] = htmlentities($row['FROM'], ENT_COMPAT, 'UTF-8');
86 86
   $row['OWNER_NAME'] = htmlentities($row['OWNER_NAME'], ENT_COMPAT, 'UTF-8');
87 87
   $row['TEXT'] = nl2br($row['TEXT']);
Please login to merge, or discard this patch.
admin/userlist.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 require('../common.' . substr(strrchr(__FILE__, '.'), 1));
18 18
 
19 19
 global $user;
20
-if($user['authlevel'] < 3) {
20
+if ($user['authlevel'] < 3) {
21 21
   AdminMessage(classLocale::$lang['adm_err_denied']);
22 22
 }
23 23
 
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
 $sort = sys_get_param_int('sort', SORT_ID);
42 42
 $sort = $sort_fields[$sort] ? $sort : SORT_ID;
43 43
 
44
-if(($action = sys_get_param_int('action')) && ($user_id = sys_get_param_id('uid'))) {
44
+if (($action = sys_get_param_int('action')) && ($user_id = sys_get_param_id('uid'))) {
45 45
   $user_selected = DBStaticUser::db_user_by_id($user_id, false, 'id, username, authlevel');
46
-  if($user_selected['authlevel'] < $user['authlevel'] && $user['authlevel'] >= 3) {
47
-    switch($action) {
46
+  if ($user_selected['authlevel'] < $user['authlevel'] && $user['authlevel'] >= 3) {
47
+    switch ($action) {
48 48
       case ACTION_DELETE:
49 49
         DeleteSelectedUser($user_id);
50 50
         sys_redirect("{$_SERVER['SCRIPT_NAME']}?sort={$sort}");
@@ -64,20 +64,20 @@  discard block
 block discarded – undo
64 64
 $template = gettemplate('admin/userlist', true);
65 65
 
66 66
 $multi_ip = array();
67
-foreach(DBStaticUser::db_user_list_admin_multiaccounts() as $ip) {
67
+foreach (DBStaticUser::db_user_list_admin_multiaccounts() as $ip) {
68 68
   $multi_ip[$ip['user_lastip']] = $ip['ip_count'];
69 69
 }
70 70
 
71 71
 $geoip = geoip_status();
72 72
 $count = 0;
73
-foreach(DBStaticUser::db_user_list_admin_sorted($sort_fields[$sort], $is_players_online_page) as $user_row ) {
73
+foreach (DBStaticUser::db_user_list_admin_sorted($sort_fields[$sort], $is_players_online_page) as $user_row) {
74 74
   $count++;
75
-  if($user_row['banaday']) {
75
+  if ($user_row['banaday']) {
76 76
     $ban_details = db_ban_list_get_details($user_row);
77 77
   }
78 78
 
79 79
   $geoip_info = $geoip ? geoip_ip_info(ip2longu($user_row['user_lastip'])) : array();
80
-  foreach($geoip_info as $key => $value) {
80
+  foreach ($geoip_info as $key => $value) {
81 81
     $geoip_info[strtoupper($key)] = $value;
82 82
     unset($geoip_info[$key]);
83 83
   }
Please login to merge, or discard this patch.