Completed
Push — work-fleets ( 3604bd...203362 )
by SuperNova.WS
06:25
created
admin/add_moon.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@
 block discarded – undo
14 14
 require('../common.' . substr(strrchr(__FILE__, '.'), 1));
15 15
 
16 16
 // if ($user['authlevel'] < 2)
17
-if($user['authlevel'] < 3)
17
+if ($user['authlevel'] < 3)
18 18
 {
19 19
   AdminMessage($lang['adm_err_denied']);
20 20
 }
21 21
 
22 22
 $template = gettemplate("admin/add_moon", true);
23 23
 
24
-if(sys_get_param_str('mode') == 'addit')
24
+if (sys_get_param_str('mode') == 'addit')
25 25
 {
26 26
   $PlanetID = sys_get_param_id('user');
27 27
   $MoonName = sys_get_param_str('name');
Please login to merge, or discard this patch.
admin/sxd/tmpl.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Templates
3
-function sxd_tpl_page(){
3
+function sxd_tpl_page() {
4 4
 global $SXD;
5 5
 return <<<HTML
6 6
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 HTML;
292 292
 }
293 293
 
294
-function sxd_tpl_auth($error = ''){
294
+function sxd_tpl_auth($error = '') {
295 295
 global $SXD;
296 296
 return <<<HTML
297 297
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">  
Please login to merge, or discard this patch.
admin/sxd/index.php 1 patch
Spacing   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -33,27 +33,27 @@  discard block
 block discarded – undo
33 33
 		define('V_PHP', sxd_ver2int(phpversion()));
34 34
 		$this->name = 'Sypex Dumper 2.0.11';
35 35
 	}
36
-	function loadLang($lng_name = 'auto'){
37
-		if($lng_name == 'auto'){
36
+	function loadLang($lng_name = 'auto') {
37
+		if ($lng_name == 'auto') {
38 38
 			include('lang/list.php');
39 39
 			$this->langs = &$langs;
40 40
 			$lng = 'en';
41
-			if(preg_match_all('/[a-z]{2}(-[a-z]{2})?/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $m)) {
42
-				foreach($m[0] AS $l){
43
-					if(isset($langs[$l])){
41
+			if (preg_match_all('/[a-z]{2}(-[a-z]{2})?/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $m)) {
42
+				foreach ($m[0] AS $l) {
43
+					if (isset($langs[$l])) {
44 44
 						$lng_name = $l;
45 45
 						break;
46 46
 					}
47 47
 				}
48 48
 			}
49 49
 		}
50
-		if(file_exists("lang/lng_{$lng_name}.php")) include("lang/lng_{$lng_name}.php");
50
+		if (file_exists("lang/lng_{$lng_name}.php")) include("lang/lng_{$lng_name}.php");
51 51
 		else include("lang/lng_en.php");
52 52
 		$this->LNG = &$LNG;
53 53
 		$this->LNG['name'] = $lng_name;
54 54
 		return true;
55 55
 	}
56
-	function init($args = false){
56
+	function init($args = false) {
57 57
 		if (get_magic_quotes_gpc()) {
58 58
 			$_POST = sxd_antimagic($_POST);
59 59
 		}
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 		$this->virtualize = false;
67 67
 		$this->cron_mode = false;
68 68
 		// Проверяем авторизацию и делаем коннект к базе
69
-		if(empty($this->CFG['my_user'])){
69
+		if (empty($this->CFG['my_user'])) {
70 70
 			$this->CFG['my_host'] = 'localhost';
71 71
 			$this->CFG['my_port'] = 3306;
72 72
 			$this->CFG['my_user'] = 'root';
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 			$this->CFG['my_db'] = '';
76 76
 		}
77 77
 		if ($args) { // консольный режим
78
-		    foreach($args AS $key => $arg){
79
-		        if (preg_match("/^-([hupoj])=(.*?)$/", $arg, $m)){
78
+		    foreach ($args AS $key => $arg) {
79
+		        if (preg_match("/^-([hupoj])=(.*?)$/", $arg, $m)) {
80 80
 		            switch ($m[1]) {
81 81
 		                case 'h': $this->CFG['my_host'] = $m[2]; break; // хост
82 82
 		                case 'o': $this->CFG['my_port'] = $m[2]; break; // порт
@@ -90,73 +90,73 @@  discard block
 block discarded – undo
90 90
 		    set_time_limit($CFG['time_cron']);
91 91
 		    // Загружаем конфиг файл, если нужно
92 92
 		    $auth = $this->connect();
93
-		    if($auth && !empty($this->CFG['sjob'])){
93
+		    if ($auth && !empty($this->CFG['sjob'])) {
94 94
 				$this->ajax($this->loadJob($this->CFG['sjob']));
95 95
 				echo file_get_contents($this->JOB['file_log']);
96
-				if(file_exists($this->JOB['file_log'])) unlink($this->JOB['file_log']);
97
-				if(file_exists($this->JOB['file_rtl'])) unlink($this->JOB['file_rtl']);
96
+				if (file_exists($this->JOB['file_log'])) unlink($this->JOB['file_log']);
97
+				if (file_exists($this->JOB['file_rtl'])) unlink($this->JOB['file_rtl']);
98 98
 		    }
99 99
 		    else echo 'Auth error';
100 100
 		    exit;
101 101
 		}
102
-		elseif(!empty($this->CFG['auth'])){ // Авторизация
102
+		elseif (!empty($this->CFG['auth'])) { // Авторизация
103 103
 			$auth = false;
104 104
 			$sfile = 'ses.php';
105 105
 			
106
-			if(!empty($_COOKIE['sxd']) && preg_match('/^[\da-f]{32}$/', $_COOKIE['sxd'])){
106
+			if (!empty($_COOKIE['sxd']) && preg_match('/^[\da-f]{32}$/', $_COOKIE['sxd'])) {
107 107
 				include($sfile);
108
-				if(isset($SES[$_COOKIE['sxd']])) {
108
+				if (isset($SES[$_COOKIE['sxd']])) {
109 109
 					$auth = true;
110 110
 					$this->CFG = $SES[$_COOKIE['sxd']]['cfg'];
111 111
 					$this->SES = &$SES;
112 112
 					$this->loadLang($this->CFG['lang']);
113 113
 				}
114 114
 			}
115
-			if(!$auth) {
115
+			if (!$auth) {
116 116
 				$user = !empty($_POST['user']) ? $_POST['user'] : '';
117 117
 				$pass = !empty($_POST['pass']) ? $_POST['pass'] : '';
118 118
 				$host = !empty($_POST['host']) ? $_POST['host'] : (!empty($this->CFG['my_host']) ? $this->CFG['my_host'] : 'localhost');
119 119
 				$port = !empty($_POST['port']) && is_numeric($_POST['port']) ? $_POST['port'] : 3306;
120 120
 				$temp = preg_split('/\s+/', $this->CFG['auth']);
121
-				if(!empty($_REQUEST['lang']) && preg_match('/^[a-z]{2}(-[a-z]{2})?$/', $_REQUEST['lang'])) {$this->loadLang($_REQUEST['lang']);}
122
-				foreach($temp AS $a){
123
-					switch($a) {
124
-						case 'cfg': 	if(empty($user)) {continue;}
125
-										$auth = !empty($CFG['user']) && isset($CFG['pass']) && $CFG['user']== $user && $CFG['pass'] == $pass;
121
+				if (!empty($_REQUEST['lang']) && preg_match('/^[a-z]{2}(-[a-z]{2})?$/', $_REQUEST['lang'])) {$this->loadLang($_REQUEST['lang']); }
122
+				foreach ($temp AS $a) {
123
+					switch ($a) {
124
+						case 'cfg': 	if (empty($user)) {continue; }
125
+										$auth = !empty($CFG['user']) && isset($CFG['pass']) && $CFG['user'] == $user && $CFG['pass'] == $pass;
126 126
 										break;
127
-						case 'mysql':	if(empty($user)) {continue;}
128
-										if($host != 'localhost' && !empty($this->CFG['my_host']) && $this->CFG['my_host'] != $host) {continue;}
127
+						case 'mysql':	if (empty($user)) {continue; }
128
+										if ($host != 'localhost' && !empty($this->CFG['my_host']) && $this->CFG['my_host'] != $host) {continue; }
129 129
 										$auth = $this->connect($host, $port, $user, $pass);
130 130
 										break;
131 131
 						default:		$file = 'auth_' . $a . '.php';
132
-										if(!file_exists($file)) continue;
132
+										if (!file_exists($file)) continue;
133 133
 										include	$file;
134 134
 					}
135
-					if($auth) break;
135
+					if ($auth) break;
136 136
 				}
137
-				if($auth){
138
-					$key = md5(rand(1,100000) . $user . microtime());
137
+				if ($auth) {
138
+					$key = md5(rand(1, 100000) . $user . microtime());
139 139
 					$CFG['lang'] = $this->LNG['name'];
140 140
 					$_COOKIE['sxd'] = $key;
141 141
 					$this->saveCFG();
142
-					if(V_PHP > 50200) setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false, true);
142
+					if (V_PHP > 50200) setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false, true);
143 143
 					else setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false);
144 144
 					header("Location: ./");
145 145
 					exit;
146 146
 				}
147
-				foreach(array('user', 'pass', 'host', 'port') AS $key){
147
+				foreach (array('user', 'pass', 'host', 'port') AS $key) {
148 148
 					$_POST[$key] = !empty($_POST[$key]) ? htmlspecialchars($_POST[$key], ENT_NOQUOTES) : '';
149 149
 				}
150 150
 				$_POST['save'] = !empty($_POST['save']) ? ' CHECKED' : '';
151 151
 			}
152 152
 			if (!$auth) {
153
-				if(!empty($_POST['ajax'])){
153
+				if (!empty($_POST['ajax'])) {
154 154
 					echo "sxd.hideLoading();alert('Session not found');";
155 155
 					exit;
156 156
 				}
157 157
 				$this->lng_list = '<option value="auto">- auto -</opinion>';
158
-				if(!isset($this->langs)) {include('lang/list.php');$this->langs = &$langs;}
159
-				foreach($this->langs AS $k => $v){
158
+				if (!isset($this->langs)) {include('lang/list.php'); $this->langs = &$langs; }
159
+				foreach ($this->langs AS $k => $v) {
160 160
 					$this->lng_list .= "<option value=\"{$k}\"" . ($k == (!empty($_REQUEST['lang']) ? $this->LNG['name'] : $this->CFG['lang']) ? ' SELECTED' : '') . ">{$v}</opinion>";
161 161
 				}
162 162
 				include('tmpl.php');
@@ -164,26 +164,26 @@  discard block
 block discarded – undo
164 164
 				exit;
165 165
 			}
166 166
 		}
167
-		if(empty($_POST['ajax']['act']) || $_POST['ajax']['act'] != 'save_connect') $this->connect();
168
-		if(isset($_POST['ajax'])) $this->ajax($_POST['ajax']);
169
-		else $this->main();exit;
167
+		if (empty($_POST['ajax']['act']) || $_POST['ajax']['act'] != 'save_connect') $this->connect();
168
+		if (isset($_POST['ajax'])) $this->ajax($_POST['ajax']);
169
+		else $this->main(); exit;
170 170
 	}
171
-	function saveToFile($name, $content){
171
+	function saveToFile($name, $content) {
172 172
 		$fp = fopen($name, "w");
173 173
 		fwrite($fp, $content);
174 174
 		fclose($fp);
175 175
 	}
176
-	function connect($host = null, $port = null, $user = null, $pass = null){
176
+	function connect($host = null, $port = null, $user = null, $pass = null) {
177 177
 		$this->error = '';
178 178
 		$this->try = true;
179
-		if(!empty($user) && isset($pass)) {
179
+		if (!empty($user) && isset($pass)) {
180 180
 			$this->CFG['my_host'] = $host;
181 181
 			$this->CFG['my_port'] = $port;
182 182
 			$this->CFG['my_user'] = $user;
183 183
 			$this->CFG['my_pass'] = $pass;
184 184
 		}
185
-		if(mysql_connect($this->CFG['my_host'] . ($this->CFG['my_host']{0} != ':' ? ":{$this->CFG['my_port']}" : ''),  $this->CFG['my_user'], $this->CFG['my_pass'])) {
186
-			if(V_PHP > 50202) mysql_set_charset('utf8') or sxd_my_error();
185
+		if (mysql_connect($this->CFG['my_host'] . ($this->CFG['my_host']{0} != ':' ? ":{$this->CFG['my_port']}" : ''), $this->CFG['my_user'], $this->CFG['my_pass'])) {
186
+			if (V_PHP > 50202) mysql_set_charset('utf8') or sxd_my_error();
187 187
 			else mysql_query('SET NAMES utf8') or sxd_my_error();
188 188
 			define('V_MYSQL', sxd_ver2int(mysql_get_server_info()));
189 189
 		}
@@ -192,9 +192,9 @@  discard block
 block discarded – undo
192 192
 			$this->error = "sxd.actions.tab_connects();alert(" . sxd_esc(mysql_error()) . ");";
193 193
 		}	
194 194
 		$this->try = false;
195
-		return V_MYSQL ? true: false;
195
+		return V_MYSQL ? true : false;
196 196
 	}
197
-	function main(){
197
+	function main() {
198 198
    		// Тулбар
199 199
 		$this->VAR['toolbar'] = sxd_php2json(
200 200
 			array(
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
   		$this->db = 'temp';
216 216
 		$zip = array($this->LNG['zip_none']);
217 217
 		if (function_exists("gzopen")) {
218
-			for($i = 1; $i <10; $i++){
218
+			for ($i = 1; $i < 10; $i++) {
219 219
 				$zip[] = "GZip: {$i}";
220 220
 			}
221 221
 			$zip[1] .= " ({$this->LNG['zip_min']})";
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 		    $zip[10] = "BZip";
226 226
 		}
227 227
 		end($zip);
228
-		$zip[key($zip)] .=  " ({$this->LNG['zip_max']})";
228
+		$zip[key($zip)] .= " ({$this->LNG['zip_max']})";
229 229
 		$this->VAR['combos'] =
230 230
 			$this->addCombo('backup_db', $this->db, 11, 'db', array()/*$this->getDBList()*/) . 
231 231
 			$this->addCombo('backup_charset', 0, 9, 'charset', $this->getCharsetList()) .
@@ -248,17 +248,17 @@  discard block
 block discarded – undo
248 248
 		include('tmpl.php');
249 249
 		echo sxd_tpl_page();
250 250
 	}
251
-	function addCombo($name, $sel, $ico, $opt_name, $opts = ''){
251
+	function addCombo($name, $sel, $ico, $opt_name, $opts = '') {
252 252
 		$opts = !empty($opts) ? "{{$opt_name}:" . sxd_php2json($opts) . '}' : "'{$opt_name}'";
253 253
 		return "sxd.addCombo('{$name}', '{$sel}', {$ico}, {$opts});\n";
254 254
 	}
255
-	function ajax($req){
255
+	function ajax($req) {
256 256
 		$res = '';
257 257
 		$act = $req['act'];
258
-		if($req['act'] == 'run_savedjob'){
258
+		if ($req['act'] == 'run_savedjob') {
259 259
 			$req = $this->loadJob($req);
260 260
 		}
261
-		switch($req['act']){
261
+		switch ($req['act']) {
262 262
 			case 'load_db': 
263 263
 				$res = $this->getObjects(str_replace('_db', '', $req['name']), $req['value']);
264 264
 				break;
@@ -274,14 +274,14 @@  discard block
 block discarded – undo
274 274
 			case 'load_connect':
275 275
 				$CFG = $this->cfg2js($this->CFG); 
276 276
 				$res = "z('con_host').value = '{$CFG['my_host']}', z('con_port').value = '{$CFG['my_port']}', z('con_user').value = '{$CFG['my_user']}',
277
-			z('con_pass').value = '', z('con_comp').checked = {$CFG['my_comp']}, z('con_db').value = '{$CFG['my_db']}', z('con_pass').changed = false;" ;
277
+			z('con_pass').value = '', z('con_comp').checked = {$CFG['my_comp']}, z('con_db').value = '{$CFG['my_db']}', z('con_pass').changed = false;";
278 278
 				break;
279 279
 			case 'save_connect': 
280 280
 				$res = $this->saveConnect($req);
281 281
 				break;
282 282
 			case 'save_job': 
283 283
 				unset($req['act']);
284
-				$this->saveJob('sj_' . $req['job'] , $req);
284
+				$this->saveJob('sj_' . $req['job'], $req);
285 285
 				$res = $this->getSavedJobs();
286 286
 				break;
287 287
 			case 'add_db': 
@@ -296,9 +296,9 @@  discard block
 block discarded – undo
296 296
 				$res = $this->saveOptions($req);
297 297
 				break;
298 298
 			case 'delete_file':
299
-				if(preg_match('/^[^\/]+?\.sql(\.(gz|bz2))?$/', $req['name'])) {
299
+				if (preg_match('/^[^\/]+?\.sql(\.(gz|bz2))?$/', $req['name'])) {
300 300
 					$file = $this->CFG['backup_path'] . $req['name'];
301
-					if(file_exists($file)) unlink($file);
301
+					if (file_exists($file)) unlink($file);
302 302
 				}
303 303
 				$res = $this->getFileListExtended();
304 304
 				break;
@@ -327,40 +327,40 @@  discard block
 block discarded – undo
327 327
 		}	
328 328
 		echo $res;
329 329
 	}
330
-	function loadJob($job){
330
+	function loadJob($job) {
331 331
 		$file = $this->CFG['backup_path'] . 'sj_' . (is_array($job) ? $job['job'] : $job) . '.job.php';
332
-		if(!file_exists($file)) return;
332
+		if (!file_exists($file)) return;
333 333
 		include($file);
334 334
 		$JOB['act'] = $JOB['type'];
335 335
 		$JOB['type'] = 'run';
336 336
 		return $JOB;
337 337
 	}
338
-	function deleteDB($name){
338
+	function deleteDB($name) {
339 339
 		$r = mysql_query('DROP DATABASE `' . sxd_esc($name, false) . '`') or sxd_my_error();
340
-		if($r){
340
+		if ($r) {
341 341
         	echo "sxd.clearOpt('db');sxd.addOpt(" . sxd_php2json(array('db' => $this->getDBList())) . ");sxd.combos.services_db.select(0,'-');";
342 342
 		}
343 343
         else
344 344
         	echo "alert(" . sxd_esc(mysql_error()) . ");";
345 345
 	}
346
-	function cfg2js($cfg){
347
-		foreach($cfg AS $k => $v){
346
+	function cfg2js($cfg) {
347
+		foreach ($cfg AS $k => $v) {
348 348
 			$cfg[$k] = sxd_esc($v, false);
349 349
 		}
350 350
 		return $cfg;
351 351
 	}
352
-	function addDb($req){
352
+	function addDb($req) {
353 353
         $r = mysql_query('CREATE DATABASE `' . sxd_esc($req['name'], false) . '`' . (V_MYSQL > 40100 ? "CHARACTER SET {$req['charset']} COLLATE {$req['collate']}" : ''));
354
-        if($r)
354
+        if ($r)
355 355
         	echo "sxd.addOpt(" . sxd_php2json(array('db' => array($req['name'] => "{$req['name']} (0)"))) . ");";
356 356
         else
357 357
         	 sxd_my_error();
358 358
 	}
359
-	function saveConnect($req){
359
+	function saveConnect($req) {
360 360
 		$this->CFG['my_host'] = $req['host'];
361
-		$this->CFG['my_port'] = (int)$req['port'];
361
+		$this->CFG['my_port'] = (int) $req['port'];
362 362
 		$this->CFG['my_user'] = $req['user'];
363
-		if(isset($req['pass'])) $this->CFG['my_pass'] = $req['pass'];
363
+		if (isset($req['pass'])) $this->CFG['my_pass'] = $req['pass'];
364 364
 		$this->CFG['my_comp'] = $req['comp'] ? 1 : 0;
365 365
 		$this->CFG['my_db']   = $req['db'];
366 366
 		$this->saveCFG();
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 			 echo $this->error;
378 378
 		}
379 379
 	}
380
-	function saveOptions($req){
380
+	function saveOptions($req) {
381 381
 		$this->CFG['time_web']    = $req['time_web'];
382 382
 		$this->CFG['time_cron']   = $req['time_cron'];
383 383
 		$this->CFG['backup_path'] = $req['backup_path'];
@@ -389,28 +389,28 @@  discard block
 block discarded – undo
389 389
 		$this->CFG['confirm']     = $req['confirm'];
390 390
 		$this->saveCFG();
391 391
 	}
392
-	function saveCFG(){
392
+	function saveCFG() {
393 393
 		if (isset($_COOKIE['sxd'])) {
394 394
 			$this->SES[$_COOKIE['sxd']] = array('cfg' => $this->CFG, 'time' => time(), 'lng' => $this->LNG['name']);
395 395
 			$this->saveToFile('ses.php', "<?php\n\$SES = " . var_export($this->SES, true) . ";\n" . "?>");
396 396
 		}
397
-        if (!$this->virtualize){
397
+        if (!$this->virtualize) {
398 398
         	$this->saveToFile('cfg.php', "<?php\n\$CFG = " . var_export($this->CFG, true) . ";\n" . "?>");
399 399
         }
400 400
 	}
401 401
 	function runServices($job) {
402 402
 		$serv = array('optimize' => 'OPTIMIZE', 'analyze' => 'ANALYZE', 'check' => 'CHECK', 'repair' => 'REPAIR');
403 403
 		$add = array('check'  => array('', 'QUICK', 'FAST', 'CHANGED', 'MEDIUM', 'EXTENDED'), 'repair' => array('', 'QUICK', 'EXTENDED'));
404
-		if(isset($serv[$job['type']])) {
404
+		if (isset($serv[$job['type']])) {
405 405
 			mysql_select_db($job['db']);
406 406
 			$filter = $object = array();
407 407
 			$this->createFilters($job['obj'], $filter, $object);
408 408
 			$r = mysql_query('SHOW TABLE STATUS') or sxd_my_error();
409 409
 			if (!$r) return;
410 410
 			$tables = array();
411
-			while($item = mysql_fetch_assoc($r)){
412
-				if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) continue;
413
-				if(sxd_check($item['Name'], $object['TA'], $filter['TA'])) $tables[] = "`{$item['Name']}`";
411
+			while ($item = mysql_fetch_assoc($r)) {
412
+				if (V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) continue;
413
+				if (sxd_check($item['Name'], $object['TA'], $filter['TA'])) $tables[] = "`{$item['Name']}`";
414 414
 			}
415 415
 			$sql = $serv[$job['type']] . ' TABLE ' . implode(',', $tables);
416 416
 			
@@ -421,20 +421,20 @@  discard block
 block discarded – undo
421 421
 			$r = mysql_query($sql) or sxd_my_error();
422 422
 			if (!$r) return;
423 423
 			$res = array();
424
-			while($item = mysql_fetch_row($r)){
424
+			while ($item = mysql_fetch_row($r)) {
425 425
 				$res[] = $item;
426 426
 			}
427
-			echo 'sxd.result.add(' . sxd_php2json($res). ');';
427
+			echo 'sxd.result.add(' . sxd_php2json($res) . ');';
428 428
 		}
429 429
 	}
430
-	function createFilters(&$obj, &$filter, &$object){
430
+	function createFilters(&$obj, &$filter, &$object) {
431 431
 		$types = array('TA', 'TC', 'VI', 'PR', 'FU', 'TR', 'EV');
432
-		foreach($types AS $type){
432
+		foreach ($types AS $type) {
433 433
 			$filter[$type] = array();
434 434
 			$object[$type] = array();
435
-			if(!empty($obj[$type])){
436
-				foreach($obj[$type] AS $v){
437
-					if(strpos($v, '*') !== false) {
435
+			if (!empty($obj[$type])) {
436
+				foreach ($obj[$type] AS $v) {
437
+					if (strpos($v, '*') !== false) {
438 438
 						$filter[$type][] = str_replace('*', '.*?', $v); 
439 439
 					}
440 440
 					else {
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 			}
446 446
 		}
447 447
 	}
448
-	function closeConnect(){
448
+	function closeConnect() {
449 449
 		//return;
450 450
 		@ignore_user_abort(1); 
451 451
 		header("SXD: {$this->name}");
@@ -456,15 +456,15 @@  discard block
 block discarded – undo
456 456
 		@ob_end_flush();
457 457
 		@flush();
458 458
 	}
459
-	function resumeJob($job){
459
+	function resumeJob($job) {
460 460
 		$this->closeConnect();
461 461
 		include($this->CFG['backup_path'] . $job['job'] . '.job.php');
462 462
 		$this->JOB = &$JOB;
463
-		if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']);
463
+		if (file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']);
464 464
 		$this->fh_rtl = fopen($this->JOB['file_rtl'], 'r+b');
465 465
 		$this->fh_log = fopen($this->JOB['file_log'], 'ab');
466 466
 		$t = fgets($this->fh_rtl);
467
-		if(!empty($t)){
467
+		if (!empty($t)) {
468 468
 			$this->rtl = explode("\t", $t);	
469 469
 		}
470 470
 		else {
@@ -492,27 +492,27 @@  discard block
 block discarded – undo
492 492
 		$rows = 0;
493 493
 		$this->tab_rows = array();
494 494
 		$todo = array();
495
-		foreach($objects AS $t => $list){
496
-			if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {}
497
-			elseif(empty($object[$t]) && empty($filter[$t])) {continue;}
495
+		foreach ($objects AS $t => $list) {
496
+			if ($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {}
497
+			elseif (empty($object[$t]) && empty($filter[$t])) {continue; }
498 498
 			if (empty($list)) continue;
499 499
 			
500
-			foreach($list AS $item){
501
-				switch($t){
500
+			foreach ($list AS $item) {
501
+				switch ($t) {
502 502
 					case 'TA':
503 503
 						$type = '';
504
-						if(sxd_check($item[0], $object['TA'], $filter['TA'])){
504
+						if (sxd_check($item[0], $object['TA'], $filter['TA'])) {
505 505
 							$type = empty($item[1]) ? 'TC' : 'TA';
506 506
 						}
507
-						elseif(sxd_check($item[0], $object['TC'], $filter['TC'])) {
507
+						elseif (sxd_check($item[0], $object['TC'], $filter['TC'])) {
508 508
 							$type = 'TC';
509 509
 						}
510 510
 						else continue;
511
-						$todo['TA'][]   = array($type, $item[0], $item[1], $item[2]);
511
+						$todo['TA'][] = array($type, $item[0], $item[1], $item[2]);
512 512
 						$rows += $type == 'TA' ? $item[1] : 0;
513 513
 					break;
514 514
 					default:
515
-						if(sxd_check($item, $object[$t], $filter[$t])) {
515
+						if (sxd_check($item, $object[$t], $filter[$t])) {
516 516
 							$todo[$t][] = array($t, $item);
517 517
 						}
518 518
 				}
@@ -522,14 +522,14 @@  discard block
 block discarded – undo
522 522
 		$this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl';
523 523
 		$this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log';
524 524
 		$this->JOB['file_stp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.stp';
525
-		if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']);
525
+		if (file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']);
526 526
 		
527 527
 		$this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r');
528 528
 		// Для чужих дампов определяем разделители строк
529
-		if(is_null($this->JOB['obj'])) {
529
+		if (is_null($this->JOB['obj'])) {
530 530
 			$s = fread($this->fh_tmp, 2048);
531
-			if(strpos($s, "\r\n")) $this->JOB['eol'] = "\r\n";
532
-			elseif(strpos($s, "\n")) $this->JOB['eol'] = "\n";
531
+			if (strpos($s, "\r\n")) $this->JOB['eol'] = "\r\n";
532
+			elseif (strpos($s, "\n")) $this->JOB['eol'] = "\n";
533 533
 			else $this->JOB['eol'] = "\r";
534 534
 			$bom = strncmp($s, "\xEF\xBB\xBF", 3) == 0 ? 3 : ((strncmp($s, "\xFE\xFF", 2) == 0 || strncmp($s, "\xFF\xFE", 2) == 0) ? 2 : 0);
535 535
 			fseek($this->fh_tmp, $bom);
@@ -543,16 +543,16 @@  discard block
 block discarded – undo
543 543
 		$this->addLog("{$this->LNG['combo_file']} {$this->JOB['file']}");
544 544
 		$this->runRestoreJob();
545 545
 	}
546
-	function runRestoreJob($continue = false){
546
+	function runRestoreJob($continue = false) {
547 547
 		$ei = false;
548
-		if($continue){
548
+		if ($continue) {
549 549
 			$this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r');
550 550
 			fseek($this->fh_tmp, $this->rtl[3]);
551
-			if(!empty($this->rtl[6])) $this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : $this->rtl[6]);
552
-			if($this->rtl[7] < $this->rtl[10]) $ei = true; 
551
+			if (!empty($this->rtl[6])) $this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : $this->rtl[6]);
552
+			if ($this->rtl[7] < $this->rtl[10]) $ei = true; 
553 553
 		}
554 554
 		mysql_select_db($this->JOB['db']);
555
-		if(is_null($this->JOB['obj'])) $this->runRestoreJobForeign($continue);
555
+		if (is_null($this->JOB['obj'])) $this->runRestoreJobForeign($continue);
556 556
 		//mysql_query("SET NAMES 'UTF8'");
557 557
 		$types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event');
558 558
 		$fcache = '';
@@ -565,34 +565,34 @@  discard block
 block discarded – undo
565 565
 		$this->rtl[1] = time();
566 566
 		fwrite($this->fh_rtl, implode("\t", $this->rtl));
567 567
 		$c = 0;
568
-		switch($this->JOB['strategy']){
568
+		switch ($this->JOB['strategy']) {
569 569
 			case 1: $tc = 'TRUNCATE'; $td = 'INSERT'; break;
570 570
 			case 2: $tc = ''; $td = 'REPLACE'; break;
571 571
 			case 3: $tc = ''; $td = 'INSERT IGNORE'; break;
572 572
 			default: $tc = 'DROP TABLE IF EXISTS'; $td = 'INSERT';
573 573
 		}
574 574
 		$tab_exists = array();
575
-		if($this->JOB['strategy'] > 0){
575
+		if ($this->JOB['strategy'] > 0) {
576 576
 			$r = mysql_query("SHOW TABLES") or sxd_my_error();
577
-			while($item = mysql_fetch_row($r)){
577
+			while ($item = mysql_fetch_row($r)) {
578 578
 				$tab_exists[$item[0]] = true;
579 579
 			}
580 580
 		}
581 581
 		$insert = $continue && $this->rtl[7] < $this->rtl[10] ? "{$td} INTO `{$this->rtl[5]}` VALUES " : '';
582 582
 		//$enable_index = array();
583
-		if(V_MYSQL > 40014) {
583
+		if (V_MYSQL > 40014) {
584 584
 			mysql_query("SET UNIQUE_CHECKS=0");
585 585
 			mysql_query("SET FOREIGN_KEY_CHECKS=0");
586
-			if(V_MYSQL > 40101) mysql_query("SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");
587
-			if(V_MYSQL > 40111) mysql_query("SET SQL_NOTES=0");
586
+			if (V_MYSQL > 40101) mysql_query("SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");
587
+			if (V_MYSQL > 40111) mysql_query("SET SQL_NOTES=0");
588 588
 		}
589 589
 		$log_sql = false;
590 590
 		$fields = '';
591 591
 		$time_old = time();
592 592
 		$exit_time = $time_old + $this->CFG['time_web'] - 1;
593
-		while($q = sxd_read_sql($this->fh_tmp, $seek, $ei)){	
594
-			if($time_old < time()) {
595
-				if(file_exists($this->JOB['file_stp'])){
593
+		while ($q = sxd_read_sql($this->fh_tmp, $seek, $ei)) {	
594
+			if ($time_old < time()) {
595
+				if (file_exists($this->JOB['file_stp'])) {
596 596
 					$type = file_get_contents($this->JOB['file_stp']);
597 597
 					$this->rtl[9] = !empty($type) ? $type : 2;
598 598
 					fseek($this->fh_rtl, 0);
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 					exit;
606 606
 				}
607 607
 				$time_old = time();
608
-				if($time_old >= $exit_time){
608
+				if ($time_old >= $exit_time) {
609 609
 					$this->rtl[9] = 3;
610 610
 					fseek($this->fh_rtl, 0);
611 611
 					$this->rtl[1] = time();
@@ -615,9 +615,9 @@  discard block
 block discarded – undo
615 615
 				}
616 616
 				clearstatcache(); 
617 617
 			}
618
-			switch($q{0}){
618
+			switch ($q{0}) {
619 619
 				case '(':
620
-					if($continue) {
620
+					if ($continue) {
621 621
 						$this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3]));
622 622
 						$continue = false;
623 623
 					}
@@ -631,12 +631,12 @@  discard block
 block discarded – undo
631 631
 						$tab = $m[2];
632 632
 						$this->rtl[7] = 0;
633 633
 						$this->rtl[8] = 0;
634
-						foreach($this->JOB['todo']['TA'] AS $t){
635
-							if($t[1] == $tab) {
634
+						foreach ($this->JOB['todo']['TA'] AS $t) {
635
+							if ($t[1] == $tab) {
636 636
 								$this->rtl[8] = $t[2];
637 637
 							}	
638 638
 						}
639
-						if($this->JOB['strategy']) {
639
+						if ($this->JOB['strategy']) {
640 640
 							$q = substr_replace($q, $insert, 0, strlen($m[0]));
641 641
 						}
642 642
 						//mysql_query("LOCK TABLES `{$tab}` WRITE") or die (mysql_error());
@@ -648,13 +648,13 @@  discard block
 block discarded – undo
648 648
 				case 'C':
649 649
 					$ex = 1;
650 650
 					if (preg_match('/^CREATE TABLE `/', $q)) {
651
-						if($this->JOB['strategy'] != 0 && isset($tab_exists[$this->rtl[5]])) $ex = 0;
651
+						if ($this->JOB['strategy'] != 0 && isset($tab_exists[$this->rtl[5]])) $ex = 0;
652 652
 						else {
653 653
 							$ex = 1;
654
-							if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){
654
+							if ((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))) {
655 655
 								$q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']);
656 656
 							}
657
-							if(!empty($this->JOB['autoinc'])) $q = preg_replace("/AUTO_INCREMENT=\d+/", "AUTO_INCREMENT=1", $q);
657
+							if (!empty($this->JOB['autoinc'])) $q = preg_replace("/AUTO_INCREMENT=\d+/", "AUTO_INCREMENT=1", $q);
658 658
 						}
659 659
 						// Достаем имена полей таблицы
660 660
 						$fields = $this->JOB['strategy'] > 0 && preg_match_all('/^\s+(`.+?`) /m', $q, $f, PREG_PATTERN_ORDER) ? '(' . implode(',', $f[1]) . ')' : '';
@@ -665,18 +665,18 @@  discard block
 block discarded – undo
665 665
 						//if(!empty($tab)) $enable_index[] = $tab;
666 666
 //						$this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : empty($m[3]) ? '' : $m[3]);
667 667
 						$this->setNames('binary');
668
-						if($m[1] == 'TC') {
668
+						if ($m[1] == 'TC') {
669 669
 							$this->addLog(sprintf($this->LNG['restore_TC'], $m[2]));
670 670
 							$insert = '';
671 671
 							$tab = '';
672 672
 							$this->rtl[4] = 'TD';
673 673
 							$this->rtl[5] = $m[2];
674 674
 							$ei = 0;
675
-							if($tc && ($this->JOB['strategy'] == 0 || isset($tab_exists[$m[2]]))) {
675
+							if ($tc && ($this->JOB['strategy'] == 0 || isset($tab_exists[$m[2]]))) {
676 676
 								mysql_query("{$tc} `{$m[2]}`") or sxd_my_error();
677 677
 							}
678 678
 						}
679
-						elseif($m[1] == 'TD'){
679
+						elseif ($m[1] == 'TD') {
680 680
 							$ei = 1;
681 681
 						}
682 682
 						else {
@@ -695,13 +695,13 @@  discard block
 block discarded – undo
695 695
 					$insert = '';
696 696
 					$ex = 1;
697 697
 			}
698
-			if($ex) {
698
+			if ($ex) {
699 699
 				$this->rtl[3] = ftell($this->fh_tmp) - $seek;
700 700
 				fseek($this->fh_rtl, 0);
701 701
 				$this->rtl[1] = time();
702 702
 				fwrite($this->fh_rtl, implode("\t", $this->rtl));
703
-				if(mysql_query($q)) {
704
-					if($insert) {
703
+				if (mysql_query($q)) {
704
+					if ($insert) {
705 705
 						$c = 1;
706 706
 					}
707 707
 				}
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
 					sxd_my_error();
711 711
 				}
712 712
 				
713
-				if($c){
713
+				if ($c) {
714 714
 					$i = mysql_affected_rows();
715 715
 					$this->rtl[3] = ftell($this->fh_tmp) - $seek;
716 716
 					$this->rtl[7] += $i;
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
 		$this->rtl[6] = '';
731 731
 		$this->rtl[7] = 0;
732 732
 		$this->rtl[8] = 0;
733
-		foreach($this->JOB['todo']['TA'] AS $tab){
733
+		foreach ($this->JOB['todo']['TA'] AS $tab) {
734 734
 			if ($tab[0] == 'TC') continue;
735 735
 			mysql_query("ALTER TABLE `{$tab[1]}` ENABLE KEYS") or sxd_my_error();
736 736
 			$this->rtl[1] = time();
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
 		fclose($this->fh_log);
748 748
 		fclose($this->fh_rtl);
749 749
 	}
750
-	function runRestoreJobForeign($continue = false){
750
+	function runRestoreJobForeign($continue = false) {
751 751
 		$ei = false;
752 752
 		
753 753
 		$fcache = '';
@@ -768,11 +768,11 @@  discard block
 block discarded – undo
768 768
 		$time_old = time();
769 769
 		$exit_time = $time_old + $this->CFG['time_web'] - 1;
770 770
 		$delimiter = ";";
771
-		while($q = sxd_read_sql($this->fh_tmp, $seek, $ei, $delimiter, $this->JOB['eol'])){
771
+		while ($q = sxd_read_sql($this->fh_tmp, $seek, $ei, $delimiter, $this->JOB['eol'])) {
772 772
 			$q = ltrim($q);
773
-			if(empty($q)) break;
774
-			if($time_old < time()) {
775
-				if(file_exists($this->JOB['file_stp'])){
773
+			if (empty($q)) break;
774
+			if ($time_old < time()) {
775
+				if (file_exists($this->JOB['file_stp'])) {
776 776
 					$type = file_get_contents($this->JOB['file_stp']);
777 777
 					$this->rtl[9] = !empty($type) ? $type : 2;
778 778
 					fseek($this->fh_rtl, 0);
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
 					exit;
786 786
 				}
787 787
 				$time_old = time();
788
-				if($time_old >= $exit_time){
788
+				if ($time_old >= $exit_time) {
789 789
 					$this->rtl[9] = 3;
790 790
 					fseek($this->fh_rtl, 0);
791 791
 					$this->rtl[1] = time();
@@ -799,9 +799,9 @@  discard block
 block discarded – undo
799 799
 				$repeat = false;
800 800
 				//error_log("-----------------\n[{$q}]\n", 3, "q.log");
801 801
 				//if(empty($q)) {continue 2;}
802
-				switch($q{0}){
802
+				switch ($q{0}) {
803 803
 					case '(':
804
-						if($continue) {
804
+						if ($continue) {
805 805
 							$this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3]));
806 806
 							$continue = false;
807 807
 						}
@@ -827,11 +827,11 @@  discard block
 block discarded – undo
827 827
 							$tab = $m[1];
828 828
 							$this->addLog(sprintf($this->LNG['restore_TC'], $tab));
829 829
 							//mysql_query("DROP TABLE IF EXISTS `{$tab}`");
830
-							if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){
830
+							if ((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))) {
831 831
 								$q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']);
832 832
 							}
833
-							elseif(empty($this->JOB['charset'])){
834
-								if(preg_match("/(CHARACTER SET|CHARSET)[=\s]+(\w+)/i", $q, $charset)){
833
+							elseif (empty($this->JOB['charset'])) {
834
+								if (preg_match("/(CHARACTER SET|CHARSET)[=\s]+(\w+)/i", $q, $charset)) {
835 835
 									$this->setNames($charset[2]);
836 836
 								}
837 837
 							}
@@ -857,15 +857,15 @@  discard block
 block discarded – undo
857 857
 						$ex = 1;
858 858
 						$ei = 0;
859 859
 				}
860
-			}  while ($repeat);
861
-			if($ex) {
860
+			} while ($repeat);
861
+			if ($ex) {
862 862
 				$this->rtl[3] = ftell($this->fh_tmp) - $seek;
863 863
 				fseek($this->fh_rtl, 0);
864 864
 				$this->rtl[1] = time();
865 865
 				fwrite($this->fh_rtl, implode("\t", $this->rtl));
866 866
 				error_log("-----------------\n{$q}\n", 3, "sql.log");
867
-				if(mysql_query($q)) {
868
-					if($insert) {
867
+				if (mysql_query($q)) {
868
+					if ($insert) {
869 869
 						$c = 1;
870 870
 					}
871 871
 				}
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
 					sxd_my_error();
875 875
 				}
876 876
 				
877
-				if($c){
877
+				if ($c) {
878 878
 					$i = mysql_affected_rows();
879 879
 					$this->rtl[3] = ftell($this->fh_tmp) - $seek;
880 880
 					$this->rtl[7] += $i;
@@ -914,37 +914,37 @@  discard block
 block discarded – undo
914 914
 			$queries[] = array("PROCEDURE STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'PR');
915 915
 			$queries[] = array("FUNCTION STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'FU');
916 916
 			$queries[] = array('TRIGGERS', 'Trigger', 'TR');
917
-			if(V_MYSQL > 50100) $queries[] = array('EVENTS', 'Name', 'EV');
917
+			if (V_MYSQL > 50100) $queries[] = array('EVENTS', 'Name', 'EV');
918 918
 		}
919 919
 		$todo = $header = array();
920 920
 		$tabs = $rows = 0;
921 921
 		$only_create = explode(' ', $this->CFG['only_create']);
922
-		foreach($queries AS $query){
922
+		foreach ($queries AS $query) {
923 923
 			$t = $query[2];
924
-			if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {}
925
-			elseif(empty($object[$t]) && empty($filter[$t])) continue;
924
+			if ($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {}
925
+			elseif (empty($object[$t]) && empty($filter[$t])) continue;
926 926
 			$r = mysql_query('SHOW ' . $query[0]) or sxd_my_error();
927 927
 			if (!$r) continue;
928 928
 			$todo[$t] = array();
929 929
 			$header[$t] = array();
930 930
 			
931
-			while($item = mysql_fetch_assoc($r)){
931
+			while ($item = mysql_fetch_assoc($r)) {
932 932
 				$n = $item[$query[1]];
933
-				switch($t){
933
+				switch ($t) {
934 934
 					case 'TA':
935 935
 					case 'TC':
936
-						if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) {
937
-							if(sxd_check($n, $object['VI'], $filter['VI'])){
936
+						if (V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) {
937
+							if (sxd_check($n, $object['VI'], $filter['VI'])) {
938 938
 								$todo['VI'] = array();
939
-								$header['VI']= array();
939
+								$header['VI'] = array();
940 940
 							}
941 941
 							continue;
942 942
 						}
943
-						elseif(sxd_check($n, $object['TA'], $filter['TA'])){
943
+						elseif (sxd_check($n, $object['TA'], $filter['TA'])) {
944 944
 							$engine = V_MYSQL > 40101 ? $item['Engine'] : $item['Type'];
945 945
 							$t = in_array($engine, $only_create) ? 'TC' : 'TA';
946 946
 						}
947
-						elseif(sxd_check($n, $object['TC'], $filter['TC'])) {
947
+						elseif (sxd_check($n, $object['TC'], $filter['TC'])) {
948 948
 							$t = 'TC';
949 949
 							$item['Rows'] = $item['Data_length'] = '';
950 950
 						}
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
 						$rows += $item['Rows'];
956 956
 					break;
957 957
 					default:
958
-						if(sxd_check($n, $object[$t], $filter[$t])) {
958
+						if (sxd_check($n, $object[$t], $filter[$t])) {
959 959
 							$todo[$t][] = array($t, $n, !empty($item['collation_connection']) ? $item['collation_connection'] : '');
960 960
 							$header[$t][] = $n;
961 961
 						}
@@ -968,7 +968,7 @@  discard block
 block discarded – undo
968 968
 			$r = mysql_query("SELECT table_name, view_definition /*!50121 , collation_connection */ FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = '{$this->JOB['db']}'") or sxd_my_error();
969 969
 			$views = $dumped = $views_collation = array();
970 970
 			$re = "/`{$this->JOB['db']}`.`(.+?)`/";
971
-			while($item = mysql_fetch_assoc($r)){
971
+			while ($item = mysql_fetch_assoc($r)) {
972 972
 				preg_match_all($re, preg_replace("/^select.+? from/i", '', $item['view_definition']), $m);
973 973
 				$used = $m[1];	
974 974
 				$views_collation[$item['table_name']] = !empty($item['collation_connection']) ? $item['collation_connection'] : '';
@@ -976,13 +976,13 @@  discard block
 block discarded – undo
976 976
 			}
977 977
 			
978 978
 			while (count($views) > 0) {
979
-				foreach($views AS $n => $view) {
979
+				foreach ($views AS $n => $view) {
980 980
 					$can_dumped = true;
981
-					foreach($view AS $k) {
981
+					foreach ($view AS $k) {
982 982
 						if (isset($views[$k]) && !isset($dumped[$k])) $can_dumped = false;	
983 983
 					}
984 984
 					if ($can_dumped) {
985
-						if(sxd_check($n, $object['VI'], $filter['VI'])){
985
+						if (sxd_check($n, $object['VI'], $filter['VI'])) {
986 986
 							$todo['VI'][] = array('VI', $n, $views_collation[$n]);
987 987
 							$header['VI'][] = $n;
988 988
 						}
@@ -999,14 +999,14 @@  discard block
 block discarded – undo
999 999
 		$this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl';
1000 1000
 		$this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log';
1001 1001
 		$this->JOB['file_stp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.stp';
1002
-		if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']);
1002
+		if (file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']);
1003 1003
 		$this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'w');
1004 1004
 		$this->JOB['file'] = sprintf('%s_%s.%s', (isset($this->JOB['title']) ? $this->JOB['job'] : $this->JOB['db']), date('Y-m-d_H-i-s'), $this->JOB['file_ext']);
1005 1005
 		$this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file'];
1006 1006
 		$this->JOB['todo'] = $todo;
1007 1007
 		$this->saveJob($this->JOB['job'], $this->JOB);
1008 1008
 		$fcache = implode('|', array('#SXD20', V_SXD, V_MYSQL, V_PHP, date('Y.m.d H:i:s'), $this->JOB['db'], $this->JOB['charset'], $tabs, $rows, sxd_esc($this->JOB['comment'], false))) . "\n";
1009
-		foreach($header AS $t => $o){
1009
+		foreach ($header AS $t => $o) {
1010 1010
 			if (!empty($o)) $fcache .= "#{$t} " . implode('|', $o) . "\n";	
1011 1011
 		}
1012 1012
 		$this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb');
@@ -1017,8 +1017,8 @@  discard block
 block discarded – undo
1017 1017
 		$this->addLog(sprintf($this->LNG['backup_begin'], $this->JOB['db']));
1018 1018
 		$this->runBackupJob();
1019 1019
 	}
1020
-	function runBackupJob($continue = false){
1021
-		if($continue){
1020
+	function runBackupJob($continue = false) {
1021
+		if ($continue) {
1022 1022
 			$this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'a');
1023 1023
 			mysql_select_db($this->JOB['db']);
1024 1024
 		}
@@ -1027,14 +1027,14 @@  discard block
 block discarded – undo
1027 1027
 		$fcache = '';
1028 1028
 		$writes = 0;
1029 1029
 		
1030
-		if(V_MYSQL > 40101) mysql_query("SET SESSION character_set_results = '" . ($this->JOB['charset'] ? $this->JOB['charset'] : 'binary') ."'") or sxd_my_error();
1030
+		if (V_MYSQL > 40101) mysql_query("SET SESSION character_set_results = '" . ($this->JOB['charset'] ? $this->JOB['charset'] : 'binary') . "'") or sxd_my_error();
1031 1031
 		$time_old = time();
1032 1032
 		$exit_time = $time_old + $this->CFG['time_web'] - 1;
1033 1033
 		$no_cache = V_MYSQL < 40101 ? 'SQL_NO_CACHE ' : '';
1034
-		foreach($this->JOB['todo'] AS $t => $o){
1034
+		foreach ($this->JOB['todo'] AS $t => $o) {
1035 1035
 			if (empty($this->rtl[4])) $this->rtl[4] = $t;
1036 1036
 			elseif ($this->rtl[4] != $t) continue;
1037
-			foreach($o AS $n){ 
1037
+			foreach ($o AS $n) { 
1038 1038
 				if (empty($this->rtl[5])) {
1039 1039
 					$this->rtl[5] = $n[1];
1040 1040
 					$this->rtl[7] = 0;
@@ -1042,19 +1042,19 @@  discard block
 block discarded – undo
1042 1042
 				}
1043 1043
 				elseif ($this->rtl[5] != $n[1]) continue;
1044 1044
 				// Делаем бэкап
1045
-				switch($n[0]){
1045
+				switch ($n[0]) {
1046 1046
 					case 'TC':
1047 1047
 					case 'TD': 				
1048 1048
 					case 'TA':
1049 1049
 						$from = '';
1050
-						if ($n[0] == 'TC' || $this->rtl[7] == 0){
1050
+						if ($n[0] == 'TC' || $this->rtl[7] == 0) {
1051 1051
 							// Бэкап структуры таблицы
1052 1052
 							$r = mysql_query("SHOW CREATE TABLE `{$n[1]}`") or sxd_my_error();
1053 1053
 							$item = mysql_fetch_assoc($r);
1054 1054
 						    $fcache .= "#\tTC`{$n[1]}`{$n[2]}\t;\n{$item['Create Table']}\t;\n";
1055 1055
 						    $this->addLog(sprintf($this->LNG['backup_TC'], $n[1]));
1056 1056
 			            	$this->rtl[7] = 0; 
1057
-						    if($n[0] == 'TC' || !$n[4]) break;
1057
+						    if ($n[0] == 'TC' || !$n[4]) break;
1058 1058
 						    // Бэкапим данные таблицы
1059 1059
 							$fcache .= "#\tTD`{$n[1]}`{$n[2]}\t;\nINSERT INTO `{$n[1]}` VALUES \n";
1060 1060
 						}
@@ -1066,7 +1066,7 @@  discard block
 block discarded – undo
1066 1066
 						$notNum = array();
1067 1067
 						$r = mysql_query("SHOW COLUMNS FROM `{$n[1]}`") or sxd_my_error();
1068 1068
 			            $fields = 0;
1069
-			            while($col = mysql_fetch_array($r)) {
1069
+			            while ($col = mysql_fetch_array($r)) {
1070 1070
 			            	// TODO: проверить типы SET, ENUM и BIT
1071 1071
             				$notNum[$fields] = preg_match("/^(tinyint|smallint|mediumint|bigint|int|float|double|real|decimal|numeric|year)/", $col['Type']) ? 0 : 1; 
1072 1072
             				$fields++;
@@ -1075,22 +1075,22 @@  discard block
 block discarded – undo
1075 1075
 			            $z = 0;
1076 1076
 			            // Достаем данные
1077 1077
 			            $r = mysql_unbuffered_query("SELECT {$no_cache}* FROM `{$n[1]}`{$from}");
1078
-			            while($row = mysql_fetch_row($r)) {
1078
+			            while ($row = mysql_fetch_row($r)) {
1079 1079
 			            	 if (strlen($fcache) >= 61440) {
1080 1080
 			            	 	$z = 0;
1081
-								if($time_old < time()) {
1082
-									if(file_exists($this->JOB['file_stp'])){
1081
+								if ($time_old < time()) {
1082
+									if (file_exists($this->JOB['file_stp'])) {
1083 1083
 										$type = file_get_contents($this->JOB['file_stp']);
1084 1084
 										$this->rtl[9] = !empty($type) ? $type : 2;
1085 1085
 										$this->write($fcache);
1086
-										if($type == 1) {
1086
+										if ($type == 1) {
1087 1087
 											
1088 1088
 										}
1089 1089
 										unset($this->rtl);
1090 1090
 										exit;
1091 1091
 									}
1092 1092
 									$time_old = time();
1093
-									if($time_old >= $exit_time){
1093
+									if ($time_old >= $exit_time) {
1094 1094
 										$this->rtl[9] = 3;
1095 1095
 										$this->write($fcache);
1096 1096
 										unset($this->rtl);
@@ -1100,9 +1100,9 @@  discard block
 block discarded – undo
1100 1100
 								}
1101 1101
 								$this->write($fcache); 
1102 1102
 							}
1103
-							for($k = 0; $k < $fields; $k++){
1104
-								if(!isset($row[$k])) {$row[$k] = '\N';}
1105
-								elseif($notNum[$k]) {$row[$k] =  '\'' . mysql_real_escape_string($row[$k]) . '\'';} // TODO: Потестить скорость эскэйпинга строк
1103
+							for ($k = 0; $k < $fields; $k++) {
1104
+								if (!isset($row[$k])) {$row[$k] = '\N'; }
1105
+								elseif ($notNum[$k]) {$row[$k] = '\'' . mysql_real_escape_string($row[$k]) . '\''; } // TODO: Потестить скорость эскэйпинга строк
1106 1106
 							}
1107 1107
 							$fcache .= '(' . implode(',', $row) . "),\n";
1108 1108
 							$this->rtl[7]++;  
@@ -1110,11 +1110,11 @@  discard block
 block discarded – undo
1110 1110
 						}
1111 1111
 						unset($row);
1112 1112
 						mysql_free_result($r);
1113
-						$fcache = substr_replace($fcache, "\t;\n",  -2, 2);
1113
+						$fcache = substr_replace($fcache, "\t;\n", -2, 2);
1114 1114
 					break;
1115 1115
 
1116 1116
 					default:
1117
-						if(V_MYSQL < 50121 && $n[0] == 'TR'){
1117
+						if (V_MYSQL < 50121 && $n[0] == 'TR') {
1118 1118
 							// SHOW CREATE TRIGGER отсутствует до MySQL 5.1.21
1119 1119
 							$r = mysql_query("SELECT * FROM `INFORMATION_SCHEMA`.`TRIGGERS` WHERE `TRIGGER_SCHEMA` = '{$this->JOB['db']}' AND `TRIGGER_NAME` = '{$n[1]}'") or sxd_my_error();
1120 1120
 							$item = mysql_fetch_assoc($r);
@@ -1141,11 +1141,11 @@  discard block
 block discarded – undo
1141 1141
 		fclose($this->fh_tmp);
1142 1142
 		rename($this->JOB['file_tmp'], $this->JOB['file_name']);
1143 1143
 		$this->addLog(sprintf($this->LNG['backup_end'], $this->JOB['db']));
1144
-		if(file_exists('sxd2ftp.php')) include('sxd2ftp.php');
1144
+		if (file_exists('sxd2ftp.php')) include('sxd2ftp.php');
1145 1145
 		if ($this->JOB['del_time'] || $this->JOB['del_count']) {
1146 1146
             $this->addLog($this->LNG['autodelete']);
1147 1147
             $deldate = '';
1148
-            if (!empty($this->JOB['del_time'])){ // Удаление по дням
1148
+            if (!empty($this->JOB['del_time'])) { // Удаление по дням
1149 1149
                 $deldate = date("Y-m-d_H-i-s", time() - intval($this->JOB['del_time']) * 86400);
1150 1150
             }
1151 1151
             $deleted = false;
@@ -1155,72 +1155,72 @@  discard block
 block discarded – undo
1155 1155
                 while (false !== ($file = readdir($dh))) { 
1156 1156
                     if (preg_match("/^{$name}_(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})\.sql/", $file, $m)) { 
1157 1157
                         if ($deldate && $m[1] < $deldate) {
1158
-                            if(unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_date'], $file));
1158
+                            if (unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_date'], $file));
1159 1159
                             else  $this->addLog(sprintf($this->LNG['del_fail'], $file));
1160 1160
                             $deleted = true;
1161 1161
                         }
1162
-                        else {$files[$m[1]] = $file;}
1162
+                        else {$files[$m[1]] = $file; }
1163 1163
                     }
1164 1164
                 }
1165 1165
                 closedir($dh);
1166 1166
                 // Сортируем файлы по дате и удаляем самые старые
1167
-                if (!empty($this->JOB['del_count'])){
1167
+                if (!empty($this->JOB['del_count'])) {
1168 1168
                     ksort($files);
1169 1169
                     $file_to_delete = count($files) - $this->JOB['del_count'];
1170
-                    foreach ($files AS $file){
1171
-                        if ($file_to_delete-- > 0){ 
1172
-                        	if(unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_count'], $file));
1170
+                    foreach ($files AS $file) {
1171
+                        if ($file_to_delete-- > 0) { 
1172
+                        	if (unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_count'], $file));
1173 1173
                             else  $this->addLog(sprintf($this->LNG['del_fail'], $file));
1174 1174
                             $deleted = true;
1175 1175
                         }
1176 1176
                     }
1177 1177
                 }
1178 1178
             }
1179
-            if(!$deleted) $this->addLog($this->LNG['del_nothing']);
1179
+            if (!$deleted) $this->addLog($this->LNG['del_nothing']);
1180 1180
 		}
1181 1181
 		fclose($this->fh_log);
1182 1182
 		fclose($this->fh_rtl);
1183 1183
 	}
1184
-	function setNames($collation){
1185
-		if(empty($collation)) return;
1186
-		if($this->rtl[6] != $collation) {
1184
+	function setNames($collation) {
1185
+		if (empty($collation)) return;
1186
+		if ($this->rtl[6] != $collation) {
1187 1187
 			mysql_query('SET NAMES \'' . preg_replace('/^(\w+?)_/', '\\1\' COLLATE \'\\1_', $collation) . '\'') or sxd_my_error();
1188 1188
 			/*if(!$this->rtl[7])*/ $this->addLog(sprintf($this->LNG['set_names'], $collation));
1189 1189
 			$this->rtl[6] = $collation;	
1190 1190
 		}
1191 1191
 	}
1192
-	function write(&$str){
1192
+	function write(&$str) {
1193 1193
 		fseek($this->fh_rtl, 0);
1194 1194
 		$this->rtl[1] = time();
1195 1195
 		$this->rtl[3] += fwrite($this->fh_tmp, $str);
1196 1196
 		fwrite($this->fh_rtl, implode("\t", $this->rtl));
1197 1197
 		$str = '';
1198 1198
 	}
1199
-	function addLog($str, $type = 1){
1199
+	function addLog($str, $type = 1) {
1200 1200
 		fwrite($this->fh_log, date('Y.m.d H:i:s') . "\t{$type}\t{$str}\n");
1201 1201
 	}
1202
-	function getDBList(){
1202
+	function getDBList() {
1203 1203
 		$dbs = $items = array();
1204 1204
         if (!V_MYSQL) return $dbs; 
1205 1205
         $qq = (V_MYSQL < 50000) ? '' : '\'';
1206 1206
 		if ($this->CFG['my_db']) {
1207 1207
 			$tmp = explode(',', $this->CFG['my_db']);
1208
-			foreach($tmp AS $d){
1208
+			foreach ($tmp AS $d) {
1209 1209
 				$d = trim($d);
1210 1210
 				$items[] = $qq . sxd_esc($d, false) . $qq;
1211 1211
 				$dbs[$d] = "{$d} (0)";
1212 1212
 			}
1213 1213
 		}
1214
-		else{
1214
+		else {
1215 1215
 			$result = mysql_query("SHOW DATABASES") or sxd_my_error();
1216
-    		while($item = mysql_fetch_row($result)){
1217
-    			if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue;
1216
+    		while ($item = mysql_fetch_row($result)) {
1217
+    			if ($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue;
1218 1218
     			$items[] = $qq . sxd_esc($item[0], false) . $qq;
1219 1219
     			$dbs[$item[0]] = "{$item[0]} (0)";
1220 1220
     		}	
1221 1221
 		}
1222
-		if(V_MYSQL < 50000){
1223
-			foreach($items AS $item){
1222
+		if (V_MYSQL < 50000) {
1223
+			foreach ($items AS $item) {
1224 1224
     			$tables = mysql_query("SHOW TABLES FROM `{$item}`") or sxd_my_error();
1225 1225
     			if ($tables) {
1226 1226
     	  			$tabs = mysql_num_rows($tables);
@@ -1231,59 +1231,59 @@  discard block
 block discarded – undo
1231 1231
 		else {
1232 1232
 			$where = (count($items) > 0) ? 'WHERE `table_schema` IN (' . implode(',', $items) . ')' : '';
1233 1233
 			$result = mysql_query("SELECT `table_schema`, COUNT(*) FROM `information_schema`.`tables` {$where} GROUP BY `table_schema`") or sxd_my_error();
1234
-			while($item = mysql_fetch_row($result)){
1235
-    			if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue;
1234
+			while ($item = mysql_fetch_row($result)) {
1235
+    			if ($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue;
1236 1236
     			$dbs[$item[0]] = "{$item[0]} ({$item[1]})";
1237 1237
     		}
1238 1238
 		}
1239 1239
 	    return $dbs;
1240 1240
 	}
1241
-	function getCharsetList(){
1241
+	function getCharsetList() {
1242 1242
 		$tmp = array(0 => '- auto -');
1243 1243
 		if (!V_MYSQL) return $tmp; 
1244
-		if(V_MYSQL > 40101) {
1244
+		if (V_MYSQL > 40101) {
1245 1245
 			$def_charsets = '';
1246
-			if(!empty($this->CFG['charsets'])){
1247
-				$def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?','*'), array('.','\w+?'), implode('|', $m[1])) . ')$/i' : '';
1246
+			if (!empty($this->CFG['charsets'])) {
1247
+				$def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?', '*'), array('.', '\w+?'), implode('|', $m[1])) . ')$/i' : '';
1248 1248
 			}
1249 1249
     		$r = mysql_query("SHOW CHARACTER SET") or sxd_my_error(); 
1250 1250
     		if ($r) {
1251
-    			while($item = mysql_fetch_assoc($r)){
1251
+    			while ($item = mysql_fetch_assoc($r)) {
1252 1252
     	  			if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']] = "{$item['Charset']}"; // ({$item['Description']})
1253 1253
     			}
1254 1254
 			}
1255 1255
 		}
1256 1256
 	    return $tmp;
1257 1257
 	}
1258
-	function getCollationList(){
1258
+	function getCollationList() {
1259 1259
 		$tmp = array(); 
1260 1260
 		if (!V_MYSQL) return $tmp; 
1261
-		if(V_MYSQL > 40101) {
1261
+		if (V_MYSQL > 40101) {
1262 1262
 			$def_charsets = '';
1263
-			if(!empty($this->CFG['charsets'])){
1264
-				$def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?','*'), array('.','\w+?'), implode('|', $m[1])) . ')$/i' : '';
1263
+			if (!empty($this->CFG['charsets'])) {
1264
+				$def_charsets = preg_match_all("/([\w*?]+)\s*/", $this->CFG['charsets'], $m, PREG_PATTERN_ORDER) ? '/^(' . str_replace(array('?', '*'), array('.', '\w+?'), implode('|', $m[1])) . ')$/i' : '';
1265 1265
 			}
1266 1266
     		$r = mysql_query("SHOW COLLATION") or sxd_my_error(); 
1267 1267
     		if ($r) {
1268
-    			while($item = mysql_fetch_assoc($r)){
1268
+    			while ($item = mysql_fetch_assoc($r)) {
1269 1269
     	  			if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']][$item['Collation']] = $item['Default'] == 'Yes' ? 1 : 0; 
1270 1270
     			}
1271 1271
 			}
1272 1272
 		}
1273 1273
 	    return $tmp;
1274 1274
 	}
1275
-	function getObjects($tree, $db_name){
1275
+	function getObjects($tree, $db_name) {
1276 1276
 		mysql_select_db($db_name);
1277 1277
 		// Достаем таблицы
1278 1278
 		$r = mysql_query('SHOW TABLE STATUS');
1279 1279
 		$tab_prefix_last = $tab_prefix = '*';
1280 1280
 		$objects = array('TA' => array(), 'VI' => array(), 'PR' => array(), 'FU' => array(), 'TR' => array(), 'EV' => array());
1281
-		if($r){
1282
-			while($item = mysql_fetch_assoc($r)){
1283
-				if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) {
1284
-					$objects['VI'][]= $item['Name'];
1281
+		if ($r) {
1282
+			while ($item = mysql_fetch_assoc($r)) {
1283
+				if (V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) {
1284
+					$objects['VI'][] = $item['Name'];
1285 1285
 				}
1286
-				else{
1286
+				else {
1287 1287
 					$objects['TA'][] = array($item['Name'], $item['Rows'], $item['Data_length']);
1288 1288
 				} 
1289 1289
 			}
@@ -1294,14 +1294,14 @@  discard block
 block discarded – undo
1294 1294
 					"FUNCTION STATUS WHERE db='{$db_name}'",
1295 1295
 					'TRIGGERS'
1296 1296
 				);
1297
-				if(V_MYSQL > 50100) $shows[] = "EVENTS WHERE db='{$db_name}'";
1297
+				if (V_MYSQL > 50100) $shows[] = "EVENTS WHERE db='{$db_name}'";
1298 1298
 				// TODO: Поправить проверку событий и триггеров
1299
-				for($i = 0, $l = count($shows); $i < $l; $i++){
1299
+				for ($i = 0, $l = count($shows); $i < $l; $i++) {
1300 1300
 					$r = mysql_query('SHOW ' . $shows[$i]);
1301
-					if($r && mysql_num_rows($r) > 0) {
1301
+					if ($r && mysql_num_rows($r) > 0) {
1302 1302
 						$col_name = $shows[$i] == 'TRIGGERS' ? 'Trigger' : 'Name';
1303 1303
 						$type = substr($shows[$i], 0, 2);
1304
-						while($item = mysql_fetch_assoc($r)){
1304
+						while ($item = mysql_fetch_assoc($r)) {
1305 1305
 							$objects[$type][] = $item[$col_name];	
1306 1306
 						}
1307 1307
 					}
@@ -1313,32 +1313,32 @@  discard block
 block discarded – undo
1313 1313
 		}
1314 1314
 		return $this->formatTree($tree, $objects);
1315 1315
 	}
1316
-	function getFileObjects($tree, $name, $formatTree = true){
1316
+	function getFileObjects($tree, $name, $formatTree = true) {
1317 1317
 		// Достаем таблицы
1318 1318
 		$objects = array('TA' => array(), 'VI' => array(), 'PR' => array(), 'FU' => array(), 'TR' => array(), 'EV' => array());
1319
-		if(!preg_match('/\.sql(\.(gz|bz2))?$/i', $name, $m)) return '';
1319
+		if (!preg_match('/\.sql(\.(gz|bz2))?$/i', $name, $m)) return '';
1320 1320
 		$name = $this->CFG['backup_path'] . $name;
1321
-		if(!is_readable($name)) {return "sxd.tree.{$tree}.error(sxd.lng('err_fopen'))";}
1321
+		if (!is_readable($name)) {return "sxd.tree.{$tree}.error(sxd.lng('err_fopen'))"; }
1322 1322
 		$fp   = $this->openFile($name, 'r');
1323 1323
 		$temp = fread($fp, 60000);
1324 1324
 		// Формат файла Sypex Dumper 2 - SXD20
1325 1325
 		//if(!preg_match('/^(#SXD20\|.+?)\n#EOH\n/s', $temp, $m)) return "sxd.tree.{$tree}.error(sxd.lng('err_sxd2'));z('restore_savejob').disabled = z('restore_runjob').disabled = true;";
1326
-		if(preg_match('/^(#SXD20\|.+?)\n#EOH\n/s', $temp, $m)){
1326
+		if (preg_match('/^(#SXD20\|.+?)\n#EOH\n/s', $temp, $m)) {
1327 1327
 			$head = explode("\n", $m[1]);
1328 1328
 			$h = explode('|', $head[0]);
1329
-			for($i = 1, $c = count($head); $i < $c; $i++){
1330
-				$objects[substr($head[$i], 1,2)] = explode('|', substr($head[$i], 4));
1329
+			for ($i = 1, $c = count($head); $i < $c; $i++) {
1330
+				$objects[substr($head[$i], 1, 2)] = explode('|', substr($head[$i], 4));
1331 1331
 			}
1332
-			for($i = 0, $l = count($objects['TA']); $i < $l; $i++){
1332
+			for ($i = 0, $l = count($objects['TA']); $i < $l; $i++) {
1333 1333
 				$objects['TA'][$i] = explode('`', $objects['TA'][$i]);
1334 1334
 			}
1335 1335
 		}
1336 1336
 		else {
1337 1337
 			$h[9] = '';
1338 1338
 		}
1339
-		return $formatTree ? $this->formatTree($tree, $objects) .  "sxd.comment.restore.value = '{$h[9]}';z('restore_savejob').disabled = z('restore_runjob').disabled = false;" : $objects;
1339
+		return $formatTree ? $this->formatTree($tree, $objects) . "sxd.comment.restore.value = '{$h[9]}';z('restore_savejob').disabled = z('restore_runjob').disabled = false;" : $objects;
1340 1340
 	}
1341
-	function formatTree($tree, &$objects){
1341
+	function formatTree($tree, &$objects) {
1342 1342
 		$obj = '';
1343 1343
 		$pid = $row = 1;
1344 1344
 		$info = array(
@@ -1351,7 +1351,7 @@  discard block
 block discarded – undo
1351 1351
 		);
1352 1352
 		// Находим таблицы с префиксами
1353 1353
 		$tab_prefix_last = $tab_prefix = '*';
1354
-		for($i = 0, $l = count($objects['TA']); $i < $l; $i++){
1354
+		for ($i = 0, $l = count($objects['TA']); $i < $l; $i++) {
1355 1355
 			$t = $objects['TA'][$i];
1356 1356
 			$tab_prefix = preg_match("/^([a-z0-9]+_)/", $t[0], $m) ? $m[1] : '*';
1357 1357
 			if ($tab_prefix != $tab_prefix_last) {
@@ -1361,18 +1361,18 @@  discard block
 block discarded – undo
1361 1361
 			$objects['TA'][$tab_prefix][] = $t;
1362 1362
 			unset($objects['TA'][$i]);
1363 1363
 		}
1364
-		foreach($objects AS $type => $o){
1365
-			if(!count($o)) continue;
1366
-			if($type == 'TA') {
1364
+		foreach ($objects AS $type => $o) {
1365
+			if (!count($o)) continue;
1366
+			if ($type == 'TA') {
1367 1367
 				$open_childs = count($o['*']) > 1 ? 0 : 1;
1368 1368
 				$obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",1,1,1],";
1369 1369
 				$row++;
1370
-				foreach($o['*'] AS $value){
1371
-					if(is_string($value)){
1372
-						if(count($o[$value]) > 1)	{
1370
+				foreach ($o['*'] AS $value) {
1371
+					if (is_string($value)) {
1372
+						if (count($o[$value]) > 1) {
1373 1373
 							$obj .= "[{$row},1,'{$value}*',1,1,{$open_childs}],";	
1374 1374
 							$pid = $row++; 
1375
-							for($i = 0, $l = count($o[$value]); $i < $l; $i++){
1375
+							for ($i = 0, $l = count($o[$value]); $i < $l; $i++) {
1376 1376
 								$checked = ($o[$value][$i][1] == '' && $o[$value][$i][2] == '') ? 2 : 1;
1377 1377
 								$obj .= "[{$row},{$pid}," . sxd_esc($o[$value][$i][0]) . ",2,{$checked},{$o[$value][$i][2]}],";
1378 1378
 								$row++;
@@ -1383,7 +1383,7 @@  discard block
 block discarded – undo
1383 1383
 						}
1384 1384
 					}
1385 1385
 					//$pid = 1;
1386
-					if (is_array($value)){
1386
+					if (is_array($value)) {
1387 1387
 						$checked = ($value[1] == '' && $value[2] == '') ? 2 : 1;
1388 1388
 						$obj .= "[{$row},1,'{$value[0]}',2,{$checked},{$value[2]}],";
1389 1389
 						$row++;	
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
 				$obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",{$info[$type][1]},1,1],";
1395 1395
 				$pid = $row++;
1396 1396
 				$info[$type][1]++;
1397
-				for($i = 0, $l = count($o); $i < $l; $i++){
1397
+				for ($i = 0, $l = count($o); $i < $l; $i++) {
1398 1398
 					$o[$i] = sxd_esc($o[$i], false);
1399 1399
 					$obj .= "[{$row},{$pid},'{$o[$i]}',{$info[$type][1]},1,0],";
1400 1400
 					$row++;	
@@ -1402,10 +1402,10 @@  discard block
 block discarded – undo
1402 1402
 			} 
1403 1403
 		}
1404 1404
 		$add = '';
1405
-		if($tree == 'restore') $add = "z('autoinc').disabled = z('restore_type').disabled = " . ($obj ? 'false' : 'true') . ";";
1406
-		return ($obj ? 'sxd.tree.' . $tree . '.drawTree([' . substr_replace($obj, ']',  -1) . ");" : "sxd.tree.{$tree}.error(sxd.lng('err_sxd2'));") . $add;	
1405
+		if ($tree == 'restore') $add = "z('autoinc').disabled = z('restore_type').disabled = " . ($obj ? 'false' : 'true') . ";";
1406
+		return ($obj ? 'sxd.tree.' . $tree . '.drawTree([' . substr_replace($obj, ']', -1) . ");" : "sxd.tree.{$tree}.error(sxd.lng('err_sxd2'));") . $add;	
1407 1407
 	}
1408
-	function getFileList(){
1408
+	function getFileList() {
1409 1409
 		$files = array();
1410 1410
 		if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) {
1411 1411
             while (false !== ($file = readdir($handle))) {
@@ -1418,7 +1418,7 @@  discard block
 block discarded – undo
1418 1418
         ksort($files);
1419 1419
 		return $files;
1420 1420
 	}
1421
-	function getSavedJobs(){
1421
+	function getSavedJobs() {
1422 1422
 		$sj = array('sj_backup' => array(), 'sj_restore' => array(),);
1423 1423
 		if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) {
1424 1424
             while (false !== ($file = readdir($handle))) {
@@ -1429,13 +1429,13 @@  discard block
 block discarded – undo
1429 1429
             }
1430 1430
             closedir($handle);
1431 1431
         }
1432
-        if(count($sj['sj_backup']) > 0){
1432
+        if (count($sj['sj_backup']) > 0) {
1433 1433
         	ksort($sj['sj_backup']);	
1434 1434
 		}
1435 1435
         else {
1436 1436
         	$sj['sj_backup'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']);	
1437 1437
 		}
1438
-		if(count($sj['sj_restore']) > 0){
1438
+		if (count($sj['sj_restore']) > 0) {
1439 1439
         	ksort($sj['sj_restore']);	
1440 1440
 		}
1441 1441
         else {
@@ -1443,7 +1443,7 @@  discard block
 block discarded – undo
1443 1443
 		}
1444 1444
 		return "sxd.clearOpt('sj_backup');sxd.clearOpt('sj_restore');sxd.addOpt(" . sxd_php2json($sj) . ");";
1445 1445
 	}
1446
-	function getFileListExtended(){
1446
+	function getFileListExtended() {
1447 1447
 		$files = array();
1448 1448
 		if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) {
1449 1449
             while (false !== ($file = readdir($handle))) {
@@ -1451,11 +1451,11 @@  discard block
 block discarded – undo
1451 1451
                     $fp   = $this->openFile($this->CFG['backup_path'] . $file, 'r');
1452 1452
                     $ext  = !empty($m[2]) ? $m[2] : 'sql';
1453 1453
                     $temp = fgets($fp);
1454
-                    if(preg_match('/^(#SXD20\|.+?)\n/s', $temp, $m)){
1454
+                    if (preg_match('/^(#SXD20\|.+?)\n/s', $temp, $m)) {
1455 1455
                     	$h = explode('|', $m[1]);
1456 1456
                     	$files[] = array($h[5], substr($h[4], 0, -3), $ext, $h[7], number_format($h[8], 0, '', ' '), filesize($this->CFG['backup_path'] . $file), $h[9], $file);	
1457 1457
 					}
1458
-					elseif(preg_match('/^(#SKD101\|.+?)\n/s', $temp, $m)){
1458
+					elseif (preg_match('/^(#SKD101\|.+?)\n/s', $temp, $m)) {
1459 1459
                     	$h = explode('|', $m[1]);
1460 1460
                     	$files[] = array($h[1], substr($h[3], 0, -3), $ext, $h[2], number_format($h[4], 0, '', ' '), filesize($this->CFG['backup_path'] . $file), 'SXD 1.0.x', $file);	
1461 1461
 					}
@@ -1466,27 +1466,27 @@  discard block
 block discarded – undo
1466 1466
             }
1467 1467
             closedir($handle);
1468 1468
         }
1469
-        function s($a, $b){
1469
+        function s($a, $b) {
1470 1470
 		    return strcmp($b[1], $a[1]);
1471 1471
 		}
1472 1472
         usort($files, 's');
1473 1473
 		return 'sxd.files.clear();sxd.files.add(' . sxd_php2json($files) . ');';
1474 1474
 	}
1475
-	function saveJob($job, $config){
1475
+	function saveJob($job, $config) {
1476 1476
 		$this->saveToFile($this->CFG['backup_path'] . $job . '.job.php', "<?php\n\$JOB = " . var_export($config, true) . ";\n" . "?>");
1477 1477
 	}
1478
-	function openFile($name, $mode){
1479
-		if($mode == 'r') {
1480
-			if(preg_match('/\.(sql|sql\.bz2|sql\.gz)$/i', $name, $m)) $this->JOB['file_ext'] = strtolower($m[1]);
1478
+	function openFile($name, $mode) {
1479
+		if ($mode == 'r') {
1480
+			if (preg_match('/\.(sql|sql\.bz2|sql\.gz)$/i', $name, $m)) $this->JOB['file_ext'] = strtolower($m[1]);
1481 1481
 		}
1482
-		else{
1483
-			switch($this->JOB['zip']) {
1482
+		else {
1483
+			switch ($this->JOB['zip']) {
1484 1484
 				case 0 : $this->JOB['file_ext'] = 'sql'; break;
1485 1485
 				case 10: $this->JOB['file_ext'] = 'sql.bz2'; break;
1486 1486
 				default: $this->JOB['file_ext'] = 'sql.gz'; break; 
1487 1487
 			}
1488 1488
 		}
1489
-		switch ($this->JOB['file_ext']){
1489
+		switch ($this->JOB['file_ext']) {
1490 1490
 			case 'sql':
1491 1491
 				return fopen($name, "{$mode}b");
1492 1492
 				break;
@@ -1500,28 +1500,28 @@  discard block
 block discarded – undo
1500 1500
 		}
1501 1501
 	}
1502 1502
 }
1503
-function sxd_read_sql($f, &$seek, $ei, $delimiter = "\t;", $eol = "\n"){
1503
+function sxd_read_sql($f, &$seek, $ei, $delimiter = "\t;", $eol = "\n") {
1504 1504
 	static $l = '';
1505 1505
 	static $r = 0;
1506 1506
 	$fs = ftell($f);
1507 1507
 	$delim_len = strlen($delimiter . $eol);
1508
-	while($r || $s = fread($f, 61440)){
1509
-		if(!$r) $l .= $s;
1508
+	while ($r || $s = fread($f, 61440)) {
1509
+		if (!$r) $l .= $s;
1510 1510
 		$pos = strpos($l, $delimiter . $eol);
1511 1511
 		if ($pos !== false) {
1512 1512
 			// Есть окончание запроса
1513 1513
 			$q = substr($l, 0, $pos);
1514
-			$l = substr($l, $pos+$delim_len);
1514
+			$l = substr($l, $pos + $delim_len);
1515 1515
 			$r = 1;
1516 1516
 			$seek = strlen($l);
1517 1517
 			return $q;
1518 1518
 		}
1519
-		if($ei) {
1519
+		if ($ei) {
1520 1520
 			$pos = strrpos($l, $eol);
1521
-			if($pos > 0 && $l{$pos-1} === ',') {
1521
+			if ($pos > 0 && $l{$pos - 1} === ',') {
1522 1522
 				// Окончание не найдено
1523
-				$q = substr($l, 0, $pos-1);
1524
-				$l = substr($l, $pos+ strlen($eol));
1523
+				$q = substr($l, 0, $pos - 1);
1524
+				$l = substr($l, $pos + strlen($eol));
1525 1525
 				$seek = strlen($l);
1526 1526
 				$r = 0;
1527 1527
 				return $q;
@@ -1534,16 +1534,16 @@  discard block
 block discarded – undo
1534 1534
 	}
1535 1535
 	return false;
1536 1536
 }
1537
-function sxd_check($n, $obj, $filt){
1537
+function sxd_check($n, $obj, $filt) {
1538 1538
 	return isset($obj[$n]) || ($filt && preg_match($filt, $n));
1539 1539
 }
1540
-function sxd_php2json($obj){
1541
-	if(count($obj) == 0) return '[]';
1540
+function sxd_php2json($obj) {
1541
+	if (count($obj) == 0) return '[]';
1542 1542
 	$is_obj = isset($obj[0]) && isset($obj[count($obj) - 1]) ? false : true;
1543 1543
 	$str = $is_obj ? '{' : '[';
1544 1544
     foreach ($obj AS $key  => $value) {
1545 1545
     	$str .= $is_obj ? "'" . addcslashes($key, "\n\r\t'\\/") . "'" . ':' : ''; 
1546
-        if     (is_array($value))   $str .= sxd_php2json($value);
1546
+        if (is_array($value))   $str .= sxd_php2json($value);
1547 1547
         elseif (is_null($value))    $str .= 'null';
1548 1548
         elseif (is_bool($value))    $str .= $value ? 'true' : 'false';
1549 1549
 		elseif (is_numeric($value)) $str .= $value;
@@ -1552,27 +1552,27 @@  discard block
 block discarded – undo
1552 1552
     }
1553 1553
 	return  substr_replace($str, $is_obj ? '}' : ']', -1);
1554 1554
 }
1555
-function sxd_ver2int($ver){
1555
+function sxd_ver2int($ver) {
1556 1556
 	return preg_match("/^(\d+)\.(\d+)\.(\d+)/", $ver, $m) ? sprintf("%d%02d%02d", $m[1], $m[2], $m[3]) : 0;
1557 1557
 }
1558
-function sxd_error_handler($errno, $errmsg, $filename, $linenum, $vars){
1558
+function sxd_error_handler($errno, $errmsg, $filename, $linenum, $vars) {
1559 1559
     global $SXD;
1560
-    if($SXD->try) return;
1561
-	if($errno == 8192) return;
1562
-    if(strpos($errmsg, 'timezone settings')) return;
1560
+    if ($SXD->try) return;
1561
+	if ($errno == 8192) return;
1562
+    if (strpos($errmsg, 'timezone settings')) return;
1563 1563
     $errortype = array(1 => 'Error', 2 => 'Warning', 4 => 'Parsing Error', 8 => 'Notice', 16 => 'Core Error', 32 => 'Core Warning', 64 => 'Compile Error',
1564 1564
 					   128 => 'Compile Warning', 256 => 'MySQL Error', 512 => 'Warning', 1024 => 'Notice',
1565 1565
 						2048 => 'Strict', 8192 => 'Deprecated', 16384 => 'Deprecated');
1566 1566
 	$str = sxd_esc("{$errortype[$errno]}: {$errmsg} ({$filename}:{$linenum})", false);
1567
-	if(SXD_DEBUG) error_log("[index.php]\n{$str}\n", 3, "backup/error.log");
1567
+	if (SXD_DEBUG) error_log("[index.php]\n{$str}\n", 3, "backup/error.log");
1568 1568
 	
1569
-    if($errno == 8 || $errno == 1024) {
1569
+    if ($errno == 8 || $errno == 1024) {
1570 1570
     	if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str;
1571 1571
     	else {
1572 1572
     		fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t3\t{$str}\n");
1573 1573
 		}
1574 1574
 	}
1575
-    elseif($errno < 1024) {
1575
+    elseif ($errno < 1024) {
1576 1576
     	$SXD->error = true;
1577 1577
     	if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str;
1578 1578
     	else {
@@ -1587,17 +1587,17 @@  discard block
 block discarded – undo
1587 1587
     	die;
1588 1588
 	}
1589 1589
 }
1590
-function sxd_esc($str, $quoted = true){
1590
+function sxd_esc($str, $quoted = true) {
1591 1591
 	return $quoted ? "'" . addcslashes($str, "\\\0\n\r\t\'") . "'" : addcslashes($str, "\\\0\n\r\t\'");
1592 1592
 }
1593
-function sxd_my_error(){
1593
+function sxd_my_error() {
1594 1594
 	trigger_error(mysql_error(), E_USER_ERROR);	
1595 1595
 }
1596
-function sxd_shutdown(){
1596
+function sxd_shutdown() {
1597 1597
 	global $SXD;
1598
-	if(isset($SXD->fh_rtl) && is_resource($SXD->fh_rtl) && !empty($SXD->rtl) && empty($SXD->error)) {
1598
+	if (isset($SXD->fh_rtl) && is_resource($SXD->fh_rtl) && !empty($SXD->rtl) && empty($SXD->error)) {
1599 1599
 		$SXD->rtl[1] = time();
1600
-		if(!empty($SXD->JOB['file_stp']) && file_exists(dirname(__FILE__) . '/' . $SXD->JOB['file_stp'])){
1600
+		if (!empty($SXD->JOB['file_stp']) && file_exists(dirname(__FILE__) . '/' . $SXD->JOB['file_stp'])) {
1601 1601
 			$type = file_get_contents(dirname(__FILE__) . '/' . $SXD->JOB['file_stp']);
1602 1602
 			$SXD->rtl[9] = !empty($type) ? $type : 2;
1603 1603
 		}
@@ -1606,6 +1606,6 @@  discard block
 block discarded – undo
1606 1606
 		fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl));
1607 1607
 	}
1608 1608
 }
1609
-function sxd_antimagic($arr){
1609
+function sxd_antimagic($arr) {
1610 1610
 	return is_array($arr) ? array_map('sxd_antimagic', $arr) : stripslashes($arr);
1611 1611
 }
Please login to merge, or discard this patch.
admin/sxd/ses.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1 1
 <?php
2
-$SES = array (
2
+$SES = array(
3 3
 );
4 4
 ?>
5 5
\ No newline at end of file
Please login to merge, or discard this patch.
admin/sxd/info.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -3,32 +3,32 @@  discard block
 block discarded – undo
3 3
 header("Content-Type: text/html; charset=utf-8");
4 4
 error_reporting(0);
5 5
 set_error_handler("sxd_error");
6
-if(!empty($_POST['ajax']['job']) && preg_match("/^[\w-]+$/", $_POST['ajax']['job'])){
6
+if (!empty($_POST['ajax']['job']) && preg_match("/^[\w-]+$/", $_POST['ajax']['job'])) {
7 7
 	$d = date("'Y.m.d H:i:s'");
8
-	if(!empty($_COOKIE['sxd'])) {
8
+	if (!empty($_COOKIE['sxd'])) {
9 9
 		include('ses.php');
10
-		if(!empty($SES[$_COOKIE['sxd']])) {
10
+		if (!empty($SES[$_COOKIE['sxd']])) {
11 11
 			$CFG = &$SES[$_COOKIE['sxd']]['cfg'];
12 12
 			include(load_lang($SES[$_COOKIE['sxd']]['lng']));
13 13
 		}
14 14
 	}
15
-	if(empty($LNG)) {
15
+	if (empty($LNG)) {
16 16
 		include('cfg.php');
17 17
 		include(load_lang($CFG['lang']));
18
-		if(!empty($CFG['auth'])) {echo "sxd.log.add({$d},[" . esc($LNG['stop_5']) . " (1)]);sxd.hideLoading();"; exit;}
18
+		if (!empty($CFG['auth'])) {echo "sxd.log.add({$d},[" . esc($LNG['stop_5']) . " (1)]);sxd.hideLoading();"; exit; }
19 19
 	} 
20 20
 	$job_name = $_POST['ajax']['job'];
21 21
 	$log_seek = !empty($_POST['ajax']['lseek']) ? (int) $_POST['ajax']['lseek'] : 0;
22 22
 	$job_file = "{$CFG['backup_path']}{$job_name}.job.php";
23 23
 	if (!file_exists($job_file)) exit;
24 24
 	include($job_file);
25
-	switch($_POST['ajax']['act']) {
25
+	switch ($_POST['ajax']['act']) {
26 26
 		case 'info':
27 27
 			if (!file_exists($JOB['file_rtl'])) exit;
28 28
 			$fh = fopen($JOB['file_rtl'], 'r+b');
29 29
 			$time = time();
30 30
 			$f = explode("\t", fgets($fh));
31
-			if(empty($f[0])) $f[0] = $time;
31
+			if (empty($f[0])) $f[0] = $time;
32 32
 			$pt = !empty($f[2]) ? round(100 * $f[10] / $f[2], 2) : 100;
33 33
 			$pc = !empty($f[8]) ? round(100 * $f[7] / $f[8], 2) : 100;
34 34
 			$lh = fopen($JOB['file_log'], 'rb');
@@ -37,46 +37,46 @@  discard block
 block discarded – undo
37 37
 			$log = '';
38 38
 			$old_time = '';
39 39
 			$logs = array();
40
-			if(!empty($rawlog)){
40
+			if (!empty($rawlog)) {
41 41
 				$temp = explode("\n", $rawlog);
42
-				foreach($temp AS $l){
43
-					if(empty($l)) continue;
42
+				foreach ($temp AS $l) {
43
+					if (empty($l)) continue;
44 44
 					$t = explode("\t", $l);
45
-					if(count($t) < 3) continue;
46
-					if($t[0] != $old_time){
47
-						if(!empty($logs)) $log .= "sxd.log.add('{$old_time}',[" . implode(',', $logs) . "]);";
45
+					if (count($t) < 3) continue;
46
+					if ($t[0] != $old_time) {
47
+						if (!empty($logs)) $log .= "sxd.log.add('{$old_time}',[" . implode(',', $logs) . "]);";
48 48
 						$old_time = $t[0];
49 49
 						$logs = array();
50 50
 					}
51 51
 					$logs[] = esc($t[2]);	
52 52
 				}
53
-				if(!empty($logs)) $log .= "sxd.log.add('{$old_time}',[" . implode(',', $logs) . "]);";
53
+				if (!empty($logs)) $log .= "sxd.log.add('{$old_time}',[" . implode(',', $logs) . "]);";
54 54
 			}
55 55
 			$log_seek = ftell($lh);
56 56
 			echo $log . "sxd.job.log_seek = {$log_seek};";
57 57
 			// Читаем лог
58
-			if($f[4] == 'EOJ') {
58
+			if ($f[4] == 'EOJ') {
59 59
 				$pt = $pc = 100; 
60 60
 				fclose($lh);
61 61
 				fclose($fh);
62 62
 				if (function_exists('usleep')) usleep(400000);
63 63
 				else sleep(1);
64
-				if($JOB['act'] == 'backup') $f[3] = filesize(file_exists($JOB['file_name']) ? $JOB['file_name'] : $JOB['file_tmp']);
64
+				if ($JOB['act'] == 'backup') $f[3] = filesize(file_exists($JOB['file_name']) ? $JOB['file_name'] : $JOB['file_tmp']);
65 65
 				// Обновляем список файлов
66
-				if($JOB['act'] == 'backup') print "sxd.actions.filelist(); z('btn_down').file = '{$JOB['file']}'; z('btn_down').style.display = '';";
66
+				if ($JOB['act'] == 'backup') print "sxd.actions.filelist(); z('btn_down').file = '{$JOB['file']}'; z('btn_down').style.display = '';";
67 67
 				echo "sxd.timer.set({$f[0]},{$f[1]},{$pt});sxd.progress.current.set({$pc}, 0, {$f[8]}, {$f[8]});sxd.progress.total.set({$pt},{$f[3]});";
68 68
 				echo "sxd.log.add({$d},['{$LNG['job_done']}', '{$LNG['js']['records']}: {$f[10]}', '{$LNG['file_size']}: ' + sxd.formatSize({$f[3]},2), '{$LNG['job_time']}: {$f[5]} {$LNG['seconds']}']);sxd.hideLoading();";
69 69
 				unlink($JOB['file_log']);
70 70
 				unlink($JOB['file_rtl']);
71 71
 				unlink($job_file);
72 72
 			}
73
-			else if($f[9] > 0){
73
+			else if ($f[9] > 0) {
74 74
 				echo "sxd.log.add({$d},[" . esc($LNG['stop_' . $f[9]]) . "]);" . (($f[9] == 3 || $f[9] == 4) ? 'sxd.resumeJob();' : 'sxd.hideLoading();');
75 75
 			}
76
-			else{
77
-				if($JOB['act'] == 'backup') $f[3] = filesize(file_exists($JOB['file_name']) ? $JOB['file_name'] : $JOB['file_tmp']);
78
-				if($f[4] != 'EK' && time() > $f[1] + 45) {
79
-					fopen($JOB['file_stp'],'w');
76
+			else {
77
+				if ($JOB['act'] == 'backup') $f[3] = filesize(file_exists($JOB['file_name']) ? $JOB['file_name'] : $JOB['file_tmp']);
78
+				if ($f[4] != 'EK' && time() > $f[1] + 45) {
79
+					fopen($JOB['file_stp'], 'w');
80 80
 					$f[9] = 0;
81 81
 					$f[1] = $time;
82 82
 					fwrite($fh, implode("\t", $f) . "\n");
@@ -86,51 +86,51 @@  discard block
 block discarded – undo
86 86
 			}
87 87
 		break;
88 88
 		case 'stop': 
89
-			$fs = fopen($JOB['file_stp'],'w');
89
+			$fs = fopen($JOB['file_stp'], 'w');
90 90
 			fwrite($fs, 1);
91 91
 			echo "sxd.log.add({$d},[" . esc($LNG['stop_job']) . "]);";
92 92
 		break;
93 93
 		case 'pause': 
94
-			fopen($JOB['file_stp'],'w');
94
+			fopen($JOB['file_stp'], 'w');
95 95
 			echo "sxd.log.add({$d},[" . esc($LNG['stop_job']) . "]);";
96 96
 		break;
97 97
 	}
98 98
 }
99 99
 else echo "sxd.hideLoading();";	
100 100
 
101
-function load_lang($lng_name = 'auto'){
102
-	if($lng_name == 'auto'){
101
+function load_lang($lng_name = 'auto') {
102
+	if ($lng_name == 'auto') {
103 103
 		include('lang/list.php');
104 104
 		$lng = 'en';
105
-		if(preg_match_all('/[a-z]{2}(-[a-z]{2})?/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $m)) {
106
-			foreach($m[0] AS $l){
107
-				if(isset($langs[$l])){
105
+		if (preg_match_all('/[a-z]{2}(-[a-z]{2})?/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $m)) {
106
+			foreach ($m[0] AS $l) {
107
+				if (isset($langs[$l])) {
108 108
 					$lng_name = $l;
109 109
 					break;
110 110
 				}
111 111
 			}
112 112
 		}
113 113
 	}
114
-	if(file_exists("lang/lng_{$lng_name}.php")) return "lang/lng_{$lng_name}.php";
114
+	if (file_exists("lang/lng_{$lng_name}.php")) return "lang/lng_{$lng_name}.php";
115 115
 	else return "lang/lng_en.php";
116 116
 }
117
-function esc($str){
117
+function esc($str) {
118 118
 	return "'" . addcslashes($str, "\\\0\n\r\t\'") . "'";
119 119
 }
120 120
 
121
-function sxd_error($errno, $errmsg, $filename, $linenum, $vars){
121
+function sxd_error($errno, $errmsg, $filename, $linenum, $vars) {
122 122
 	global $JOB;
123
-	if($errno == 8192) return;
124
-	if(strpos($errmsg, 'timezone settings')) return;
125
-	if(!empty($JOB['file_stp'])) fopen($JOB['file_stp'],'w');
123
+	if ($errno == 8192) return;
124
+	if (strpos($errmsg, 'timezone settings')) return;
125
+	if (!empty($JOB['file_stp'])) fopen($JOB['file_stp'], 'w');
126 126
 	$errortype = array(1 => 'Error', 2 => 'Warning', 4 => 'Parsing Error', 8 => 'Notice', 16 => 'Core Error', 32 => 'Core Warning', 64 => 'Compile Error', 
127 127
 					   128 => 'Compile Warning', 256 => 'User Error', 512 => 'User Warning', 1024 => 'User Notice');
128 128
 	$str = "{$errortype[$errno]}: {$errmsg} ({$filename}:{$linenum})";
129 129
 	//error_log("[info.php]\n{$str}\n", 3, "error.log"); 
130
-    if($errno == 8 || $errno == 1024) {
130
+    if ($errno == 8 || $errno == 1024) {
131 131
     	echo "sxd.log.add('" . date("Y.m.d H:i:s") . "',[" . esc($str) . "], 4);sxd.hideLoading();";
132 132
 	}
133
-    elseif($errno < 1024) {
133
+    elseif ($errno < 1024) {
134 134
     	echo "sxd.log.add('" . date("Y.m.d H:i:s") . "',[" . esc($str) . "], 4);sxd.hideLoading();";
135 135
     	die;
136 136
 	}
Please login to merge, or discard this patch.
admin/sxd/cfg.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-$CFG = array (
2
+$CFG = array(
3 3
   'charsets' => 'cp1251 utf8 latin1',
4 4
   'lang' => 'auto',
5 5
   'time_web' => '600',
Please login to merge, or discard this patch.
admin/sxd/load.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 error_reporting(0);
3
-if(!empty($_SERVER['QUERY_STRING']) && preg_match("/^(\w+)(\.v\d+)?(pro)?\.(lng\.js|js|css|gif|png|ico)$/", $_SERVER['QUERY_STRING'], $m)){
3
+if (!empty($_SERVER['QUERY_STRING']) && preg_match("/^(\w+)(\.v\d+)?(pro)?\.(lng\.js|js|css|gif|png|ico)$/", $_SERVER['QUERY_STRING'], $m)) {
4 4
 	$compress = true;
5 5
 	$skin = '';
6 6
 	$file = $skin;
7 7
 	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 1209600) . ' GMT');
8 8
 	header('Cache-Control: max-age=1209600, public');
9
-	switch($m[4]) {
9
+	switch ($m[4]) {
10 10
 		case 'css': $type = 'text/css; charset=UTF-8'; break;
11 11
 		case 'js':  $type = 'application/x-javascript; charset=UTF-8'; break;
12 12
 		case 'lng.js': 
@@ -15,24 +15,24 @@  discard block
 block discarded – undo
15 15
 			include("lang/lng_{$m[1]}.php");
16 16
 			echo 'sxdlng = ' . sxd_php2json($LNG['js']) . ';';
17 17
 			exit;
18
-		case 'png': $file = 'img/'; $type = 'image/png';$compress = false; break;
19
-		case 'gif': $file = 'img/'; $type = 'image/gif';$compress = false; break;
20
-		case 'ico': $file = ''; $type = 'image/x-icon';$compress = false; break;
18
+		case 'png': $file = 'img/'; $type = 'image/png'; $compress = false; break;
19
+		case 'gif': $file = 'img/'; $type = 'image/gif'; $compress = false; break;
20
+		case 'ico': $file = ''; $type = 'image/x-icon'; $compress = false; break;
21 21
 	}	
22 22
 	$file .= $m[1] . '.' . $m[4];
23
-	if(is_file($file)){
23
+	if (is_file($file)) {
24 24
 		//if($compress) if(!ini_get('zlib.output_compression') && function_exists('ob_gzhandler')) ob_start('ob_gzhandler');
25 25
 		header('Content-Type: ' . $type);
26
-		readfile($file);exit;
26
+		readfile($file); exit;
27 27
 	}
28 28
 }
29
-function sxd_php2json($obj){
30
-	if(count($obj) == 0) return '[]';
29
+function sxd_php2json($obj) {
30
+	if (count($obj) == 0) return '[]';
31 31
 	$is_obj = isset($obj[count($obj) - 1]) ? false : true;
32 32
 	$str = $is_obj ? '{' : '[';
33 33
     foreach ($obj AS $key  => $value) {
34 34
     	$str .= $is_obj ? "'" . addcslashes($key, "\n\r\t'\\/") . "'" . ':' : ''; 
35
-        if     (is_array($value))   $str .= sxd_php2json($value);
35
+        if (is_array($value))   $str .= sxd_php2json($value);
36 36
         elseif (is_null($value))    $str .= 'null';
37 37
         elseif (is_bool($value))    $str .= $value ? 'true' : 'false';
38 38
 		elseif (is_numeric($value)) $str .= $value;
Please login to merge, or discard this patch.
admin/planet_edit.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 require('../common.' . substr(strrchr(__FILE__, '.'), 1));
8 8
 
9 9
 // if($user['authlevel'] < 2)
10
-if($user['authlevel'] < 3)
10
+if ($user['authlevel'] < 3)
11 11
 {
12 12
   AdminMessage($lang['adm_err_denied']);
13 13
 }
@@ -21,30 +21,30 @@  discard block
 block discarded – undo
21 21
 $planet_id = sys_get_param_id('planet_id');
22 22
 
23 23
 $unit_list = sys_get_param('unit_list');
24
-if(sys_get_param('change_data') && !empty($unit_list))
24
+if (sys_get_param('change_data') && !empty($unit_list))
25 25
 {
26 26
   $query_string = array();
27
-  foreach($unit_list as $unit_id => $unit_amount)
27
+  foreach ($unit_list as $unit_id => $unit_amount)
28 28
   {
29
-    if($unit_query_string = admin_planet_edit_query_string($unit_id, $unit_amount, $mode))
29
+    if ($unit_query_string = admin_planet_edit_query_string($unit_id, $unit_amount, $mode))
30 30
     {
31 31
       $query_string[] = $unit_query_string;
32 32
     }
33 33
   }
34 34
 
35
-  if(!empty($query_string))
35
+  if (!empty($query_string))
36 36
   {
37 37
     db_planet_set_by_id($planet_id, implode(', ', $query_string));
38 38
   }
39 39
 }
40 40
 
41
-if($planet_id)
41
+if ($planet_id)
42 42
 {
43 43
   $edit_planet_row = db_planet_by_id($planet_id);
44 44
   admin_planet_edit_template($template, $edit_planet_row, $mode);
45 45
 }
46 46
 
47
-foreach($admin_planet_edit_mode_list as $page_mode => $mode_locale)
47
+foreach ($admin_planet_edit_mode_list as $page_mode => $mode_locale)
48 48
 {
49 49
   $template->assign_block_vars('page_menu', array(
50 50
     'ID' => $page_mode,
Please login to merge, or discard this patch.
admin/adm_quest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-define('INSIDE'  , true);
11
-define('INSTALL' , false);
12
-define('IN_ADMIN'  , true);
10
+define('INSIDE', true);
11
+define('INSTALL', false);
12
+define('IN_ADMIN', true);
13 13
 
14 14
 require('../common.' . substr(strrchr(__FILE__, '.'), 1));
15 15
 
16
-if($user['authlevel'] < 2)
16
+if ($user['authlevel'] < 2)
17 17
 {
18 18
   AdminMessage($lang['adm_err_denied']);
19 19
 }
Please login to merge, or discard this patch.