@@ -22,17 +22,17 @@ discard block |
||
22 | 22 | $sn_group_factories = sn_get_groups('factories'); |
23 | 23 | $planet_density = sn_get_groups('planet_density'); |
24 | 24 | |
25 | - if(sys_get_param('save_production')) { |
|
25 | + if (sys_get_param('save_production')) { |
|
26 | 26 | $production = sys_get_param('percent'); |
27 | - if(is_array($production) && !empty($production)) { |
|
27 | + if (is_array($production) && !empty($production)) { |
|
28 | 28 | // sn_db_transaction_start(); |
29 | 29 | $query = array(); |
30 | 30 | $planet_row_list = db_planet_list_sorted($user, false, '*'); |
31 | 31 | // while($planet = db_fetch($planet_row_list)) |
32 | - foreach($planet_row_list as $planet) { |
|
33 | - foreach($sn_group_factories as $factory_unit_id) { |
|
32 | + foreach ($planet_row_list as $planet) { |
|
33 | + foreach ($sn_group_factories as $factory_unit_id) { |
|
34 | 34 | $unit_db_name_porcent = pname_factory_production_field_name($factory_unit_id); |
35 | - if( |
|
35 | + if ( |
|
36 | 36 | get_unit_param($factory_unit_id, P_MINING_IS_MANAGED) |
37 | 37 | && isset($production[$factory_unit_id][$planet['id']]) |
38 | 38 | && ($actual_porcent = intval($production[$factory_unit_id][$planet['id']] / 10)) >= 0 |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | } |
44 | 44 | } |
45 | 45 | } |
46 | - foreach($query as $planet_id => $query_data) { |
|
46 | + foreach ($query as $planet_id => $query_data) { |
|
47 | 47 | db_planet_set_by_id($planet_id, implode(',', $query_data)); |
48 | 48 | } |
49 | 49 | // sn_db_transaction_commit(); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | $planet_row_list = db_planet_list_sorted($user); |
54 | 54 | // while ($planet = db_fetch($planet_row_list)) |
55 | - foreach($planet_row_list as $planet) { |
|
55 | + foreach ($planet_row_list as $planet) { |
|
56 | 56 | sn_db_transaction_start(); |
57 | 57 | $global_data = sys_o_get_updated($user, $planet['id'], SN_TIME_NOW, false, true); |
58 | 58 | $planets[$planet['id']] = $global_data['planet']; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $template = gettemplate('imperium', $template); |
65 | 65 | $template->assign_var('amount', count($planets) + 2); |
66 | 66 | |
67 | - for($i = 100; $i >= 0; $i -= 10) { |
|
67 | + for ($i = 100; $i >= 0; $i -= 10) { |
|
68 | 68 | $template->assign_block_vars('percent', array('PERCENT' => $i)); |
69 | 69 | } |
70 | 70 | |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | $total['temp_min'] = 1000; |
75 | 75 | $total['temp_max'] = -999; |
76 | 76 | |
77 | - foreach($planets as $planet_index => &$planet) { |
|
77 | + foreach ($planets as $planet_index => &$planet) { |
|
78 | 78 | $list_planet_que = $ques[$planet_index]; |
79 | 79 | $planet_template = tpl_parse_planet($planet); |
80 | 80 | |
81 | 81 | $planet_fleet_id = 0; |
82 | - $fleet_list = $planet_template['fleet_list'];//flt_get_fleets_to_planet($planet); |
|
83 | - if($fleet_list['own']['count']) { |
|
82 | + $fleet_list = $planet_template['fleet_list']; //flt_get_fleets_to_planet($planet); |
|
83 | + if ($fleet_list['own']['count']) { |
|
84 | 84 | $planet_fleet_id = "p{$fleet_id}"; |
85 | 85 | $fleets[] = tpl_parse_fleet_sn($fleet_list['own']['total'], $planet_fleet_id); |
86 | 86 | $fleet_id++; |
@@ -141,17 +141,17 @@ discard block |
||
141 | 141 | UNIT_DEFENCE => 'defense', |
142 | 142 | ); |
143 | 143 | |
144 | - foreach($show_groups as $unit_group_id => $mode) { |
|
144 | + foreach ($show_groups as $unit_group_id => $mode) { |
|
145 | 145 | $template->assign_block_vars('prods', array( |
146 | 146 | 'NAME' => classLocale::$lang['tech'][$unit_group_id], |
147 | 147 | )); |
148 | 148 | $unit_group = get_unit_param('techtree', $unit_group_id); |
149 | - foreach($unit_group as $unit_id) { |
|
149 | + foreach ($unit_group as $unit_id) { |
|
150 | 150 | $unit_count = $unit_count_abs = 0; |
151 | 151 | $block_vars = array(); |
152 | 152 | $unit_is_factory = in_array($unit_id, $sn_group_factories) && get_unit_param($unit_id, P_MINING_IS_MANAGED); |
153 | 153 | // $unit_db_name = pname_resource_name($unit_id); |
154 | - foreach($planets as $planet) { |
|
154 | + foreach ($planets as $planet) { |
|
155 | 155 | $unit_level_plain = mrc_get_level($user, $planet, $unit_id, false, true); |
156 | 156 | |
157 | 157 | $level_plus['FACTORY'] = $unit_is_factory; |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | $level_plus['LEVEL_PLUS_GREEN'] = 0; |
160 | 160 | |
161 | 161 | $level_plus['PERCENT'] = $unit_is_factory ? ($unit_level_plain ? $planet[pname_factory_production_field_name($unit_id)] * 10 : -1) : -1; |
162 | - switch($mode) { |
|
162 | + switch ($mode) { |
|
163 | 163 | /* |
164 | 164 | case 'structures': |
165 | 165 | $level_plus_build = $ques[$planet['id']]['in_que'][que_get_unit_que($unit_id)][$user['id']][$planet['id']][$unit_id]; |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | case 'structures': |
180 | 180 | case 'defense': |
181 | 181 | $level_plus_build = $ques[$planet['id']]['in_que'][que_get_unit_que($unit_id)][$user['id']][$planet['id']][$unit_id]; |
182 | - if($level_plus_build) { |
|
182 | + if ($level_plus_build) { |
|
183 | 183 | $level_plus['LEVEL_PLUS_GREEN'] = $level_plus_build < 0 ? $level_plus_build : "+{$level_plus_build}"; |
184 | 184 | // $level_plus['LEVEL_PLUS_GREEN'] = "+{$level_plus_build}"; |
185 | 185 | $total['units'][$unit_id]['LEVEL_PLUS_GREEN'] += $level_plus['LEVEL_PLUS_GREEN']; |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $unit_count_abs += $unit_level_plain + abs($level_plus['LEVEL_PLUS_YELLOW']) + abs($level_plus['LEVEL_PLUS_GREEN']); |
200 | 200 | } |
201 | 201 | |
202 | - if($unit_count_abs) { |
|
202 | + if ($unit_count_abs) { |
|
203 | 203 | $template->assign_block_vars('prods', array( |
204 | 204 | 'ID' => $unit_id, |
205 | 205 | 'FIELD' => 'unit_' . $unit_id, // pname_resource_name($unit_id), // TODO Делать это прямо в темплейте |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | 'MODE' => $mode, |
208 | 208 | )); |
209 | 209 | |
210 | - foreach($block_vars as $block_var) { |
|
210 | + foreach ($block_vars as $block_var) { |
|
211 | 211 | $template->assign_block_vars('prods.planet', $block_var); |
212 | 212 | } |
213 | 213 | $unit_green = $total['units'][$unit_id]['LEVEL_PLUS_GREEN']; |
@@ -16,7 +16,7 @@ |
||
16 | 16 | $query = db_user_list("`authlevel` > 0 ORDER BY `authlevel` ASC"); |
17 | 17 | |
18 | 18 | // while($row = db_fetch($query)) |
19 | - foreach($query as $row) { |
|
19 | + foreach ($query as $row) { |
|
20 | 20 | $template_result['.']['contact'][] = array( |
21 | 21 | 'NAME' => $row['username'], |
22 | 22 | 'LEVEL' => classLocale::$lang['user_level'][$row['authlevel']], |
@@ -76,23 +76,23 @@ discard block |
||
76 | 76 | function sn_db_connect($external_db_settings = null) { |
77 | 77 | $this->db_disconnect(); |
78 | 78 | |
79 | - if(!empty($external_db_settings) && is_array($external_db_settings)) { |
|
79 | + if (!empty($external_db_settings) && is_array($external_db_settings)) { |
|
80 | 80 | $this->dbsettings = $external_db_settings; |
81 | 81 | } |
82 | 82 | |
83 | - if(empty($this->dbsettings)) { |
|
83 | + if (empty($this->dbsettings)) { |
|
84 | 84 | $this->load_db_settings(); |
85 | 85 | } |
86 | 86 | |
87 | 87 | // TODO - фатальные (?) ошибки на каждом шагу. Хотя - скорее Эксепшны |
88 | - if(!empty($this->dbsettings)) { |
|
88 | + if (!empty($this->dbsettings)) { |
|
89 | 89 | $driver_name = empty($this->dbsettings['sn_driver']) ? 'db_mysql_v5' : $this->dbsettings['sn_driver']; |
90 | 90 | $this->driver = new $driver_name(); |
91 | 91 | $this->db_prefix = $this->dbsettings['prefix']; |
92 | 92 | |
93 | 93 | $this->connected = $this->connected || $this->driver_connect(); |
94 | 94 | |
95 | - if($this->connected) { |
|
95 | + if ($this->connected) { |
|
96 | 96 | $this->table_list = $this->db_get_table_list(); |
97 | 97 | // TODO Проверка на пустоту |
98 | 98 | } |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | function driver_connect() { |
107 | 107 | global $debug; |
108 | 108 | |
109 | - if(!is_object($this->driver)) { |
|
109 | + if (!is_object($this->driver)) { |
|
110 | 110 | $debug->error_fatal('DB Error - No driver for MySQL found!'); |
111 | 111 | } |
112 | 112 | |
113 | - if(!method_exists($this->driver, 'mysql_connect')) { |
|
113 | + if (!method_exists($this->driver, 'mysql_connect')) { |
|
114 | 114 | $debug->error_fatal('DB Error - WRONG MySQL driver!'); |
115 | 115 | } |
116 | 116 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | function db_disconnect() { |
121 | - if($this->connected) { |
|
121 | + if ($this->connected) { |
|
122 | 122 | $this->connected = !$this->driver_disconnect(); |
123 | 123 | $this->connected = false; |
124 | 124 | } |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | function doquery($query, $table = '', $fetch = false, $skip_query_check = false) { |
130 | 130 | global $numqueries, $debug, $config; |
131 | 131 | |
132 | - if(!is_string($table)) { |
|
132 | + if (!is_string($table)) { |
|
133 | 133 | $fetch = $table; |
134 | 134 | } |
135 | 135 | |
136 | - if(!$this->connected) { |
|
136 | + if (!$this->connected) { |
|
137 | 137 | $this->sn_db_connect(); |
138 | 138 | } |
139 | 139 | |
@@ -142,30 +142,30 @@ discard block |
||
142 | 142 | $skip_query_check ? $this->security_query_check_bad_words($query) : false; |
143 | 143 | |
144 | 144 | $sql = $query; |
145 | - if(strpos($sql, '{{') !== false) { |
|
146 | - foreach($this->table_list as $tableName) { |
|
145 | + if (strpos($sql, '{{') !== false) { |
|
146 | + foreach ($this->table_list as $tableName) { |
|
147 | 147 | $sql = str_replace("{{{$tableName}}}", $this->db_prefix . $tableName, $sql); |
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | - if($config->debug) { |
|
151 | + if ($config->debug) { |
|
152 | 152 | $numqueries++; |
153 | 153 | $arr = debug_backtrace(); |
154 | - $file = end(explode('/',$arr[0]['file'])); |
|
154 | + $file = end(explode('/', $arr[0]['file'])); |
|
155 | 155 | $line = $arr[0]['line']; |
156 | 156 | $debug->add("<tr><th>Query $numqueries: </th><th>$query</th><th>$file($line)</th><th>$table</th><th>$fetch</th></tr>"); |
157 | 157 | } |
158 | 158 | |
159 | - if(defined('DEBUG_SQL_COMMENT')) { |
|
159 | + if (defined('DEBUG_SQL_COMMENT')) { |
|
160 | 160 | $backtrace = debug_backtrace(); |
161 | 161 | $sql_comment = $debug->compact_backtrace($backtrace, defined('DEBUG_SQL_COMMENT_LONG')); |
162 | 162 | |
163 | 163 | $sql_commented = '/* ' . implode("<br />", $sql_comment) . '<br /> */ ' . preg_replace("/\s+/", ' ', $sql); |
164 | - if(defined('DEBUG_SQL_ONLINE')) { |
|
164 | + if (defined('DEBUG_SQL_ONLINE')) { |
|
165 | 165 | $debug->warning($sql_commented, 'SQL Debug', LOG_DEBUG_SQL); |
166 | 166 | } |
167 | 167 | |
168 | - if(defined('DEBUG_SQL_ERROR')) { |
|
168 | + if (defined('DEBUG_SQL_ERROR')) { |
|
169 | 169 | array_unshift($sql_comment, preg_replace("/\s+/", ' ', $sql)); |
170 | 170 | $debug->add_to_array($sql_comment); |
171 | 171 | // $debug->add_to_array($sql_comment . preg_replace("/\s+/", ' ', $sql)); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | $sql = $sql_commented; |
174 | 174 | } |
175 | 175 | |
176 | - $sqlquery = $this->db_sql_query($sql) or $debug->error(db_error()."<br />$sql<br />",'SQL Error'); |
|
176 | + $sqlquery = $this->db_sql_query($sql) or $debug->error(db_error() . "<br />$sql<br />", 'SQL Error'); |
|
177 | 177 | |
178 | 178 | return $fetch ? $this->db_fetch($sqlquery) : $sqlquery; |
179 | 179 | } |
@@ -183,16 +183,16 @@ discard block |
||
183 | 183 | // TODO Заменить это на новый логгер |
184 | 184 | global $config, $is_watching, $user, $debug; |
185 | 185 | |
186 | - if(!$is_watching && $config->game_watchlist_array && in_array($user['id'], $config->game_watchlist_array)) |
|
186 | + if (!$is_watching && $config->game_watchlist_array && in_array($user['id'], $config->game_watchlist_array)) |
|
187 | 187 | { |
188 | - if(!preg_match('/^(select|commit|rollback|start transaction)/i', $query)) { |
|
188 | + if (!preg_match('/^(select|commit|rollback|start transaction)/i', $query)) { |
|
189 | 189 | $is_watching = true; |
190 | 190 | $msg = "\$query = \"{$query}\"\n\r"; |
191 | - if(!empty($_POST)) { |
|
192 | - $msg .= "\n\r" . dump($_POST,'$_POST'); |
|
191 | + if (!empty($_POST)) { |
|
192 | + $msg .= "\n\r" . dump($_POST, '$_POST'); |
|
193 | 193 | } |
194 | - if(!empty($_GET)) { |
|
195 | - $msg .= "\n\r" . dump($_GET,'$_GET'); |
|
194 | + if (!empty($_GET)) { |
|
195 | + $msg .= "\n\r" . dump($_GET, '$_GET'); |
|
196 | 196 | } |
197 | 197 | $debug->warning($msg, "Watching user {$user['id']}", 399, array('base_dump' => true)); |
198 | 198 | $is_watching = false; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | function security_query_check_bad_words($query) { |
205 | 205 | global $user, $dm_change_legit, $mm_change_legit; |
206 | 206 | |
207 | - switch(true) { |
|
207 | + switch (true) { |
|
208 | 208 | case stripos($query, 'RUNCATE TABL') != false: |
209 | 209 | case stripos($query, 'ROP TABL') != false: |
210 | 210 | case stripos($query, 'ENAME TABL') != false: |
@@ -215,33 +215,33 @@ discard block |
||
215 | 215 | case stripos($query, 'RPG_POINTS') != false && stripos(trim($query), 'UPDATE ') === 0 && !$dm_change_legit: |
216 | 216 | case stripos($query, 'METAMATTER') != false && stripos(trim($query), 'UPDATE ') === 0 && !$mm_change_legit: |
217 | 217 | case stripos($query, 'AUTHLEVEL') != false && $user['authlevel'] < 3 && stripos($query, 'SELECT') !== 0: |
218 | - $report = "Hacking attempt (".date("d.m.Y H:i:s")." - [".time()."]):\n"; |
|
218 | + $report = "Hacking attempt (" . date("d.m.Y H:i:s") . " - [" . time() . "]):\n"; |
|
219 | 219 | $report .= ">Database Inforamation\n"; |
220 | - $report .= "\tID - ".$user['id']."\n"; |
|
221 | - $report .= "\tUser - ".$user['username']."\n"; |
|
222 | - $report .= "\tAuth level - ".$user['authlevel']."\n"; |
|
223 | - $report .= "\tAdmin Notes - ".$user['adminNotes']."\n"; |
|
224 | - $report .= "\tCurrent Planet - ".$user['current_planet']."\n"; |
|
225 | - $report .= "\tUser IP - ".$user['user_lastip']."\n"; |
|
226 | - $report .= "\tUser IP at Reg - ".$user['ip_at_reg']."\n"; |
|
227 | - $report .= "\tUser Agent- ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
228 | - $report .= "\tCurrent Page - ".$user['current_page']."\n"; |
|
229 | - $report .= "\tRegister Time - ".$user['register_time']."\n"; |
|
220 | + $report .= "\tID - " . $user['id'] . "\n"; |
|
221 | + $report .= "\tUser - " . $user['username'] . "\n"; |
|
222 | + $report .= "\tAuth level - " . $user['authlevel'] . "\n"; |
|
223 | + $report .= "\tAdmin Notes - " . $user['adminNotes'] . "\n"; |
|
224 | + $report .= "\tCurrent Planet - " . $user['current_planet'] . "\n"; |
|
225 | + $report .= "\tUser IP - " . $user['user_lastip'] . "\n"; |
|
226 | + $report .= "\tUser IP at Reg - " . $user['ip_at_reg'] . "\n"; |
|
227 | + $report .= "\tUser Agent- " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
228 | + $report .= "\tCurrent Page - " . $user['current_page'] . "\n"; |
|
229 | + $report .= "\tRegister Time - " . $user['register_time'] . "\n"; |
|
230 | 230 | $report .= "\n"; |
231 | 231 | |
232 | 232 | $report .= ">Query Information\n"; |
233 | - $report .= "\tQuery - ".$query."\n"; |
|
233 | + $report .= "\tQuery - " . $query . "\n"; |
|
234 | 234 | $report .= "\n"; |
235 | 235 | |
236 | 236 | $report .= ">\$_SERVER Information\n"; |
237 | - $report .= "\tIP - ".$_SERVER['REMOTE_ADDR']."\n"; |
|
238 | - $report .= "\tHost Name - ".$_SERVER['HTTP_HOST']."\n"; |
|
239 | - $report .= "\tUser Agent - ".$_SERVER['HTTP_USER_AGENT']."\n"; |
|
240 | - $report .= "\tRequest Method - ".$_SERVER['REQUEST_METHOD']."\n"; |
|
241 | - $report .= "\tCame From - ".$_SERVER['HTTP_REFERER']."\n"; |
|
242 | - $report .= "\tPage is - ".$_SERVER['SCRIPT_NAME']."\n"; |
|
243 | - $report .= "\tUses Port - ".$_SERVER['REMOTE_PORT']."\n"; |
|
244 | - $report .= "\tServer Protocol - ".$_SERVER['SERVER_PROTOCOL']."\n"; |
|
237 | + $report .= "\tIP - " . $_SERVER['REMOTE_ADDR'] . "\n"; |
|
238 | + $report .= "\tHost Name - " . $_SERVER['HTTP_HOST'] . "\n"; |
|
239 | + $report .= "\tUser Agent - " . $_SERVER['HTTP_USER_AGENT'] . "\n"; |
|
240 | + $report .= "\tRequest Method - " . $_SERVER['REQUEST_METHOD'] . "\n"; |
|
241 | + $report .= "\tCame From - " . $_SERVER['HTTP_REFERER'] . "\n"; |
|
242 | + $report .= "\tPage is - " . $_SERVER['SCRIPT_NAME'] . "\n"; |
|
243 | + $report .= "\tUses Port - " . $_SERVER['REMOTE_PORT'] . "\n"; |
|
244 | + $report .= "\tServer Protocol - " . $_SERVER['SERVER_PROTOCOL'] . "\n"; |
|
245 | 245 | |
246 | 246 | $report .= "\n--------------------------------------------------------------------------------------------------\n"; |
247 | 247 | |
@@ -261,11 +261,11 @@ discard block |
||
261 | 261 | $prefix_length = strlen($this->db_prefix); |
262 | 262 | |
263 | 263 | $tl = array(); |
264 | - while($row = $this->db_fetch($query)) { |
|
265 | - foreach($row as $table_name) { |
|
266 | - if(strpos($table_name, $this->db_prefix) === 0) { |
|
264 | + while ($row = $this->db_fetch($query)) { |
|
265 | + foreach ($row as $table_name) { |
|
266 | + if (strpos($table_name, $this->db_prefix) === 0) { |
|
267 | 267 | $table_name = substr($table_name, $prefix_length); |
268 | - } elseif($prefixed_only) { |
|
268 | + } elseif ($prefixed_only) { |
|
269 | 269 | continue; |
270 | 270 | } |
271 | 271 | // $table_name = str_replace($db_prefix, '', $table_name); |