@@ -168,6 +168,11 @@ discard block |
||
| 168 | 168 | if(isset($_POST['ajax'])) $this->ajax($_POST['ajax']); |
| 169 | 169 | else $this->main();exit; |
| 170 | 170 | } |
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @param string $name |
|
| 174 | + * @param string $content |
|
| 175 | + */ |
|
| 171 | 176 | function saveToFile($name, $content){ |
| 172 | 177 | $fp = fopen($name, "w"); |
| 173 | 178 | fwrite($fp, $content); |
@@ -248,6 +253,12 @@ discard block |
||
| 248 | 253 | include('tmpl.php'); |
| 249 | 254 | echo sxd_tpl_page(); |
| 250 | 255 | } |
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @param string $name |
|
| 259 | + * @param integer $ico |
|
| 260 | + * @param string $opt_name |
|
| 261 | + */ |
|
| 251 | 262 | function addCombo($name, $sel, $ico, $opt_name, $opts = ''){ |
| 252 | 263 | $opts = !empty($opts) ? "{{$opt_name}:" . sxd_php2json($opts) . '}' : "'{$opt_name}'"; |
| 253 | 264 | return "sxd.addCombo('{$name}', '{$sel}', {$ico}, {$opts});\n"; |
@@ -1313,6 +1324,10 @@ discard block |
||
| 1313 | 1324 | } |
| 1314 | 1325 | return $this->formatTree($tree, $objects); |
| 1315 | 1326 | } |
| 1327 | + |
|
| 1328 | + /** |
|
| 1329 | + * @param string $tree |
|
| 1330 | + */ |
|
| 1316 | 1331 | function getFileObjects($tree, $name, $formatTree = true){ |
| 1317 | 1332 | // Достаем таблицы |
| 1318 | 1333 | $objects = array('TA' => array(), 'VI' => array(), 'PR' => array(), 'FU' => array(), 'TR' => array(), 'EV' => array()); |
@@ -1475,6 +1490,10 @@ discard block |
||
| 1475 | 1490 | function saveJob($job, $config){ |
| 1476 | 1491 | $this->saveToFile($this->CFG['backup_path'] . $job . '.job.php', "<?php\n\$JOB = " . var_export($config, true) . ";\n" . "?>"); |
| 1477 | 1492 | } |
| 1493 | + |
|
| 1494 | + /** |
|
| 1495 | + * @param string $mode |
|
| 1496 | + */ |
|
| 1478 | 1497 | function openFile($name, $mode){ |
| 1479 | 1498 | if($mode == 'r') { |
| 1480 | 1499 | if(preg_match('/\.(sql|sql\.bz2|sql\.gz)$/i', $name, $m)) $this->JOB['file_ext'] = strtolower($m[1]); |
@@ -1552,6 +1571,9 @@ discard block |
||
| 1552 | 1571 | } |
| 1553 | 1572 | return substr_replace($str, $is_obj ? '}' : ']', -1); |
| 1554 | 1573 | } |
| 1574 | +/** |
|
| 1575 | + * @param string $ver |
|
| 1576 | + */ |
|
| 1555 | 1577 | function sxd_ver2int($ver){ |
| 1556 | 1578 | return preg_match("/^(\d+)\.(\d+)\.(\d+)/", $ver, $m) ? sprintf("%d%02d%02d", $m[1], $m[2], $m[3]) : 0; |
| 1557 | 1579 | } |
@@ -22,1127 +22,1127 @@ discard block |
||
| 22 | 22 | $SXD->init(!empty($argc) && $argc > 1 ? $argv : false); |
| 23 | 23 | |
| 24 | 24 | class Sypex_Dumper { |
| 25 | - function Sypex_Dumper() { |
|
| 26 | - define('C_DEFAULT', 1); |
|
| 27 | - define('C_RESULT', 2); |
|
| 28 | - define('C_ERROR', 3); |
|
| 29 | - define('C_WARNING', 4); |
|
| 30 | - define('SXD_DEBUG', false); |
|
| 31 | - define('TIMER', array_sum(explode(' ', microtime()))); |
|
| 32 | - define('V_SXD', 20011); |
|
| 33 | - define('V_PHP', sxd_ver2int(phpversion())); |
|
| 34 | - $this->name = 'Sypex Dumper 2.0.11'; |
|
| 35 | - } |
|
| 36 | - function loadLang($lng_name = 'auto'){ |
|
| 37 | - if($lng_name == 'auto'){ |
|
| 38 | - include('lang/list.php'); |
|
| 39 | - $this->langs = &$langs; |
|
| 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])){ |
|
| 44 | - $lng_name = $l; |
|
| 45 | - break; |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - if(file_exists("lang/lng_{$lng_name}.php")) include("lang/lng_{$lng_name}.php"); |
|
| 51 | - else include("lang/lng_en.php"); |
|
| 52 | - $this->LNG = &$LNG; |
|
| 53 | - $this->LNG['name'] = $lng_name; |
|
| 54 | - return true; |
|
| 55 | - } |
|
| 56 | - function init($args = false){ |
|
| 57 | - if (get_magic_quotes_gpc()) { |
|
| 58 | - $_POST = sxd_antimagic($_POST); |
|
| 59 | - } |
|
| 60 | - include('cfg.php'); |
|
| 61 | - $this->loadLang($CFG['lang']); |
|
| 62 | - if (!ini_get('safe_mode') && function_exists('set_time_limit') && strpos(ini_get('disable_functions'), 'set_time_limit') === false) @set_time_limit($CFG['time_web']); |
|
| 63 | - elseif (ini_get('max_execution_time') < $CFG['time_web']) $CFG['time_web'] = ini_get('max_execution_time'); |
|
| 64 | - $this->CFG = &$CFG; |
|
| 65 | - $this->try = false; |
|
| 66 | - $this->virtualize = false; |
|
| 67 | - $this->cron_mode = false; |
|
| 68 | - // Проверяем авторизацию и делаем коннект к базе |
|
| 69 | - if(empty($this->CFG['my_user'])){ |
|
| 70 | - $this->CFG['my_host'] = 'localhost'; |
|
| 71 | - $this->CFG['my_port'] = 3306; |
|
| 72 | - $this->CFG['my_user'] = 'root'; |
|
| 73 | - $this->CFG['my_pass'] = ''; |
|
| 74 | - $this->CFG['my_comp'] = 0; |
|
| 75 | - $this->CFG['my_db'] = ''; |
|
| 76 | - } |
|
| 77 | - if ($args) { // консольный режим |
|
| 78 | - foreach($args AS $key => $arg){ |
|
| 79 | - if (preg_match("/^-([hupoj])=(.*?)$/", $arg, $m)){ |
|
| 80 | - switch ($m[1]) { |
|
| 81 | - case 'h': $this->CFG['my_host'] = $m[2]; break; // хост |
|
| 82 | - case 'o': $this->CFG['my_port'] = $m[2]; break; // порт |
|
| 83 | - case 'u': $this->CFG['my_user'] = $m[2]; break; // логин |
|
| 84 | - case 'p': $this->CFG['my_pass'] = $m[2]; break; // пароль |
|
| 85 | - case 'j': $this->CFG['sjob'] = $m[2]; break; // job-файл |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - $this->cron_mode = true; |
|
| 90 | - set_time_limit($CFG['time_cron']); |
|
| 91 | - // Загружаем конфиг файл, если нужно |
|
| 92 | - $auth = $this->connect(); |
|
| 93 | - if($auth && !empty($this->CFG['sjob'])){ |
|
| 94 | - $this->ajax($this->loadJob($this->CFG['sjob'])); |
|
| 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']); |
|
| 98 | - } |
|
| 99 | - else echo 'Auth error'; |
|
| 100 | - exit; |
|
| 101 | - } |
|
| 102 | - elseif(!empty($this->CFG['auth'])){ // Авторизация |
|
| 103 | - $auth = false; |
|
| 104 | - $sfile = 'ses.php'; |
|
| 25 | + function Sypex_Dumper() { |
|
| 26 | + define('C_DEFAULT', 1); |
|
| 27 | + define('C_RESULT', 2); |
|
| 28 | + define('C_ERROR', 3); |
|
| 29 | + define('C_WARNING', 4); |
|
| 30 | + define('SXD_DEBUG', false); |
|
| 31 | + define('TIMER', array_sum(explode(' ', microtime()))); |
|
| 32 | + define('V_SXD', 20011); |
|
| 33 | + define('V_PHP', sxd_ver2int(phpversion())); |
|
| 34 | + $this->name = 'Sypex Dumper 2.0.11'; |
|
| 35 | + } |
|
| 36 | + function loadLang($lng_name = 'auto'){ |
|
| 37 | + if($lng_name == 'auto'){ |
|
| 38 | + include('lang/list.php'); |
|
| 39 | + $this->langs = &$langs; |
|
| 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])){ |
|
| 44 | + $lng_name = $l; |
|
| 45 | + break; |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + if(file_exists("lang/lng_{$lng_name}.php")) include("lang/lng_{$lng_name}.php"); |
|
| 51 | + else include("lang/lng_en.php"); |
|
| 52 | + $this->LNG = &$LNG; |
|
| 53 | + $this->LNG['name'] = $lng_name; |
|
| 54 | + return true; |
|
| 55 | + } |
|
| 56 | + function init($args = false){ |
|
| 57 | + if (get_magic_quotes_gpc()) { |
|
| 58 | + $_POST = sxd_antimagic($_POST); |
|
| 59 | + } |
|
| 60 | + include('cfg.php'); |
|
| 61 | + $this->loadLang($CFG['lang']); |
|
| 62 | + if (!ini_get('safe_mode') && function_exists('set_time_limit') && strpos(ini_get('disable_functions'), 'set_time_limit') === false) @set_time_limit($CFG['time_web']); |
|
| 63 | + elseif (ini_get('max_execution_time') < $CFG['time_web']) $CFG['time_web'] = ini_get('max_execution_time'); |
|
| 64 | + $this->CFG = &$CFG; |
|
| 65 | + $this->try = false; |
|
| 66 | + $this->virtualize = false; |
|
| 67 | + $this->cron_mode = false; |
|
| 68 | + // Проверяем авторизацию и делаем коннект к базе |
|
| 69 | + if(empty($this->CFG['my_user'])){ |
|
| 70 | + $this->CFG['my_host'] = 'localhost'; |
|
| 71 | + $this->CFG['my_port'] = 3306; |
|
| 72 | + $this->CFG['my_user'] = 'root'; |
|
| 73 | + $this->CFG['my_pass'] = ''; |
|
| 74 | + $this->CFG['my_comp'] = 0; |
|
| 75 | + $this->CFG['my_db'] = ''; |
|
| 76 | + } |
|
| 77 | + if ($args) { // консольный режим |
|
| 78 | + foreach($args AS $key => $arg){ |
|
| 79 | + if (preg_match("/^-([hupoj])=(.*?)$/", $arg, $m)){ |
|
| 80 | + switch ($m[1]) { |
|
| 81 | + case 'h': $this->CFG['my_host'] = $m[2]; break; // хост |
|
| 82 | + case 'o': $this->CFG['my_port'] = $m[2]; break; // порт |
|
| 83 | + case 'u': $this->CFG['my_user'] = $m[2]; break; // логин |
|
| 84 | + case 'p': $this->CFG['my_pass'] = $m[2]; break; // пароль |
|
| 85 | + case 'j': $this->CFG['sjob'] = $m[2]; break; // job-файл |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + $this->cron_mode = true; |
|
| 90 | + set_time_limit($CFG['time_cron']); |
|
| 91 | + // Загружаем конфиг файл, если нужно |
|
| 92 | + $auth = $this->connect(); |
|
| 93 | + if($auth && !empty($this->CFG['sjob'])){ |
|
| 94 | + $this->ajax($this->loadJob($this->CFG['sjob'])); |
|
| 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']); |
|
| 98 | + } |
|
| 99 | + else echo 'Auth error'; |
|
| 100 | + exit; |
|
| 101 | + } |
|
| 102 | + elseif(!empty($this->CFG['auth'])){ // Авторизация |
|
| 103 | + $auth = false; |
|
| 104 | + $sfile = 'ses.php'; |
|
| 105 | 105 | |
| 106 | - if(!empty($_COOKIE['sxd']) && preg_match('/^[\da-f]{32}$/', $_COOKIE['sxd'])){ |
|
| 107 | - include($sfile); |
|
| 108 | - if(isset($SES[$_COOKIE['sxd']])) { |
|
| 109 | - $auth = true; |
|
| 110 | - $this->CFG = $SES[$_COOKIE['sxd']]['cfg']; |
|
| 111 | - $this->SES = &$SES; |
|
| 112 | - $this->loadLang($this->CFG['lang']); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - if(!$auth) { |
|
| 116 | - $user = !empty($_POST['user']) ? $_POST['user'] : ''; |
|
| 117 | - $pass = !empty($_POST['pass']) ? $_POST['pass'] : ''; |
|
| 118 | - $host = !empty($_POST['host']) ? $_POST['host'] : (!empty($this->CFG['my_host']) ? $this->CFG['my_host'] : 'localhost'); |
|
| 119 | - $port = !empty($_POST['port']) && is_numeric($_POST['port']) ? $_POST['port'] : 3306; |
|
| 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; |
|
| 126 | - break; |
|
| 127 | - case 'mysql': if(empty($user)) {continue;} |
|
| 128 | - if($host != 'localhost' && !empty($this->CFG['my_host']) && $this->CFG['my_host'] != $host) {continue;} |
|
| 129 | - $auth = $this->connect($host, $port, $user, $pass); |
|
| 130 | - break; |
|
| 131 | - default: $file = 'auth_' . $a . '.php'; |
|
| 132 | - if(!file_exists($file)) continue; |
|
| 133 | - include $file; |
|
| 134 | - } |
|
| 135 | - if($auth) break; |
|
| 136 | - } |
|
| 137 | - if($auth){ |
|
| 138 | - $key = md5(rand(1,100000) . $user . microtime()); |
|
| 139 | - $CFG['lang'] = $this->LNG['name']; |
|
| 140 | - $_COOKIE['sxd'] = $key; |
|
| 141 | - $this->saveCFG(); |
|
| 142 | - if(V_PHP > 50200) setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false, true); |
|
| 143 | - else setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false); |
|
| 144 | - header("Location: ./"); |
|
| 145 | - exit; |
|
| 146 | - } |
|
| 147 | - foreach(array('user', 'pass', 'host', 'port') AS $key){ |
|
| 148 | - $_POST[$key] = !empty($_POST[$key]) ? htmlspecialchars($_POST[$key], ENT_NOQUOTES) : ''; |
|
| 149 | - } |
|
| 150 | - $_POST['save'] = !empty($_POST['save']) ? ' CHECKED' : ''; |
|
| 151 | - } |
|
| 152 | - if (!$auth) { |
|
| 153 | - if(!empty($_POST['ajax'])){ |
|
| 154 | - echo "sxd.hideLoading();alert('Session not found');"; |
|
| 155 | - exit; |
|
| 156 | - } |
|
| 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){ |
|
| 160 | - $this->lng_list .= "<option value=\"{$k}\"" . ($k == (!empty($_REQUEST['lang']) ? $this->LNG['name'] : $this->CFG['lang']) ? ' SELECTED' : '') . ">{$v}</opinion>"; |
|
| 161 | - } |
|
| 162 | - include('tmpl.php'); |
|
| 163 | - echo sxd_tpl_auth(); |
|
| 164 | - exit; |
|
| 165 | - } |
|
| 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; |
|
| 170 | - } |
|
| 171 | - function saveToFile($name, $content){ |
|
| 172 | - $fp = fopen($name, "w"); |
|
| 173 | - fwrite($fp, $content); |
|
| 174 | - fclose($fp); |
|
| 175 | - } |
|
| 176 | - function connect($host = null, $port = null, $user = null, $pass = null){ |
|
| 177 | - $this->error = ''; |
|
| 178 | - $this->try = true; |
|
| 179 | - if(!empty($user) && isset($pass)) { |
|
| 180 | - $this->CFG['my_host'] = $host; |
|
| 181 | - $this->CFG['my_port'] = $port; |
|
| 182 | - $this->CFG['my_user'] = $user; |
|
| 183 | - $this->CFG['my_pass'] = $pass; |
|
| 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(); |
|
| 187 | - else mysql_query('SET NAMES utf8') or sxd_my_error(); |
|
| 188 | - define('V_MYSQL', sxd_ver2int(mysql_get_server_info())); |
|
| 189 | - } |
|
| 190 | - else { |
|
| 191 | - define('V_MYSQL', 0); |
|
| 192 | - $this->error = "sxd.actions.tab_connects();alert(" . sxd_esc(mysql_error()) . ");"; |
|
| 193 | - } |
|
| 194 | - $this->try = false; |
|
| 195 | - return V_MYSQL ? true: false; |
|
| 196 | - } |
|
| 197 | - function main(){ |
|
| 198 | - // Тулбар |
|
| 199 | - $this->VAR['toolbar'] = sxd_php2json( |
|
| 200 | - array( |
|
| 201 | - array('backup', $this->LNG['tbar_backup'], 1, 3), |
|
| 202 | - array('restore', $this->LNG['tbar_restore'], 2, 3), |
|
| 203 | - array('|'), |
|
| 204 | - array('files', $this->LNG['tbar_files'], 3, 1), |
|
| 205 | - array('services', $this->LNG['tbar_services'], 5, 1), |
|
| 206 | - array('|'), |
|
| 207 | - array('createdb', $this->LNG['tbar_createdb'], 7, 0), |
|
| 208 | - array('connects', $this->LNG['tbar_connects'], 6, 0), |
|
| 209 | - array('|'), |
|
| 210 | - array('options', $this->LNG['tbar_options'], 4, 1), |
|
| 211 | - array('|'), |
|
| 212 | - array('exit', $this->LNG['tbar_exit'], 8, 1), |
|
| 213 | - ) |
|
| 214 | - ); |
|
| 215 | - $this->db = 'temp'; |
|
| 216 | - $zip = array($this->LNG['zip_none']); |
|
| 217 | - if (function_exists("gzopen")) { |
|
| 218 | - for($i = 1; $i <10; $i++){ |
|
| 219 | - $zip[] = "GZip: {$i}"; |
|
| 220 | - } |
|
| 221 | - $zip[1] .= " ({$this->LNG['zip_min']})"; |
|
| 222 | - $zip[7] .= " ({$this->LNG['default']})"; |
|
| 223 | - } |
|
| 224 | - if (function_exists("bzopen")) { |
|
| 225 | - $zip[10] = "BZip"; |
|
| 226 | - } |
|
| 227 | - end($zip); |
|
| 228 | - $zip[key($zip)] .= " ({$this->LNG['zip_max']})"; |
|
| 229 | - $this->VAR['combos'] = |
|
| 230 | - $this->addCombo('backup_db', $this->db, 11, 'db', array()/*$this->getDBList()*/) . |
|
| 231 | - $this->addCombo('backup_charset', 0, 9, 'charset', $this->getCharsetList()) . |
|
| 232 | - $this->addCombo('backup_zip', 7, 10, 'zip', $zip) . |
|
| 233 | - $this->addCombo('restore_db', $this->db, 11, 'db') . |
|
| 234 | - $this->addCombo('restore_charset', 0, 9, 'charset') . |
|
| 235 | - $this->addCombo('restore_file', 0, 12, 'files', $this->getFileList()) . |
|
| 236 | - $this->addCombo('restore_type', 0, 13, 'types', array("CREATE + INSERT ({$this->LNG['default']})", 'TRUNCATE + INSERT', 'REPLACE', 'INSERT IGNORE')) . |
|
| 237 | - $this->addCombo('services_db', $this->db, 11, 'db') . |
|
| 238 | - $this->addCombo('services_check', 0, 5, 'check', array("- {$this->LNG['default']} -", 'QUICK', 'FAST', 'CHANGED', 'MEDIUM', 'EXTENDED')) . |
|
| 239 | - $this->addCombo('services_repair', 0, 5, 'repair', array("- {$this->LNG['default']} -", 'QUICK', 'EXTENDED')) . |
|
| 240 | - $this->addCombo('db_charset', 0, 9, 'collation', $this->getCollationList()) . |
|
| 241 | - $this->addCombo('db_charset_col', 0, 15, 'collation:db_charset') |
|
| 242 | - ; |
|
| 243 | - if (!V_MYSQL) $this->VAR['combos'] .= $this->error; |
|
| 244 | - $this->VAR['combos'] .= $this->getSavedJobs() . "sxd.confirms = {$this->CFG['confirm']};sxd.actions.dblist();"; |
|
| 245 | - $this->LNG['del_date'] = sprintf($this->LNG['del_date'], '<input type="text" id="del_time" class=txt style="width:24px;" maxlength="3">'); |
|
| 246 | - $this->LNG['del_count'] = sprintf($this->LNG['del_count'], '<input id="del_count" type="text" class=txt style="width:18px;" maxlength="2">'); |
|
| 106 | + if(!empty($_COOKIE['sxd']) && preg_match('/^[\da-f]{32}$/', $_COOKIE['sxd'])){ |
|
| 107 | + include($sfile); |
|
| 108 | + if(isset($SES[$_COOKIE['sxd']])) { |
|
| 109 | + $auth = true; |
|
| 110 | + $this->CFG = $SES[$_COOKIE['sxd']]['cfg']; |
|
| 111 | + $this->SES = &$SES; |
|
| 112 | + $this->loadLang($this->CFG['lang']); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + if(!$auth) { |
|
| 116 | + $user = !empty($_POST['user']) ? $_POST['user'] : ''; |
|
| 117 | + $pass = !empty($_POST['pass']) ? $_POST['pass'] : ''; |
|
| 118 | + $host = !empty($_POST['host']) ? $_POST['host'] : (!empty($this->CFG['my_host']) ? $this->CFG['my_host'] : 'localhost'); |
|
| 119 | + $port = !empty($_POST['port']) && is_numeric($_POST['port']) ? $_POST['port'] : 3306; |
|
| 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; |
|
| 126 | + break; |
|
| 127 | + case 'mysql': if(empty($user)) {continue;} |
|
| 128 | + if($host != 'localhost' && !empty($this->CFG['my_host']) && $this->CFG['my_host'] != $host) {continue;} |
|
| 129 | + $auth = $this->connect($host, $port, $user, $pass); |
|
| 130 | + break; |
|
| 131 | + default: $file = 'auth_' . $a . '.php'; |
|
| 132 | + if(!file_exists($file)) continue; |
|
| 133 | + include $file; |
|
| 134 | + } |
|
| 135 | + if($auth) break; |
|
| 136 | + } |
|
| 137 | + if($auth){ |
|
| 138 | + $key = md5(rand(1,100000) . $user . microtime()); |
|
| 139 | + $CFG['lang'] = $this->LNG['name']; |
|
| 140 | + $_COOKIE['sxd'] = $key; |
|
| 141 | + $this->saveCFG(); |
|
| 142 | + if(V_PHP > 50200) setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false, true); |
|
| 143 | + else setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false); |
|
| 144 | + header("Location: ./"); |
|
| 145 | + exit; |
|
| 146 | + } |
|
| 147 | + foreach(array('user', 'pass', 'host', 'port') AS $key){ |
|
| 148 | + $_POST[$key] = !empty($_POST[$key]) ? htmlspecialchars($_POST[$key], ENT_NOQUOTES) : ''; |
|
| 149 | + } |
|
| 150 | + $_POST['save'] = !empty($_POST['save']) ? ' CHECKED' : ''; |
|
| 151 | + } |
|
| 152 | + if (!$auth) { |
|
| 153 | + if(!empty($_POST['ajax'])){ |
|
| 154 | + echo "sxd.hideLoading();alert('Session not found');"; |
|
| 155 | + exit; |
|
| 156 | + } |
|
| 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){ |
|
| 160 | + $this->lng_list .= "<option value=\"{$k}\"" . ($k == (!empty($_REQUEST['lang']) ? $this->LNG['name'] : $this->CFG['lang']) ? ' SELECTED' : '') . ">{$v}</opinion>"; |
|
| 161 | + } |
|
| 162 | + include('tmpl.php'); |
|
| 163 | + echo sxd_tpl_auth(); |
|
| 164 | + exit; |
|
| 165 | + } |
|
| 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; |
|
| 170 | + } |
|
| 171 | + function saveToFile($name, $content){ |
|
| 172 | + $fp = fopen($name, "w"); |
|
| 173 | + fwrite($fp, $content); |
|
| 174 | + fclose($fp); |
|
| 175 | + } |
|
| 176 | + function connect($host = null, $port = null, $user = null, $pass = null){ |
|
| 177 | + $this->error = ''; |
|
| 178 | + $this->try = true; |
|
| 179 | + if(!empty($user) && isset($pass)) { |
|
| 180 | + $this->CFG['my_host'] = $host; |
|
| 181 | + $this->CFG['my_port'] = $port; |
|
| 182 | + $this->CFG['my_user'] = $user; |
|
| 183 | + $this->CFG['my_pass'] = $pass; |
|
| 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(); |
|
| 187 | + else mysql_query('SET NAMES utf8') or sxd_my_error(); |
|
| 188 | + define('V_MYSQL', sxd_ver2int(mysql_get_server_info())); |
|
| 189 | + } |
|
| 190 | + else { |
|
| 191 | + define('V_MYSQL', 0); |
|
| 192 | + $this->error = "sxd.actions.tab_connects();alert(" . sxd_esc(mysql_error()) . ");"; |
|
| 193 | + } |
|
| 194 | + $this->try = false; |
|
| 195 | + return V_MYSQL ? true: false; |
|
| 196 | + } |
|
| 197 | + function main(){ |
|
| 198 | + // Тулбар |
|
| 199 | + $this->VAR['toolbar'] = sxd_php2json( |
|
| 200 | + array( |
|
| 201 | + array('backup', $this->LNG['tbar_backup'], 1, 3), |
|
| 202 | + array('restore', $this->LNG['tbar_restore'], 2, 3), |
|
| 203 | + array('|'), |
|
| 204 | + array('files', $this->LNG['tbar_files'], 3, 1), |
|
| 205 | + array('services', $this->LNG['tbar_services'], 5, 1), |
|
| 206 | + array('|'), |
|
| 207 | + array('createdb', $this->LNG['tbar_createdb'], 7, 0), |
|
| 208 | + array('connects', $this->LNG['tbar_connects'], 6, 0), |
|
| 209 | + array('|'), |
|
| 210 | + array('options', $this->LNG['tbar_options'], 4, 1), |
|
| 211 | + array('|'), |
|
| 212 | + array('exit', $this->LNG['tbar_exit'], 8, 1), |
|
| 213 | + ) |
|
| 214 | + ); |
|
| 215 | + $this->db = 'temp'; |
|
| 216 | + $zip = array($this->LNG['zip_none']); |
|
| 217 | + if (function_exists("gzopen")) { |
|
| 218 | + for($i = 1; $i <10; $i++){ |
|
| 219 | + $zip[] = "GZip: {$i}"; |
|
| 220 | + } |
|
| 221 | + $zip[1] .= " ({$this->LNG['zip_min']})"; |
|
| 222 | + $zip[7] .= " ({$this->LNG['default']})"; |
|
| 223 | + } |
|
| 224 | + if (function_exists("bzopen")) { |
|
| 225 | + $zip[10] = "BZip"; |
|
| 226 | + } |
|
| 227 | + end($zip); |
|
| 228 | + $zip[key($zip)] .= " ({$this->LNG['zip_max']})"; |
|
| 229 | + $this->VAR['combos'] = |
|
| 230 | + $this->addCombo('backup_db', $this->db, 11, 'db', array()/*$this->getDBList()*/) . |
|
| 231 | + $this->addCombo('backup_charset', 0, 9, 'charset', $this->getCharsetList()) . |
|
| 232 | + $this->addCombo('backup_zip', 7, 10, 'zip', $zip) . |
|
| 233 | + $this->addCombo('restore_db', $this->db, 11, 'db') . |
|
| 234 | + $this->addCombo('restore_charset', 0, 9, 'charset') . |
|
| 235 | + $this->addCombo('restore_file', 0, 12, 'files', $this->getFileList()) . |
|
| 236 | + $this->addCombo('restore_type', 0, 13, 'types', array("CREATE + INSERT ({$this->LNG['default']})", 'TRUNCATE + INSERT', 'REPLACE', 'INSERT IGNORE')) . |
|
| 237 | + $this->addCombo('services_db', $this->db, 11, 'db') . |
|
| 238 | + $this->addCombo('services_check', 0, 5, 'check', array("- {$this->LNG['default']} -", 'QUICK', 'FAST', 'CHANGED', 'MEDIUM', 'EXTENDED')) . |
|
| 239 | + $this->addCombo('services_repair', 0, 5, 'repair', array("- {$this->LNG['default']} -", 'QUICK', 'EXTENDED')) . |
|
| 240 | + $this->addCombo('db_charset', 0, 9, 'collation', $this->getCollationList()) . |
|
| 241 | + $this->addCombo('db_charset_col', 0, 15, 'collation:db_charset') |
|
| 242 | + ; |
|
| 243 | + if (!V_MYSQL) $this->VAR['combos'] .= $this->error; |
|
| 244 | + $this->VAR['combos'] .= $this->getSavedJobs() . "sxd.confirms = {$this->CFG['confirm']};sxd.actions.dblist();"; |
|
| 245 | + $this->LNG['del_date'] = sprintf($this->LNG['del_date'], '<input type="text" id="del_time" class=txt style="width:24px;" maxlength="3">'); |
|
| 246 | + $this->LNG['del_count'] = sprintf($this->LNG['del_count'], '<input id="del_count" type="text" class=txt style="width:18px;" maxlength="2">'); |
|
| 247 | 247 | |
| 248 | - include('tmpl.php'); |
|
| 249 | - echo sxd_tpl_page(); |
|
| 250 | - } |
|
| 251 | - function addCombo($name, $sel, $ico, $opt_name, $opts = ''){ |
|
| 252 | - $opts = !empty($opts) ? "{{$opt_name}:" . sxd_php2json($opts) . '}' : "'{$opt_name}'"; |
|
| 253 | - return "sxd.addCombo('{$name}', '{$sel}', {$ico}, {$opts});\n"; |
|
| 254 | - } |
|
| 255 | - function ajax($req){ |
|
| 256 | - $res = ''; |
|
| 257 | - $act = $req['act']; |
|
| 258 | - if($req['act'] == 'run_savedjob'){ |
|
| 259 | - $req = $this->loadJob($req); |
|
| 260 | - } |
|
| 261 | - switch($req['act']){ |
|
| 262 | - case 'load_db': |
|
| 263 | - $res = $this->getObjects(str_replace('_db', '', $req['name']), $req['value']); |
|
| 264 | - break; |
|
| 265 | - case 'load_files': |
|
| 266 | - $res = $this->getFileObjects('restore', $req['value']); |
|
| 267 | - break; |
|
| 268 | - case 'filelist': |
|
| 269 | - $res = "sxd.clearOpt('files');sxd.addOpt(" . sxd_php2json(array('files' => $this->getFileList())) . ");"; |
|
| 270 | - break; |
|
| 271 | - case 'dblist': |
|
| 272 | - $res = "sxd.clearOpt('db');sxd.addOpt(" . sxd_php2json(array('db' => $this->getDBList())) . ");sxd.combos.restore_db.select(0,'-');sxd.combos.services_db.select(0,'-');sxd.combos.backup_db.select(0,'-');"; |
|
| 273 | - break; |
|
| 274 | - case 'load_connect': |
|
| 275 | - $CFG = $this->cfg2js($this->CFG); |
|
| 276 | - $res = "z('con_host').value = '{$CFG['my_host']}', z('con_port').value = '{$CFG['my_port']}', z('con_user').value = '{$CFG['my_user']}', |
|
| 248 | + include('tmpl.php'); |
|
| 249 | + echo sxd_tpl_page(); |
|
| 250 | + } |
|
| 251 | + function addCombo($name, $sel, $ico, $opt_name, $opts = ''){ |
|
| 252 | + $opts = !empty($opts) ? "{{$opt_name}:" . sxd_php2json($opts) . '}' : "'{$opt_name}'"; |
|
| 253 | + return "sxd.addCombo('{$name}', '{$sel}', {$ico}, {$opts});\n"; |
|
| 254 | + } |
|
| 255 | + function ajax($req){ |
|
| 256 | + $res = ''; |
|
| 257 | + $act = $req['act']; |
|
| 258 | + if($req['act'] == 'run_savedjob'){ |
|
| 259 | + $req = $this->loadJob($req); |
|
| 260 | + } |
|
| 261 | + switch($req['act']){ |
|
| 262 | + case 'load_db': |
|
| 263 | + $res = $this->getObjects(str_replace('_db', '', $req['name']), $req['value']); |
|
| 264 | + break; |
|
| 265 | + case 'load_files': |
|
| 266 | + $res = $this->getFileObjects('restore', $req['value']); |
|
| 267 | + break; |
|
| 268 | + case 'filelist': |
|
| 269 | + $res = "sxd.clearOpt('files');sxd.addOpt(" . sxd_php2json(array('files' => $this->getFileList())) . ");"; |
|
| 270 | + break; |
|
| 271 | + case 'dblist': |
|
| 272 | + $res = "sxd.clearOpt('db');sxd.addOpt(" . sxd_php2json(array('db' => $this->getDBList())) . ");sxd.combos.restore_db.select(0,'-');sxd.combos.services_db.select(0,'-');sxd.combos.backup_db.select(0,'-');"; |
|
| 273 | + break; |
|
| 274 | + case 'load_connect': |
|
| 275 | + $CFG = $this->cfg2js($this->CFG); |
|
| 276 | + $res = "z('con_host').value = '{$CFG['my_host']}', z('con_port').value = '{$CFG['my_port']}', z('con_user').value = '{$CFG['my_user']}', |
|
| 277 | 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 | - break; |
|
| 279 | - case 'save_connect': |
|
| 280 | - $res = $this->saveConnect($req); |
|
| 281 | - break; |
|
| 282 | - case 'save_job': |
|
| 283 | - unset($req['act']); |
|
| 284 | - $this->saveJob('sj_' . $req['job'] , $req); |
|
| 285 | - $res = $this->getSavedJobs(); |
|
| 286 | - break; |
|
| 287 | - case 'add_db': |
|
| 288 | - $res = $this->addDb($req); |
|
| 289 | - break; |
|
| 290 | - case 'load_options': |
|
| 291 | - $CFG = $this->cfg2js($this->CFG); |
|
| 292 | - $res = "z('time_web').value = '{$CFG['time_web']}', z('time_cron').value = '{$CFG['time_cron']}', z('backup_path').value = '{$CFG['backup_path']}', |
|
| 278 | + break; |
|
| 279 | + case 'save_connect': |
|
| 280 | + $res = $this->saveConnect($req); |
|
| 281 | + break; |
|
| 282 | + case 'save_job': |
|
| 283 | + unset($req['act']); |
|
| 284 | + $this->saveJob('sj_' . $req['job'] , $req); |
|
| 285 | + $res = $this->getSavedJobs(); |
|
| 286 | + break; |
|
| 287 | + case 'add_db': |
|
| 288 | + $res = $this->addDb($req); |
|
| 289 | + break; |
|
| 290 | + case 'load_options': |
|
| 291 | + $CFG = $this->cfg2js($this->CFG); |
|
| 292 | + $res = "z('time_web').value = '{$CFG['time_web']}', z('time_cron').value = '{$CFG['time_cron']}', z('backup_path').value = '{$CFG['backup_path']}', |
|
| 293 | 293 | z('backup_url').value = '{$CFG['backup_url']}', z('globstat').checked = {$CFG['globstat']}, z('charsets').value = '{$CFG['charsets']}', z('only_create').value = '{$CFG['only_create']}', z('auth').value = '{$CFG['auth']}', z('conf_import').checked = {$CFG['confirm']} & 1, z('conf_file').checked = {$CFG['confirm']} & 2, z('conf_db').checked = {$CFG['confirm']} & 4;sxd.confirms = {$this->CFG['confirm']};"; |
| 294 | - break; |
|
| 295 | - case 'save_options': |
|
| 296 | - $res = $this->saveOptions($req); |
|
| 297 | - break; |
|
| 298 | - case 'delete_file': |
|
| 299 | - if(preg_match('/^[^\/]+?\.sql(\.(gz|bz2))?$/', $req['name'])) { |
|
| 300 | - $file = $this->CFG['backup_path'] . $req['name']; |
|
| 301 | - if(file_exists($file)) unlink($file); |
|
| 302 | - } |
|
| 303 | - $res = $this->getFileListExtended(); |
|
| 304 | - break; |
|
| 305 | - case 'delete_db': |
|
| 306 | - $res = $this->deleteDB($req['name']); |
|
| 307 | - break; |
|
| 308 | - case 'load_files_ext': |
|
| 309 | - $res .= $this->getFileListExtended(); |
|
| 310 | - break; |
|
| 311 | - case 'services': |
|
| 312 | - $this->runServices($req); |
|
| 313 | - break; |
|
| 314 | - case 'backup': |
|
| 315 | - $this->addBackupJob($req); |
|
| 316 | - break; |
|
| 317 | - case 'restore': |
|
| 318 | - $this->addRestoreJob($req); |
|
| 319 | - break; |
|
| 320 | - case 'resume': |
|
| 321 | - $this->resumeJob($req); |
|
| 322 | - break; |
|
| 323 | - case 'exit': |
|
| 324 | - setcookie('sxd', '', 0); |
|
| 325 | - $res = "top.location.href = " . sxd_esc($this->CFG['exitURL']) . ";"; |
|
| 326 | - break; |
|
| 327 | - } |
|
| 328 | - echo $res; |
|
| 329 | - } |
|
| 330 | - function loadJob($job){ |
|
| 331 | - $file = $this->CFG['backup_path'] . 'sj_' . (is_array($job) ? $job['job'] : $job) . '.job.php'; |
|
| 332 | - if(!file_exists($file)) return; |
|
| 333 | - include($file); |
|
| 334 | - $JOB['act'] = $JOB['type']; |
|
| 335 | - $JOB['type'] = 'run'; |
|
| 336 | - return $JOB; |
|
| 337 | - } |
|
| 338 | - function deleteDB($name){ |
|
| 339 | - $r = mysql_query('DROP DATABASE `' . sxd_esc($name, false) . '`') or sxd_my_error(); |
|
| 340 | - if($r){ |
|
| 341 | - echo "sxd.clearOpt('db');sxd.addOpt(" . sxd_php2json(array('db' => $this->getDBList())) . ");sxd.combos.services_db.select(0,'-');"; |
|
| 342 | - } |
|
| 294 | + break; |
|
| 295 | + case 'save_options': |
|
| 296 | + $res = $this->saveOptions($req); |
|
| 297 | + break; |
|
| 298 | + case 'delete_file': |
|
| 299 | + if(preg_match('/^[^\/]+?\.sql(\.(gz|bz2))?$/', $req['name'])) { |
|
| 300 | + $file = $this->CFG['backup_path'] . $req['name']; |
|
| 301 | + if(file_exists($file)) unlink($file); |
|
| 302 | + } |
|
| 303 | + $res = $this->getFileListExtended(); |
|
| 304 | + break; |
|
| 305 | + case 'delete_db': |
|
| 306 | + $res = $this->deleteDB($req['name']); |
|
| 307 | + break; |
|
| 308 | + case 'load_files_ext': |
|
| 309 | + $res .= $this->getFileListExtended(); |
|
| 310 | + break; |
|
| 311 | + case 'services': |
|
| 312 | + $this->runServices($req); |
|
| 313 | + break; |
|
| 314 | + case 'backup': |
|
| 315 | + $this->addBackupJob($req); |
|
| 316 | + break; |
|
| 317 | + case 'restore': |
|
| 318 | + $this->addRestoreJob($req); |
|
| 319 | + break; |
|
| 320 | + case 'resume': |
|
| 321 | + $this->resumeJob($req); |
|
| 322 | + break; |
|
| 323 | + case 'exit': |
|
| 324 | + setcookie('sxd', '', 0); |
|
| 325 | + $res = "top.location.href = " . sxd_esc($this->CFG['exitURL']) . ";"; |
|
| 326 | + break; |
|
| 327 | + } |
|
| 328 | + echo $res; |
|
| 329 | + } |
|
| 330 | + function loadJob($job){ |
|
| 331 | + $file = $this->CFG['backup_path'] . 'sj_' . (is_array($job) ? $job['job'] : $job) . '.job.php'; |
|
| 332 | + if(!file_exists($file)) return; |
|
| 333 | + include($file); |
|
| 334 | + $JOB['act'] = $JOB['type']; |
|
| 335 | + $JOB['type'] = 'run'; |
|
| 336 | + return $JOB; |
|
| 337 | + } |
|
| 338 | + function deleteDB($name){ |
|
| 339 | + $r = mysql_query('DROP DATABASE `' . sxd_esc($name, false) . '`') or sxd_my_error(); |
|
| 340 | + if($r){ |
|
| 341 | + echo "sxd.clearOpt('db');sxd.addOpt(" . sxd_php2json(array('db' => $this->getDBList())) . ");sxd.combos.services_db.select(0,'-');"; |
|
| 342 | + } |
|
| 343 | 343 | else |
| 344 | - echo "alert(" . sxd_esc(mysql_error()) . ");"; |
|
| 345 | - } |
|
| 346 | - function cfg2js($cfg){ |
|
| 347 | - foreach($cfg AS $k => $v){ |
|
| 348 | - $cfg[$k] = sxd_esc($v, false); |
|
| 349 | - } |
|
| 350 | - return $cfg; |
|
| 351 | - } |
|
| 352 | - function addDb($req){ |
|
| 344 | + echo "alert(" . sxd_esc(mysql_error()) . ");"; |
|
| 345 | + } |
|
| 346 | + function cfg2js($cfg){ |
|
| 347 | + foreach($cfg AS $k => $v){ |
|
| 348 | + $cfg[$k] = sxd_esc($v, false); |
|
| 349 | + } |
|
| 350 | + return $cfg; |
|
| 351 | + } |
|
| 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 | 354 | if($r) |
| 355 | - echo "sxd.addOpt(" . sxd_php2json(array('db' => array($req['name'] => "{$req['name']} (0)"))) . ");"; |
|
| 355 | + echo "sxd.addOpt(" . sxd_php2json(array('db' => array($req['name'] => "{$req['name']} (0)"))) . ");"; |
|
| 356 | 356 | else |
| 357 | - sxd_my_error(); |
|
| 358 | - } |
|
| 359 | - function saveConnect($req){ |
|
| 360 | - $this->CFG['my_host'] = $req['host']; |
|
| 361 | - $this->CFG['my_port'] = (int)$req['port']; |
|
| 362 | - $this->CFG['my_user'] = $req['user']; |
|
| 363 | - if(isset($req['pass'])) $this->CFG['my_pass'] = $req['pass']; |
|
| 364 | - $this->CFG['my_comp'] = $req['comp'] ? 1 : 0; |
|
| 365 | - $this->CFG['my_db'] = $req['db']; |
|
| 366 | - $this->saveCFG(); |
|
| 357 | + sxd_my_error(); |
|
| 358 | + } |
|
| 359 | + function saveConnect($req){ |
|
| 360 | + $this->CFG['my_host'] = $req['host']; |
|
| 361 | + $this->CFG['my_port'] = (int)$req['port']; |
|
| 362 | + $this->CFG['my_user'] = $req['user']; |
|
| 363 | + if(isset($req['pass'])) $this->CFG['my_pass'] = $req['pass']; |
|
| 364 | + $this->CFG['my_comp'] = $req['comp'] ? 1 : 0; |
|
| 365 | + $this->CFG['my_db'] = $req['db']; |
|
| 366 | + $this->saveCFG(); |
|
| 367 | 367 | $this->connect(); |
| 368 | 368 | if (V_MYSQL) { |
| 369 | - $tmp = array( |
|
| 370 | - 'db' => $this->getDBList(), |
|
| 371 | - 'charset' => $this->getCharsetList(), |
|
| 372 | - 'collation' => $this->getCollationList() |
|
| 373 | - ); |
|
| 374 | - echo "sxd.clearOpt('db');sxd.clearOpt('charset');sxd.clearOpt('collation');sxd.addOpt(" . sxd_php2json($tmp) . ");sxd.combos.backup_db.select(0,'-');sxd.combos.restore_db.select(0,'-');sxd.combos.services_db.select(0,'-');sxd.combos.backup_charset.select(0,'-');sxd.combos.services_db.select(0,'-');sxd.combos.db_charset.select(0,'-');"; |
|
| 375 | - } |
|
| 376 | - else { |
|
| 377 | - echo $this->error; |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - function saveOptions($req){ |
|
| 381 | - $this->CFG['time_web'] = $req['time_web']; |
|
| 382 | - $this->CFG['time_cron'] = $req['time_cron']; |
|
| 383 | - $this->CFG['backup_path'] = $req['backup_path']; |
|
| 384 | - $this->CFG['backup_url'] = $req['backup_url']; |
|
| 385 | - $this->CFG['globstat'] = $req['globstat'] ? 1 : 0; |
|
| 386 | - $this->CFG['charsets'] = $req['charsets']; |
|
| 387 | - $this->CFG['only_create'] = $req['only_create']; |
|
| 388 | - $this->CFG['auth'] = $req['auth']; |
|
| 389 | - $this->CFG['confirm'] = $req['confirm']; |
|
| 390 | - $this->saveCFG(); |
|
| 391 | - } |
|
| 392 | - function saveCFG(){ |
|
| 393 | - if (isset($_COOKIE['sxd'])) { |
|
| 394 | - $this->SES[$_COOKIE['sxd']] = array('cfg' => $this->CFG, 'time' => time(), 'lng' => $this->LNG['name']); |
|
| 395 | - $this->saveToFile('ses.php', "<?php\n\$SES = " . var_export($this->SES, true) . ";\n" . "?>"); |
|
| 396 | - } |
|
| 369 | + $tmp = array( |
|
| 370 | + 'db' => $this->getDBList(), |
|
| 371 | + 'charset' => $this->getCharsetList(), |
|
| 372 | + 'collation' => $this->getCollationList() |
|
| 373 | + ); |
|
| 374 | + echo "sxd.clearOpt('db');sxd.clearOpt('charset');sxd.clearOpt('collation');sxd.addOpt(" . sxd_php2json($tmp) . ");sxd.combos.backup_db.select(0,'-');sxd.combos.restore_db.select(0,'-');sxd.combos.services_db.select(0,'-');sxd.combos.backup_charset.select(0,'-');sxd.combos.services_db.select(0,'-');sxd.combos.db_charset.select(0,'-');"; |
|
| 375 | + } |
|
| 376 | + else { |
|
| 377 | + echo $this->error; |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + function saveOptions($req){ |
|
| 381 | + $this->CFG['time_web'] = $req['time_web']; |
|
| 382 | + $this->CFG['time_cron'] = $req['time_cron']; |
|
| 383 | + $this->CFG['backup_path'] = $req['backup_path']; |
|
| 384 | + $this->CFG['backup_url'] = $req['backup_url']; |
|
| 385 | + $this->CFG['globstat'] = $req['globstat'] ? 1 : 0; |
|
| 386 | + $this->CFG['charsets'] = $req['charsets']; |
|
| 387 | + $this->CFG['only_create'] = $req['only_create']; |
|
| 388 | + $this->CFG['auth'] = $req['auth']; |
|
| 389 | + $this->CFG['confirm'] = $req['confirm']; |
|
| 390 | + $this->saveCFG(); |
|
| 391 | + } |
|
| 392 | + function saveCFG(){ |
|
| 393 | + if (isset($_COOKIE['sxd'])) { |
|
| 394 | + $this->SES[$_COOKIE['sxd']] = array('cfg' => $this->CFG, 'time' => time(), 'lng' => $this->LNG['name']); |
|
| 395 | + $this->saveToFile('ses.php', "<?php\n\$SES = " . var_export($this->SES, true) . ";\n" . "?>"); |
|
| 396 | + } |
|
| 397 | 397 | if (!$this->virtualize){ |
| 398 | - $this->saveToFile('cfg.php', "<?php\n\$CFG = " . var_export($this->CFG, true) . ";\n" . "?>"); |
|
| 398 | + $this->saveToFile('cfg.php', "<?php\n\$CFG = " . var_export($this->CFG, true) . ";\n" . "?>"); |
|
| 399 | 399 | } |
| 400 | - } |
|
| 401 | - function runServices($job) { |
|
| 402 | - $serv = array('optimize' => 'OPTIMIZE', 'analyze' => 'ANALYZE', 'check' => 'CHECK', 'repair' => 'REPAIR'); |
|
| 403 | - $add = array('check' => array('', 'QUICK', 'FAST', 'CHANGED', 'MEDIUM', 'EXTENDED'), 'repair' => array('', 'QUICK', 'EXTENDED')); |
|
| 404 | - if(isset($serv[$job['type']])) { |
|
| 405 | - mysql_select_db($job['db']); |
|
| 406 | - $filter = $object = array(); |
|
| 407 | - $this->createFilters($job['obj'], $filter, $object); |
|
| 408 | - $r = mysql_query('SHOW TABLE STATUS') or sxd_my_error(); |
|
| 409 | - if (!$r) return; |
|
| 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']}`"; |
|
| 414 | - } |
|
| 415 | - $sql = $serv[$job['type']] . ' TABLE ' . implode(',', $tables); |
|
| 400 | + } |
|
| 401 | + function runServices($job) { |
|
| 402 | + $serv = array('optimize' => 'OPTIMIZE', 'analyze' => 'ANALYZE', 'check' => 'CHECK', 'repair' => 'REPAIR'); |
|
| 403 | + $add = array('check' => array('', 'QUICK', 'FAST', 'CHANGED', 'MEDIUM', 'EXTENDED'), 'repair' => array('', 'QUICK', 'EXTENDED')); |
|
| 404 | + if(isset($serv[$job['type']])) { |
|
| 405 | + mysql_select_db($job['db']); |
|
| 406 | + $filter = $object = array(); |
|
| 407 | + $this->createFilters($job['obj'], $filter, $object); |
|
| 408 | + $r = mysql_query('SHOW TABLE STATUS') or sxd_my_error(); |
|
| 409 | + if (!$r) return; |
|
| 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']}`"; |
|
| 414 | + } |
|
| 415 | + $sql = $serv[$job['type']] . ' TABLE ' . implode(',', $tables); |
|
| 416 | 416 | |
| 417 | - if ($job['type'] == 'check' || $job['type'] == 'repair') { |
|
| 418 | - $sql .= isset($add[$job['type']][$job[$job['type']]]) ? ' ' . $add[$job['type']][$job[$job['type']]] : ''; |
|
| 419 | - } |
|
| 417 | + if ($job['type'] == 'check' || $job['type'] == 'repair') { |
|
| 418 | + $sql .= isset($add[$job['type']][$job[$job['type']]]) ? ' ' . $add[$job['type']][$job[$job['type']]] : ''; |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - $r = mysql_query($sql) or sxd_my_error(); |
|
| 422 | - if (!$r) return; |
|
| 423 | - $res = array(); |
|
| 424 | - while($item = mysql_fetch_row($r)){ |
|
| 425 | - $res[] = $item; |
|
| 426 | - } |
|
| 427 | - echo 'sxd.result.add(' . sxd_php2json($res). ');'; |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - function createFilters(&$obj, &$filter, &$object){ |
|
| 431 | - $types = array('TA', 'TC', 'VI', 'PR', 'FU', 'TR', 'EV'); |
|
| 432 | - foreach($types AS $type){ |
|
| 433 | - $filter[$type] = array(); |
|
| 434 | - $object[$type] = array(); |
|
| 435 | - if(!empty($obj[$type])){ |
|
| 436 | - foreach($obj[$type] AS $v){ |
|
| 437 | - if(strpos($v, '*') !== false) { |
|
| 438 | - $filter[$type][] = str_replace('*', '.*?', $v); |
|
| 439 | - } |
|
| 440 | - else { |
|
| 441 | - $object[$type][$v] = true; |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - $filter[$type] = count($filter[$type]) > 0 ? '/^(' . implode('|', $filter[$type]) . ')$/i' : ''; |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - function closeConnect(){ |
|
| 449 | - //return; |
|
| 450 | - @ignore_user_abort(1); |
|
| 451 | - header("SXD: {$this->name}"); |
|
| 452 | - $size = ob_get_length(); |
|
| 421 | + $r = mysql_query($sql) or sxd_my_error(); |
|
| 422 | + if (!$r) return; |
|
| 423 | + $res = array(); |
|
| 424 | + while($item = mysql_fetch_row($r)){ |
|
| 425 | + $res[] = $item; |
|
| 426 | + } |
|
| 427 | + echo 'sxd.result.add(' . sxd_php2json($res). ');'; |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + function createFilters(&$obj, &$filter, &$object){ |
|
| 431 | + $types = array('TA', 'TC', 'VI', 'PR', 'FU', 'TR', 'EV'); |
|
| 432 | + foreach($types AS $type){ |
|
| 433 | + $filter[$type] = array(); |
|
| 434 | + $object[$type] = array(); |
|
| 435 | + if(!empty($obj[$type])){ |
|
| 436 | + foreach($obj[$type] AS $v){ |
|
| 437 | + if(strpos($v, '*') !== false) { |
|
| 438 | + $filter[$type][] = str_replace('*', '.*?', $v); |
|
| 439 | + } |
|
| 440 | + else { |
|
| 441 | + $object[$type][$v] = true; |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + $filter[$type] = count($filter[$type]) > 0 ? '/^(' . implode('|', $filter[$type]) . ')$/i' : ''; |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + function closeConnect(){ |
|
| 449 | + //return; |
|
| 450 | + @ignore_user_abort(1); |
|
| 451 | + header("SXD: {$this->name}"); |
|
| 452 | + $size = ob_get_length(); |
|
| 453 | 453 | // @fastcgi_finish_request(); |
| 454 | - header("Content-Length: {$size}"); |
|
| 455 | - header("Connection: close"); |
|
| 456 | - @ob_end_flush(); |
|
| 457 | - @flush(); |
|
| 458 | - } |
|
| 459 | - function resumeJob($job){ |
|
| 460 | - $this->closeConnect(); |
|
| 461 | - include($this->CFG['backup_path'] . $job['job'] . '.job.php'); |
|
| 462 | - $this->JOB = &$JOB; |
|
| 463 | - if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 464 | - $this->fh_rtl = fopen($this->JOB['file_rtl'], 'r+b'); |
|
| 465 | - $this->fh_log = fopen($this->JOB['file_log'], 'ab'); |
|
| 466 | - $t = fgets($this->fh_rtl); |
|
| 467 | - if(!empty($t)){ |
|
| 468 | - $this->rtl = explode("\t", $t); |
|
| 469 | - } |
|
| 470 | - else { |
|
| 471 | - $this->addLog($this->LNG['not_found_rtl']); |
|
| 472 | - exit; |
|
| 473 | - } |
|
| 474 | - // TODO: проверить удаление кодировки |
|
| 475 | - //$this->rtl[6] = ''; |
|
| 476 | - fseek($this->fh_rtl, 0); |
|
| 477 | - $this->rtl[1] = time(); |
|
| 478 | - $this->rtl[9] = 0; |
|
| 479 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 480 | - if ($this->JOB['act'] == 'backup') $this->runBackupJob(true); |
|
| 481 | - elseif ($this->JOB['act'] == 'restore') $this->runRestoreJob(true); |
|
| 482 | - } |
|
| 483 | - function addRestoreJob($job) { |
|
| 484 | - $this->closeConnect(); |
|
| 485 | - $this->JOB = $job; |
|
| 486 | - // Создаем список объектов и фильтр |
|
| 487 | - $filter = $object = array(); |
|
| 488 | - $this->createFilters($this->JOB['obj'], $filter, $object); |
|
| 454 | + header("Content-Length: {$size}"); |
|
| 455 | + header("Connection: close"); |
|
| 456 | + @ob_end_flush(); |
|
| 457 | + @flush(); |
|
| 458 | + } |
|
| 459 | + function resumeJob($job){ |
|
| 460 | + $this->closeConnect(); |
|
| 461 | + include($this->CFG['backup_path'] . $job['job'] . '.job.php'); |
|
| 462 | + $this->JOB = &$JOB; |
|
| 463 | + if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 464 | + $this->fh_rtl = fopen($this->JOB['file_rtl'], 'r+b'); |
|
| 465 | + $this->fh_log = fopen($this->JOB['file_log'], 'ab'); |
|
| 466 | + $t = fgets($this->fh_rtl); |
|
| 467 | + if(!empty($t)){ |
|
| 468 | + $this->rtl = explode("\t", $t); |
|
| 469 | + } |
|
| 470 | + else { |
|
| 471 | + $this->addLog($this->LNG['not_found_rtl']); |
|
| 472 | + exit; |
|
| 473 | + } |
|
| 474 | + // TODO: проверить удаление кодировки |
|
| 475 | + //$this->rtl[6] = ''; |
|
| 476 | + fseek($this->fh_rtl, 0); |
|
| 477 | + $this->rtl[1] = time(); |
|
| 478 | + $this->rtl[9] = 0; |
|
| 479 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 480 | + if ($this->JOB['act'] == 'backup') $this->runBackupJob(true); |
|
| 481 | + elseif ($this->JOB['act'] == 'restore') $this->runRestoreJob(true); |
|
| 482 | + } |
|
| 483 | + function addRestoreJob($job) { |
|
| 484 | + $this->closeConnect(); |
|
| 485 | + $this->JOB = $job; |
|
| 486 | + // Создаем список объектов и фильтр |
|
| 487 | + $filter = $object = array(); |
|
| 488 | + $this->createFilters($this->JOB['obj'], $filter, $object); |
|
| 489 | 489 | |
| 490 | - $objects = $this->getFileObjects('restore', $this->JOB['file'], false); |
|
| 491 | - $todo = array(); |
|
| 492 | - $rows = 0; |
|
| 493 | - $this->tab_rows = array(); |
|
| 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;} |
|
| 498 | - if (empty($list)) continue; |
|
| 490 | + $objects = $this->getFileObjects('restore', $this->JOB['file'], false); |
|
| 491 | + $todo = array(); |
|
| 492 | + $rows = 0; |
|
| 493 | + $this->tab_rows = array(); |
|
| 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;} |
|
| 498 | + if (empty($list)) continue; |
|
| 499 | 499 | |
| 500 | - foreach($list AS $item){ |
|
| 501 | - switch($t){ |
|
| 502 | - case 'TA': |
|
| 503 | - $type = ''; |
|
| 504 | - if(sxd_check($item[0], $object['TA'], $filter['TA'])){ |
|
| 505 | - $type = empty($item[1]) ? 'TC' : 'TA'; |
|
| 506 | - } |
|
| 507 | - elseif(sxd_check($item[0], $object['TC'], $filter['TC'])) { |
|
| 508 | - $type = 'TC'; |
|
| 509 | - } |
|
| 510 | - else continue; |
|
| 511 | - $todo['TA'][] = array($type, $item[0], $item[1], $item[2]); |
|
| 512 | - $rows += $type == 'TA' ? $item[1] : 0; |
|
| 513 | - break; |
|
| 514 | - default: |
|
| 515 | - if(sxd_check($item, $object[$t], $filter[$t])) { |
|
| 516 | - $todo[$t][] = array($t, $item); |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - $this->JOB['file_tmp'] = $this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file']; |
|
| 522 | - $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
|
| 523 | - $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
|
| 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']); |
|
| 500 | + foreach($list AS $item){ |
|
| 501 | + switch($t){ |
|
| 502 | + case 'TA': |
|
| 503 | + $type = ''; |
|
| 504 | + if(sxd_check($item[0], $object['TA'], $filter['TA'])){ |
|
| 505 | + $type = empty($item[1]) ? 'TC' : 'TA'; |
|
| 506 | + } |
|
| 507 | + elseif(sxd_check($item[0], $object['TC'], $filter['TC'])) { |
|
| 508 | + $type = 'TC'; |
|
| 509 | + } |
|
| 510 | + else continue; |
|
| 511 | + $todo['TA'][] = array($type, $item[0], $item[1], $item[2]); |
|
| 512 | + $rows += $type == 'TA' ? $item[1] : 0; |
|
| 513 | + break; |
|
| 514 | + default: |
|
| 515 | + if(sxd_check($item, $object[$t], $filter[$t])) { |
|
| 516 | + $todo[$t][] = array($t, $item); |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + $this->JOB['file_tmp'] = $this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file']; |
|
| 522 | + $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
|
| 523 | + $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
|
| 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']); |
|
| 526 | 526 | |
| 527 | - $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
|
| 528 | - // Для чужих дампов определяем разделители строк |
|
| 529 | - if(is_null($this->JOB['obj'])) { |
|
| 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"; |
|
| 533 | - else $this->JOB['eol'] = "\r"; |
|
| 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 | - fseek($this->fh_tmp, $bom); |
|
| 536 | - } |
|
| 537 | - $this->JOB['todo'] = $todo; |
|
| 538 | - $this->saveJob($this->JOB['job'], $this->JOB); |
|
| 539 | - $this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb'); |
|
| 540 | - $this->fh_log = fopen($this->JOB['file_log'], 'wb'); |
|
| 541 | - $this->rtl = array(time(), time(), $rows, 0, '', '', '', 0, 0, 0, 0, TIMER, "\n"); |
|
| 542 | - $this->addLog(sprintf($this->LNG['restore_begin'], $this->JOB['db'])); |
|
| 543 | - $this->addLog("{$this->LNG['combo_file']} {$this->JOB['file']}"); |
|
| 544 | - $this->runRestoreJob(); |
|
| 545 | - } |
|
| 546 | - function runRestoreJob($continue = false){ |
|
| 547 | - $ei = false; |
|
| 548 | - if($continue){ |
|
| 549 | - $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
|
| 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; |
|
| 553 | - } |
|
| 554 | - mysql_select_db($this->JOB['db']); |
|
| 555 | - if(is_null($this->JOB['obj'])) $this->runRestoreJobForeign($continue); |
|
| 556 | - //mysql_query("SET NAMES 'UTF8'"); |
|
| 557 | - $types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event'); |
|
| 558 | - $fcache = ''; |
|
| 559 | - $writes = 0; |
|
| 560 | - $old_charset = ''; |
|
| 561 | - $tab = ''; |
|
| 562 | - $seek = 0; |
|
| 563 | - $this->rtl[3] = ftell($this->fh_tmp); |
|
| 564 | - fseek($this->fh_rtl, 0); |
|
| 565 | - $this->rtl[1] = time(); |
|
| 566 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 567 | - $c = 0; |
|
| 568 | - switch($this->JOB['strategy']){ |
|
| 569 | - case 1: $tc = 'TRUNCATE'; $td = 'INSERT'; break; |
|
| 570 | - case 2: $tc = ''; $td = 'REPLACE'; break; |
|
| 571 | - case 3: $tc = ''; $td = 'INSERT IGNORE'; break; |
|
| 572 | - default: $tc = 'DROP TABLE IF EXISTS'; $td = 'INSERT'; |
|
| 573 | - } |
|
| 574 | - $tab_exists = array(); |
|
| 575 | - if($this->JOB['strategy'] > 0){ |
|
| 576 | - $r = mysql_query("SHOW TABLES") or sxd_my_error(); |
|
| 577 | - while($item = mysql_fetch_row($r)){ |
|
| 578 | - $tab_exists[$item[0]] = true; |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - $insert = $continue && $this->rtl[7] < $this->rtl[10] ? "{$td} INTO `{$this->rtl[5]}` VALUES " : ''; |
|
| 582 | - //$enable_index = array(); |
|
| 583 | - if(V_MYSQL > 40014) { |
|
| 584 | - mysql_query("SET UNIQUE_CHECKS=0"); |
|
| 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"); |
|
| 588 | - } |
|
| 589 | - $log_sql = false; |
|
| 590 | - $fields = ''; |
|
| 591 | - $time_old = time(); |
|
| 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'])){ |
|
| 596 | - $type = file_get_contents($this->JOB['file_stp']); |
|
| 597 | - $this->rtl[9] = !empty($type) ? $type : 2; |
|
| 598 | - fseek($this->fh_rtl, 0); |
|
| 599 | - $this->rtl[1] = time(); |
|
| 600 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 601 | - /*if($type == 1) { |
|
| 527 | + $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
|
| 528 | + // Для чужих дампов определяем разделители строк |
|
| 529 | + if(is_null($this->JOB['obj'])) { |
|
| 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"; |
|
| 533 | + else $this->JOB['eol'] = "\r"; |
|
| 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 | + fseek($this->fh_tmp, $bom); |
|
| 536 | + } |
|
| 537 | + $this->JOB['todo'] = $todo; |
|
| 538 | + $this->saveJob($this->JOB['job'], $this->JOB); |
|
| 539 | + $this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb'); |
|
| 540 | + $this->fh_log = fopen($this->JOB['file_log'], 'wb'); |
|
| 541 | + $this->rtl = array(time(), time(), $rows, 0, '', '', '', 0, 0, 0, 0, TIMER, "\n"); |
|
| 542 | + $this->addLog(sprintf($this->LNG['restore_begin'], $this->JOB['db'])); |
|
| 543 | + $this->addLog("{$this->LNG['combo_file']} {$this->JOB['file']}"); |
|
| 544 | + $this->runRestoreJob(); |
|
| 545 | + } |
|
| 546 | + function runRestoreJob($continue = false){ |
|
| 547 | + $ei = false; |
|
| 548 | + if($continue){ |
|
| 549 | + $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
|
| 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; |
|
| 553 | + } |
|
| 554 | + mysql_select_db($this->JOB['db']); |
|
| 555 | + if(is_null($this->JOB['obj'])) $this->runRestoreJobForeign($continue); |
|
| 556 | + //mysql_query("SET NAMES 'UTF8'"); |
|
| 557 | + $types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event'); |
|
| 558 | + $fcache = ''; |
|
| 559 | + $writes = 0; |
|
| 560 | + $old_charset = ''; |
|
| 561 | + $tab = ''; |
|
| 562 | + $seek = 0; |
|
| 563 | + $this->rtl[3] = ftell($this->fh_tmp); |
|
| 564 | + fseek($this->fh_rtl, 0); |
|
| 565 | + $this->rtl[1] = time(); |
|
| 566 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 567 | + $c = 0; |
|
| 568 | + switch($this->JOB['strategy']){ |
|
| 569 | + case 1: $tc = 'TRUNCATE'; $td = 'INSERT'; break; |
|
| 570 | + case 2: $tc = ''; $td = 'REPLACE'; break; |
|
| 571 | + case 3: $tc = ''; $td = 'INSERT IGNORE'; break; |
|
| 572 | + default: $tc = 'DROP TABLE IF EXISTS'; $td = 'INSERT'; |
|
| 573 | + } |
|
| 574 | + $tab_exists = array(); |
|
| 575 | + if($this->JOB['strategy'] > 0){ |
|
| 576 | + $r = mysql_query("SHOW TABLES") or sxd_my_error(); |
|
| 577 | + while($item = mysql_fetch_row($r)){ |
|
| 578 | + $tab_exists[$item[0]] = true; |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + $insert = $continue && $this->rtl[7] < $this->rtl[10] ? "{$td} INTO `{$this->rtl[5]}` VALUES " : ''; |
|
| 582 | + //$enable_index = array(); |
|
| 583 | + if(V_MYSQL > 40014) { |
|
| 584 | + mysql_query("SET UNIQUE_CHECKS=0"); |
|
| 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"); |
|
| 588 | + } |
|
| 589 | + $log_sql = false; |
|
| 590 | + $fields = ''; |
|
| 591 | + $time_old = time(); |
|
| 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'])){ |
|
| 596 | + $type = file_get_contents($this->JOB['file_stp']); |
|
| 597 | + $this->rtl[9] = !empty($type) ? $type : 2; |
|
| 598 | + fseek($this->fh_rtl, 0); |
|
| 599 | + $this->rtl[1] = time(); |
|
| 600 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 601 | + /*if($type == 1) { |
|
| 602 | 602 | |
| 603 | 603 | }*/ |
| 604 | - unset($this->rtl); |
|
| 605 | - exit; |
|
| 606 | - } |
|
| 607 | - $time_old = time(); |
|
| 608 | - if($time_old >= $exit_time){ |
|
| 609 | - $this->rtl[9] = 3; |
|
| 610 | - fseek($this->fh_rtl, 0); |
|
| 611 | - $this->rtl[1] = time(); |
|
| 612 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 613 | - unset($this->rtl); |
|
| 614 | - exit; |
|
| 615 | - } |
|
| 616 | - clearstatcache(); |
|
| 617 | - } |
|
| 618 | - switch($q{0}){ |
|
| 619 | - case '(': |
|
| 620 | - if($continue) { |
|
| 621 | - $this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3])); |
|
| 622 | - $continue = false; |
|
| 623 | - } |
|
| 624 | - $q = $insert . $q; |
|
| 625 | - $ex = 1; |
|
| 626 | - $c = 1; |
|
| 627 | - break; |
|
| 628 | - case 'I': |
|
| 629 | - if (preg_match('/^INSERT( INTO `(.+?)`) VALUES/', $q, $m)) { |
|
| 630 | - $insert = $td . $m[1] . $fields . " VALUES \n"; |
|
| 631 | - $tab = $m[2]; |
|
| 632 | - $this->rtl[7] = 0; |
|
| 633 | - $this->rtl[8] = 0; |
|
| 634 | - foreach($this->JOB['todo']['TA'] AS $t){ |
|
| 635 | - if($t[1] == $tab) { |
|
| 636 | - $this->rtl[8] = $t[2]; |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - if($this->JOB['strategy']) { |
|
| 640 | - $q = substr_replace($q, $insert, 0, strlen($m[0])); |
|
| 641 | - } |
|
| 642 | - //mysql_query("LOCK TABLES `{$tab}` WRITE") or die (mysql_error()); |
|
| 643 | - mysql_query("ALTER TABLE `{$tab}` DISABLE KEYS") or sxd_my_error(); |
|
| 644 | - //if(!empty($this->JOB['autoinc'])) mysql_query("ALTER TABLE `{$tab}` AUTO_INCREMENT = 1") or sxd_my_error(); |
|
| 645 | - $ex = 1; |
|
| 646 | - } |
|
| 647 | - break; |
|
| 648 | - case 'C': |
|
| 649 | - $ex = 1; |
|
| 650 | - if (preg_match('/^CREATE TABLE `/', $q)) { |
|
| 651 | - if($this->JOB['strategy'] != 0 && isset($tab_exists[$this->rtl[5]])) $ex = 0; |
|
| 652 | - else { |
|
| 653 | - $ex = 1; |
|
| 654 | - if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
|
| 655 | - $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
|
| 656 | - } |
|
| 657 | - if(!empty($this->JOB['autoinc'])) $q = preg_replace("/AUTO_INCREMENT=\d+/", "AUTO_INCREMENT=1", $q); |
|
| 658 | - } |
|
| 659 | - // Достаем имена полей таблицы |
|
| 660 | - $fields = $this->JOB['strategy'] > 0 && preg_match_all('/^\s+(`.+?`) /m', $q, $f, PREG_PATTERN_ORDER) ? '(' . implode(',', $f[1]) . ')' : ''; |
|
| 661 | - } |
|
| 662 | - break; |
|
| 663 | - case '#': // Команды для дампера |
|
| 664 | - if (preg_match("/\#\t(TC|TD|VI|PR|FU|TR|EV)`(.+?)`(([^_]+?)_.+?)?$/", $q, $m)) { |
|
| 665 | - //if(!empty($tab)) $enable_index[] = $tab; |
|
| 604 | + unset($this->rtl); |
|
| 605 | + exit; |
|
| 606 | + } |
|
| 607 | + $time_old = time(); |
|
| 608 | + if($time_old >= $exit_time){ |
|
| 609 | + $this->rtl[9] = 3; |
|
| 610 | + fseek($this->fh_rtl, 0); |
|
| 611 | + $this->rtl[1] = time(); |
|
| 612 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 613 | + unset($this->rtl); |
|
| 614 | + exit; |
|
| 615 | + } |
|
| 616 | + clearstatcache(); |
|
| 617 | + } |
|
| 618 | + switch($q{0}){ |
|
| 619 | + case '(': |
|
| 620 | + if($continue) { |
|
| 621 | + $this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3])); |
|
| 622 | + $continue = false; |
|
| 623 | + } |
|
| 624 | + $q = $insert . $q; |
|
| 625 | + $ex = 1; |
|
| 626 | + $c = 1; |
|
| 627 | + break; |
|
| 628 | + case 'I': |
|
| 629 | + if (preg_match('/^INSERT( INTO `(.+?)`) VALUES/', $q, $m)) { |
|
| 630 | + $insert = $td . $m[1] . $fields . " VALUES \n"; |
|
| 631 | + $tab = $m[2]; |
|
| 632 | + $this->rtl[7] = 0; |
|
| 633 | + $this->rtl[8] = 0; |
|
| 634 | + foreach($this->JOB['todo']['TA'] AS $t){ |
|
| 635 | + if($t[1] == $tab) { |
|
| 636 | + $this->rtl[8] = $t[2]; |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + if($this->JOB['strategy']) { |
|
| 640 | + $q = substr_replace($q, $insert, 0, strlen($m[0])); |
|
| 641 | + } |
|
| 642 | + //mysql_query("LOCK TABLES `{$tab}` WRITE") or die (mysql_error()); |
|
| 643 | + mysql_query("ALTER TABLE `{$tab}` DISABLE KEYS") or sxd_my_error(); |
|
| 644 | + //if(!empty($this->JOB['autoinc'])) mysql_query("ALTER TABLE `{$tab}` AUTO_INCREMENT = 1") or sxd_my_error(); |
|
| 645 | + $ex = 1; |
|
| 646 | + } |
|
| 647 | + break; |
|
| 648 | + case 'C': |
|
| 649 | + $ex = 1; |
|
| 650 | + if (preg_match('/^CREATE TABLE `/', $q)) { |
|
| 651 | + if($this->JOB['strategy'] != 0 && isset($tab_exists[$this->rtl[5]])) $ex = 0; |
|
| 652 | + else { |
|
| 653 | + $ex = 1; |
|
| 654 | + if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
|
| 655 | + $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
|
| 656 | + } |
|
| 657 | + if(!empty($this->JOB['autoinc'])) $q = preg_replace("/AUTO_INCREMENT=\d+/", "AUTO_INCREMENT=1", $q); |
|
| 658 | + } |
|
| 659 | + // Достаем имена полей таблицы |
|
| 660 | + $fields = $this->JOB['strategy'] > 0 && preg_match_all('/^\s+(`.+?`) /m', $q, $f, PREG_PATTERN_ORDER) ? '(' . implode(',', $f[1]) . ')' : ''; |
|
| 661 | + } |
|
| 662 | + break; |
|
| 663 | + case '#': // Команды для дампера |
|
| 664 | + if (preg_match("/\#\t(TC|TD|VI|PR|FU|TR|EV)`(.+?)`(([^_]+?)_.+?)?$/", $q, $m)) { |
|
| 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 | - $this->setNames('binary'); |
|
| 668 | - if($m[1] == 'TC') { |
|
| 669 | - $this->addLog(sprintf($this->LNG['restore_TC'], $m[2])); |
|
| 670 | - $insert = ''; |
|
| 671 | - $tab = ''; |
|
| 672 | - $this->rtl[4] = 'TD'; |
|
| 673 | - $this->rtl[5] = $m[2]; |
|
| 674 | - $ei = 0; |
|
| 675 | - if($tc && ($this->JOB['strategy'] == 0 || isset($tab_exists[$m[2]]))) { |
|
| 676 | - mysql_query("{$tc} `{$m[2]}`") or sxd_my_error(); |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - elseif($m[1] == 'TD'){ |
|
| 680 | - $ei = 1; |
|
| 681 | - } |
|
| 682 | - else { |
|
| 683 | - $this->rtl[4] = $m[1]; |
|
| 684 | - $this->rtl[5] = $m[2]; |
|
| 685 | - $this->rtl[7] = 0; |
|
| 686 | - $this->rtl[8] = 0; |
|
| 687 | - mysql_query("DROP {$types[$m[1]]} IF EXISTS `{$m[2]}`") or sxd_my_error(); |
|
| 688 | - $this->addLog(sprintf($this->LNG["restore_{$m[1]}"], $m[2])); |
|
| 689 | - $ei = 0; |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - $ex = 0; |
|
| 693 | - break; |
|
| 694 | - default: |
|
| 695 | - $insert = ''; |
|
| 696 | - $ex = 1; |
|
| 697 | - } |
|
| 698 | - if($ex) { |
|
| 699 | - $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 700 | - fseek($this->fh_rtl, 0); |
|
| 701 | - $this->rtl[1] = time(); |
|
| 702 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 703 | - if(mysql_query($q)) { |
|
| 704 | - if($insert) { |
|
| 705 | - $c = 1; |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - else { |
|
| 709 | - error_log(date('r') . "\n----------\n{$q}\n", 3, "backup/sql_error.log"); |
|
| 710 | - sxd_my_error(); |
|
| 711 | - } |
|
| 667 | + $this->setNames('binary'); |
|
| 668 | + if($m[1] == 'TC') { |
|
| 669 | + $this->addLog(sprintf($this->LNG['restore_TC'], $m[2])); |
|
| 670 | + $insert = ''; |
|
| 671 | + $tab = ''; |
|
| 672 | + $this->rtl[4] = 'TD'; |
|
| 673 | + $this->rtl[5] = $m[2]; |
|
| 674 | + $ei = 0; |
|
| 675 | + if($tc && ($this->JOB['strategy'] == 0 || isset($tab_exists[$m[2]]))) { |
|
| 676 | + mysql_query("{$tc} `{$m[2]}`") or sxd_my_error(); |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + elseif($m[1] == 'TD'){ |
|
| 680 | + $ei = 1; |
|
| 681 | + } |
|
| 682 | + else { |
|
| 683 | + $this->rtl[4] = $m[1]; |
|
| 684 | + $this->rtl[5] = $m[2]; |
|
| 685 | + $this->rtl[7] = 0; |
|
| 686 | + $this->rtl[8] = 0; |
|
| 687 | + mysql_query("DROP {$types[$m[1]]} IF EXISTS `{$m[2]}`") or sxd_my_error(); |
|
| 688 | + $this->addLog(sprintf($this->LNG["restore_{$m[1]}"], $m[2])); |
|
| 689 | + $ei = 0; |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + $ex = 0; |
|
| 693 | + break; |
|
| 694 | + default: |
|
| 695 | + $insert = ''; |
|
| 696 | + $ex = 1; |
|
| 697 | + } |
|
| 698 | + if($ex) { |
|
| 699 | + $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 700 | + fseek($this->fh_rtl, 0); |
|
| 701 | + $this->rtl[1] = time(); |
|
| 702 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 703 | + if(mysql_query($q)) { |
|
| 704 | + if($insert) { |
|
| 705 | + $c = 1; |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + else { |
|
| 709 | + error_log(date('r') . "\n----------\n{$q}\n", 3, "backup/sql_error.log"); |
|
| 710 | + sxd_my_error(); |
|
| 711 | + } |
|
| 712 | 712 | |
| 713 | - if($c){ |
|
| 714 | - $i = mysql_affected_rows(); |
|
| 715 | - $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 716 | - $this->rtl[7] += $i; |
|
| 717 | - $this->rtl[10] += $i; |
|
| 718 | - fseek($this->fh_rtl, 0); |
|
| 719 | - $this->rtl[1] = time(); |
|
| 720 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 721 | - $c = 1; |
|
| 722 | - } |
|
| 723 | - } |
|
| 713 | + if($c){ |
|
| 714 | + $i = mysql_affected_rows(); |
|
| 715 | + $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 716 | + $this->rtl[7] += $i; |
|
| 717 | + $this->rtl[10] += $i; |
|
| 718 | + fseek($this->fh_rtl, 0); |
|
| 719 | + $this->rtl[1] = time(); |
|
| 720 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 721 | + $c = 1; |
|
| 722 | + } |
|
| 723 | + } |
|
| 724 | 724 | |
| 725 | - } |
|
| 726 | - // Включаем ключи |
|
| 727 | - $this->addLog($this->LNG['restore_keys']); |
|
| 728 | - $this->rtl[4] = 'EK'; |
|
| 729 | - $this->rtl[5] = ''; |
|
| 730 | - $this->rtl[6] = ''; |
|
| 731 | - $this->rtl[7] = 0; |
|
| 732 | - $this->rtl[8] = 0; |
|
| 733 | - foreach($this->JOB['todo']['TA'] AS $tab){ |
|
| 734 | - if ($tab[0] == 'TC') continue; |
|
| 735 | - mysql_query("ALTER TABLE `{$tab[1]}` ENABLE KEYS") or sxd_my_error(); |
|
| 736 | - $this->rtl[1] = time(); |
|
| 737 | - $this->rtl[5] = $tab[1]; |
|
| 738 | - fseek($this->fh_rtl, 0); |
|
| 739 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 740 | - } |
|
| 741 | - $this->rtl[4] = 'EOJ'; |
|
| 742 | - $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4); |
|
| 725 | + } |
|
| 726 | + // Включаем ключи |
|
| 727 | + $this->addLog($this->LNG['restore_keys']); |
|
| 728 | + $this->rtl[4] = 'EK'; |
|
| 729 | + $this->rtl[5] = ''; |
|
| 730 | + $this->rtl[6] = ''; |
|
| 731 | + $this->rtl[7] = 0; |
|
| 732 | + $this->rtl[8] = 0; |
|
| 733 | + foreach($this->JOB['todo']['TA'] AS $tab){ |
|
| 734 | + if ($tab[0] == 'TC') continue; |
|
| 735 | + mysql_query("ALTER TABLE `{$tab[1]}` ENABLE KEYS") or sxd_my_error(); |
|
| 736 | + $this->rtl[1] = time(); |
|
| 737 | + $this->rtl[5] = $tab[1]; |
|
| 738 | + fseek($this->fh_rtl, 0); |
|
| 739 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 740 | + } |
|
| 741 | + $this->rtl[4] = 'EOJ'; |
|
| 742 | + $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4); |
|
| 743 | 743 | |
| 744 | - fseek($this->fh_rtl, 0); |
|
| 745 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 746 | - $this->addLog(sprintf($this->LNG['restore_end'], $this->JOB['db'])); |
|
| 747 | - fclose($this->fh_log); |
|
| 748 | - fclose($this->fh_rtl); |
|
| 749 | - } |
|
| 750 | - function runRestoreJobForeign($continue = false){ |
|
| 751 | - $ei = false; |
|
| 744 | + fseek($this->fh_rtl, 0); |
|
| 745 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 746 | + $this->addLog(sprintf($this->LNG['restore_end'], $this->JOB['db'])); |
|
| 747 | + fclose($this->fh_log); |
|
| 748 | + fclose($this->fh_rtl); |
|
| 749 | + } |
|
| 750 | + function runRestoreJobForeign($continue = false){ |
|
| 751 | + $ei = false; |
|
| 752 | 752 | |
| 753 | - $fcache = ''; |
|
| 754 | - $writes = 0; |
|
| 755 | - $old_charset = ''; |
|
| 756 | - $tab = ''; |
|
| 757 | - $seek = 0; |
|
| 758 | - $this->rtl[3] = ftell($this->fh_tmp); |
|
| 759 | - fseek($this->fh_rtl, 0); |
|
| 760 | - $this->rtl[1] = time(); |
|
| 761 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 762 | - $c = 0; |
|
| 753 | + $fcache = ''; |
|
| 754 | + $writes = 0; |
|
| 755 | + $old_charset = ''; |
|
| 756 | + $tab = ''; |
|
| 757 | + $seek = 0; |
|
| 758 | + $this->rtl[3] = ftell($this->fh_tmp); |
|
| 759 | + fseek($this->fh_rtl, 0); |
|
| 760 | + $this->rtl[1] = time(); |
|
| 761 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 762 | + $c = 0; |
|
| 763 | 763 | |
| 764 | - $log_sql = false; |
|
| 765 | - $fields = ''; |
|
| 766 | - $insert = ''; |
|
| 767 | - $last_tab = ''; |
|
| 768 | - $time_old = time(); |
|
| 769 | - $exit_time = $time_old + $this->CFG['time_web'] - 1; |
|
| 770 | - $delimiter = ";"; |
|
| 771 | - while($q = sxd_read_sql($this->fh_tmp, $seek, $ei, $delimiter, $this->JOB['eol'])){ |
|
| 772 | - $q = ltrim($q); |
|
| 773 | - if(empty($q)) break; |
|
| 774 | - if($time_old < time()) { |
|
| 775 | - if(file_exists($this->JOB['file_stp'])){ |
|
| 776 | - $type = file_get_contents($this->JOB['file_stp']); |
|
| 777 | - $this->rtl[9] = !empty($type) ? $type : 2; |
|
| 778 | - fseek($this->fh_rtl, 0); |
|
| 779 | - $this->rtl[1] = time(); |
|
| 780 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 781 | - /*if($type == 1) { |
|
| 764 | + $log_sql = false; |
|
| 765 | + $fields = ''; |
|
| 766 | + $insert = ''; |
|
| 767 | + $last_tab = ''; |
|
| 768 | + $time_old = time(); |
|
| 769 | + $exit_time = $time_old + $this->CFG['time_web'] - 1; |
|
| 770 | + $delimiter = ";"; |
|
| 771 | + while($q = sxd_read_sql($this->fh_tmp, $seek, $ei, $delimiter, $this->JOB['eol'])){ |
|
| 772 | + $q = ltrim($q); |
|
| 773 | + if(empty($q)) break; |
|
| 774 | + if($time_old < time()) { |
|
| 775 | + if(file_exists($this->JOB['file_stp'])){ |
|
| 776 | + $type = file_get_contents($this->JOB['file_stp']); |
|
| 777 | + $this->rtl[9] = !empty($type) ? $type : 2; |
|
| 778 | + fseek($this->fh_rtl, 0); |
|
| 779 | + $this->rtl[1] = time(); |
|
| 780 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 781 | + /*if($type == 1) { |
|
| 782 | 782 | |
| 783 | 783 | }*/ |
| 784 | - unset($this->rtl); |
|
| 785 | - exit; |
|
| 786 | - } |
|
| 787 | - $time_old = time(); |
|
| 788 | - if($time_old >= $exit_time){ |
|
| 789 | - $this->rtl[9] = 3; |
|
| 790 | - fseek($this->fh_rtl, 0); |
|
| 791 | - $this->rtl[1] = time(); |
|
| 792 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 793 | - unset($this->rtl); |
|
| 794 | - exit; |
|
| 795 | - } |
|
| 796 | - clearstatcache(); |
|
| 797 | - } |
|
| 798 | - do { |
|
| 799 | - $repeat = false; |
|
| 800 | - //error_log("-----------------\n[{$q}]\n", 3, "q.log"); |
|
| 801 | - //if(empty($q)) {continue 2;} |
|
| 802 | - switch($q{0}){ |
|
| 803 | - case '(': |
|
| 804 | - if($continue) { |
|
| 805 | - $this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3])); |
|
| 806 | - $continue = false; |
|
| 807 | - } |
|
| 808 | - $q = $insert . $q; |
|
| 809 | - $ex = 1; |
|
| 810 | - $c = 1; |
|
| 811 | - break; |
|
| 812 | - case 'I': |
|
| 784 | + unset($this->rtl); |
|
| 785 | + exit; |
|
| 786 | + } |
|
| 787 | + $time_old = time(); |
|
| 788 | + if($time_old >= $exit_time){ |
|
| 789 | + $this->rtl[9] = 3; |
|
| 790 | + fseek($this->fh_rtl, 0); |
|
| 791 | + $this->rtl[1] = time(); |
|
| 792 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 793 | + unset($this->rtl); |
|
| 794 | + exit; |
|
| 795 | + } |
|
| 796 | + clearstatcache(); |
|
| 797 | + } |
|
| 798 | + do { |
|
| 799 | + $repeat = false; |
|
| 800 | + //error_log("-----------------\n[{$q}]\n", 3, "q.log"); |
|
| 801 | + //if(empty($q)) {continue 2;} |
|
| 802 | + switch($q{0}){ |
|
| 803 | + case '(': |
|
| 804 | + if($continue) { |
|
| 805 | + $this->addLog(sprintf("{$this->LNG['restore_TC']} {$this->LNG['continue_from']}", $this->rtl[5], $this->rtl[3])); |
|
| 806 | + $continue = false; |
|
| 807 | + } |
|
| 808 | + $q = $insert . $q; |
|
| 809 | + $ex = 1; |
|
| 810 | + $c = 1; |
|
| 811 | + break; |
|
| 812 | + case 'I': |
|
| 813 | 813 | |
| 814 | - if (preg_match('/^(INSERT( INTO `?(.+?)`?).+?\sVALUES)/s', $q, $m)) { |
|
| 815 | - $insert = trim($m[1]) . ' '; |
|
| 816 | - $tab = $m[3]; |
|
| 817 | - $this->rtl[7] = 0; |
|
| 818 | - $this->rtl[8] = 0; |
|
| 819 | - $ex = 1; |
|
| 820 | - } |
|
| 821 | - break; |
|
| 822 | - case 'C': |
|
| 823 | - $ex = 1; |
|
| 824 | - $ei = 1; |
|
| 825 | - if (preg_match('/^CREATE TABLE.+?`(.+?)`/', $q, $m)) { |
|
| 826 | - $ex = 1; |
|
| 827 | - $tab = $m[1]; |
|
| 828 | - $this->addLog(sprintf($this->LNG['restore_TC'], $tab)); |
|
| 829 | - //mysql_query("DROP TABLE IF EXISTS `{$tab}`"); |
|
| 830 | - if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
|
| 831 | - $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
|
| 832 | - } |
|
| 833 | - elseif(empty($this->JOB['charset'])){ |
|
| 834 | - if(preg_match("/(CHARACTER SET|CHARSET)[=\s]+(\w+)/i", $q, $charset)){ |
|
| 835 | - $this->setNames($charset[2]); |
|
| 836 | - } |
|
| 837 | - } |
|
| 838 | - } |
|
| 839 | - break; |
|
| 840 | - case '-' && $q{1} == '-': |
|
| 841 | - case '#': |
|
| 842 | - $repeat = true; |
|
| 843 | - $q = ltrim(substr($q, strpos($q, $this->JOB['eol']))); |
|
| 844 | - $ex = 0; |
|
| 845 | - break; |
|
| 846 | - case '/': |
|
| 847 | - case 'S': |
|
| 848 | - if (preg_match('/SET NAMES (\w+)/', $q, $m)) { |
|
| 849 | - $this->JOB['charset'] = $m[1]; |
|
| 850 | - $this->setNames($this->JOB['charset']); |
|
| 851 | - $ex = 0; |
|
| 852 | - } |
|
| 853 | - else $ex = 1; |
|
| 854 | - break; |
|
| 855 | - default: |
|
| 856 | - $insert = ''; |
|
| 857 | - $ex = 1; |
|
| 858 | - $ei = 0; |
|
| 859 | - } |
|
| 860 | - } while ($repeat); |
|
| 861 | - if($ex) { |
|
| 862 | - $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 863 | - fseek($this->fh_rtl, 0); |
|
| 864 | - $this->rtl[1] = time(); |
|
| 865 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 866 | - error_log("-----------------\n{$q}\n", 3, "sql.log"); |
|
| 867 | - if(mysql_query($q)) { |
|
| 868 | - if($insert) { |
|
| 869 | - $c = 1; |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - else { |
|
| 873 | - error_log("-----------------\n{$q}\n", 3, "error.log"); |
|
| 874 | - sxd_my_error(); |
|
| 875 | - } |
|
| 814 | + if (preg_match('/^(INSERT( INTO `?(.+?)`?).+?\sVALUES)/s', $q, $m)) { |
|
| 815 | + $insert = trim($m[1]) . ' '; |
|
| 816 | + $tab = $m[3]; |
|
| 817 | + $this->rtl[7] = 0; |
|
| 818 | + $this->rtl[8] = 0; |
|
| 819 | + $ex = 1; |
|
| 820 | + } |
|
| 821 | + break; |
|
| 822 | + case 'C': |
|
| 823 | + $ex = 1; |
|
| 824 | + $ei = 1; |
|
| 825 | + if (preg_match('/^CREATE TABLE.+?`(.+?)`/', $q, $m)) { |
|
| 826 | + $ex = 1; |
|
| 827 | + $tab = $m[1]; |
|
| 828 | + $this->addLog(sprintf($this->LNG['restore_TC'], $tab)); |
|
| 829 | + //mysql_query("DROP TABLE IF EXISTS `{$tab}`"); |
|
| 830 | + if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
|
| 831 | + $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
|
| 832 | + } |
|
| 833 | + elseif(empty($this->JOB['charset'])){ |
|
| 834 | + if(preg_match("/(CHARACTER SET|CHARSET)[=\s]+(\w+)/i", $q, $charset)){ |
|
| 835 | + $this->setNames($charset[2]); |
|
| 836 | + } |
|
| 837 | + } |
|
| 838 | + } |
|
| 839 | + break; |
|
| 840 | + case '-' && $q{1} == '-': |
|
| 841 | + case '#': |
|
| 842 | + $repeat = true; |
|
| 843 | + $q = ltrim(substr($q, strpos($q, $this->JOB['eol']))); |
|
| 844 | + $ex = 0; |
|
| 845 | + break; |
|
| 846 | + case '/': |
|
| 847 | + case 'S': |
|
| 848 | + if (preg_match('/SET NAMES (\w+)/', $q, $m)) { |
|
| 849 | + $this->JOB['charset'] = $m[1]; |
|
| 850 | + $this->setNames($this->JOB['charset']); |
|
| 851 | + $ex = 0; |
|
| 852 | + } |
|
| 853 | + else $ex = 1; |
|
| 854 | + break; |
|
| 855 | + default: |
|
| 856 | + $insert = ''; |
|
| 857 | + $ex = 1; |
|
| 858 | + $ei = 0; |
|
| 859 | + } |
|
| 860 | + } while ($repeat); |
|
| 861 | + if($ex) { |
|
| 862 | + $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 863 | + fseek($this->fh_rtl, 0); |
|
| 864 | + $this->rtl[1] = time(); |
|
| 865 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 866 | + error_log("-----------------\n{$q}\n", 3, "sql.log"); |
|
| 867 | + if(mysql_query($q)) { |
|
| 868 | + if($insert) { |
|
| 869 | + $c = 1; |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + else { |
|
| 873 | + error_log("-----------------\n{$q}\n", 3, "error.log"); |
|
| 874 | + sxd_my_error(); |
|
| 875 | + } |
|
| 876 | 876 | |
| 877 | - if($c){ |
|
| 878 | - $i = mysql_affected_rows(); |
|
| 879 | - $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 880 | - $this->rtl[7] += $i; |
|
| 881 | - $this->rtl[10] += $i; |
|
| 882 | - fseek($this->fh_rtl, 0); |
|
| 883 | - $this->rtl[1] = time(); |
|
| 884 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 885 | - $c = 1; |
|
| 886 | - } |
|
| 887 | - } |
|
| 877 | + if($c){ |
|
| 878 | + $i = mysql_affected_rows(); |
|
| 879 | + $this->rtl[3] = ftell($this->fh_tmp) - $seek; |
|
| 880 | + $this->rtl[7] += $i; |
|
| 881 | + $this->rtl[10] += $i; |
|
| 882 | + fseek($this->fh_rtl, 0); |
|
| 883 | + $this->rtl[1] = time(); |
|
| 884 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 885 | + $c = 1; |
|
| 886 | + } |
|
| 887 | + } |
|
| 888 | 888 | |
| 889 | - } |
|
| 889 | + } |
|
| 890 | 890 | |
| 891 | - $this->rtl[4] = 'EOJ'; |
|
| 892 | - $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4); |
|
| 893 | - $this->rtl[7] = 0; |
|
| 894 | - $this->rtl[8] = 0; |
|
| 891 | + $this->rtl[4] = 'EOJ'; |
|
| 892 | + $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4); |
|
| 893 | + $this->rtl[7] = 0; |
|
| 894 | + $this->rtl[8] = 0; |
|
| 895 | 895 | |
| 896 | - fseek($this->fh_rtl, 0); |
|
| 897 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 898 | - $this->addLog(sprintf($this->LNG['restore_end'], $this->JOB['db'])); |
|
| 899 | - fclose($this->fh_log); |
|
| 900 | - fclose($this->fh_rtl); |
|
| 901 | - } |
|
| 902 | - function addBackupJob($job) { |
|
| 903 | - $this->closeConnect(); |
|
| 904 | - // Создаем новое задание |
|
| 905 | - $this->JOB = $job; |
|
| 906 | - mysql_select_db($this->JOB['db']); |
|
| 907 | - // Создаем список объектов и фильтр |
|
| 908 | - $filter = $object = array(); |
|
| 909 | - $this->createFilters($this->JOB['obj'], $filter, $object); |
|
| 910 | - $queries = array( |
|
| 911 | - array('TABLE STATUS', 'Name', 'TA') |
|
| 912 | - ); |
|
| 913 | - if (V_MYSQL > 50014) { |
|
| 914 | - $queries[] = array("PROCEDURE STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'PR'); |
|
| 915 | - $queries[] = array("FUNCTION STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'FU'); |
|
| 916 | - $queries[] = array('TRIGGERS', 'Trigger', 'TR'); |
|
| 917 | - if(V_MYSQL > 50100) $queries[] = array('EVENTS', 'Name', 'EV'); |
|
| 918 | - } |
|
| 919 | - $todo = $header = array(); |
|
| 920 | - $tabs = $rows = 0; |
|
| 921 | - $only_create = explode(' ', $this->CFG['only_create']); |
|
| 922 | - foreach($queries AS $query){ |
|
| 923 | - $t = $query[2]; |
|
| 924 | - if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
|
| 925 | - elseif(empty($object[$t]) && empty($filter[$t])) continue; |
|
| 926 | - $r = mysql_query('SHOW ' . $query[0]) or sxd_my_error(); |
|
| 927 | - if (!$r) continue; |
|
| 928 | - $todo[$t] = array(); |
|
| 929 | - $header[$t] = array(); |
|
| 896 | + fseek($this->fh_rtl, 0); |
|
| 897 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 898 | + $this->addLog(sprintf($this->LNG['restore_end'], $this->JOB['db'])); |
|
| 899 | + fclose($this->fh_log); |
|
| 900 | + fclose($this->fh_rtl); |
|
| 901 | + } |
|
| 902 | + function addBackupJob($job) { |
|
| 903 | + $this->closeConnect(); |
|
| 904 | + // Создаем новое задание |
|
| 905 | + $this->JOB = $job; |
|
| 906 | + mysql_select_db($this->JOB['db']); |
|
| 907 | + // Создаем список объектов и фильтр |
|
| 908 | + $filter = $object = array(); |
|
| 909 | + $this->createFilters($this->JOB['obj'], $filter, $object); |
|
| 910 | + $queries = array( |
|
| 911 | + array('TABLE STATUS', 'Name', 'TA') |
|
| 912 | + ); |
|
| 913 | + if (V_MYSQL > 50014) { |
|
| 914 | + $queries[] = array("PROCEDURE STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'PR'); |
|
| 915 | + $queries[] = array("FUNCTION STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'FU'); |
|
| 916 | + $queries[] = array('TRIGGERS', 'Trigger', 'TR'); |
|
| 917 | + if(V_MYSQL > 50100) $queries[] = array('EVENTS', 'Name', 'EV'); |
|
| 918 | + } |
|
| 919 | + $todo = $header = array(); |
|
| 920 | + $tabs = $rows = 0; |
|
| 921 | + $only_create = explode(' ', $this->CFG['only_create']); |
|
| 922 | + foreach($queries AS $query){ |
|
| 923 | + $t = $query[2]; |
|
| 924 | + if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
|
| 925 | + elseif(empty($object[$t]) && empty($filter[$t])) continue; |
|
| 926 | + $r = mysql_query('SHOW ' . $query[0]) or sxd_my_error(); |
|
| 927 | + if (!$r) continue; |
|
| 928 | + $todo[$t] = array(); |
|
| 929 | + $header[$t] = array(); |
|
| 930 | 930 | |
| 931 | - while($item = mysql_fetch_assoc($r)){ |
|
| 932 | - $n = $item[$query[1]]; |
|
| 933 | - switch($t){ |
|
| 934 | - case 'TA': |
|
| 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'])){ |
|
| 938 | - $todo['VI'] = array(); |
|
| 939 | - $header['VI']= array(); |
|
| 940 | - } |
|
| 941 | - continue; |
|
| 942 | - } |
|
| 943 | - elseif(sxd_check($n, $object['TA'], $filter['TA'])){ |
|
| 944 | - $engine = V_MYSQL > 40101 ? $item['Engine'] : $item['Type']; |
|
| 945 | - $t = in_array($engine, $only_create) ? 'TC' : 'TA'; |
|
| 946 | - } |
|
| 947 | - elseif(sxd_check($n, $object['TC'], $filter['TC'])) { |
|
| 948 | - $t = 'TC'; |
|
| 949 | - $item['Rows'] = $item['Data_length'] = ''; |
|
| 950 | - } |
|
| 951 | - else continue; |
|
| 952 | - $todo['TA'][] = array($t, $n, !empty($item['Collation']) ? $item['Collation'] : '', $item['Auto_increment'], $item['Rows'], $item['Data_length']); |
|
| 953 | - $header['TA'][] = "{$n}`{$item['Rows']}`{$item['Data_length']}"; |
|
| 954 | - $tabs++; |
|
| 955 | - $rows += $item['Rows']; |
|
| 956 | - break; |
|
| 957 | - default: |
|
| 958 | - if(sxd_check($n, $object[$t], $filter[$t])) { |
|
| 959 | - $todo[$t][] = array($t, $n, !empty($item['collation_connection']) ? $item['collation_connection'] : ''); |
|
| 960 | - $header[$t][] = $n; |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - } |
|
| 931 | + while($item = mysql_fetch_assoc($r)){ |
|
| 932 | + $n = $item[$query[1]]; |
|
| 933 | + switch($t){ |
|
| 934 | + case 'TA': |
|
| 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'])){ |
|
| 938 | + $todo['VI'] = array(); |
|
| 939 | + $header['VI']= array(); |
|
| 940 | + } |
|
| 941 | + continue; |
|
| 942 | + } |
|
| 943 | + elseif(sxd_check($n, $object['TA'], $filter['TA'])){ |
|
| 944 | + $engine = V_MYSQL > 40101 ? $item['Engine'] : $item['Type']; |
|
| 945 | + $t = in_array($engine, $only_create) ? 'TC' : 'TA'; |
|
| 946 | + } |
|
| 947 | + elseif(sxd_check($n, $object['TC'], $filter['TC'])) { |
|
| 948 | + $t = 'TC'; |
|
| 949 | + $item['Rows'] = $item['Data_length'] = ''; |
|
| 950 | + } |
|
| 951 | + else continue; |
|
| 952 | + $todo['TA'][] = array($t, $n, !empty($item['Collation']) ? $item['Collation'] : '', $item['Auto_increment'], $item['Rows'], $item['Data_length']); |
|
| 953 | + $header['TA'][] = "{$n}`{$item['Rows']}`{$item['Data_length']}"; |
|
| 954 | + $tabs++; |
|
| 955 | + $rows += $item['Rows']; |
|
| 956 | + break; |
|
| 957 | + default: |
|
| 958 | + if(sxd_check($n, $object[$t], $filter[$t])) { |
|
| 959 | + $todo[$t][] = array($t, $n, !empty($item['collation_connection']) ? $item['collation_connection'] : ''); |
|
| 960 | + $header[$t][] = $n; |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + } |
|
| 964 | 964 | |
| 965 | - } |
|
| 966 | - if (V_MYSQL > 50014 && (!empty($object['VI']) || !empty($filter['VI']))) { |
|
| 967 | - // Бэкап обзоров, нужно отсортировать зависимые |
|
| 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 | - $views = $dumped = $views_collation = array(); |
|
| 970 | - $re = "/`{$this->JOB['db']}`.`(.+?)`/"; |
|
| 971 | - while($item = mysql_fetch_assoc($r)){ |
|
| 972 | - preg_match_all($re, preg_replace("/^select.+? from/i", '', $item['view_definition']), $m); |
|
| 973 | - $used = $m[1]; |
|
| 974 | - $views_collation[$item['table_name']] = !empty($item['collation_connection']) ? $item['collation_connection'] : ''; |
|
| 975 | - $views[$item['table_name']] = $used; |
|
| 976 | - } |
|
| 965 | + } |
|
| 966 | + if (V_MYSQL > 50014 && (!empty($object['VI']) || !empty($filter['VI']))) { |
|
| 967 | + // Бэкап обзоров, нужно отсортировать зависимые |
|
| 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 | + $views = $dumped = $views_collation = array(); |
|
| 970 | + $re = "/`{$this->JOB['db']}`.`(.+?)`/"; |
|
| 971 | + while($item = mysql_fetch_assoc($r)){ |
|
| 972 | + preg_match_all($re, preg_replace("/^select.+? from/i", '', $item['view_definition']), $m); |
|
| 973 | + $used = $m[1]; |
|
| 974 | + $views_collation[$item['table_name']] = !empty($item['collation_connection']) ? $item['collation_connection'] : ''; |
|
| 975 | + $views[$item['table_name']] = $used; |
|
| 976 | + } |
|
| 977 | 977 | |
| 978 | - while (count($views) > 0) { |
|
| 979 | - foreach($views AS $n => $view) { |
|
| 980 | - $can_dumped = true; |
|
| 981 | - foreach($view AS $k) { |
|
| 982 | - if (isset($views[$k]) && !isset($dumped[$k])) $can_dumped = false; |
|
| 983 | - } |
|
| 984 | - if ($can_dumped) { |
|
| 985 | - if(sxd_check($n, $object['VI'], $filter['VI'])){ |
|
| 986 | - $todo['VI'][] = array('VI', $n, $views_collation[$n]); |
|
| 987 | - $header['VI'][] = $n; |
|
| 988 | - } |
|
| 989 | - $dumped[$n] = 1; |
|
| 990 | - unset($views[$n]); |
|
| 991 | - } |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - unset($dumped); |
|
| 995 | - unset($views); |
|
| 996 | - unset($views_collation); |
|
| 997 | - } |
|
| 998 | - $this->JOB['file_tmp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.tmp'; |
|
| 999 | - $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
|
| 1000 | - $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
|
| 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']); |
|
| 1003 | - $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'w'); |
|
| 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 | - $this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file']; |
|
| 1006 | - $this->JOB['todo'] = $todo; |
|
| 1007 | - $this->saveJob($this->JOB['job'], $this->JOB); |
|
| 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){ |
|
| 1010 | - if (!empty($o)) $fcache .= "#{$t} " . implode('|', $o) . "\n"; |
|
| 1011 | - } |
|
| 1012 | - $this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb'); |
|
| 1013 | - $this->fh_log = fopen($this->JOB['file_log'], 'wb'); |
|
| 1014 | - $this->rtl = array(time(), time(), $rows, 0, '', '', '', 0, 0, 0, 0, TIMER, "\n"); |
|
| 1015 | - $fcache .= "#EOH\n\n"; |
|
| 1016 | - $this->write($fcache); |
|
| 1017 | - $this->addLog(sprintf($this->LNG['backup_begin'], $this->JOB['db'])); |
|
| 1018 | - $this->runBackupJob(); |
|
| 1019 | - } |
|
| 1020 | - function runBackupJob($continue = false){ |
|
| 1021 | - if($continue){ |
|
| 1022 | - $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'a'); |
|
| 1023 | - mysql_select_db($this->JOB['db']); |
|
| 1024 | - } |
|
| 1025 | - mysql_query("SET SQL_QUOTE_SHOW_CREATE = 1"); |
|
| 1026 | - $types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event'); |
|
| 1027 | - $fcache = ''; |
|
| 1028 | - $writes = 0; |
|
| 978 | + while (count($views) > 0) { |
|
| 979 | + foreach($views AS $n => $view) { |
|
| 980 | + $can_dumped = true; |
|
| 981 | + foreach($view AS $k) { |
|
| 982 | + if (isset($views[$k]) && !isset($dumped[$k])) $can_dumped = false; |
|
| 983 | + } |
|
| 984 | + if ($can_dumped) { |
|
| 985 | + if(sxd_check($n, $object['VI'], $filter['VI'])){ |
|
| 986 | + $todo['VI'][] = array('VI', $n, $views_collation[$n]); |
|
| 987 | + $header['VI'][] = $n; |
|
| 988 | + } |
|
| 989 | + $dumped[$n] = 1; |
|
| 990 | + unset($views[$n]); |
|
| 991 | + } |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + unset($dumped); |
|
| 995 | + unset($views); |
|
| 996 | + unset($views_collation); |
|
| 997 | + } |
|
| 998 | + $this->JOB['file_tmp'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.tmp'; |
|
| 999 | + $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
|
| 1000 | + $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
|
| 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']); |
|
| 1003 | + $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'w'); |
|
| 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 | + $this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file']; |
|
| 1006 | + $this->JOB['todo'] = $todo; |
|
| 1007 | + $this->saveJob($this->JOB['job'], $this->JOB); |
|
| 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){ |
|
| 1010 | + if (!empty($o)) $fcache .= "#{$t} " . implode('|', $o) . "\n"; |
|
| 1011 | + } |
|
| 1012 | + $this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb'); |
|
| 1013 | + $this->fh_log = fopen($this->JOB['file_log'], 'wb'); |
|
| 1014 | + $this->rtl = array(time(), time(), $rows, 0, '', '', '', 0, 0, 0, 0, TIMER, "\n"); |
|
| 1015 | + $fcache .= "#EOH\n\n"; |
|
| 1016 | + $this->write($fcache); |
|
| 1017 | + $this->addLog(sprintf($this->LNG['backup_begin'], $this->JOB['db'])); |
|
| 1018 | + $this->runBackupJob(); |
|
| 1019 | + } |
|
| 1020 | + function runBackupJob($continue = false){ |
|
| 1021 | + if($continue){ |
|
| 1022 | + $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'a'); |
|
| 1023 | + mysql_select_db($this->JOB['db']); |
|
| 1024 | + } |
|
| 1025 | + mysql_query("SET SQL_QUOTE_SHOW_CREATE = 1"); |
|
| 1026 | + $types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event'); |
|
| 1027 | + $fcache = ''; |
|
| 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(); |
|
| 1031 | - $time_old = time(); |
|
| 1032 | - $exit_time = $time_old + $this->CFG['time_web'] - 1; |
|
| 1033 | - $no_cache = V_MYSQL < 40101 ? 'SQL_NO_CACHE ' : ''; |
|
| 1034 | - foreach($this->JOB['todo'] AS $t => $o){ |
|
| 1035 | - if (empty($this->rtl[4])) $this->rtl[4] = $t; |
|
| 1036 | - elseif ($this->rtl[4] != $t) continue; |
|
| 1037 | - foreach($o AS $n){ |
|
| 1038 | - if (empty($this->rtl[5])) { |
|
| 1039 | - $this->rtl[5] = $n[1]; |
|
| 1040 | - $this->rtl[7] = 0; |
|
| 1041 | - $this->rtl[8] = !empty($n[4]) ? $n[4] : 0; |
|
| 1042 | - } |
|
| 1043 | - elseif ($this->rtl[5] != $n[1]) continue; |
|
| 1044 | - // Делаем бэкап |
|
| 1045 | - switch($n[0]){ |
|
| 1046 | - case 'TC': |
|
| 1047 | - case 'TD': |
|
| 1048 | - case 'TA': |
|
| 1049 | - $from = ''; |
|
| 1050 | - if ($n[0] == 'TC' || $this->rtl[7] == 0){ |
|
| 1051 | - // Бэкап структуры таблицы |
|
| 1052 | - $r = mysql_query("SHOW CREATE TABLE `{$n[1]}`") or sxd_my_error(); |
|
| 1053 | - $item = mysql_fetch_assoc($r); |
|
| 1054 | - $fcache .= "#\tTC`{$n[1]}`{$n[2]}\t;\n{$item['Create Table']}\t;\n"; |
|
| 1055 | - $this->addLog(sprintf($this->LNG['backup_TC'], $n[1])); |
|
| 1056 | - $this->rtl[7] = 0; |
|
| 1057 | - if($n[0] == 'TC' || !$n[4]) break; |
|
| 1058 | - // Бэкапим данные таблицы |
|
| 1059 | - $fcache .= "#\tTD`{$n[1]}`{$n[2]}\t;\nINSERT INTO `{$n[1]}` VALUES \n"; |
|
| 1060 | - } |
|
| 1061 | - else { |
|
| 1062 | - $from = " LIMIT {$this->rtl[7]}, {$this->rtl[8]}"; |
|
| 1063 | - $this->addLog(sprintf("{$this->LNG['backup_TC']} {$this->LNG['continue_from']}", $n[1], $this->rtl[7])); |
|
| 1064 | - } |
|
| 1065 | - // Определяем типы полей |
|
| 1066 | - $notNum = array(); |
|
| 1067 | - $r = mysql_query("SHOW COLUMNS FROM `{$n[1]}`") or sxd_my_error(); |
|
| 1068 | - $fields = 0; |
|
| 1069 | - while($col = mysql_fetch_array($r)) { |
|
| 1070 | - // TODO: проверить типы SET, ENUM и BIT |
|
| 1071 | - $notNum[$fields] = preg_match("/^(tinyint|smallint|mediumint|bigint|int|float|double|real|decimal|numeric|year)/", $col['Type']) ? 0 : 1; |
|
| 1072 | - $fields++; |
|
| 1073 | - } |
|
| 1074 | - $time_old = time(); |
|
| 1075 | - $z = 0; |
|
| 1076 | - // Достаем данные |
|
| 1077 | - $r = mysql_unbuffered_query("SELECT {$no_cache}* FROM `{$n[1]}`{$from}"); |
|
| 1078 | - while($row = mysql_fetch_row($r)) { |
|
| 1079 | - if (strlen($fcache) >= 61440) { |
|
| 1080 | - $z = 0; |
|
| 1081 | - if($time_old < time()) { |
|
| 1082 | - if(file_exists($this->JOB['file_stp'])){ |
|
| 1083 | - $type = file_get_contents($this->JOB['file_stp']); |
|
| 1084 | - $this->rtl[9] = !empty($type) ? $type : 2; |
|
| 1085 | - $this->write($fcache); |
|
| 1086 | - if($type == 1) { |
|
| 1030 | + if(V_MYSQL > 40101) mysql_query("SET SESSION character_set_results = '" . ($this->JOB['charset'] ? $this->JOB['charset'] : 'binary') ."'") or sxd_my_error(); |
|
| 1031 | + $time_old = time(); |
|
| 1032 | + $exit_time = $time_old + $this->CFG['time_web'] - 1; |
|
| 1033 | + $no_cache = V_MYSQL < 40101 ? 'SQL_NO_CACHE ' : ''; |
|
| 1034 | + foreach($this->JOB['todo'] AS $t => $o){ |
|
| 1035 | + if (empty($this->rtl[4])) $this->rtl[4] = $t; |
|
| 1036 | + elseif ($this->rtl[4] != $t) continue; |
|
| 1037 | + foreach($o AS $n){ |
|
| 1038 | + if (empty($this->rtl[5])) { |
|
| 1039 | + $this->rtl[5] = $n[1]; |
|
| 1040 | + $this->rtl[7] = 0; |
|
| 1041 | + $this->rtl[8] = !empty($n[4]) ? $n[4] : 0; |
|
| 1042 | + } |
|
| 1043 | + elseif ($this->rtl[5] != $n[1]) continue; |
|
| 1044 | + // Делаем бэкап |
|
| 1045 | + switch($n[0]){ |
|
| 1046 | + case 'TC': |
|
| 1047 | + case 'TD': |
|
| 1048 | + case 'TA': |
|
| 1049 | + $from = ''; |
|
| 1050 | + if ($n[0] == 'TC' || $this->rtl[7] == 0){ |
|
| 1051 | + // Бэкап структуры таблицы |
|
| 1052 | + $r = mysql_query("SHOW CREATE TABLE `{$n[1]}`") or sxd_my_error(); |
|
| 1053 | + $item = mysql_fetch_assoc($r); |
|
| 1054 | + $fcache .= "#\tTC`{$n[1]}`{$n[2]}\t;\n{$item['Create Table']}\t;\n"; |
|
| 1055 | + $this->addLog(sprintf($this->LNG['backup_TC'], $n[1])); |
|
| 1056 | + $this->rtl[7] = 0; |
|
| 1057 | + if($n[0] == 'TC' || !$n[4]) break; |
|
| 1058 | + // Бэкапим данные таблицы |
|
| 1059 | + $fcache .= "#\tTD`{$n[1]}`{$n[2]}\t;\nINSERT INTO `{$n[1]}` VALUES \n"; |
|
| 1060 | + } |
|
| 1061 | + else { |
|
| 1062 | + $from = " LIMIT {$this->rtl[7]}, {$this->rtl[8]}"; |
|
| 1063 | + $this->addLog(sprintf("{$this->LNG['backup_TC']} {$this->LNG['continue_from']}", $n[1], $this->rtl[7])); |
|
| 1064 | + } |
|
| 1065 | + // Определяем типы полей |
|
| 1066 | + $notNum = array(); |
|
| 1067 | + $r = mysql_query("SHOW COLUMNS FROM `{$n[1]}`") or sxd_my_error(); |
|
| 1068 | + $fields = 0; |
|
| 1069 | + while($col = mysql_fetch_array($r)) { |
|
| 1070 | + // TODO: проверить типы SET, ENUM и BIT |
|
| 1071 | + $notNum[$fields] = preg_match("/^(tinyint|smallint|mediumint|bigint|int|float|double|real|decimal|numeric|year)/", $col['Type']) ? 0 : 1; |
|
| 1072 | + $fields++; |
|
| 1073 | + } |
|
| 1074 | + $time_old = time(); |
|
| 1075 | + $z = 0; |
|
| 1076 | + // Достаем данные |
|
| 1077 | + $r = mysql_unbuffered_query("SELECT {$no_cache}* FROM `{$n[1]}`{$from}"); |
|
| 1078 | + while($row = mysql_fetch_row($r)) { |
|
| 1079 | + if (strlen($fcache) >= 61440) { |
|
| 1080 | + $z = 0; |
|
| 1081 | + if($time_old < time()) { |
|
| 1082 | + if(file_exists($this->JOB['file_stp'])){ |
|
| 1083 | + $type = file_get_contents($this->JOB['file_stp']); |
|
| 1084 | + $this->rtl[9] = !empty($type) ? $type : 2; |
|
| 1085 | + $this->write($fcache); |
|
| 1086 | + if($type == 1) { |
|
| 1087 | 1087 | |
| 1088 | - } |
|
| 1089 | - unset($this->rtl); |
|
| 1090 | - exit; |
|
| 1091 | - } |
|
| 1092 | - $time_old = time(); |
|
| 1093 | - if($time_old >= $exit_time){ |
|
| 1094 | - $this->rtl[9] = 3; |
|
| 1095 | - $this->write($fcache); |
|
| 1096 | - unset($this->rtl); |
|
| 1097 | - exit; |
|
| 1098 | - } |
|
| 1099 | - clearstatcache(); |
|
| 1100 | - } |
|
| 1101 | - $this->write($fcache); |
|
| 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: Потестить скорость эскэйпинга строк |
|
| 1106 | - } |
|
| 1107 | - $fcache .= '(' . implode(',', $row) . "),\n"; |
|
| 1108 | - $this->rtl[7]++; |
|
| 1109 | - $this->rtl[10]++; |
|
| 1110 | - } |
|
| 1111 | - unset($row); |
|
| 1112 | - mysql_free_result($r); |
|
| 1113 | - $fcache = substr_replace($fcache, "\t;\n", -2, 2); |
|
| 1114 | - break; |
|
| 1088 | + } |
|
| 1089 | + unset($this->rtl); |
|
| 1090 | + exit; |
|
| 1091 | + } |
|
| 1092 | + $time_old = time(); |
|
| 1093 | + if($time_old >= $exit_time){ |
|
| 1094 | + $this->rtl[9] = 3; |
|
| 1095 | + $this->write($fcache); |
|
| 1096 | + unset($this->rtl); |
|
| 1097 | + exit; |
|
| 1098 | + } |
|
| 1099 | + clearstatcache(); |
|
| 1100 | + } |
|
| 1101 | + $this->write($fcache); |
|
| 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: Потестить скорость эскэйпинга строк |
|
| 1106 | + } |
|
| 1107 | + $fcache .= '(' . implode(',', $row) . "),\n"; |
|
| 1108 | + $this->rtl[7]++; |
|
| 1109 | + $this->rtl[10]++; |
|
| 1110 | + } |
|
| 1111 | + unset($row); |
|
| 1112 | + mysql_free_result($r); |
|
| 1113 | + $fcache = substr_replace($fcache, "\t;\n", -2, 2); |
|
| 1114 | + break; |
|
| 1115 | 1115 | |
| 1116 | - default: |
|
| 1117 | - if(V_MYSQL < 50121 && $n[0] == 'TR'){ |
|
| 1118 | - // SHOW CREATE TRIGGER отсутствует до MySQL 5.1.21 |
|
| 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 | - $item = mysql_fetch_assoc($r); |
|
| 1121 | - $fcache .= "#\tTR`{$n[1]}`{$n[2]}\t;\nCREATE TRIGGER `{$item['TRIGGER_NAME']}` {$item['ACTION_TIMING']} {$item['EVENT_MANIPULATION']} ON `{$item['EVENT_OBJECT_TABLE']}` FOR EACH ROW {$item['ACTION_STATEMENT']}\t;\n"; |
|
| 1122 | - } |
|
| 1123 | - else { |
|
| 1124 | - $this->addLog(sprintf($this->LNG['backup_' . $n[0]], $n[1])); |
|
| 1125 | - $r = mysql_query("SHOW CREATE {$types[$n[0]]} `{$n[1]}`") or sxd_my_error(); |
|
| 1126 | - $item = mysql_fetch_assoc($r); |
|
| 1127 | - $fcache .= "#\t{$n[0]}`{$n[1]}`{$n[2]}\t;\n" . preg_replace("/DEFINER=`.+?`@`.+?` /", '', ($n[0] == 'TR' ? $item['SQL Original Statement'] : $item['Create ' . $types[$n[0]]])) . "\t;\n"; |
|
| 1128 | - } |
|
| 1129 | - } |
|
| 1116 | + default: |
|
| 1117 | + if(V_MYSQL < 50121 && $n[0] == 'TR'){ |
|
| 1118 | + // SHOW CREATE TRIGGER отсутствует до MySQL 5.1.21 |
|
| 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 | + $item = mysql_fetch_assoc($r); |
|
| 1121 | + $fcache .= "#\tTR`{$n[1]}`{$n[2]}\t;\nCREATE TRIGGER `{$item['TRIGGER_NAME']}` {$item['ACTION_TIMING']} {$item['EVENT_MANIPULATION']} ON `{$item['EVENT_OBJECT_TABLE']}` FOR EACH ROW {$item['ACTION_STATEMENT']}\t;\n"; |
|
| 1122 | + } |
|
| 1123 | + else { |
|
| 1124 | + $this->addLog(sprintf($this->LNG['backup_' . $n[0]], $n[1])); |
|
| 1125 | + $r = mysql_query("SHOW CREATE {$types[$n[0]]} `{$n[1]}`") or sxd_my_error(); |
|
| 1126 | + $item = mysql_fetch_assoc($r); |
|
| 1127 | + $fcache .= "#\t{$n[0]}`{$n[1]}`{$n[2]}\t;\n" . preg_replace("/DEFINER=`.+?`@`.+?` /", '', ($n[0] == 'TR' ? $item['SQL Original Statement'] : $item['Create ' . $types[$n[0]]])) . "\t;\n"; |
|
| 1128 | + } |
|
| 1129 | + } |
|
| 1130 | 1130 | |
| 1131 | - $this->rtl[5] = ''; |
|
| 1132 | - } |
|
| 1133 | - $this->rtl[4] = ''; |
|
| 1134 | - } |
|
| 1135 | - $this->rtl[4] = 'EOJ'; |
|
| 1136 | - $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4); |
|
| 1137 | - $this->rtl[6] = ''; |
|
| 1138 | - $this->rtl[7] = 0; |
|
| 1139 | - $this->rtl[8] = 0; |
|
| 1140 | - $this->write($fcache); |
|
| 1141 | - fclose($this->fh_tmp); |
|
| 1142 | - rename($this->JOB['file_tmp'], $this->JOB['file_name']); |
|
| 1143 | - $this->addLog(sprintf($this->LNG['backup_end'], $this->JOB['db'])); |
|
| 1144 | - if(file_exists('sxd2ftp.php')) include('sxd2ftp.php'); |
|
| 1145 | - if ($this->JOB['del_time'] || $this->JOB['del_count']) { |
|
| 1131 | + $this->rtl[5] = ''; |
|
| 1132 | + } |
|
| 1133 | + $this->rtl[4] = ''; |
|
| 1134 | + } |
|
| 1135 | + $this->rtl[4] = 'EOJ'; |
|
| 1136 | + $this->rtl[5] = round(array_sum(explode(' ', microtime())) - $this->rtl[11], 4); |
|
| 1137 | + $this->rtl[6] = ''; |
|
| 1138 | + $this->rtl[7] = 0; |
|
| 1139 | + $this->rtl[8] = 0; |
|
| 1140 | + $this->write($fcache); |
|
| 1141 | + fclose($this->fh_tmp); |
|
| 1142 | + rename($this->JOB['file_tmp'], $this->JOB['file_name']); |
|
| 1143 | + $this->addLog(sprintf($this->LNG['backup_end'], $this->JOB['db'])); |
|
| 1144 | + if(file_exists('sxd2ftp.php')) include('sxd2ftp.php'); |
|
| 1145 | + if ($this->JOB['del_time'] || $this->JOB['del_count']) { |
|
| 1146 | 1146 | $this->addLog($this->LNG['autodelete']); |
| 1147 | 1147 | $deldate = ''; |
| 1148 | 1148 | if (!empty($this->JOB['del_time'])){ // Удаление по дням |
@@ -1169,7 +1169,7 @@ discard block |
||
| 1169 | 1169 | $file_to_delete = count($files) - $this->JOB['del_count']; |
| 1170 | 1170 | foreach ($files AS $file){ |
| 1171 | 1171 | if ($file_to_delete-- > 0){ |
| 1172 | - if(unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_count'], $file)); |
|
| 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 | } |
@@ -1177,237 +1177,237 @@ discard block |
||
| 1177 | 1177 | } |
| 1178 | 1178 | } |
| 1179 | 1179 | if(!$deleted) $this->addLog($this->LNG['del_nothing']); |
| 1180 | - } |
|
| 1181 | - fclose($this->fh_log); |
|
| 1182 | - fclose($this->fh_rtl); |
|
| 1183 | - } |
|
| 1184 | - function setNames($collation){ |
|
| 1185 | - if(empty($collation)) return; |
|
| 1186 | - if($this->rtl[6] != $collation) { |
|
| 1187 | - mysql_query('SET NAMES \'' . preg_replace('/^(\w+?)_/', '\\1\' COLLATE \'\\1_', $collation) . '\'') or sxd_my_error(); |
|
| 1188 | - /*if(!$this->rtl[7])*/ $this->addLog(sprintf($this->LNG['set_names'], $collation)); |
|
| 1189 | - $this->rtl[6] = $collation; |
|
| 1190 | - } |
|
| 1191 | - } |
|
| 1192 | - function write(&$str){ |
|
| 1193 | - fseek($this->fh_rtl, 0); |
|
| 1194 | - $this->rtl[1] = time(); |
|
| 1195 | - $this->rtl[3] += fwrite($this->fh_tmp, $str); |
|
| 1196 | - fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 1197 | - $str = ''; |
|
| 1198 | - } |
|
| 1199 | - function addLog($str, $type = 1){ |
|
| 1200 | - fwrite($this->fh_log, date('Y.m.d H:i:s') . "\t{$type}\t{$str}\n"); |
|
| 1201 | - } |
|
| 1202 | - function getDBList(){ |
|
| 1203 | - $dbs = $items = array(); |
|
| 1180 | + } |
|
| 1181 | + fclose($this->fh_log); |
|
| 1182 | + fclose($this->fh_rtl); |
|
| 1183 | + } |
|
| 1184 | + function setNames($collation){ |
|
| 1185 | + if(empty($collation)) return; |
|
| 1186 | + if($this->rtl[6] != $collation) { |
|
| 1187 | + mysql_query('SET NAMES \'' . preg_replace('/^(\w+?)_/', '\\1\' COLLATE \'\\1_', $collation) . '\'') or sxd_my_error(); |
|
| 1188 | + /*if(!$this->rtl[7])*/ $this->addLog(sprintf($this->LNG['set_names'], $collation)); |
|
| 1189 | + $this->rtl[6] = $collation; |
|
| 1190 | + } |
|
| 1191 | + } |
|
| 1192 | + function write(&$str){ |
|
| 1193 | + fseek($this->fh_rtl, 0); |
|
| 1194 | + $this->rtl[1] = time(); |
|
| 1195 | + $this->rtl[3] += fwrite($this->fh_tmp, $str); |
|
| 1196 | + fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
|
| 1197 | + $str = ''; |
|
| 1198 | + } |
|
| 1199 | + function addLog($str, $type = 1){ |
|
| 1200 | + fwrite($this->fh_log, date('Y.m.d H:i:s') . "\t{$type}\t{$str}\n"); |
|
| 1201 | + } |
|
| 1202 | + function getDBList(){ |
|
| 1203 | + $dbs = $items = array(); |
|
| 1204 | 1204 | if (!V_MYSQL) return $dbs; |
| 1205 | 1205 | $qq = (V_MYSQL < 50000) ? '' : '\''; |
| 1206 | - if ($this->CFG['my_db']) { |
|
| 1207 | - $tmp = explode(',', $this->CFG['my_db']); |
|
| 1208 | - foreach($tmp AS $d){ |
|
| 1209 | - $d = trim($d); |
|
| 1210 | - $items[] = $qq . sxd_esc($d, false) . $qq; |
|
| 1211 | - $dbs[$d] = "{$d} (0)"; |
|
| 1212 | - } |
|
| 1213 | - } |
|
| 1214 | - else{ |
|
| 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; |
|
| 1218 | - $items[] = $qq . sxd_esc($item[0], false) . $qq; |
|
| 1219 | - $dbs[$item[0]] = "{$item[0]} (0)"; |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - if(V_MYSQL < 50000){ |
|
| 1223 | - foreach($items AS $item){ |
|
| 1224 | - $tables = mysql_query("SHOW TABLES FROM `{$item}`") or sxd_my_error(); |
|
| 1225 | - if ($tables) { |
|
| 1226 | - $tabs = mysql_num_rows($tables); |
|
| 1227 | - $dbs[$item] = "{$item} ({$tabs})"; |
|
| 1228 | - } |
|
| 1229 | - } |
|
| 1230 | - } |
|
| 1231 | - else { |
|
| 1232 | - $where = (count($items) > 0) ? 'WHERE `table_schema` IN (' . implode(',', $items) . ')' : ''; |
|
| 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; |
|
| 1236 | - $dbs[$item[0]] = "{$item[0]} ({$item[1]})"; |
|
| 1237 | - } |
|
| 1238 | - } |
|
| 1239 | - return $dbs; |
|
| 1240 | - } |
|
| 1241 | - function getCharsetList(){ |
|
| 1242 | - $tmp = array(0 => '- auto -'); |
|
| 1243 | - if (!V_MYSQL) return $tmp; |
|
| 1244 | - if(V_MYSQL > 40101) { |
|
| 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' : ''; |
|
| 1248 | - } |
|
| 1249 | - $r = mysql_query("SHOW CHARACTER SET") or sxd_my_error(); |
|
| 1250 | - if ($r) { |
|
| 1251 | - while($item = mysql_fetch_assoc($r)){ |
|
| 1252 | - if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']] = "{$item['Charset']}"; // ({$item['Description']}) |
|
| 1253 | - } |
|
| 1254 | - } |
|
| 1255 | - } |
|
| 1256 | - return $tmp; |
|
| 1257 | - } |
|
| 1258 | - function getCollationList(){ |
|
| 1259 | - $tmp = array(); |
|
| 1260 | - if (!V_MYSQL) return $tmp; |
|
| 1261 | - if(V_MYSQL > 40101) { |
|
| 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' : ''; |
|
| 1265 | - } |
|
| 1266 | - $r = mysql_query("SHOW COLLATION") or sxd_my_error(); |
|
| 1267 | - if ($r) { |
|
| 1268 | - while($item = mysql_fetch_assoc($r)){ |
|
| 1269 | - if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']][$item['Collation']] = $item['Default'] == 'Yes' ? 1 : 0; |
|
| 1270 | - } |
|
| 1271 | - } |
|
| 1272 | - } |
|
| 1273 | - return $tmp; |
|
| 1274 | - } |
|
| 1275 | - function getObjects($tree, $db_name){ |
|
| 1276 | - mysql_select_db($db_name); |
|
| 1277 | - // Достаем таблицы |
|
| 1278 | - $r = mysql_query('SHOW TABLE STATUS'); |
|
| 1279 | - $tab_prefix_last = $tab_prefix = '*'; |
|
| 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']; |
|
| 1285 | - } |
|
| 1286 | - else{ |
|
| 1287 | - $objects['TA'][] = array($item['Name'], $item['Rows'], $item['Data_length']); |
|
| 1288 | - } |
|
| 1289 | - } |
|
| 1206 | + if ($this->CFG['my_db']) { |
|
| 1207 | + $tmp = explode(',', $this->CFG['my_db']); |
|
| 1208 | + foreach($tmp AS $d){ |
|
| 1209 | + $d = trim($d); |
|
| 1210 | + $items[] = $qq . sxd_esc($d, false) . $qq; |
|
| 1211 | + $dbs[$d] = "{$d} (0)"; |
|
| 1212 | + } |
|
| 1213 | + } |
|
| 1214 | + else{ |
|
| 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; |
|
| 1218 | + $items[] = $qq . sxd_esc($item[0], false) . $qq; |
|
| 1219 | + $dbs[$item[0]] = "{$item[0]} (0)"; |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + if(V_MYSQL < 50000){ |
|
| 1223 | + foreach($items AS $item){ |
|
| 1224 | + $tables = mysql_query("SHOW TABLES FROM `{$item}`") or sxd_my_error(); |
|
| 1225 | + if ($tables) { |
|
| 1226 | + $tabs = mysql_num_rows($tables); |
|
| 1227 | + $dbs[$item] = "{$item} ({$tabs})"; |
|
| 1228 | + } |
|
| 1229 | + } |
|
| 1230 | + } |
|
| 1231 | + else { |
|
| 1232 | + $where = (count($items) > 0) ? 'WHERE `table_schema` IN (' . implode(',', $items) . ')' : ''; |
|
| 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; |
|
| 1236 | + $dbs[$item[0]] = "{$item[0]} ({$item[1]})"; |
|
| 1237 | + } |
|
| 1238 | + } |
|
| 1239 | + return $dbs; |
|
| 1240 | + } |
|
| 1241 | + function getCharsetList(){ |
|
| 1242 | + $tmp = array(0 => '- auto -'); |
|
| 1243 | + if (!V_MYSQL) return $tmp; |
|
| 1244 | + if(V_MYSQL > 40101) { |
|
| 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' : ''; |
|
| 1248 | + } |
|
| 1249 | + $r = mysql_query("SHOW CHARACTER SET") or sxd_my_error(); |
|
| 1250 | + if ($r) { |
|
| 1251 | + while($item = mysql_fetch_assoc($r)){ |
|
| 1252 | + if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']] = "{$item['Charset']}"; // ({$item['Description']}) |
|
| 1253 | + } |
|
| 1254 | + } |
|
| 1255 | + } |
|
| 1256 | + return $tmp; |
|
| 1257 | + } |
|
| 1258 | + function getCollationList(){ |
|
| 1259 | + $tmp = array(); |
|
| 1260 | + if (!V_MYSQL) return $tmp; |
|
| 1261 | + if(V_MYSQL > 40101) { |
|
| 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' : ''; |
|
| 1265 | + } |
|
| 1266 | + $r = mysql_query("SHOW COLLATION") or sxd_my_error(); |
|
| 1267 | + if ($r) { |
|
| 1268 | + while($item = mysql_fetch_assoc($r)){ |
|
| 1269 | + if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']][$item['Collation']] = $item['Default'] == 'Yes' ? 1 : 0; |
|
| 1270 | + } |
|
| 1271 | + } |
|
| 1272 | + } |
|
| 1273 | + return $tmp; |
|
| 1274 | + } |
|
| 1275 | + function getObjects($tree, $db_name){ |
|
| 1276 | + mysql_select_db($db_name); |
|
| 1277 | + // Достаем таблицы |
|
| 1278 | + $r = mysql_query('SHOW TABLE STATUS'); |
|
| 1279 | + $tab_prefix_last = $tab_prefix = '*'; |
|
| 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']; |
|
| 1285 | + } |
|
| 1286 | + else{ |
|
| 1287 | + $objects['TA'][] = array($item['Name'], $item['Rows'], $item['Data_length']); |
|
| 1288 | + } |
|
| 1289 | + } |
|
| 1290 | 1290 | |
| 1291 | - if (V_MYSQL > 50014 && $tree != 'services') { |
|
| 1292 | - $shows = array( |
|
| 1293 | - "PROCEDURE STATUS WHERE db='{$db_name}'", |
|
| 1294 | - "FUNCTION STATUS WHERE db='{$db_name}'", |
|
| 1295 | - 'TRIGGERS' |
|
| 1296 | - ); |
|
| 1297 | - if(V_MYSQL > 50100) $shows[] = "EVENTS WHERE db='{$db_name}'"; |
|
| 1298 | - // TODO: Поправить проверку событий и триггеров |
|
| 1299 | - for($i = 0, $l = count($shows); $i < $l; $i++){ |
|
| 1300 | - $r = mysql_query('SHOW ' . $shows[$i]); |
|
| 1301 | - if($r && mysql_num_rows($r) > 0) { |
|
| 1302 | - $col_name = $shows[$i] == 'TRIGGERS' ? 'Trigger' : 'Name'; |
|
| 1303 | - $type = substr($shows[$i], 0, 2); |
|
| 1304 | - while($item = mysql_fetch_assoc($r)){ |
|
| 1305 | - $objects[$type][] = $item[$col_name]; |
|
| 1306 | - } |
|
| 1307 | - } |
|
| 1308 | - } |
|
| 1309 | - } |
|
| 1310 | - else { |
|
| 1311 | - $objects['VI'] = array(); |
|
| 1312 | - } |
|
| 1313 | - } |
|
| 1314 | - return $this->formatTree($tree, $objects); |
|
| 1315 | - } |
|
| 1316 | - function getFileObjects($tree, $name, $formatTree = true){ |
|
| 1317 | - // Достаем таблицы |
|
| 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 ''; |
|
| 1320 | - $name = $this->CFG['backup_path'] . $name; |
|
| 1321 | - if(!is_readable($name)) {return "sxd.tree.{$tree}.error(sxd.lng('err_fopen'))";} |
|
| 1322 | - $fp = $this->openFile($name, 'r'); |
|
| 1323 | - $temp = fread($fp, 60000); |
|
| 1324 | - // Формат файла Sypex Dumper 2 - SXD20 |
|
| 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)){ |
|
| 1327 | - $head = explode("\n", $m[1]); |
|
| 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)); |
|
| 1331 | - } |
|
| 1332 | - for($i = 0, $l = count($objects['TA']); $i < $l; $i++){ |
|
| 1333 | - $objects['TA'][$i] = explode('`', $objects['TA'][$i]); |
|
| 1334 | - } |
|
| 1335 | - } |
|
| 1336 | - else { |
|
| 1337 | - $h[9] = ''; |
|
| 1338 | - } |
|
| 1339 | - return $formatTree ? $this->formatTree($tree, $objects) . "sxd.comment.restore.value = '{$h[9]}';z('restore_savejob').disabled = z('restore_runjob').disabled = false;" : $objects; |
|
| 1340 | - } |
|
| 1341 | - function formatTree($tree, &$objects){ |
|
| 1342 | - $obj = ''; |
|
| 1343 | - $pid = $row = 1; |
|
| 1344 | - $info = array( |
|
| 1345 | - 'TA' => array($this->LNG['obj_tables'], 1), |
|
| 1346 | - 'VI' => array($this->LNG['obj_views'], 3), |
|
| 1347 | - 'PR' => array($this->LNG['obj_procs'], 5), |
|
| 1348 | - 'FU' => array($this->LNG['obj_funcs'], 7), |
|
| 1349 | - 'TR' => array($this->LNG['obj_trigs'], 9), |
|
| 1350 | - 'EV' => array($this->LNG['obj_events'], 11) |
|
| 1351 | - ); |
|
| 1352 | - // Находим таблицы с префиксами |
|
| 1353 | - $tab_prefix_last = $tab_prefix = '*'; |
|
| 1354 | - for($i = 0, $l = count($objects['TA']); $i < $l; $i++){ |
|
| 1355 | - $t = $objects['TA'][$i]; |
|
| 1356 | - $tab_prefix = preg_match("/^([a-z0-9]+_)/", $t[0], $m) ? $m[1] : '*'; |
|
| 1357 | - if ($tab_prefix != $tab_prefix_last) { |
|
| 1358 | - if ($tab_prefix != '*') $objects['TA']['*'][] = $tab_prefix; |
|
| 1359 | - $tab_prefix_last = $tab_prefix; |
|
| 1360 | - } |
|
| 1361 | - $objects['TA'][$tab_prefix][] = $t; |
|
| 1362 | - unset($objects['TA'][$i]); |
|
| 1363 | - } |
|
| 1364 | - foreach($objects AS $type => $o){ |
|
| 1365 | - if(!count($o)) continue; |
|
| 1366 | - if($type == 'TA') { |
|
| 1367 | - $open_childs = count($o['*']) > 1 ? 0 : 1; |
|
| 1368 | - $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",1,1,1],"; |
|
| 1369 | - $row++; |
|
| 1370 | - foreach($o['*'] AS $value){ |
|
| 1371 | - if(is_string($value)){ |
|
| 1372 | - if(count($o[$value]) > 1) { |
|
| 1373 | - $obj .= "[{$row},1,'{$value}*',1,1,{$open_childs}],"; |
|
| 1374 | - $pid = $row++; |
|
| 1375 | - for($i = 0, $l = count($o[$value]); $i < $l; $i++){ |
|
| 1376 | - $checked = ($o[$value][$i][1] == '' && $o[$value][$i][2] == '') ? 2 : 1; |
|
| 1377 | - $obj .= "[{$row},{$pid}," . sxd_esc($o[$value][$i][0]) . ",2,{$checked},{$o[$value][$i][2]}],"; |
|
| 1378 | - $row++; |
|
| 1379 | - } |
|
| 1380 | - } |
|
| 1381 | - else { |
|
| 1382 | - $value = $o[$value][0]; |
|
| 1383 | - } |
|
| 1384 | - } |
|
| 1385 | - //$pid = 1; |
|
| 1386 | - if (is_array($value)){ |
|
| 1387 | - $checked = ($value[1] == '' && $value[2] == '') ? 2 : 1; |
|
| 1388 | - $obj .= "[{$row},1,'{$value[0]}',2,{$checked},{$value[2]}],"; |
|
| 1389 | - $row++; |
|
| 1390 | - } |
|
| 1391 | - } |
|
| 1392 | - } |
|
| 1393 | - else { |
|
| 1394 | - $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",{$info[$type][1]},1,1],"; |
|
| 1395 | - $pid = $row++; |
|
| 1396 | - $info[$type][1]++; |
|
| 1397 | - for($i = 0, $l = count($o); $i < $l; $i++){ |
|
| 1398 | - $o[$i] = sxd_esc($o[$i], false); |
|
| 1399 | - $obj .= "[{$row},{$pid},'{$o[$i]}',{$info[$type][1]},1,0],"; |
|
| 1400 | - $row++; |
|
| 1401 | - } |
|
| 1402 | - } |
|
| 1403 | - } |
|
| 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; |
|
| 1407 | - } |
|
| 1408 | - function getFileList(){ |
|
| 1409 | - $files = array(); |
|
| 1410 | - if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
|
| 1291 | + if (V_MYSQL > 50014 && $tree != 'services') { |
|
| 1292 | + $shows = array( |
|
| 1293 | + "PROCEDURE STATUS WHERE db='{$db_name}'", |
|
| 1294 | + "FUNCTION STATUS WHERE db='{$db_name}'", |
|
| 1295 | + 'TRIGGERS' |
|
| 1296 | + ); |
|
| 1297 | + if(V_MYSQL > 50100) $shows[] = "EVENTS WHERE db='{$db_name}'"; |
|
| 1298 | + // TODO: Поправить проверку событий и триггеров |
|
| 1299 | + for($i = 0, $l = count($shows); $i < $l; $i++){ |
|
| 1300 | + $r = mysql_query('SHOW ' . $shows[$i]); |
|
| 1301 | + if($r && mysql_num_rows($r) > 0) { |
|
| 1302 | + $col_name = $shows[$i] == 'TRIGGERS' ? 'Trigger' : 'Name'; |
|
| 1303 | + $type = substr($shows[$i], 0, 2); |
|
| 1304 | + while($item = mysql_fetch_assoc($r)){ |
|
| 1305 | + $objects[$type][] = $item[$col_name]; |
|
| 1306 | + } |
|
| 1307 | + } |
|
| 1308 | + } |
|
| 1309 | + } |
|
| 1310 | + else { |
|
| 1311 | + $objects['VI'] = array(); |
|
| 1312 | + } |
|
| 1313 | + } |
|
| 1314 | + return $this->formatTree($tree, $objects); |
|
| 1315 | + } |
|
| 1316 | + function getFileObjects($tree, $name, $formatTree = true){ |
|
| 1317 | + // Достаем таблицы |
|
| 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 ''; |
|
| 1320 | + $name = $this->CFG['backup_path'] . $name; |
|
| 1321 | + if(!is_readable($name)) {return "sxd.tree.{$tree}.error(sxd.lng('err_fopen'))";} |
|
| 1322 | + $fp = $this->openFile($name, 'r'); |
|
| 1323 | + $temp = fread($fp, 60000); |
|
| 1324 | + // Формат файла Sypex Dumper 2 - SXD20 |
|
| 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)){ |
|
| 1327 | + $head = explode("\n", $m[1]); |
|
| 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)); |
|
| 1331 | + } |
|
| 1332 | + for($i = 0, $l = count($objects['TA']); $i < $l; $i++){ |
|
| 1333 | + $objects['TA'][$i] = explode('`', $objects['TA'][$i]); |
|
| 1334 | + } |
|
| 1335 | + } |
|
| 1336 | + else { |
|
| 1337 | + $h[9] = ''; |
|
| 1338 | + } |
|
| 1339 | + return $formatTree ? $this->formatTree($tree, $objects) . "sxd.comment.restore.value = '{$h[9]}';z('restore_savejob').disabled = z('restore_runjob').disabled = false;" : $objects; |
|
| 1340 | + } |
|
| 1341 | + function formatTree($tree, &$objects){ |
|
| 1342 | + $obj = ''; |
|
| 1343 | + $pid = $row = 1; |
|
| 1344 | + $info = array( |
|
| 1345 | + 'TA' => array($this->LNG['obj_tables'], 1), |
|
| 1346 | + 'VI' => array($this->LNG['obj_views'], 3), |
|
| 1347 | + 'PR' => array($this->LNG['obj_procs'], 5), |
|
| 1348 | + 'FU' => array($this->LNG['obj_funcs'], 7), |
|
| 1349 | + 'TR' => array($this->LNG['obj_trigs'], 9), |
|
| 1350 | + 'EV' => array($this->LNG['obj_events'], 11) |
|
| 1351 | + ); |
|
| 1352 | + // Находим таблицы с префиксами |
|
| 1353 | + $tab_prefix_last = $tab_prefix = '*'; |
|
| 1354 | + for($i = 0, $l = count($objects['TA']); $i < $l; $i++){ |
|
| 1355 | + $t = $objects['TA'][$i]; |
|
| 1356 | + $tab_prefix = preg_match("/^([a-z0-9]+_)/", $t[0], $m) ? $m[1] : '*'; |
|
| 1357 | + if ($tab_prefix != $tab_prefix_last) { |
|
| 1358 | + if ($tab_prefix != '*') $objects['TA']['*'][] = $tab_prefix; |
|
| 1359 | + $tab_prefix_last = $tab_prefix; |
|
| 1360 | + } |
|
| 1361 | + $objects['TA'][$tab_prefix][] = $t; |
|
| 1362 | + unset($objects['TA'][$i]); |
|
| 1363 | + } |
|
| 1364 | + foreach($objects AS $type => $o){ |
|
| 1365 | + if(!count($o)) continue; |
|
| 1366 | + if($type == 'TA') { |
|
| 1367 | + $open_childs = count($o['*']) > 1 ? 0 : 1; |
|
| 1368 | + $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",1,1,1],"; |
|
| 1369 | + $row++; |
|
| 1370 | + foreach($o['*'] AS $value){ |
|
| 1371 | + if(is_string($value)){ |
|
| 1372 | + if(count($o[$value]) > 1) { |
|
| 1373 | + $obj .= "[{$row},1,'{$value}*',1,1,{$open_childs}],"; |
|
| 1374 | + $pid = $row++; |
|
| 1375 | + for($i = 0, $l = count($o[$value]); $i < $l; $i++){ |
|
| 1376 | + $checked = ($o[$value][$i][1] == '' && $o[$value][$i][2] == '') ? 2 : 1; |
|
| 1377 | + $obj .= "[{$row},{$pid}," . sxd_esc($o[$value][$i][0]) . ",2,{$checked},{$o[$value][$i][2]}],"; |
|
| 1378 | + $row++; |
|
| 1379 | + } |
|
| 1380 | + } |
|
| 1381 | + else { |
|
| 1382 | + $value = $o[$value][0]; |
|
| 1383 | + } |
|
| 1384 | + } |
|
| 1385 | + //$pid = 1; |
|
| 1386 | + if (is_array($value)){ |
|
| 1387 | + $checked = ($value[1] == '' && $value[2] == '') ? 2 : 1; |
|
| 1388 | + $obj .= "[{$row},1,'{$value[0]}',2,{$checked},{$value[2]}],"; |
|
| 1389 | + $row++; |
|
| 1390 | + } |
|
| 1391 | + } |
|
| 1392 | + } |
|
| 1393 | + else { |
|
| 1394 | + $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",{$info[$type][1]},1,1],"; |
|
| 1395 | + $pid = $row++; |
|
| 1396 | + $info[$type][1]++; |
|
| 1397 | + for($i = 0, $l = count($o); $i < $l; $i++){ |
|
| 1398 | + $o[$i] = sxd_esc($o[$i], false); |
|
| 1399 | + $obj .= "[{$row},{$pid},'{$o[$i]}',{$info[$type][1]},1,0],"; |
|
| 1400 | + $row++; |
|
| 1401 | + } |
|
| 1402 | + } |
|
| 1403 | + } |
|
| 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; |
|
| 1407 | + } |
|
| 1408 | + function getFileList(){ |
|
| 1409 | + $files = array(); |
|
| 1410 | + if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
|
| 1411 | 1411 | while (false !== ($file = readdir($handle))) { |
| 1412 | 1412 | if (preg_match("/^.+?\.sql(\.(gz|bz2))?$/", $file)) { |
| 1413 | 1413 | $files[$file] = $file; |
@@ -1416,196 +1416,196 @@ discard block |
||
| 1416 | 1416 | closedir($handle); |
| 1417 | 1417 | } |
| 1418 | 1418 | ksort($files); |
| 1419 | - return $files; |
|
| 1420 | - } |
|
| 1421 | - function getSavedJobs(){ |
|
| 1422 | - $sj = array('sj_backup' => array(), 'sj_restore' => array(),); |
|
| 1423 | - if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
|
| 1419 | + return $files; |
|
| 1420 | + } |
|
| 1421 | + function getSavedJobs(){ |
|
| 1422 | + $sj = array('sj_backup' => array(), 'sj_restore' => array(),); |
|
| 1423 | + if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
|
| 1424 | 1424 | while (false !== ($file = readdir($handle))) { |
| 1425 | 1425 | if (preg_match("/^sj_(.+?)\.job.php$/", $file)) { |
| 1426 | - include($this->CFG['backup_path'] . $file); |
|
| 1426 | + include($this->CFG['backup_path'] . $file); |
|
| 1427 | 1427 | $sj['sj_' . $JOB['type']][$JOB['job']] = "<b>{$JOB['job']}</b><br><i>{$JOB['title']} </i>"; |
| 1428 | 1428 | } |
| 1429 | 1429 | } |
| 1430 | 1430 | closedir($handle); |
| 1431 | 1431 | } |
| 1432 | 1432 | if(count($sj['sj_backup']) > 0){ |
| 1433 | - ksort($sj['sj_backup']); |
|
| 1434 | - } |
|
| 1433 | + ksort($sj['sj_backup']); |
|
| 1434 | + } |
|
| 1435 | 1435 | else { |
| 1436 | - $sj['sj_backup'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']); |
|
| 1437 | - } |
|
| 1438 | - if(count($sj['sj_restore']) > 0){ |
|
| 1439 | - ksort($sj['sj_restore']); |
|
| 1440 | - } |
|
| 1436 | + $sj['sj_backup'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']); |
|
| 1437 | + } |
|
| 1438 | + if(count($sj['sj_restore']) > 0){ |
|
| 1439 | + ksort($sj['sj_restore']); |
|
| 1440 | + } |
|
| 1441 | 1441 | else { |
| 1442 | - $sj['sj_restore'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']); |
|
| 1443 | - } |
|
| 1444 | - return "sxd.clearOpt('sj_backup');sxd.clearOpt('sj_restore');sxd.addOpt(" . sxd_php2json($sj) . ");"; |
|
| 1445 | - } |
|
| 1446 | - function getFileListExtended(){ |
|
| 1447 | - $files = array(); |
|
| 1448 | - if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
|
| 1442 | + $sj['sj_restore'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']); |
|
| 1443 | + } |
|
| 1444 | + return "sxd.clearOpt('sj_backup');sxd.clearOpt('sj_restore');sxd.addOpt(" . sxd_php2json($sj) . ");"; |
|
| 1445 | + } |
|
| 1446 | + function getFileListExtended(){ |
|
| 1447 | + $files = array(); |
|
| 1448 | + if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
|
| 1449 | 1449 | while (false !== ($file = readdir($handle))) { |
| 1450 | 1450 | if (preg_match("/^.+?\.sql(\.(gz|bz2))?$/", $file, $m)) { |
| 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 | 1454 | if(preg_match('/^(#SXD20\|.+?)\n/s', $temp, $m)){ |
| 1455 | - $h = explode('|', $m[1]); |
|
| 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 | - } |
|
| 1458 | - elseif(preg_match('/^(#SKD101\|.+?)\n/s', $temp, $m)){ |
|
| 1459 | - $h = explode('|', $m[1]); |
|
| 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 | - } |
|
| 1462 | - else { |
|
| 1463 | - $files[] = array($file, '-', $ext, '-', '-', filesize($this->CFG['backup_path'] . $file), '', $file); |
|
| 1464 | - } |
|
| 1455 | + $h = explode('|', $m[1]); |
|
| 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 | + } |
|
| 1458 | + elseif(preg_match('/^(#SKD101\|.+?)\n/s', $temp, $m)){ |
|
| 1459 | + $h = explode('|', $m[1]); |
|
| 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 | + } |
|
| 1462 | + else { |
|
| 1463 | + $files[] = array($file, '-', $ext, '-', '-', filesize($this->CFG['backup_path'] . $file), '', $file); |
|
| 1464 | + } |
|
| 1465 | 1465 | } |
| 1466 | 1466 | } |
| 1467 | 1467 | closedir($handle); |
| 1468 | 1468 | } |
| 1469 | 1469 | function s($a, $b){ |
| 1470 | - return strcmp($b[1], $a[1]); |
|
| 1471 | - } |
|
| 1470 | + return strcmp($b[1], $a[1]); |
|
| 1471 | + } |
|
| 1472 | 1472 | usort($files, 's'); |
| 1473 | - return 'sxd.files.clear();sxd.files.add(' . sxd_php2json($files) . ');'; |
|
| 1474 | - } |
|
| 1475 | - function saveJob($job, $config){ |
|
| 1476 | - $this->saveToFile($this->CFG['backup_path'] . $job . '.job.php', "<?php\n\$JOB = " . var_export($config, true) . ";\n" . "?>"); |
|
| 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]); |
|
| 1481 | - } |
|
| 1482 | - else{ |
|
| 1483 | - switch($this->JOB['zip']) { |
|
| 1484 | - case 0 : $this->JOB['file_ext'] = 'sql'; break; |
|
| 1485 | - case 10: $this->JOB['file_ext'] = 'sql.bz2'; break; |
|
| 1486 | - default: $this->JOB['file_ext'] = 'sql.gz'; break; |
|
| 1487 | - } |
|
| 1488 | - } |
|
| 1489 | - switch ($this->JOB['file_ext']){ |
|
| 1490 | - case 'sql': |
|
| 1491 | - return fopen($name, "{$mode}b"); |
|
| 1492 | - break; |
|
| 1493 | - case 'sql.bz2': |
|
| 1494 | - return bzopen($name, $mode); |
|
| 1495 | - break; |
|
| 1496 | - case 'sql.gz': |
|
| 1497 | - return gzopen($name, $mode . ($mode == 'w' ? $this->JOB['zip'] : '')); |
|
| 1498 | - break; |
|
| 1499 | - default: return false; |
|
| 1500 | - } |
|
| 1501 | - } |
|
| 1473 | + return 'sxd.files.clear();sxd.files.add(' . sxd_php2json($files) . ');'; |
|
| 1474 | + } |
|
| 1475 | + function saveJob($job, $config){ |
|
| 1476 | + $this->saveToFile($this->CFG['backup_path'] . $job . '.job.php', "<?php\n\$JOB = " . var_export($config, true) . ";\n" . "?>"); |
|
| 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]); |
|
| 1481 | + } |
|
| 1482 | + else{ |
|
| 1483 | + switch($this->JOB['zip']) { |
|
| 1484 | + case 0 : $this->JOB['file_ext'] = 'sql'; break; |
|
| 1485 | + case 10: $this->JOB['file_ext'] = 'sql.bz2'; break; |
|
| 1486 | + default: $this->JOB['file_ext'] = 'sql.gz'; break; |
|
| 1487 | + } |
|
| 1488 | + } |
|
| 1489 | + switch ($this->JOB['file_ext']){ |
|
| 1490 | + case 'sql': |
|
| 1491 | + return fopen($name, "{$mode}b"); |
|
| 1492 | + break; |
|
| 1493 | + case 'sql.bz2': |
|
| 1494 | + return bzopen($name, $mode); |
|
| 1495 | + break; |
|
| 1496 | + case 'sql.gz': |
|
| 1497 | + return gzopen($name, $mode . ($mode == 'w' ? $this->JOB['zip'] : '')); |
|
| 1498 | + break; |
|
| 1499 | + default: return false; |
|
| 1500 | + } |
|
| 1501 | + } |
|
| 1502 | 1502 | } |
| 1503 | 1503 | function sxd_read_sql($f, &$seek, $ei, $delimiter = "\t;", $eol = "\n"){ |
| 1504 | - static $l = ''; |
|
| 1505 | - static $r = 0; |
|
| 1506 | - $fs = ftell($f); |
|
| 1507 | - $delim_len = strlen($delimiter . $eol); |
|
| 1508 | - while($r || $s = fread($f, 61440)){ |
|
| 1509 | - if(!$r) $l .= $s; |
|
| 1510 | - $pos = strpos($l, $delimiter . $eol); |
|
| 1511 | - if ($pos !== false) { |
|
| 1512 | - // Есть окончание запроса |
|
| 1513 | - $q = substr($l, 0, $pos); |
|
| 1514 | - $l = substr($l, $pos+$delim_len); |
|
| 1515 | - $r = 1; |
|
| 1516 | - $seek = strlen($l); |
|
| 1517 | - return $q; |
|
| 1518 | - } |
|
| 1519 | - if($ei) { |
|
| 1520 | - $pos = strrpos($l, $eol); |
|
| 1521 | - if($pos > 0 && $l{$pos-1} === ',') { |
|
| 1522 | - // Окончание не найдено |
|
| 1523 | - $q = substr($l, 0, $pos-1); |
|
| 1524 | - $l = substr($l, $pos+ strlen($eol)); |
|
| 1525 | - $seek = strlen($l); |
|
| 1526 | - $r = 0; |
|
| 1527 | - return $q; |
|
| 1528 | - } |
|
| 1529 | - } |
|
| 1530 | - $r = 0; |
|
| 1531 | - } |
|
| 1532 | - if (!empty($l)) { |
|
| 1533 | - return $l; |
|
| 1534 | - } |
|
| 1535 | - return false; |
|
| 1504 | + static $l = ''; |
|
| 1505 | + static $r = 0; |
|
| 1506 | + $fs = ftell($f); |
|
| 1507 | + $delim_len = strlen($delimiter . $eol); |
|
| 1508 | + while($r || $s = fread($f, 61440)){ |
|
| 1509 | + if(!$r) $l .= $s; |
|
| 1510 | + $pos = strpos($l, $delimiter . $eol); |
|
| 1511 | + if ($pos !== false) { |
|
| 1512 | + // Есть окончание запроса |
|
| 1513 | + $q = substr($l, 0, $pos); |
|
| 1514 | + $l = substr($l, $pos+$delim_len); |
|
| 1515 | + $r = 1; |
|
| 1516 | + $seek = strlen($l); |
|
| 1517 | + return $q; |
|
| 1518 | + } |
|
| 1519 | + if($ei) { |
|
| 1520 | + $pos = strrpos($l, $eol); |
|
| 1521 | + if($pos > 0 && $l{$pos-1} === ',') { |
|
| 1522 | + // Окончание не найдено |
|
| 1523 | + $q = substr($l, 0, $pos-1); |
|
| 1524 | + $l = substr($l, $pos+ strlen($eol)); |
|
| 1525 | + $seek = strlen($l); |
|
| 1526 | + $r = 0; |
|
| 1527 | + return $q; |
|
| 1528 | + } |
|
| 1529 | + } |
|
| 1530 | + $r = 0; |
|
| 1531 | + } |
|
| 1532 | + if (!empty($l)) { |
|
| 1533 | + return $l; |
|
| 1534 | + } |
|
| 1535 | + return false; |
|
| 1536 | 1536 | } |
| 1537 | 1537 | function sxd_check($n, $obj, $filt){ |
| 1538 | - return isset($obj[$n]) || ($filt && preg_match($filt, $n)); |
|
| 1538 | + return isset($obj[$n]) || ($filt && preg_match($filt, $n)); |
|
| 1539 | 1539 | } |
| 1540 | 1540 | function sxd_php2json($obj){ |
| 1541 | - if(count($obj) == 0) return '[]'; |
|
| 1542 | - $is_obj = isset($obj[0]) && isset($obj[count($obj) - 1]) ? false : true; |
|
| 1543 | - $str = $is_obj ? '{' : '['; |
|
| 1541 | + if(count($obj) == 0) return '[]'; |
|
| 1542 | + $is_obj = isset($obj[0]) && isset($obj[count($obj) - 1]) ? false : true; |
|
| 1543 | + $str = $is_obj ? '{' : '['; |
|
| 1544 | 1544 | foreach ($obj AS $key => $value) { |
| 1545 | - $str .= $is_obj ? "'" . addcslashes($key, "\n\r\t'\\/") . "'" . ':' : ''; |
|
| 1545 | + $str .= $is_obj ? "'" . addcslashes($key, "\n\r\t'\\/") . "'" . ':' : ''; |
|
| 1546 | 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 | - elseif (is_numeric($value)) $str .= $value; |
|
| 1550 | - else $str .= "'" . addcslashes($value, "\n\r\t'\\/") . "'"; |
|
| 1551 | - $str .= ','; |
|
| 1549 | + elseif (is_numeric($value)) $str .= $value; |
|
| 1550 | + else $str .= "'" . addcslashes($value, "\n\r\t'\\/") . "'"; |
|
| 1551 | + $str .= ','; |
|
| 1552 | 1552 | } |
| 1553 | - return substr_replace($str, $is_obj ? '}' : ']', -1); |
|
| 1553 | + return substr_replace($str, $is_obj ? '}' : ']', -1); |
|
| 1554 | 1554 | } |
| 1555 | 1555 | function sxd_ver2int($ver){ |
| 1556 | - return preg_match("/^(\d+)\.(\d+)\.(\d+)/", $ver, $m) ? sprintf("%d%02d%02d", $m[1], $m[2], $m[3]) : 0; |
|
| 1556 | + return preg_match("/^(\d+)\.(\d+)\.(\d+)/", $ver, $m) ? sprintf("%d%02d%02d", $m[1], $m[2], $m[3]) : 0; |
|
| 1557 | 1557 | } |
| 1558 | 1558 | function sxd_error_handler($errno, $errmsg, $filename, $linenum, $vars){ |
| 1559 | 1559 | global $SXD; |
| 1560 | 1560 | if($SXD->try) return; |
| 1561 | - if($errno == 8192) return; |
|
| 1561 | + if($errno == 8192) return; |
|
| 1562 | 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 | - 128 => 'Compile Warning', 256 => 'MySQL Error', 512 => 'Warning', 1024 => 'Notice', |
|
| 1565 | - 2048 => 'Strict', 8192 => 'Deprecated', 16384 => 'Deprecated'); |
|
| 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"); |
|
| 1564 | + 128 => 'Compile Warning', 256 => 'MySQL Error', 512 => 'Warning', 1024 => 'Notice', |
|
| 1565 | + 2048 => 'Strict', 8192 => 'Deprecated', 16384 => 'Deprecated'); |
|
| 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"); |
|
| 1568 | 1568 | |
| 1569 | 1569 | if($errno == 8 || $errno == 1024) { |
| 1570 | - if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1571 | - else { |
|
| 1572 | - fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t3\t{$str}\n"); |
|
| 1573 | - } |
|
| 1574 | - } |
|
| 1570 | + if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1571 | + else { |
|
| 1572 | + fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t3\t{$str}\n"); |
|
| 1573 | + } |
|
| 1574 | + } |
|
| 1575 | 1575 | elseif($errno < 1024) { |
| 1576 | - $SXD->error = true; |
|
| 1577 | - if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1578 | - else { |
|
| 1579 | - $SXD->rtl[1] = time(); |
|
| 1580 | - $SXD->rtl[9] = 5; |
|
| 1581 | - fseek($SXD->fh_rtl, 0); |
|
| 1582 | - fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl)); |
|
| 1583 | - fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t4\t{$str}\n"); |
|
| 1584 | - unset($SXD->rtl); |
|
| 1585 | - } |
|
| 1576 | + $SXD->error = true; |
|
| 1577 | + if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1578 | + else { |
|
| 1579 | + $SXD->rtl[1] = time(); |
|
| 1580 | + $SXD->rtl[9] = 5; |
|
| 1581 | + fseek($SXD->fh_rtl, 0); |
|
| 1582 | + fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl)); |
|
| 1583 | + fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t4\t{$str}\n"); |
|
| 1584 | + unset($SXD->rtl); |
|
| 1585 | + } |
|
| 1586 | 1586 | |
| 1587 | - die; |
|
| 1588 | - } |
|
| 1587 | + die; |
|
| 1588 | + } |
|
| 1589 | 1589 | } |
| 1590 | 1590 | function sxd_esc($str, $quoted = true){ |
| 1591 | - return $quoted ? "'" . addcslashes($str, "\\\0\n\r\t\'") . "'" : addcslashes($str, "\\\0\n\r\t\'"); |
|
| 1591 | + return $quoted ? "'" . addcslashes($str, "\\\0\n\r\t\'") . "'" : addcslashes($str, "\\\0\n\r\t\'"); |
|
| 1592 | 1592 | } |
| 1593 | 1593 | function sxd_my_error(){ |
| 1594 | - trigger_error(mysql_error(), E_USER_ERROR); |
|
| 1594 | + trigger_error(mysql_error(), E_USER_ERROR); |
|
| 1595 | 1595 | } |
| 1596 | 1596 | function sxd_shutdown(){ |
| 1597 | - global $SXD; |
|
| 1598 | - if(isset($SXD->fh_rtl) && is_resource($SXD->fh_rtl) && !empty($SXD->rtl) && empty($SXD->error)) { |
|
| 1599 | - $SXD->rtl[1] = time(); |
|
| 1600 | - if(!empty($SXD->JOB['file_stp']) && file_exists(dirname(__FILE__) . '/' . $SXD->JOB['file_stp'])){ |
|
| 1601 | - $type = file_get_contents(dirname(__FILE__) . '/' . $SXD->JOB['file_stp']); |
|
| 1602 | - $SXD->rtl[9] = !empty($type) ? $type : 2; |
|
| 1603 | - } |
|
| 1604 | - else $SXD->rtl[9] = 5; |
|
| 1605 | - fseek($SXD->fh_rtl, 0); |
|
| 1606 | - fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl)); |
|
| 1607 | - } |
|
| 1597 | + global $SXD; |
|
| 1598 | + if(isset($SXD->fh_rtl) && is_resource($SXD->fh_rtl) && !empty($SXD->rtl) && empty($SXD->error)) { |
|
| 1599 | + $SXD->rtl[1] = time(); |
|
| 1600 | + if(!empty($SXD->JOB['file_stp']) && file_exists(dirname(__FILE__) . '/' . $SXD->JOB['file_stp'])){ |
|
| 1601 | + $type = file_get_contents(dirname(__FILE__) . '/' . $SXD->JOB['file_stp']); |
|
| 1602 | + $SXD->rtl[9] = !empty($type) ? $type : 2; |
|
| 1603 | + } |
|
| 1604 | + else $SXD->rtl[9] = 5; |
|
| 1605 | + fseek($SXD->fh_rtl, 0); |
|
| 1606 | + fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl)); |
|
| 1607 | + } |
|
| 1608 | 1608 | } |
| 1609 | 1609 | function sxd_antimagic($arr){ |
| 1610 | - return is_array($arr) ? array_map('sxd_antimagic', $arr) : stripslashes($arr); |
|
| 1610 | + return is_array($arr) ? array_map('sxd_antimagic', $arr) : stripslashes($arr); |
|
| 1611 | 1611 | } |
@@ -33,27 +33,27 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -14,7 +14,9 @@ discard block |
||
| 14 | 14 | header("Content-Type: text/html; charset=utf-8"); |
| 15 | 15 | //error_reporting(E_ALL); |
| 16 | 16 | error_reporting(0); |
| 17 | -if (!ini_get('zlib.output_compression') && function_exists('ob_gzhandler')) ob_start('ob_gzhandler'); |
|
| 17 | +if (!ini_get('zlib.output_compression') && function_exists('ob_gzhandler')) { |
|
| 18 | + ob_start('ob_gzhandler'); |
|
| 19 | +} |
|
| 18 | 20 | set_error_handler('sxd_error_handler'); |
| 19 | 21 | register_shutdown_function('sxd_shutdown'); |
| 20 | 22 | $SXD = new Sypex_Dumper(); |
@@ -33,7 +35,7 @@ discard block |
||
| 33 | 35 | define('V_PHP', sxd_ver2int(phpversion())); |
| 34 | 36 | $this->name = 'Sypex Dumper 2.0.11'; |
| 35 | 37 | } |
| 36 | - function loadLang($lng_name = 'auto'){ |
|
| 38 | + function loadLang($lng_name = 'auto') { |
|
| 37 | 39 | if($lng_name == 'auto'){ |
| 38 | 40 | include('lang/list.php'); |
| 39 | 41 | $this->langs = &$langs; |
@@ -47,20 +49,26 @@ discard block |
||
| 47 | 49 | } |
| 48 | 50 | } |
| 49 | 51 | } |
| 50 | - if(file_exists("lang/lng_{$lng_name}.php")) include("lang/lng_{$lng_name}.php"); |
|
| 51 | - else include("lang/lng_en.php"); |
|
| 52 | + if(file_exists("lang/lng_{$lng_name}.php")) { |
|
| 53 | + include("lang/lng_{$lng_name}.php"); |
|
| 54 | + } else { |
|
| 55 | + include("lang/lng_en.php"); |
|
| 56 | + } |
|
| 52 | 57 | $this->LNG = &$LNG; |
| 53 | 58 | $this->LNG['name'] = $lng_name; |
| 54 | 59 | return true; |
| 55 | 60 | } |
| 56 | - function init($args = false){ |
|
| 61 | + function init($args = false) { |
|
| 57 | 62 | if (get_magic_quotes_gpc()) { |
| 58 | 63 | $_POST = sxd_antimagic($_POST); |
| 59 | 64 | } |
| 60 | 65 | include('cfg.php'); |
| 61 | 66 | $this->loadLang($CFG['lang']); |
| 62 | - if (!ini_get('safe_mode') && function_exists('set_time_limit') && strpos(ini_get('disable_functions'), 'set_time_limit') === false) @set_time_limit($CFG['time_web']); |
|
| 63 | - elseif (ini_get('max_execution_time') < $CFG['time_web']) $CFG['time_web'] = ini_get('max_execution_time'); |
|
| 67 | + if (!ini_get('safe_mode') && function_exists('set_time_limit') && strpos(ini_get('disable_functions'), 'set_time_limit') === false) { |
|
| 68 | + @set_time_limit($CFG['time_web']); |
|
| 69 | + } elseif (ini_get('max_execution_time') < $CFG['time_web']) { |
|
| 70 | + $CFG['time_web'] = ini_get('max_execution_time'); |
|
| 71 | + } |
|
| 64 | 72 | $this->CFG = &$CFG; |
| 65 | 73 | $this->try = false; |
| 66 | 74 | $this->virtualize = false; |
@@ -93,13 +101,17 @@ discard block |
||
| 93 | 101 | if($auth && !empty($this->CFG['sjob'])){ |
| 94 | 102 | $this->ajax($this->loadJob($this->CFG['sjob'])); |
| 95 | 103 | 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']); |
|
| 104 | + if(file_exists($this->JOB['file_log'])) { |
|
| 105 | + unlink($this->JOB['file_log']); |
|
| 106 | + } |
|
| 107 | + if(file_exists($this->JOB['file_rtl'])) { |
|
| 108 | + unlink($this->JOB['file_rtl']); |
|
| 109 | + } |
|
| 110 | + } else { |
|
| 111 | + echo 'Auth error'; |
|
| 98 | 112 | } |
| 99 | - else echo 'Auth error'; |
|
| 100 | 113 | exit; |
| 101 | - } |
|
| 102 | - elseif(!empty($this->CFG['auth'])){ // Авторизация |
|
| 114 | + } elseif(!empty($this->CFG['auth'])){ // Авторизация |
|
| 103 | 115 | $auth = false; |
| 104 | 116 | $sfile = 'ses.php'; |
| 105 | 117 | |
@@ -129,18 +141,25 @@ discard block |
||
| 129 | 141 | $auth = $this->connect($host, $port, $user, $pass); |
| 130 | 142 | break; |
| 131 | 143 | default: $file = 'auth_' . $a . '.php'; |
| 132 | - if(!file_exists($file)) continue; |
|
| 144 | + if(!file_exists($file)) { |
|
| 145 | + continue; |
|
| 146 | + } |
|
| 133 | 147 | include $file; |
| 134 | 148 | } |
| 135 | - if($auth) break; |
|
| 149 | + if($auth) { |
|
| 150 | + break; |
|
| 151 | + } |
|
| 136 | 152 | } |
| 137 | 153 | if($auth){ |
| 138 | 154 | $key = md5(rand(1,100000) . $user . microtime()); |
| 139 | 155 | $CFG['lang'] = $this->LNG['name']; |
| 140 | 156 | $_COOKIE['sxd'] = $key; |
| 141 | 157 | $this->saveCFG(); |
| 142 | - if(V_PHP > 50200) setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false, true); |
|
| 143 | - else setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false); |
|
| 158 | + if(V_PHP > 50200) { |
|
| 159 | + setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false, true); |
|
| 160 | + } else { |
|
| 161 | + setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0, '', '', false); |
|
| 162 | + } |
|
| 144 | 163 | header("Location: ./"); |
| 145 | 164 | exit; |
| 146 | 165 | } |
@@ -164,16 +183,22 @@ discard block |
||
| 164 | 183 | exit; |
| 165 | 184 | } |
| 166 | 185 | } |
| 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; |
|
| 186 | + if(empty($_POST['ajax']['act']) || $_POST['ajax']['act'] != 'save_connect') { |
|
| 187 | + $this->connect(); |
|
| 188 | + } |
|
| 189 | + if(isset($_POST['ajax'])) { |
|
| 190 | + $this->ajax($_POST['ajax']); |
|
| 191 | + } else { |
|
| 192 | + $this->main(); |
|
| 193 | + } |
|
| 194 | + exit; |
|
| 170 | 195 | } |
| 171 | - function saveToFile($name, $content){ |
|
| 196 | + function saveToFile($name, $content) { |
|
| 172 | 197 | $fp = fopen($name, "w"); |
| 173 | 198 | fwrite($fp, $content); |
| 174 | 199 | fclose($fp); |
| 175 | 200 | } |
| 176 | - function connect($host = null, $port = null, $user = null, $pass = null){ |
|
| 201 | + function connect($host = null, $port = null, $user = null, $pass = null) { |
|
| 177 | 202 | $this->error = ''; |
| 178 | 203 | $this->try = true; |
| 179 | 204 | if(!empty($user) && isset($pass)) { |
@@ -183,18 +208,20 @@ discard block |
||
| 183 | 208 | $this->CFG['my_pass'] = $pass; |
| 184 | 209 | } |
| 185 | 210 | 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 | - else mysql_query('SET NAMES utf8') or sxd_my_error(); |
|
| 211 | + if(V_PHP > 50202) { |
|
| 212 | + mysql_set_charset('utf8') or sxd_my_error(); |
|
| 213 | + } else { |
|
| 214 | + mysql_query('SET NAMES utf8') or sxd_my_error(); |
|
| 215 | + } |
|
| 188 | 216 | define('V_MYSQL', sxd_ver2int(mysql_get_server_info())); |
| 189 | - } |
|
| 190 | - else { |
|
| 217 | + } else { |
|
| 191 | 218 | define('V_MYSQL', 0); |
| 192 | 219 | $this->error = "sxd.actions.tab_connects();alert(" . sxd_esc(mysql_error()) . ");"; |
| 193 | 220 | } |
| 194 | 221 | $this->try = false; |
| 195 | 222 | return V_MYSQL ? true: false; |
| 196 | 223 | } |
| 197 | - function main(){ |
|
| 224 | + function main() { |
|
| 198 | 225 | // Тулбар |
| 199 | 226 | $this->VAR['toolbar'] = sxd_php2json( |
| 200 | 227 | array( |
@@ -240,7 +267,9 @@ discard block |
||
| 240 | 267 | $this->addCombo('db_charset', 0, 9, 'collation', $this->getCollationList()) . |
| 241 | 268 | $this->addCombo('db_charset_col', 0, 15, 'collation:db_charset') |
| 242 | 269 | ; |
| 243 | - if (!V_MYSQL) $this->VAR['combos'] .= $this->error; |
|
| 270 | + if (!V_MYSQL) { |
|
| 271 | + $this->VAR['combos'] .= $this->error; |
|
| 272 | + } |
|
| 244 | 273 | $this->VAR['combos'] .= $this->getSavedJobs() . "sxd.confirms = {$this->CFG['confirm']};sxd.actions.dblist();"; |
| 245 | 274 | $this->LNG['del_date'] = sprintf($this->LNG['del_date'], '<input type="text" id="del_time" class=txt style="width:24px;" maxlength="3">'); |
| 246 | 275 | $this->LNG['del_count'] = sprintf($this->LNG['del_count'], '<input id="del_count" type="text" class=txt style="width:18px;" maxlength="2">'); |
@@ -248,11 +277,11 @@ discard block |
||
| 248 | 277 | include('tmpl.php'); |
| 249 | 278 | echo sxd_tpl_page(); |
| 250 | 279 | } |
| 251 | - function addCombo($name, $sel, $ico, $opt_name, $opts = ''){ |
|
| 280 | + function addCombo($name, $sel, $ico, $opt_name, $opts = '') { |
|
| 252 | 281 | $opts = !empty($opts) ? "{{$opt_name}:" . sxd_php2json($opts) . '}' : "'{$opt_name}'"; |
| 253 | 282 | return "sxd.addCombo('{$name}', '{$sel}', {$ico}, {$opts});\n"; |
| 254 | 283 | } |
| 255 | - function ajax($req){ |
|
| 284 | + function ajax($req) { |
|
| 256 | 285 | $res = ''; |
| 257 | 286 | $act = $req['act']; |
| 258 | 287 | if($req['act'] == 'run_savedjob'){ |
@@ -298,7 +327,9 @@ discard block |
||
| 298 | 327 | case 'delete_file': |
| 299 | 328 | if(preg_match('/^[^\/]+?\.sql(\.(gz|bz2))?$/', $req['name'])) { |
| 300 | 329 | $file = $this->CFG['backup_path'] . $req['name']; |
| 301 | - if(file_exists($file)) unlink($file); |
|
| 330 | + if(file_exists($file)) { |
|
| 331 | + unlink($file); |
|
| 332 | + } |
|
| 302 | 333 | } |
| 303 | 334 | $res = $this->getFileListExtended(); |
| 304 | 335 | break; |
@@ -327,40 +358,45 @@ discard block |
||
| 327 | 358 | } |
| 328 | 359 | echo $res; |
| 329 | 360 | } |
| 330 | - function loadJob($job){ |
|
| 361 | + function loadJob($job) { |
|
| 331 | 362 | $file = $this->CFG['backup_path'] . 'sj_' . (is_array($job) ? $job['job'] : $job) . '.job.php'; |
| 332 | - if(!file_exists($file)) return; |
|
| 363 | + if(!file_exists($file)) { |
|
| 364 | + return; |
|
| 365 | + } |
|
| 333 | 366 | include($file); |
| 334 | 367 | $JOB['act'] = $JOB['type']; |
| 335 | 368 | $JOB['type'] = 'run'; |
| 336 | 369 | return $JOB; |
| 337 | 370 | } |
| 338 | - function deleteDB($name){ |
|
| 371 | + function deleteDB($name) { |
|
| 339 | 372 | $r = mysql_query('DROP DATABASE `' . sxd_esc($name, false) . '`') or sxd_my_error(); |
| 340 | 373 | if($r){ |
| 341 | 374 | echo "sxd.clearOpt('db');sxd.addOpt(" . sxd_php2json(array('db' => $this->getDBList())) . ");sxd.combos.services_db.select(0,'-');"; |
| 342 | - } |
|
| 343 | - else |
|
| 344 | - echo "alert(" . sxd_esc(mysql_error()) . ");"; |
|
| 375 | + } else { |
|
| 376 | + echo "alert(" . sxd_esc(mysql_error()) . ");"; |
|
| 377 | + } |
|
| 345 | 378 | } |
| 346 | - function cfg2js($cfg){ |
|
| 379 | + function cfg2js($cfg) { |
|
| 347 | 380 | foreach($cfg AS $k => $v){ |
| 348 | 381 | $cfg[$k] = sxd_esc($v, false); |
| 349 | 382 | } |
| 350 | 383 | return $cfg; |
| 351 | 384 | } |
| 352 | - function addDb($req){ |
|
| 385 | + function addDb($req) { |
|
| 353 | 386 | $r = mysql_query('CREATE DATABASE `' . sxd_esc($req['name'], false) . '`' . (V_MYSQL > 40100 ? "CHARACTER SET {$req['charset']} COLLATE {$req['collate']}" : '')); |
| 354 | - if($r) |
|
| 355 | - echo "sxd.addOpt(" . sxd_php2json(array('db' => array($req['name'] => "{$req['name']} (0)"))) . ");"; |
|
| 356 | - else |
|
| 357 | - sxd_my_error(); |
|
| 387 | + if($r) { |
|
| 388 | + echo "sxd.addOpt(" . sxd_php2json(array('db' => array($req['name'] => "{$req['name']} (0)"))) . ");"; |
|
| 389 | + } else { |
|
| 390 | + sxd_my_error(); |
|
| 391 | + } |
|
| 358 | 392 | } |
| 359 | - function saveConnect($req){ |
|
| 393 | + function saveConnect($req) { |
|
| 360 | 394 | $this->CFG['my_host'] = $req['host']; |
| 361 | 395 | $this->CFG['my_port'] = (int)$req['port']; |
| 362 | 396 | $this->CFG['my_user'] = $req['user']; |
| 363 | - if(isset($req['pass'])) $this->CFG['my_pass'] = $req['pass']; |
|
| 397 | + if(isset($req['pass'])) { |
|
| 398 | + $this->CFG['my_pass'] = $req['pass']; |
|
| 399 | + } |
|
| 364 | 400 | $this->CFG['my_comp'] = $req['comp'] ? 1 : 0; |
| 365 | 401 | $this->CFG['my_db'] = $req['db']; |
| 366 | 402 | $this->saveCFG(); |
@@ -372,12 +408,11 @@ discard block |
||
| 372 | 408 | 'collation' => $this->getCollationList() |
| 373 | 409 | ); |
| 374 | 410 | echo "sxd.clearOpt('db');sxd.clearOpt('charset');sxd.clearOpt('collation');sxd.addOpt(" . sxd_php2json($tmp) . ");sxd.combos.backup_db.select(0,'-');sxd.combos.restore_db.select(0,'-');sxd.combos.services_db.select(0,'-');sxd.combos.backup_charset.select(0,'-');sxd.combos.services_db.select(0,'-');sxd.combos.db_charset.select(0,'-');"; |
| 375 | - } |
|
| 376 | - else { |
|
| 411 | + } else { |
|
| 377 | 412 | echo $this->error; |
| 378 | 413 | } |
| 379 | 414 | } |
| 380 | - function saveOptions($req){ |
|
| 415 | + function saveOptions($req) { |
|
| 381 | 416 | $this->CFG['time_web'] = $req['time_web']; |
| 382 | 417 | $this->CFG['time_cron'] = $req['time_cron']; |
| 383 | 418 | $this->CFG['backup_path'] = $req['backup_path']; |
@@ -389,7 +424,7 @@ discard block |
||
| 389 | 424 | $this->CFG['confirm'] = $req['confirm']; |
| 390 | 425 | $this->saveCFG(); |
| 391 | 426 | } |
| 392 | - function saveCFG(){ |
|
| 427 | + function saveCFG() { |
|
| 393 | 428 | if (isset($_COOKIE['sxd'])) { |
| 394 | 429 | $this->SES[$_COOKIE['sxd']] = array('cfg' => $this->CFG, 'time' => time(), 'lng' => $this->LNG['name']); |
| 395 | 430 | $this->saveToFile('ses.php', "<?php\n\$SES = " . var_export($this->SES, true) . ";\n" . "?>"); |
@@ -406,11 +441,17 @@ discard block |
||
| 406 | 441 | $filter = $object = array(); |
| 407 | 442 | $this->createFilters($job['obj'], $filter, $object); |
| 408 | 443 | $r = mysql_query('SHOW TABLE STATUS') or sxd_my_error(); |
| 409 | - if (!$r) return; |
|
| 444 | + if (!$r) { |
|
| 445 | + return; |
|
| 446 | + } |
|
| 410 | 447 | $tables = array(); |
| 411 | 448 | 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']}`"; |
|
| 449 | + if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) { |
|
| 450 | + continue; |
|
| 451 | + } |
|
| 452 | + if(sxd_check($item['Name'], $object['TA'], $filter['TA'])) { |
|
| 453 | + $tables[] = "`{$item['Name']}`"; |
|
| 454 | + } |
|
| 414 | 455 | } |
| 415 | 456 | $sql = $serv[$job['type']] . ' TABLE ' . implode(',', $tables); |
| 416 | 457 | |
@@ -419,7 +460,9 @@ discard block |
||
| 419 | 460 | } |
| 420 | 461 | |
| 421 | 462 | $r = mysql_query($sql) or sxd_my_error(); |
| 422 | - if (!$r) return; |
|
| 463 | + if (!$r) { |
|
| 464 | + return; |
|
| 465 | + } |
|
| 423 | 466 | $res = array(); |
| 424 | 467 | while($item = mysql_fetch_row($r)){ |
| 425 | 468 | $res[] = $item; |
@@ -427,7 +470,7 @@ discard block |
||
| 427 | 470 | echo 'sxd.result.add(' . sxd_php2json($res). ');'; |
| 428 | 471 | } |
| 429 | 472 | } |
| 430 | - function createFilters(&$obj, &$filter, &$object){ |
|
| 473 | + function createFilters(&$obj, &$filter, &$object) { |
|
| 431 | 474 | $types = array('TA', 'TC', 'VI', 'PR', 'FU', 'TR', 'EV'); |
| 432 | 475 | foreach($types AS $type){ |
| 433 | 476 | $filter[$type] = array(); |
@@ -436,8 +479,7 @@ discard block |
||
| 436 | 479 | foreach($obj[$type] AS $v){ |
| 437 | 480 | if(strpos($v, '*') !== false) { |
| 438 | 481 | $filter[$type][] = str_replace('*', '.*?', $v); |
| 439 | - } |
|
| 440 | - else { |
|
| 482 | + } else { |
|
| 441 | 483 | $object[$type][$v] = true; |
| 442 | 484 | } |
| 443 | 485 | } |
@@ -445,7 +487,7 @@ discard block |
||
| 445 | 487 | } |
| 446 | 488 | } |
| 447 | 489 | } |
| 448 | - function closeConnect(){ |
|
| 490 | + function closeConnect() { |
|
| 449 | 491 | //return; |
| 450 | 492 | @ignore_user_abort(1); |
| 451 | 493 | header("SXD: {$this->name}"); |
@@ -456,18 +498,19 @@ discard block |
||
| 456 | 498 | @ob_end_flush(); |
| 457 | 499 | @flush(); |
| 458 | 500 | } |
| 459 | - function resumeJob($job){ |
|
| 501 | + function resumeJob($job) { |
|
| 460 | 502 | $this->closeConnect(); |
| 461 | 503 | include($this->CFG['backup_path'] . $job['job'] . '.job.php'); |
| 462 | 504 | $this->JOB = &$JOB; |
| 463 | - if(file_exists($this->JOB['file_stp'])) unlink($this->JOB['file_stp']); |
|
| 505 | + if(file_exists($this->JOB['file_stp'])) { |
|
| 506 | + unlink($this->JOB['file_stp']); |
|
| 507 | + } |
|
| 464 | 508 | $this->fh_rtl = fopen($this->JOB['file_rtl'], 'r+b'); |
| 465 | 509 | $this->fh_log = fopen($this->JOB['file_log'], 'ab'); |
| 466 | 510 | $t = fgets($this->fh_rtl); |
| 467 | 511 | if(!empty($t)){ |
| 468 | 512 | $this->rtl = explode("\t", $t); |
| 469 | - } |
|
| 470 | - else { |
|
| 513 | + } else { |
|
| 471 | 514 | $this->addLog($this->LNG['not_found_rtl']); |
| 472 | 515 | exit; |
| 473 | 516 | } |
@@ -477,8 +520,11 @@ discard block |
||
| 477 | 520 | $this->rtl[1] = time(); |
| 478 | 521 | $this->rtl[9] = 0; |
| 479 | 522 | fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
| 480 | - if ($this->JOB['act'] == 'backup') $this->runBackupJob(true); |
|
| 481 | - elseif ($this->JOB['act'] == 'restore') $this->runRestoreJob(true); |
|
| 523 | + if ($this->JOB['act'] == 'backup') { |
|
| 524 | + $this->runBackupJob(true); |
|
| 525 | + } elseif ($this->JOB['act'] == 'restore') { |
|
| 526 | + $this->runRestoreJob(true); |
|
| 527 | + } |
|
| 482 | 528 | } |
| 483 | 529 | function addRestoreJob($job) { |
| 484 | 530 | $this->closeConnect(); |
@@ -493,9 +539,10 @@ discard block |
||
| 493 | 539 | $this->tab_rows = array(); |
| 494 | 540 | $todo = array(); |
| 495 | 541 | 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 | - if (empty($list)) continue; |
|
| 542 | + if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} elseif(empty($object[$t]) && empty($filter[$t])) {continue;} |
|
| 543 | + if (empty($list)) { |
|
| 544 | + continue; |
|
| 545 | + } |
|
| 499 | 546 | |
| 500 | 547 | foreach($list AS $item){ |
| 501 | 548 | switch($t){ |
@@ -503,11 +550,11 @@ discard block |
||
| 503 | 550 | $type = ''; |
| 504 | 551 | if(sxd_check($item[0], $object['TA'], $filter['TA'])){ |
| 505 | 552 | $type = empty($item[1]) ? 'TC' : 'TA'; |
| 506 | - } |
|
| 507 | - elseif(sxd_check($item[0], $object['TC'], $filter['TC'])) { |
|
| 553 | + } elseif(sxd_check($item[0], $object['TC'], $filter['TC'])) { |
|
| 508 | 554 | $type = 'TC'; |
| 555 | + } else { |
|
| 556 | + continue; |
|
| 509 | 557 | } |
| 510 | - else continue; |
|
| 511 | 558 | $todo['TA'][] = array($type, $item[0], $item[1], $item[2]); |
| 512 | 559 | $rows += $type == 'TA' ? $item[1] : 0; |
| 513 | 560 | break; |
@@ -522,15 +569,21 @@ discard block |
||
| 522 | 569 | $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
| 523 | 570 | $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
| 524 | 571 | $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']); |
|
| 572 | + if(file_exists($this->JOB['file_stp'])) { |
|
| 573 | + unlink($this->JOB['file_stp']); |
|
| 574 | + } |
|
| 526 | 575 | |
| 527 | 576 | $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
| 528 | 577 | // Для чужих дампов определяем разделители строк |
| 529 | 578 | if(is_null($this->JOB['obj'])) { |
| 530 | 579 | $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"; |
|
| 533 | - else $this->JOB['eol'] = "\r"; |
|
| 580 | + if(strpos($s, "\r\n")) { |
|
| 581 | + $this->JOB['eol'] = "\r\n"; |
|
| 582 | + } elseif(strpos($s, "\n")) { |
|
| 583 | + $this->JOB['eol'] = "\n"; |
|
| 584 | + } else { |
|
| 585 | + $this->JOB['eol'] = "\r"; |
|
| 586 | + } |
|
| 534 | 587 | $bom = strncmp($s, "\xEF\xBB\xBF", 3) == 0 ? 3 : ((strncmp($s, "\xFE\xFF", 2) == 0 || strncmp($s, "\xFF\xFE", 2) == 0) ? 2 : 0); |
| 535 | 588 | fseek($this->fh_tmp, $bom); |
| 536 | 589 | } |
@@ -543,16 +596,22 @@ discard block |
||
| 543 | 596 | $this->addLog("{$this->LNG['combo_file']} {$this->JOB['file']}"); |
| 544 | 597 | $this->runRestoreJob(); |
| 545 | 598 | } |
| 546 | - function runRestoreJob($continue = false){ |
|
| 599 | + function runRestoreJob($continue = false) { |
|
| 547 | 600 | $ei = false; |
| 548 | 601 | if($continue){ |
| 549 | 602 | $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'r'); |
| 550 | 603 | 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; |
|
| 604 | + if(!empty($this->rtl[6])) { |
|
| 605 | + $this->setNames($this->JOB['correct'] == 1 && !empty($this->JOB['charset']) ? $this->JOB['charset'] : $this->rtl[6]); |
|
| 606 | + } |
|
| 607 | + if($this->rtl[7] < $this->rtl[10]) { |
|
| 608 | + $ei = true; |
|
| 609 | + } |
|
| 553 | 610 | } |
| 554 | 611 | mysql_select_db($this->JOB['db']); |
| 555 | - if(is_null($this->JOB['obj'])) $this->runRestoreJobForeign($continue); |
|
| 612 | + if(is_null($this->JOB['obj'])) { |
|
| 613 | + $this->runRestoreJobForeign($continue); |
|
| 614 | + } |
|
| 556 | 615 | //mysql_query("SET NAMES 'UTF8'"); |
| 557 | 616 | $types = array('VI' => 'View', 'PR' => 'Procedure', 'FU' => 'Function', 'TR' => 'Trigger', 'EV' => 'Event'); |
| 558 | 617 | $fcache = ''; |
@@ -583,8 +642,12 @@ discard block |
||
| 583 | 642 | if(V_MYSQL > 40014) { |
| 584 | 643 | mysql_query("SET UNIQUE_CHECKS=0"); |
| 585 | 644 | 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"); |
|
| 645 | + if(V_MYSQL > 40101) { |
|
| 646 | + mysql_query("SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'"); |
|
| 647 | + } |
|
| 648 | + if(V_MYSQL > 40111) { |
|
| 649 | + mysql_query("SET SQL_NOTES=0"); |
|
| 650 | + } |
|
| 588 | 651 | } |
| 589 | 652 | $log_sql = false; |
| 590 | 653 | $fields = ''; |
@@ -648,13 +711,16 @@ discard block |
||
| 648 | 711 | case 'C': |
| 649 | 712 | $ex = 1; |
| 650 | 713 | if (preg_match('/^CREATE TABLE `/', $q)) { |
| 651 | - if($this->JOB['strategy'] != 0 && isset($tab_exists[$this->rtl[5]])) $ex = 0; |
|
| 652 | - else { |
|
| 714 | + if($this->JOB['strategy'] != 0 && isset($tab_exists[$this->rtl[5]])) { |
|
| 715 | + $ex = 0; |
|
| 716 | + } else { |
|
| 653 | 717 | $ex = 1; |
| 654 | 718 | if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
| 655 | 719 | $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
| 656 | 720 | } |
| 657 | - if(!empty($this->JOB['autoinc'])) $q = preg_replace("/AUTO_INCREMENT=\d+/", "AUTO_INCREMENT=1", $q); |
|
| 721 | + if(!empty($this->JOB['autoinc'])) { |
|
| 722 | + $q = preg_replace("/AUTO_INCREMENT=\d+/", "AUTO_INCREMENT=1", $q); |
|
| 723 | + } |
|
| 658 | 724 | } |
| 659 | 725 | // Достаем имена полей таблицы |
| 660 | 726 | $fields = $this->JOB['strategy'] > 0 && preg_match_all('/^\s+(`.+?`) /m', $q, $f, PREG_PATTERN_ORDER) ? '(' . implode(',', $f[1]) . ')' : ''; |
@@ -675,11 +741,9 @@ discard block |
||
| 675 | 741 | if($tc && ($this->JOB['strategy'] == 0 || isset($tab_exists[$m[2]]))) { |
| 676 | 742 | mysql_query("{$tc} `{$m[2]}`") or sxd_my_error(); |
| 677 | 743 | } |
| 678 | - } |
|
| 679 | - elseif($m[1] == 'TD'){ |
|
| 744 | + } elseif($m[1] == 'TD'){ |
|
| 680 | 745 | $ei = 1; |
| 681 | - } |
|
| 682 | - else { |
|
| 746 | + } else { |
|
| 683 | 747 | $this->rtl[4] = $m[1]; |
| 684 | 748 | $this->rtl[5] = $m[2]; |
| 685 | 749 | $this->rtl[7] = 0; |
@@ -704,8 +768,7 @@ discard block |
||
| 704 | 768 | if($insert) { |
| 705 | 769 | $c = 1; |
| 706 | 770 | } |
| 707 | - } |
|
| 708 | - else { |
|
| 771 | + } else { |
|
| 709 | 772 | error_log(date('r') . "\n----------\n{$q}\n", 3, "backup/sql_error.log"); |
| 710 | 773 | sxd_my_error(); |
| 711 | 774 | } |
@@ -731,7 +794,9 @@ discard block |
||
| 731 | 794 | $this->rtl[7] = 0; |
| 732 | 795 | $this->rtl[8] = 0; |
| 733 | 796 | foreach($this->JOB['todo']['TA'] AS $tab){ |
| 734 | - if ($tab[0] == 'TC') continue; |
|
| 797 | + if ($tab[0] == 'TC') { |
|
| 798 | + continue; |
|
| 799 | + } |
|
| 735 | 800 | mysql_query("ALTER TABLE `{$tab[1]}` ENABLE KEYS") or sxd_my_error(); |
| 736 | 801 | $this->rtl[1] = time(); |
| 737 | 802 | $this->rtl[5] = $tab[1]; |
@@ -747,7 +812,7 @@ discard block |
||
| 747 | 812 | fclose($this->fh_log); |
| 748 | 813 | fclose($this->fh_rtl); |
| 749 | 814 | } |
| 750 | - function runRestoreJobForeign($continue = false){ |
|
| 815 | + function runRestoreJobForeign($continue = false) { |
|
| 751 | 816 | $ei = false; |
| 752 | 817 | |
| 753 | 818 | $fcache = ''; |
@@ -770,7 +835,9 @@ discard block |
||
| 770 | 835 | $delimiter = ";"; |
| 771 | 836 | while($q = sxd_read_sql($this->fh_tmp, $seek, $ei, $delimiter, $this->JOB['eol'])){ |
| 772 | 837 | $q = ltrim($q); |
| 773 | - if(empty($q)) break; |
|
| 838 | + if(empty($q)) { |
|
| 839 | + break; |
|
| 840 | + } |
|
| 774 | 841 | if($time_old < time()) { |
| 775 | 842 | if(file_exists($this->JOB['file_stp'])){ |
| 776 | 843 | $type = file_get_contents($this->JOB['file_stp']); |
@@ -829,8 +896,7 @@ discard block |
||
| 829 | 896 | //mysql_query("DROP TABLE IF EXISTS `{$tab}`"); |
| 830 | 897 | if((!empty($this->JOB['correct']) && !empty($this->JOB['charset']))){ |
| 831 | 898 | $q = preg_replace('/(DEFAULT)?\s*(CHARSET|CHARACTER SET|COLLATE)[=\s]+\w+/i', '', $q) . (V_MYSQL < 40100 ? '' : ' DEFAULT CHARSET=' . $this->JOB['charset']); |
| 832 | - } |
|
| 833 | - elseif(empty($this->JOB['charset'])){ |
|
| 899 | + } elseif(empty($this->JOB['charset'])){ |
|
| 834 | 900 | if(preg_match("/(CHARACTER SET|CHARSET)[=\s]+(\w+)/i", $q, $charset)){ |
| 835 | 901 | $this->setNames($charset[2]); |
| 836 | 902 | } |
@@ -849,8 +915,9 @@ discard block |
||
| 849 | 915 | $this->JOB['charset'] = $m[1]; |
| 850 | 916 | $this->setNames($this->JOB['charset']); |
| 851 | 917 | $ex = 0; |
| 918 | + } else { |
|
| 919 | + $ex = 1; |
|
| 852 | 920 | } |
| 853 | - else $ex = 1; |
|
| 854 | 921 | break; |
| 855 | 922 | default: |
| 856 | 923 | $insert = ''; |
@@ -868,8 +935,7 @@ discard block |
||
| 868 | 935 | if($insert) { |
| 869 | 936 | $c = 1; |
| 870 | 937 | } |
| 871 | - } |
|
| 872 | - else { |
|
| 938 | + } else { |
|
| 873 | 939 | error_log("-----------------\n{$q}\n", 3, "error.log"); |
| 874 | 940 | sxd_my_error(); |
| 875 | 941 | } |
@@ -914,17 +980,22 @@ discard block |
||
| 914 | 980 | $queries[] = array("PROCEDURE STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'PR'); |
| 915 | 981 | $queries[] = array("FUNCTION STATUS WHERE db='{$this->JOB['db']}'", 'Name', 'FU'); |
| 916 | 982 | $queries[] = array('TRIGGERS', 'Trigger', 'TR'); |
| 917 | - if(V_MYSQL > 50100) $queries[] = array('EVENTS', 'Name', 'EV'); |
|
| 983 | + if(V_MYSQL > 50100) { |
|
| 984 | + $queries[] = array('EVENTS', 'Name', 'EV'); |
|
| 985 | + } |
|
| 918 | 986 | } |
| 919 | 987 | $todo = $header = array(); |
| 920 | 988 | $tabs = $rows = 0; |
| 921 | 989 | $only_create = explode(' ', $this->CFG['only_create']); |
| 922 | 990 | foreach($queries AS $query){ |
| 923 | 991 | $t = $query[2]; |
| 924 | - if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
|
| 925 | - elseif(empty($object[$t]) && empty($filter[$t])) continue; |
|
| 992 | + if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} elseif(empty($object[$t]) && empty($filter[$t])) { |
|
| 993 | + continue; |
|
| 994 | + } |
|
| 926 | 995 | $r = mysql_query('SHOW ' . $query[0]) or sxd_my_error(); |
| 927 | - if (!$r) continue; |
|
| 996 | + if (!$r) { |
|
| 997 | + continue; |
|
| 998 | + } |
|
| 928 | 999 | $todo[$t] = array(); |
| 929 | 1000 | $header[$t] = array(); |
| 930 | 1001 | |
@@ -939,16 +1010,15 @@ discard block |
||
| 939 | 1010 | $header['VI']= array(); |
| 940 | 1011 | } |
| 941 | 1012 | continue; |
| 942 | - } |
|
| 943 | - elseif(sxd_check($n, $object['TA'], $filter['TA'])){ |
|
| 1013 | + } elseif(sxd_check($n, $object['TA'], $filter['TA'])){ |
|
| 944 | 1014 | $engine = V_MYSQL > 40101 ? $item['Engine'] : $item['Type']; |
| 945 | 1015 | $t = in_array($engine, $only_create) ? 'TC' : 'TA'; |
| 946 | - } |
|
| 947 | - elseif(sxd_check($n, $object['TC'], $filter['TC'])) { |
|
| 1016 | + } elseif(sxd_check($n, $object['TC'], $filter['TC'])) { |
|
| 948 | 1017 | $t = 'TC'; |
| 949 | 1018 | $item['Rows'] = $item['Data_length'] = ''; |
| 1019 | + } else { |
|
| 1020 | + continue; |
|
| 950 | 1021 | } |
| 951 | - else continue; |
|
| 952 | 1022 | $todo['TA'][] = array($t, $n, !empty($item['Collation']) ? $item['Collation'] : '', $item['Auto_increment'], $item['Rows'], $item['Data_length']); |
| 953 | 1023 | $header['TA'][] = "{$n}`{$item['Rows']}`{$item['Data_length']}"; |
| 954 | 1024 | $tabs++; |
@@ -979,7 +1049,9 @@ discard block |
||
| 979 | 1049 | foreach($views AS $n => $view) { |
| 980 | 1050 | $can_dumped = true; |
| 981 | 1051 | foreach($view AS $k) { |
| 982 | - if (isset($views[$k]) && !isset($dumped[$k])) $can_dumped = false; |
|
| 1052 | + if (isset($views[$k]) && !isset($dumped[$k])) { |
|
| 1053 | + $can_dumped = false; |
|
| 1054 | + } |
|
| 983 | 1055 | } |
| 984 | 1056 | if ($can_dumped) { |
| 985 | 1057 | if(sxd_check($n, $object['VI'], $filter['VI'])){ |
@@ -999,7 +1071,9 @@ discard block |
||
| 999 | 1071 | $this->JOB['file_rtl'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.rtl'; |
| 1000 | 1072 | $this->JOB['file_log'] = $this->CFG['backup_path'] . $this->JOB['job'] . '.log'; |
| 1001 | 1073 | $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']); |
|
| 1074 | + if(file_exists($this->JOB['file_stp'])) { |
|
| 1075 | + unlink($this->JOB['file_stp']); |
|
| 1076 | + } |
|
| 1003 | 1077 | $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'w'); |
| 1004 | 1078 | $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 | 1079 | $this->JOB['file_name'] = $this->CFG['backup_path'] . $this->JOB['file']; |
@@ -1007,7 +1081,9 @@ discard block |
||
| 1007 | 1081 | $this->saveJob($this->JOB['job'], $this->JOB); |
| 1008 | 1082 | $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 | 1083 | foreach($header AS $t => $o){ |
| 1010 | - if (!empty($o)) $fcache .= "#{$t} " . implode('|', $o) . "\n"; |
|
| 1084 | + if (!empty($o)) { |
|
| 1085 | + $fcache .= "#{$t} " . implode('|', $o) . "\n"; |
|
| 1086 | + } |
|
| 1011 | 1087 | } |
| 1012 | 1088 | $this->fh_rtl = fopen($this->JOB['file_rtl'], 'wb'); |
| 1013 | 1089 | $this->fh_log = fopen($this->JOB['file_log'], 'wb'); |
@@ -1017,7 +1093,7 @@ discard block |
||
| 1017 | 1093 | $this->addLog(sprintf($this->LNG['backup_begin'], $this->JOB['db'])); |
| 1018 | 1094 | $this->runBackupJob(); |
| 1019 | 1095 | } |
| 1020 | - function runBackupJob($continue = false){ |
|
| 1096 | + function runBackupJob($continue = false) { |
|
| 1021 | 1097 | if($continue){ |
| 1022 | 1098 | $this->fh_tmp = $this->openFile($this->JOB['file_tmp'], 'a'); |
| 1023 | 1099 | mysql_select_db($this->JOB['db']); |
@@ -1027,20 +1103,26 @@ discard block |
||
| 1027 | 1103 | $fcache = ''; |
| 1028 | 1104 | $writes = 0; |
| 1029 | 1105 | |
| 1030 | - if(V_MYSQL > 40101) mysql_query("SET SESSION character_set_results = '" . ($this->JOB['charset'] ? $this->JOB['charset'] : 'binary') ."'") or sxd_my_error(); |
|
| 1106 | + if(V_MYSQL > 40101) { |
|
| 1107 | + mysql_query("SET SESSION character_set_results = '" . ($this->JOB['charset'] ? $this->JOB['charset'] : 'binary') ."'") or sxd_my_error(); |
|
| 1108 | + } |
|
| 1031 | 1109 | $time_old = time(); |
| 1032 | 1110 | $exit_time = $time_old + $this->CFG['time_web'] - 1; |
| 1033 | 1111 | $no_cache = V_MYSQL < 40101 ? 'SQL_NO_CACHE ' : ''; |
| 1034 | 1112 | foreach($this->JOB['todo'] AS $t => $o){ |
| 1035 | - if (empty($this->rtl[4])) $this->rtl[4] = $t; |
|
| 1036 | - elseif ($this->rtl[4] != $t) continue; |
|
| 1113 | + if (empty($this->rtl[4])) { |
|
| 1114 | + $this->rtl[4] = $t; |
|
| 1115 | + } elseif ($this->rtl[4] != $t) { |
|
| 1116 | + continue; |
|
| 1117 | + } |
|
| 1037 | 1118 | foreach($o AS $n){ |
| 1038 | 1119 | if (empty($this->rtl[5])) { |
| 1039 | 1120 | $this->rtl[5] = $n[1]; |
| 1040 | 1121 | $this->rtl[7] = 0; |
| 1041 | 1122 | $this->rtl[8] = !empty($n[4]) ? $n[4] : 0; |
| 1123 | + } elseif ($this->rtl[5] != $n[1]) { |
|
| 1124 | + continue; |
|
| 1042 | 1125 | } |
| 1043 | - elseif ($this->rtl[5] != $n[1]) continue; |
|
| 1044 | 1126 | // Делаем бэкап |
| 1045 | 1127 | switch($n[0]){ |
| 1046 | 1128 | case 'TC': |
@@ -1054,11 +1136,12 @@ discard block |
||
| 1054 | 1136 | $fcache .= "#\tTC`{$n[1]}`{$n[2]}\t;\n{$item['Create Table']}\t;\n"; |
| 1055 | 1137 | $this->addLog(sprintf($this->LNG['backup_TC'], $n[1])); |
| 1056 | 1138 | $this->rtl[7] = 0; |
| 1057 | - if($n[0] == 'TC' || !$n[4]) break; |
|
| 1139 | + if($n[0] == 'TC' || !$n[4]) { |
|
| 1140 | + break; |
|
| 1141 | + } |
|
| 1058 | 1142 | // Бэкапим данные таблицы |
| 1059 | 1143 | $fcache .= "#\tTD`{$n[1]}`{$n[2]}\t;\nINSERT INTO `{$n[1]}` VALUES \n"; |
| 1060 | - } |
|
| 1061 | - else { |
|
| 1144 | + } else { |
|
| 1062 | 1145 | $from = " LIMIT {$this->rtl[7]}, {$this->rtl[8]}"; |
| 1063 | 1146 | $this->addLog(sprintf("{$this->LNG['backup_TC']} {$this->LNG['continue_from']}", $n[1], $this->rtl[7])); |
| 1064 | 1147 | } |
@@ -1101,8 +1184,7 @@ discard block |
||
| 1101 | 1184 | $this->write($fcache); |
| 1102 | 1185 | } |
| 1103 | 1186 | 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: Потестить скорость эскэйпинга строк |
|
| 1187 | + if(!isset($row[$k])) {$row[$k] = '\N';} elseif($notNum[$k]) {$row[$k] = '\'' . mysql_real_escape_string($row[$k]) . '\'';} // TODO: Потестить скорость эскэйпинга строк |
|
| 1106 | 1188 | } |
| 1107 | 1189 | $fcache .= '(' . implode(',', $row) . "),\n"; |
| 1108 | 1190 | $this->rtl[7]++; |
@@ -1119,8 +1201,7 @@ discard block |
||
| 1119 | 1201 | $r = mysql_query("SELECT * FROM `INFORMATION_SCHEMA`.`TRIGGERS` WHERE `TRIGGER_SCHEMA` = '{$this->JOB['db']}' AND `TRIGGER_NAME` = '{$n[1]}'") or sxd_my_error(); |
| 1120 | 1202 | $item = mysql_fetch_assoc($r); |
| 1121 | 1203 | $fcache .= "#\tTR`{$n[1]}`{$n[2]}\t;\nCREATE TRIGGER `{$item['TRIGGER_NAME']}` {$item['ACTION_TIMING']} {$item['EVENT_MANIPULATION']} ON `{$item['EVENT_OBJECT_TABLE']}` FOR EACH ROW {$item['ACTION_STATEMENT']}\t;\n"; |
| 1122 | - } |
|
| 1123 | - else { |
|
| 1204 | + } else { |
|
| 1124 | 1205 | $this->addLog(sprintf($this->LNG['backup_' . $n[0]], $n[1])); |
| 1125 | 1206 | $r = mysql_query("SHOW CREATE {$types[$n[0]]} `{$n[1]}`") or sxd_my_error(); |
| 1126 | 1207 | $item = mysql_fetch_assoc($r); |
@@ -1141,7 +1222,9 @@ discard block |
||
| 1141 | 1222 | fclose($this->fh_tmp); |
| 1142 | 1223 | rename($this->JOB['file_tmp'], $this->JOB['file_name']); |
| 1143 | 1224 | $this->addLog(sprintf($this->LNG['backup_end'], $this->JOB['db'])); |
| 1144 | - if(file_exists('sxd2ftp.php')) include('sxd2ftp.php'); |
|
| 1225 | + if(file_exists('sxd2ftp.php')) { |
|
| 1226 | + include('sxd2ftp.php'); |
|
| 1227 | + } |
|
| 1145 | 1228 | if ($this->JOB['del_time'] || $this->JOB['del_count']) { |
| 1146 | 1229 | $this->addLog($this->LNG['autodelete']); |
| 1147 | 1230 | $deldate = ''; |
@@ -1155,11 +1238,13 @@ discard block |
||
| 1155 | 1238 | while (false !== ($file = readdir($dh))) { |
| 1156 | 1239 | if (preg_match("/^{$name}_(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})\.sql/", $file, $m)) { |
| 1157 | 1240 | if ($deldate && $m[1] < $deldate) { |
| 1158 | - if(unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_date'], $file)); |
|
| 1159 | - else $this->addLog(sprintf($this->LNG['del_fail'], $file)); |
|
| 1241 | + if(unlink($this->CFG['backup_path'] . $file)) { |
|
| 1242 | + $this->addLog(sprintf($this->LNG['del_by_date'], $file)); |
|
| 1243 | + } else { |
|
| 1244 | + $this->addLog(sprintf($this->LNG['del_fail'], $file)); |
|
| 1245 | + } |
|
| 1160 | 1246 | $deleted = true; |
| 1161 | - } |
|
| 1162 | - else {$files[$m[1]] = $file;} |
|
| 1247 | + } else {$files[$m[1]] = $file;} |
|
| 1163 | 1248 | } |
| 1164 | 1249 | } |
| 1165 | 1250 | closedir($dh); |
@@ -1169,39 +1254,48 @@ discard block |
||
| 1169 | 1254 | $file_to_delete = count($files) - $this->JOB['del_count']; |
| 1170 | 1255 | foreach ($files AS $file){ |
| 1171 | 1256 | if ($file_to_delete-- > 0){ |
| 1172 | - if(unlink($this->CFG['backup_path'] . $file)) $this->addLog(sprintf($this->LNG['del_by_count'], $file)); |
|
| 1173 | - else $this->addLog(sprintf($this->LNG['del_fail'], $file)); |
|
| 1257 | + if(unlink($this->CFG['backup_path'] . $file)) { |
|
| 1258 | + $this->addLog(sprintf($this->LNG['del_by_count'], $file)); |
|
| 1259 | + } else { |
|
| 1260 | + $this->addLog(sprintf($this->LNG['del_fail'], $file)); |
|
| 1261 | + } |
|
| 1174 | 1262 | $deleted = true; |
| 1175 | 1263 | } |
| 1176 | 1264 | } |
| 1177 | 1265 | } |
| 1178 | 1266 | } |
| 1179 | - if(!$deleted) $this->addLog($this->LNG['del_nothing']); |
|
| 1267 | + if(!$deleted) { |
|
| 1268 | + $this->addLog($this->LNG['del_nothing']); |
|
| 1269 | + } |
|
| 1180 | 1270 | } |
| 1181 | 1271 | fclose($this->fh_log); |
| 1182 | 1272 | fclose($this->fh_rtl); |
| 1183 | 1273 | } |
| 1184 | - function setNames($collation){ |
|
| 1185 | - if(empty($collation)) return; |
|
| 1274 | + function setNames($collation) { |
|
| 1275 | + if(empty($collation)) { |
|
| 1276 | + return; |
|
| 1277 | + } |
|
| 1186 | 1278 | if($this->rtl[6] != $collation) { |
| 1187 | 1279 | mysql_query('SET NAMES \'' . preg_replace('/^(\w+?)_/', '\\1\' COLLATE \'\\1_', $collation) . '\'') or sxd_my_error(); |
| 1188 | 1280 | /*if(!$this->rtl[7])*/ $this->addLog(sprintf($this->LNG['set_names'], $collation)); |
| 1189 | 1281 | $this->rtl[6] = $collation; |
| 1190 | 1282 | } |
| 1191 | 1283 | } |
| 1192 | - function write(&$str){ |
|
| 1284 | + function write(&$str) { |
|
| 1193 | 1285 | fseek($this->fh_rtl, 0); |
| 1194 | 1286 | $this->rtl[1] = time(); |
| 1195 | 1287 | $this->rtl[3] += fwrite($this->fh_tmp, $str); |
| 1196 | 1288 | fwrite($this->fh_rtl, implode("\t", $this->rtl)); |
| 1197 | 1289 | $str = ''; |
| 1198 | 1290 | } |
| 1199 | - function addLog($str, $type = 1){ |
|
| 1291 | + function addLog($str, $type = 1) { |
|
| 1200 | 1292 | fwrite($this->fh_log, date('Y.m.d H:i:s') . "\t{$type}\t{$str}\n"); |
| 1201 | 1293 | } |
| 1202 | - function getDBList(){ |
|
| 1294 | + function getDBList() { |
|
| 1203 | 1295 | $dbs = $items = array(); |
| 1204 | - if (!V_MYSQL) return $dbs; |
|
| 1296 | + if (!V_MYSQL) { |
|
| 1297 | + return $dbs; |
|
| 1298 | + } |
|
| 1205 | 1299 | $qq = (V_MYSQL < 50000) ? '' : '\''; |
| 1206 | 1300 | if ($this->CFG['my_db']) { |
| 1207 | 1301 | $tmp = explode(',', $this->CFG['my_db']); |
@@ -1210,11 +1304,12 @@ discard block |
||
| 1210 | 1304 | $items[] = $qq . sxd_esc($d, false) . $qq; |
| 1211 | 1305 | $dbs[$d] = "{$d} (0)"; |
| 1212 | 1306 | } |
| 1213 | - } |
|
| 1214 | - else{ |
|
| 1307 | + } else{ |
|
| 1215 | 1308 | $result = mysql_query("SHOW DATABASES") or sxd_my_error(); |
| 1216 | 1309 | while($item = mysql_fetch_row($result)){ |
| 1217 | - if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue; |
|
| 1310 | + if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') { |
|
| 1311 | + continue; |
|
| 1312 | + } |
|
| 1218 | 1313 | $items[] = $qq . sxd_esc($item[0], false) . $qq; |
| 1219 | 1314 | $dbs[$item[0]] = "{$item[0]} (0)"; |
| 1220 | 1315 | } |
@@ -1227,20 +1322,23 @@ discard block |
||
| 1227 | 1322 | $dbs[$item] = "{$item} ({$tabs})"; |
| 1228 | 1323 | } |
| 1229 | 1324 | } |
| 1230 | - } |
|
| 1231 | - else { |
|
| 1325 | + } else { |
|
| 1232 | 1326 | $where = (count($items) > 0) ? 'WHERE `table_schema` IN (' . implode(',', $items) . ')' : ''; |
| 1233 | 1327 | $result = mysql_query("SELECT `table_schema`, COUNT(*) FROM `information_schema`.`tables` {$where} GROUP BY `table_schema`") or sxd_my_error(); |
| 1234 | 1328 | while($item = mysql_fetch_row($result)){ |
| 1235 | - if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') continue; |
|
| 1329 | + if($item[0] == 'information_schema' || $item[0] == 'mysql' || $item[0] == 'performance_schema') { |
|
| 1330 | + continue; |
|
| 1331 | + } |
|
| 1236 | 1332 | $dbs[$item[0]] = "{$item[0]} ({$item[1]})"; |
| 1237 | 1333 | } |
| 1238 | 1334 | } |
| 1239 | 1335 | return $dbs; |
| 1240 | 1336 | } |
| 1241 | - function getCharsetList(){ |
|
| 1337 | + function getCharsetList() { |
|
| 1242 | 1338 | $tmp = array(0 => '- auto -'); |
| 1243 | - if (!V_MYSQL) return $tmp; |
|
| 1339 | + if (!V_MYSQL) { |
|
| 1340 | + return $tmp; |
|
| 1341 | + } |
|
| 1244 | 1342 | if(V_MYSQL > 40101) { |
| 1245 | 1343 | $def_charsets = ''; |
| 1246 | 1344 | if(!empty($this->CFG['charsets'])){ |
@@ -1249,15 +1347,20 @@ discard block |
||
| 1249 | 1347 | $r = mysql_query("SHOW CHARACTER SET") or sxd_my_error(); |
| 1250 | 1348 | if ($r) { |
| 1251 | 1349 | while($item = mysql_fetch_assoc($r)){ |
| 1252 | - if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']] = "{$item['Charset']}"; // ({$item['Description']}) |
|
| 1350 | + if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) { |
|
| 1351 | + $tmp[$item['Charset']] = "{$item['Charset']}"; |
|
| 1352 | + } |
|
| 1353 | + // ({$item['Description']}) |
|
| 1253 | 1354 | } |
| 1254 | 1355 | } |
| 1255 | 1356 | } |
| 1256 | 1357 | return $tmp; |
| 1257 | 1358 | } |
| 1258 | - function getCollationList(){ |
|
| 1359 | + function getCollationList() { |
|
| 1259 | 1360 | $tmp = array(); |
| 1260 | - if (!V_MYSQL) return $tmp; |
|
| 1361 | + if (!V_MYSQL) { |
|
| 1362 | + return $tmp; |
|
| 1363 | + } |
|
| 1261 | 1364 | if(V_MYSQL > 40101) { |
| 1262 | 1365 | $def_charsets = ''; |
| 1263 | 1366 | if(!empty($this->CFG['charsets'])){ |
@@ -1266,13 +1369,15 @@ discard block |
||
| 1266 | 1369 | $r = mysql_query("SHOW COLLATION") or sxd_my_error(); |
| 1267 | 1370 | if ($r) { |
| 1268 | 1371 | while($item = mysql_fetch_assoc($r)){ |
| 1269 | - if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) $tmp[$item['Charset']][$item['Collation']] = $item['Default'] == 'Yes' ? 1 : 0; |
|
| 1372 | + if (empty($def_charsets) || preg_match($def_charsets, $item['Charset'])) { |
|
| 1373 | + $tmp[$item['Charset']][$item['Collation']] = $item['Default'] == 'Yes' ? 1 : 0; |
|
| 1374 | + } |
|
| 1270 | 1375 | } |
| 1271 | 1376 | } |
| 1272 | 1377 | } |
| 1273 | 1378 | return $tmp; |
| 1274 | 1379 | } |
| 1275 | - function getObjects($tree, $db_name){ |
|
| 1380 | + function getObjects($tree, $db_name) { |
|
| 1276 | 1381 | mysql_select_db($db_name); |
| 1277 | 1382 | // Достаем таблицы |
| 1278 | 1383 | $r = mysql_query('SHOW TABLE STATUS'); |
@@ -1282,8 +1387,7 @@ discard block |
||
| 1282 | 1387 | while($item = mysql_fetch_assoc($r)){ |
| 1283 | 1388 | if(V_MYSQL > 40101 && is_null($item['Engine']) && preg_match('/^VIEW/i', $item['Comment'])) { |
| 1284 | 1389 | $objects['VI'][]= $item['Name']; |
| 1285 | - } |
|
| 1286 | - else{ |
|
| 1390 | + } else{ |
|
| 1287 | 1391 | $objects['TA'][] = array($item['Name'], $item['Rows'], $item['Data_length']); |
| 1288 | 1392 | } |
| 1289 | 1393 | } |
@@ -1294,7 +1398,9 @@ discard block |
||
| 1294 | 1398 | "FUNCTION STATUS WHERE db='{$db_name}'", |
| 1295 | 1399 | 'TRIGGERS' |
| 1296 | 1400 | ); |
| 1297 | - if(V_MYSQL > 50100) $shows[] = "EVENTS WHERE db='{$db_name}'"; |
|
| 1401 | + if(V_MYSQL > 50100) { |
|
| 1402 | + $shows[] = "EVENTS WHERE db='{$db_name}'"; |
|
| 1403 | + } |
|
| 1298 | 1404 | // TODO: Поправить проверку событий и триггеров |
| 1299 | 1405 | for($i = 0, $l = count($shows); $i < $l; $i++){ |
| 1300 | 1406 | $r = mysql_query('SHOW ' . $shows[$i]); |
@@ -1306,17 +1412,18 @@ discard block |
||
| 1306 | 1412 | } |
| 1307 | 1413 | } |
| 1308 | 1414 | } |
| 1309 | - } |
|
| 1310 | - else { |
|
| 1415 | + } else { |
|
| 1311 | 1416 | $objects['VI'] = array(); |
| 1312 | 1417 | } |
| 1313 | 1418 | } |
| 1314 | 1419 | return $this->formatTree($tree, $objects); |
| 1315 | 1420 | } |
| 1316 | - function getFileObjects($tree, $name, $formatTree = true){ |
|
| 1421 | + function getFileObjects($tree, $name, $formatTree = true) { |
|
| 1317 | 1422 | // Достаем таблицы |
| 1318 | 1423 | $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 ''; |
|
| 1424 | + if(!preg_match('/\.sql(\.(gz|bz2))?$/i', $name, $m)) { |
|
| 1425 | + return ''; |
|
| 1426 | + } |
|
| 1320 | 1427 | $name = $this->CFG['backup_path'] . $name; |
| 1321 | 1428 | if(!is_readable($name)) {return "sxd.tree.{$tree}.error(sxd.lng('err_fopen'))";} |
| 1322 | 1429 | $fp = $this->openFile($name, 'r'); |
@@ -1332,13 +1439,12 @@ discard block |
||
| 1332 | 1439 | for($i = 0, $l = count($objects['TA']); $i < $l; $i++){ |
| 1333 | 1440 | $objects['TA'][$i] = explode('`', $objects['TA'][$i]); |
| 1334 | 1441 | } |
| 1335 | - } |
|
| 1336 | - else { |
|
| 1442 | + } else { |
|
| 1337 | 1443 | $h[9] = ''; |
| 1338 | 1444 | } |
| 1339 | 1445 | return $formatTree ? $this->formatTree($tree, $objects) . "sxd.comment.restore.value = '{$h[9]}';z('restore_savejob').disabled = z('restore_runjob').disabled = false;" : $objects; |
| 1340 | 1446 | } |
| 1341 | - function formatTree($tree, &$objects){ |
|
| 1447 | + function formatTree($tree, &$objects) { |
|
| 1342 | 1448 | $obj = ''; |
| 1343 | 1449 | $pid = $row = 1; |
| 1344 | 1450 | $info = array( |
@@ -1355,14 +1461,18 @@ discard block |
||
| 1355 | 1461 | $t = $objects['TA'][$i]; |
| 1356 | 1462 | $tab_prefix = preg_match("/^([a-z0-9]+_)/", $t[0], $m) ? $m[1] : '*'; |
| 1357 | 1463 | if ($tab_prefix != $tab_prefix_last) { |
| 1358 | - if ($tab_prefix != '*') $objects['TA']['*'][] = $tab_prefix; |
|
| 1464 | + if ($tab_prefix != '*') { |
|
| 1465 | + $objects['TA']['*'][] = $tab_prefix; |
|
| 1466 | + } |
|
| 1359 | 1467 | $tab_prefix_last = $tab_prefix; |
| 1360 | 1468 | } |
| 1361 | 1469 | $objects['TA'][$tab_prefix][] = $t; |
| 1362 | 1470 | unset($objects['TA'][$i]); |
| 1363 | 1471 | } |
| 1364 | 1472 | foreach($objects AS $type => $o){ |
| 1365 | - if(!count($o)) continue; |
|
| 1473 | + if(!count($o)) { |
|
| 1474 | + continue; |
|
| 1475 | + } |
|
| 1366 | 1476 | if($type == 'TA') { |
| 1367 | 1477 | $open_childs = count($o['*']) > 1 ? 0 : 1; |
| 1368 | 1478 | $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",1,1,1],"; |
@@ -1377,8 +1487,7 @@ discard block |
||
| 1377 | 1487 | $obj .= "[{$row},{$pid}," . sxd_esc($o[$value][$i][0]) . ",2,{$checked},{$o[$value][$i][2]}],"; |
| 1378 | 1488 | $row++; |
| 1379 | 1489 | } |
| 1380 | - } |
|
| 1381 | - else { |
|
| 1490 | + } else { |
|
| 1382 | 1491 | $value = $o[$value][0]; |
| 1383 | 1492 | } |
| 1384 | 1493 | } |
@@ -1389,8 +1498,7 @@ discard block |
||
| 1389 | 1498 | $row++; |
| 1390 | 1499 | } |
| 1391 | 1500 | } |
| 1392 | - } |
|
| 1393 | - else { |
|
| 1501 | + } else { |
|
| 1394 | 1502 | $obj .= "[{$row},0," . sxd_esc($info[$type][0]) . ",{$info[$type][1]},1,1],"; |
| 1395 | 1503 | $pid = $row++; |
| 1396 | 1504 | $info[$type][1]++; |
@@ -1402,10 +1510,12 @@ discard block |
||
| 1402 | 1510 | } |
| 1403 | 1511 | } |
| 1404 | 1512 | $add = ''; |
| 1405 | - if($tree == 'restore') $add = "z('autoinc').disabled = z('restore_type').disabled = " . ($obj ? 'false' : 'true') . ";"; |
|
| 1513 | + if($tree == 'restore') { |
|
| 1514 | + $add = "z('autoinc').disabled = z('restore_type').disabled = " . ($obj ? 'false' : 'true') . ";"; |
|
| 1515 | + } |
|
| 1406 | 1516 | return ($obj ? 'sxd.tree.' . $tree . '.drawTree([' . substr_replace($obj, ']', -1) . ");" : "sxd.tree.{$tree}.error(sxd.lng('err_sxd2'));") . $add; |
| 1407 | 1517 | } |
| 1408 | - function getFileList(){ |
|
| 1518 | + function getFileList() { |
|
| 1409 | 1519 | $files = array(); |
| 1410 | 1520 | if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
| 1411 | 1521 | while (false !== ($file = readdir($handle))) { |
@@ -1418,7 +1528,7 @@ discard block |
||
| 1418 | 1528 | ksort($files); |
| 1419 | 1529 | return $files; |
| 1420 | 1530 | } |
| 1421 | - function getSavedJobs(){ |
|
| 1531 | + function getSavedJobs() { |
|
| 1422 | 1532 | $sj = array('sj_backup' => array(), 'sj_restore' => array(),); |
| 1423 | 1533 | if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
| 1424 | 1534 | while (false !== ($file = readdir($handle))) { |
@@ -1431,19 +1541,17 @@ discard block |
||
| 1431 | 1541 | } |
| 1432 | 1542 | if(count($sj['sj_backup']) > 0){ |
| 1433 | 1543 | ksort($sj['sj_backup']); |
| 1434 | - } |
|
| 1435 | - else { |
|
| 1544 | + } else { |
|
| 1436 | 1545 | $sj['sj_backup'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']); |
| 1437 | 1546 | } |
| 1438 | 1547 | if(count($sj['sj_restore']) > 0){ |
| 1439 | 1548 | ksort($sj['sj_restore']); |
| 1440 | - } |
|
| 1441 | - else { |
|
| 1549 | + } else { |
|
| 1442 | 1550 | $sj['sj_restore'] = array(0 => '<b>No Saved Jobs</b><br>' . $this->LNG['no_saved']); |
| 1443 | 1551 | } |
| 1444 | 1552 | return "sxd.clearOpt('sj_backup');sxd.clearOpt('sj_restore');sxd.addOpt(" . sxd_php2json($sj) . ");"; |
| 1445 | 1553 | } |
| 1446 | - function getFileListExtended(){ |
|
| 1554 | + function getFileListExtended() { |
|
| 1447 | 1555 | $files = array(); |
| 1448 | 1556 | if (is_dir($this->CFG['backup_path']) && false !== ($handle = opendir($this->CFG['backup_path']))) { |
| 1449 | 1557 | while (false !== ($file = readdir($handle))) { |
@@ -1454,32 +1562,31 @@ discard block |
||
| 1454 | 1562 | if(preg_match('/^(#SXD20\|.+?)\n/s', $temp, $m)){ |
| 1455 | 1563 | $h = explode('|', $m[1]); |
| 1456 | 1564 | $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 | - } |
|
| 1458 | - elseif(preg_match('/^(#SKD101\|.+?)\n/s', $temp, $m)){ |
|
| 1565 | + } elseif(preg_match('/^(#SKD101\|.+?)\n/s', $temp, $m)){ |
|
| 1459 | 1566 | $h = explode('|', $m[1]); |
| 1460 | 1567 | $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 | - } |
|
| 1462 | - else { |
|
| 1568 | + } else { |
|
| 1463 | 1569 | $files[] = array($file, '-', $ext, '-', '-', filesize($this->CFG['backup_path'] . $file), '', $file); |
| 1464 | 1570 | } |
| 1465 | 1571 | } |
| 1466 | 1572 | } |
| 1467 | 1573 | closedir($handle); |
| 1468 | 1574 | } |
| 1469 | - function s($a, $b){ |
|
| 1575 | + function s($a, $b) { |
|
| 1470 | 1576 | return strcmp($b[1], $a[1]); |
| 1471 | 1577 | } |
| 1472 | 1578 | usort($files, 's'); |
| 1473 | 1579 | return 'sxd.files.clear();sxd.files.add(' . sxd_php2json($files) . ');'; |
| 1474 | 1580 | } |
| 1475 | - function saveJob($job, $config){ |
|
| 1581 | + function saveJob($job, $config) { |
|
| 1476 | 1582 | $this->saveToFile($this->CFG['backup_path'] . $job . '.job.php', "<?php\n\$JOB = " . var_export($config, true) . ";\n" . "?>"); |
| 1477 | 1583 | } |
| 1478 | - function openFile($name, $mode){ |
|
| 1584 | + function openFile($name, $mode) { |
|
| 1479 | 1585 | if($mode == 'r') { |
| 1480 | - if(preg_match('/\.(sql|sql\.bz2|sql\.gz)$/i', $name, $m)) $this->JOB['file_ext'] = strtolower($m[1]); |
|
| 1481 | - } |
|
| 1482 | - else{ |
|
| 1586 | + if(preg_match('/\.(sql|sql\.bz2|sql\.gz)$/i', $name, $m)) { |
|
| 1587 | + $this->JOB['file_ext'] = strtolower($m[1]); |
|
| 1588 | + } |
|
| 1589 | + } else{ |
|
| 1483 | 1590 | switch($this->JOB['zip']) { |
| 1484 | 1591 | case 0 : $this->JOB['file_ext'] = 'sql'; break; |
| 1485 | 1592 | case 10: $this->JOB['file_ext'] = 'sql.bz2'; break; |
@@ -1500,13 +1607,15 @@ discard block |
||
| 1500 | 1607 | } |
| 1501 | 1608 | } |
| 1502 | 1609 | } |
| 1503 | -function sxd_read_sql($f, &$seek, $ei, $delimiter = "\t;", $eol = "\n"){ |
|
| 1610 | +function sxd_read_sql($f, &$seek, $ei, $delimiter = "\t;", $eol = "\n") { |
|
| 1504 | 1611 | static $l = ''; |
| 1505 | 1612 | static $r = 0; |
| 1506 | 1613 | $fs = ftell($f); |
| 1507 | 1614 | $delim_len = strlen($delimiter . $eol); |
| 1508 | 1615 | while($r || $s = fread($f, 61440)){ |
| 1509 | - if(!$r) $l .= $s; |
|
| 1616 | + if(!$r) { |
|
| 1617 | + $l .= $s; |
|
| 1618 | + } |
|
| 1510 | 1619 | $pos = strpos($l, $delimiter . $eol); |
| 1511 | 1620 | if ($pos !== false) { |
| 1512 | 1621 | // Есть окончание запроса |
@@ -1534,48 +1643,65 @@ discard block |
||
| 1534 | 1643 | } |
| 1535 | 1644 | return false; |
| 1536 | 1645 | } |
| 1537 | -function sxd_check($n, $obj, $filt){ |
|
| 1646 | +function sxd_check($n, $obj, $filt) { |
|
| 1538 | 1647 | return isset($obj[$n]) || ($filt && preg_match($filt, $n)); |
| 1539 | 1648 | } |
| 1540 | -function sxd_php2json($obj){ |
|
| 1541 | - if(count($obj) == 0) return '[]'; |
|
| 1649 | +function sxd_php2json($obj) { |
|
| 1650 | + if(count($obj) == 0) { |
|
| 1651 | + return '[]'; |
|
| 1652 | + } |
|
| 1542 | 1653 | $is_obj = isset($obj[0]) && isset($obj[count($obj) - 1]) ? false : true; |
| 1543 | 1654 | $str = $is_obj ? '{' : '['; |
| 1544 | 1655 | foreach ($obj AS $key => $value) { |
| 1545 | 1656 | $str .= $is_obj ? "'" . addcslashes($key, "\n\r\t'\\/") . "'" . ':' : ''; |
| 1546 | - if (is_array($value)) $str .= sxd_php2json($value); |
|
| 1547 | - elseif (is_null($value)) $str .= 'null'; |
|
| 1548 | - elseif (is_bool($value)) $str .= $value ? 'true' : 'false'; |
|
| 1549 | - elseif (is_numeric($value)) $str .= $value; |
|
| 1550 | - else $str .= "'" . addcslashes($value, "\n\r\t'\\/") . "'"; |
|
| 1657 | + if (is_array($value)) { |
|
| 1658 | + $str .= sxd_php2json($value); |
|
| 1659 | + } elseif (is_null($value)) { |
|
| 1660 | + $str .= 'null'; |
|
| 1661 | + } elseif (is_bool($value)) { |
|
| 1662 | + $str .= $value ? 'true' : 'false'; |
|
| 1663 | + } elseif (is_numeric($value)) { |
|
| 1664 | + $str .= $value; |
|
| 1665 | + } else { |
|
| 1666 | + $str .= "'" . addcslashes($value, "\n\r\t'\\/") . "'"; |
|
| 1667 | + } |
|
| 1551 | 1668 | $str .= ','; |
| 1552 | 1669 | } |
| 1553 | 1670 | return substr_replace($str, $is_obj ? '}' : ']', -1); |
| 1554 | 1671 | } |
| 1555 | -function sxd_ver2int($ver){ |
|
| 1672 | +function sxd_ver2int($ver) { |
|
| 1556 | 1673 | return preg_match("/^(\d+)\.(\d+)\.(\d+)/", $ver, $m) ? sprintf("%d%02d%02d", $m[1], $m[2], $m[3]) : 0; |
| 1557 | 1674 | } |
| 1558 | -function sxd_error_handler($errno, $errmsg, $filename, $linenum, $vars){ |
|
| 1675 | +function sxd_error_handler($errno, $errmsg, $filename, $linenum, $vars) { |
|
| 1559 | 1676 | global $SXD; |
| 1560 | - if($SXD->try) return; |
|
| 1561 | - if($errno == 8192) return; |
|
| 1562 | - if(strpos($errmsg, 'timezone settings')) return; |
|
| 1677 | + if($SXD->try) { |
|
| 1678 | + return; |
|
| 1679 | + } |
|
| 1680 | + if($errno == 8192) { |
|
| 1681 | + return; |
|
| 1682 | + } |
|
| 1683 | + if(strpos($errmsg, 'timezone settings')) { |
|
| 1684 | + return; |
|
| 1685 | + } |
|
| 1563 | 1686 | $errortype = array(1 => 'Error', 2 => 'Warning', 4 => 'Parsing Error', 8 => 'Notice', 16 => 'Core Error', 32 => 'Core Warning', 64 => 'Compile Error', |
| 1564 | 1687 | 128 => 'Compile Warning', 256 => 'MySQL Error', 512 => 'Warning', 1024 => 'Notice', |
| 1565 | 1688 | 2048 => 'Strict', 8192 => 'Deprecated', 16384 => 'Deprecated'); |
| 1566 | 1689 | $str = sxd_esc("{$errortype[$errno]}: {$errmsg} ({$filename}:{$linenum})", false); |
| 1567 | - if(SXD_DEBUG) error_log("[index.php]\n{$str}\n", 3, "backup/error.log"); |
|
| 1690 | + if(SXD_DEBUG) { |
|
| 1691 | + error_log("[index.php]\n{$str}\n", 3, "backup/error.log"); |
|
| 1692 | + } |
|
| 1568 | 1693 | |
| 1569 | 1694 | if($errno == 8 || $errno == 1024) { |
| 1570 | - if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1571 | - else { |
|
| 1695 | + if (!$SXD->fh_log && !$SXD->fh_rtl) { |
|
| 1696 | + echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1697 | + } else { |
|
| 1572 | 1698 | fwrite($SXD->fh_log, date('Y.m.d H:i:s') . "\t3\t{$str}\n"); |
| 1573 | 1699 | } |
| 1574 | - } |
|
| 1575 | - elseif($errno < 1024) { |
|
| 1700 | + } elseif($errno < 1024) { |
|
| 1576 | 1701 | $SXD->error = true; |
| 1577 | - if (!$SXD->fh_log && !$SXD->fh_rtl) echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1578 | - else { |
|
| 1702 | + if (!$SXD->fh_log && !$SXD->fh_rtl) { |
|
| 1703 | + echo isset($_POST['ajax']) ? "alert('" . ($str) . "');" : $str; |
|
| 1704 | + } else { |
|
| 1579 | 1705 | $SXD->rtl[1] = time(); |
| 1580 | 1706 | $SXD->rtl[9] = 5; |
| 1581 | 1707 | fseek($SXD->fh_rtl, 0); |
@@ -1587,25 +1713,26 @@ discard block |
||
| 1587 | 1713 | die; |
| 1588 | 1714 | } |
| 1589 | 1715 | } |
| 1590 | -function sxd_esc($str, $quoted = true){ |
|
| 1716 | +function sxd_esc($str, $quoted = true) { |
|
| 1591 | 1717 | return $quoted ? "'" . addcslashes($str, "\\\0\n\r\t\'") . "'" : addcslashes($str, "\\\0\n\r\t\'"); |
| 1592 | 1718 | } |
| 1593 | -function sxd_my_error(){ |
|
| 1719 | +function sxd_my_error() { |
|
| 1594 | 1720 | trigger_error(mysql_error(), E_USER_ERROR); |
| 1595 | 1721 | } |
| 1596 | -function sxd_shutdown(){ |
|
| 1722 | +function sxd_shutdown() { |
|
| 1597 | 1723 | global $SXD; |
| 1598 | 1724 | if(isset($SXD->fh_rtl) && is_resource($SXD->fh_rtl) && !empty($SXD->rtl) && empty($SXD->error)) { |
| 1599 | 1725 | $SXD->rtl[1] = time(); |
| 1600 | 1726 | if(!empty($SXD->JOB['file_stp']) && file_exists(dirname(__FILE__) . '/' . $SXD->JOB['file_stp'])){ |
| 1601 | 1727 | $type = file_get_contents(dirname(__FILE__) . '/' . $SXD->JOB['file_stp']); |
| 1602 | 1728 | $SXD->rtl[9] = !empty($type) ? $type : 2; |
| 1729 | + } else { |
|
| 1730 | + $SXD->rtl[9] = 5; |
|
| 1603 | 1731 | } |
| 1604 | - else $SXD->rtl[9] = 5; |
|
| 1605 | 1732 | fseek($SXD->fh_rtl, 0); |
| 1606 | 1733 | fwrite($SXD->fh_rtl, implode("\t", $SXD->rtl)); |
| 1607 | 1734 | } |
| 1608 | 1735 | } |
| 1609 | -function sxd_antimagic($arr){ |
|
| 1736 | +function sxd_antimagic($arr) { |
|
| 1610 | 1737 | return is_array($arr) ? array_map('sxd_antimagic', $arr) : stripslashes($arr); |
| 1611 | 1738 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | $this->langs = &$langs; |
| 40 | 40 | $lng = 'en'; |
| 41 | 41 | if(preg_match_all('/[a-z]{2}(-[a-z]{2})?/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $m)) { |
| 42 | - foreach($m[0] AS $l){ |
|
| 42 | + foreach($m[0] as $l){ |
|
| 43 | 43 | if(isset($langs[$l])){ |
| 44 | 44 | $lng_name = $l; |
| 45 | 45 | break; |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $this->CFG['my_db'] = ''; |
| 76 | 76 | } |
| 77 | 77 | if ($args) { // консольный режим |
| 78 | - foreach($args AS $key => $arg){ |
|
| 78 | + foreach($args as $key => $arg){ |
|
| 79 | 79 | if (preg_match("/^-([hupoj])=(.*?)$/", $arg, $m)){ |
| 80 | 80 | switch ($m[1]) { |
| 81 | 81 | case 'h': $this->CFG['my_host'] = $m[2]; break; // хост |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $port = !empty($_POST['port']) && is_numeric($_POST['port']) ? $_POST['port'] : 3306; |
| 120 | 120 | $temp = preg_split('/\s+/', $this->CFG['auth']); |
| 121 | 121 | if(!empty($_REQUEST['lang']) && preg_match('/^[a-z]{2}(-[a-z]{2})?$/', $_REQUEST['lang'])) {$this->loadLang($_REQUEST['lang']);} |
| 122 | - foreach($temp AS $a){ |
|
| 122 | + foreach($temp as $a){ |
|
| 123 | 123 | switch($a) { |
| 124 | 124 | case 'cfg': if(empty($user)) {continue;} |
| 125 | 125 | $auth = !empty($CFG['user']) && isset($CFG['pass']) && $CFG['user']== $user && $CFG['pass'] == $pass; |
@@ -144,7 +144,7 @@ discard block |
||
| 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' : ''; |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | } |
| 157 | 157 | $this->lng_list = '<option value="auto">- auto -</opinion>'; |
| 158 | 158 | if(!isset($this->langs)) {include('lang/list.php');$this->langs = &$langs;} |
| 159 | - foreach($this->langs AS $k => $v){ |
|
| 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'); |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | echo "alert(" . sxd_esc(mysql_error()) . ");"; |
| 345 | 345 | } |
| 346 | 346 | function cfg2js($cfg){ |
| 347 | - foreach($cfg AS $k => $v){ |
|
| 347 | + foreach($cfg as $k => $v){ |
|
| 348 | 348 | $cfg[$k] = sxd_esc($v, false); |
| 349 | 349 | } |
| 350 | 350 | return $cfg; |
@@ -429,11 +429,11 @@ discard block |
||
| 429 | 429 | } |
| 430 | 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 | 435 | if(!empty($obj[$type])){ |
| 436 | - foreach($obj[$type] AS $v){ |
|
| 436 | + foreach($obj[$type] as $v){ |
|
| 437 | 437 | if(strpos($v, '*') !== false) { |
| 438 | 438 | $filter[$type][] = str_replace('*', '.*?', $v); |
| 439 | 439 | } |
@@ -492,12 +492,12 @@ discard block |
||
| 492 | 492 | $rows = 0; |
| 493 | 493 | $this->tab_rows = array(); |
| 494 | 494 | $todo = array(); |
| 495 | - foreach($objects AS $t => $list){ |
|
| 495 | + foreach($objects as $t => $list){ |
|
| 496 | 496 | if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
| 497 | 497 | elseif(empty($object[$t]) && empty($filter[$t])) {continue;} |
| 498 | 498 | if (empty($list)) continue; |
| 499 | 499 | |
| 500 | - foreach($list AS $item){ |
|
| 500 | + foreach($list as $item){ |
|
| 501 | 501 | switch($t){ |
| 502 | 502 | case 'TA': |
| 503 | 503 | $type = ''; |
@@ -631,7 +631,7 @@ discard block |
||
| 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){ |
|
| 634 | + foreach($this->JOB['todo']['TA'] as $t){ |
|
| 635 | 635 | if($t[1] == $tab) { |
| 636 | 636 | $this->rtl[8] = $t[2]; |
| 637 | 637 | } |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | $this->rtl[5] = $m[2]; |
| 685 | 685 | $this->rtl[7] = 0; |
| 686 | 686 | $this->rtl[8] = 0; |
| 687 | - mysql_query("DROP {$types[$m[1]]} IF EXISTS `{$m[2]}`") or sxd_my_error(); |
|
| 687 | + mysql_query("drop {$types[$m[1]]} IF EXISTS `{$m[2]}`") or sxd_my_error(); |
|
| 688 | 688 | $this->addLog(sprintf($this->LNG["restore_{$m[1]}"], $m[2])); |
| 689 | 689 | $ei = 0; |
| 690 | 690 | } |
@@ -730,7 +730,7 @@ discard block |
||
| 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(); |
@@ -919,7 +919,7 @@ discard block |
||
| 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 | 924 | if($t == 'TA' && (!empty($object['TC']) || !empty($filter['TC']))) {} |
| 925 | 925 | elseif(empty($object[$t]) && empty($filter[$t])) continue; |
@@ -976,9 +976,9 @@ discard block |
||
| 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) { |
@@ -1006,7 +1006,7 @@ discard block |
||
| 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'); |
@@ -1031,10 +1031,10 @@ discard block |
||
| 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; |
@@ -1074,7 +1074,7 @@ discard block |
||
| 1074 | 1074 | $time_old = time(); |
| 1075 | 1075 | $z = 0; |
| 1076 | 1076 | // Достаем данные |
| 1077 | - $r = mysql_unbuffered_query("SELECT {$no_cache}* FROM `{$n[1]}`{$from}"); |
|
| 1077 | + $r = mysql_unbuffered_query("select {$no_cache}* FROM `{$n[1]}`{$from}"); |
|
| 1078 | 1078 | while($row = mysql_fetch_row($r)) { |
| 1079 | 1079 | if (strlen($fcache) >= 61440) { |
| 1080 | 1080 | $z = 0; |
@@ -1167,7 +1167,7 @@ discard block |
||
| 1167 | 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){ |
|
| 1170 | + foreach ($files as $file){ |
|
| 1171 | 1171 | if ($file_to_delete-- > 0){ |
| 1172 | 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)); |
@@ -1205,7 +1205,7 @@ discard block |
||
| 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)"; |
@@ -1220,7 +1220,7 @@ discard block |
||
| 1220 | 1220 | } |
| 1221 | 1221 | } |
| 1222 | 1222 | if(V_MYSQL < 50000){ |
| 1223 | - foreach($items AS $item){ |
|
| 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); |
@@ -1361,13 +1361,13 @@ discard block |
||
| 1361 | 1361 | $objects['TA'][$tab_prefix][] = $t; |
| 1362 | 1362 | unset($objects['TA'][$i]); |
| 1363 | 1363 | } |
| 1364 | - foreach($objects AS $type => $o){ |
|
| 1364 | + foreach($objects as $type => $o){ |
|
| 1365 | 1365 | if(!count($o)) continue; |
| 1366 | 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){ |
|
| 1370 | + foreach($o['*'] as $value){ |
|
| 1371 | 1371 | if(is_string($value)){ |
| 1372 | 1372 | if(count($o[$value]) > 1) { |
| 1373 | 1373 | $obj .= "[{$row},1,'{$value}*',1,1,{$open_childs}],"; |
@@ -1541,7 +1541,7 @@ discard block |
||
| 1541 | 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 | - foreach ($obj AS $key => $value) { |
|
| 1544 | + foreach ($obj as $key => $value) { |
|
| 1545 | 1545 | $str .= $is_obj ? "'" . addcslashes($key, "\n\r\t'\\/") . "'" . ':' : ''; |
| 1546 | 1546 | if (is_array($value)) $str .= sxd_php2json($value); |
| 1547 | 1547 | elseif (is_null($value)) $str .= 'null'; |
@@ -10,6 +10,7 @@ discard block |
||
| 10 | 10 | * |
| 11 | 11 | * 1.0 - copyright (c) 2010 by Gorlum for http://supernova.ws |
| 12 | 12 | * @version 1.0 |
| 13 | + * @param integer $lab_require |
|
| 13 | 14 | */ |
| 14 | 15 | function eco_get_lab_max_effective_level(&$user, $lab_require) |
| 15 | 16 | { |
@@ -193,6 +194,9 @@ discard block |
||
| 193 | 194 | return $result; |
| 194 | 195 | } |
| 195 | 196 | |
| 197 | +/** |
|
| 198 | + * @param integer[] $unit_list |
|
| 199 | + */ |
|
| 196 | 200 | function eco_is_builds_in_que($planet_que, $unit_list) |
| 197 | 201 | { |
| 198 | 202 | $eco_is_builds_in_que = false; |
@@ -55,6 +55,9 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
| 58 | +/** |
|
| 59 | + * @param integer $build_mode |
|
| 60 | + */ |
|
| 58 | 61 | function que_build($user, $planet, $build_mode = BUILD_CREATE, $redirect = true) { |
| 59 | 62 | global $lang, $config; |
| 60 | 63 | |
@@ -378,6 +381,9 @@ discard block |
||
| 378 | 381 | return classSupernova::db_que_list_by_type_location($user_id, $planet_id, $que_type, $for_update); |
| 379 | 382 | } |
| 380 | 383 | |
| 384 | +/** |
|
| 385 | + * @param integer $unit_id |
|
| 386 | + */ |
|
| 381 | 387 | function que_add_unit($unit_id, $user = array(), $planet = array(), $build_data, $unit_level = 0, $unit_amount = 1, $build_mode = BUILD_CREATE) { |
| 382 | 388 | // TODO Унифицировать проверки |
| 383 | 389 | |
@@ -7,8 +7,8 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | function que_get_unit_que($unit_id) { |
| 9 | 9 | $que_type = false; |
| 10 | - foreach(sn_get_groups('ques') as $que_id => $que_data) { |
|
| 11 | - if(in_array($unit_id, $que_data['unit_list'])) { |
|
| 10 | + foreach (sn_get_groups('ques') as $que_id => $que_data) { |
|
| 11 | + if (in_array($unit_id, $que_data['unit_list'])) { |
|
| 12 | 12 | $que_type = $que_id; |
| 13 | 13 | break; |
| 14 | 14 | } |
@@ -19,14 +19,14 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | function que_get_max_que_length($user, $planet, $que_id, $que_data = null) { |
| 22 | - if(empty($que_data)) { |
|
| 22 | + if (empty($que_data)) { |
|
| 23 | 23 | $que_data = sn_get_groups('ques'); |
| 24 | 24 | $que_data = $que_data[$que_id]; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | $que_length = 1; |
| 29 | - switch($que_id) { |
|
| 29 | + switch ($que_id) { |
|
| 30 | 30 | case QUE_RESEARCH: |
| 31 | 31 | $que_length = classSupernova::$config->server_que_length_research + mrc_get_level($user, null, UNIT_PREMIUM); // TODO - вынести в модуль |
| 32 | 32 | break; |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | function eco_que_str2arr($que_str) { |
| 42 | 42 | $que_arr = explode(';', $que_str); |
| 43 | - foreach($que_arr as $que_index => &$que_item) { |
|
| 44 | - if($que_item) { |
|
| 43 | + foreach ($que_arr as $que_index => &$que_item) { |
|
| 44 | + if ($que_item) { |
|
| 45 | 45 | $que_item = explode(',', $que_item); |
| 46 | 46 | } else { |
| 47 | 47 | unset($que_arr[$que_index]); |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | function eco_que_arr2str($que_arr) { |
| 55 | - foreach($que_arr as &$que_item) { |
|
| 55 | + foreach ($que_arr as &$que_item) { |
|
| 56 | 56 | $que_item = implode(',', $que_item); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -64,28 +64,28 @@ discard block |
||
| 64 | 64 | $classLocale = classLocale::$lang; |
| 65 | 65 | |
| 66 | 66 | $is_autoconvert = false; |
| 67 | - if($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) { |
|
| 67 | + if ($build_mode == BUILD_AUTOCONVERT || sys_get_param_int('auto_convert')) { |
|
| 68 | 68 | $build_mode = BUILD_CREATE; |
| 69 | 69 | $is_autoconvert = true; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $unit_amount_qued = 0; |
| 73 | 73 | try { |
| 74 | - if(!$user['id']) { |
|
| 74 | + if (!$user['id']) { |
|
| 75 | 75 | throw new exception('{Нет идентификатора пользователя - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $unit_id = sys_get_param_int('unit_id'); |
| 79 | - if(!$unit_id) { |
|
| 79 | + if (!$unit_id) { |
|
| 80 | 80 | throw new exception('{Нет идентификатора юнита - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | $que_id = que_get_unit_que($unit_id); |
| 84 | - if(!$que_id) { |
|
| 84 | + if (!$que_id) { |
|
| 85 | 85 | throw new exception('{Неправильный тип очереди - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) { |
|
| 88 | + if ($build_mode == BUILD_DESTROY && $que_id != QUE_STRUCTURES) { |
|
| 89 | 89 | throw new exception('{Уничтожать можно только здания на планете}', ERR_ERROR); // TODO EXCEPTION |
| 90 | 90 | } |
| 91 | 91 | |
@@ -93,11 +93,11 @@ discard block |
||
| 93 | 93 | $que_data = $que_data[$que_id]; |
| 94 | 94 | |
| 95 | 95 | // TODO Переделать под подочереди |
| 96 | - if($que_id == QUE_STRUCTURES) { |
|
| 96 | + if ($que_id == QUE_STRUCTURES) { |
|
| 97 | 97 | $sn_groups_build_allow = sn_get_groups('build_allow'); |
| 98 | 98 | $que_data['unit_list'] = $sn_groups_build_allow[$planet['planet_type']]; |
| 99 | 99 | |
| 100 | - if(!isset($que_data['unit_list'][$unit_id])) { |
|
| 100 | + if (!isset($que_data['unit_list'][$unit_id])) { |
|
| 101 | 101 | throw new exception('{Это здание нельзя строить на ' . ($planet['planet_type'] == PT_PLANET ? 'планете' : 'луне'), ERR_ERROR); // TODO EXCEPTION |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | // Это нужно, что бы заблокировать пользователя и работу с очередями |
| 109 | 109 | $user = DBStaticUser::db_user_by_id($user['id']); |
| 110 | 110 | // Это нужно, что бы заблокировать планету от списания ресурсов |
| 111 | - if(isset($planet['id']) && $planet['id']) { |
|
| 111 | + if (isset($planet['id']) && $planet['id']) { |
|
| 112 | 112 | $planet = DBStaticPlanet::db_planet_by_id($planet['id'], true); |
| 113 | 113 | } else { |
| 114 | 114 | $planet['id'] = 0; |
@@ -120,12 +120,12 @@ discard block |
||
| 120 | 120 | $in_que = &$que['in_que'][$que_id][$user['id']][$planet_id]; |
| 121 | 121 | $que_max_length = que_get_max_que_length($user, $planet, $que_id, $que_data); |
| 122 | 122 | // TODO Добавить вызовы функций проверок текущей и максимальной длин очередей |
| 123 | - if(count($in_que) >= $que_max_length) { |
|
| 123 | + if (count($in_que) >= $que_max_length) { |
|
| 124 | 124 | throw new exception('{Все слоты очереди заняты}', ERR_ERROR); // TODO EXCEPTION |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // TODO Отдельно посмотреть на уничтожение зданий - что бы можно было уничтожать их без планов |
| 128 | - switch(eco_can_build_unit($user, $planet, $unit_id)) { |
|
| 128 | + switch (eco_can_build_unit($user, $planet, $unit_id)) { |
|
| 129 | 129 | case BUILD_ALLOWED: |
| 130 | 130 | break; |
| 131 | 131 | case BUILD_UNIT_BUSY: |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | break; // TODO EXCEPTION eco_bld_msg_err_laboratory_upgrading |
| 134 | 134 | // case BUILD_REQUIRE_NOT_MEET: |
| 135 | 135 | default: |
| 136 | - if($build_mode == BUILD_CREATE) { |
|
| 136 | + if ($build_mode == BUILD_CREATE) { |
|
| 137 | 137 | throw new exception('{Требования не удовлетворены}', ERR_ERROR); |
| 138 | 138 | } |
| 139 | 139 | break; // TODO EXCEPTION eco_bld_msg_err_requirements_not_meet |
@@ -143,33 +143,33 @@ discard block |
||
| 143 | 143 | $unit_amount_qued = $unit_amount; |
| 144 | 144 | $units_qued = isset($in_que[$unit_id]) ? $in_que[$unit_id] : 0; |
| 145 | 145 | $unit_level = mrc_get_level($user, $planet, $unit_id, true, true) + $units_qued; |
| 146 | - if($unit_max = get_unit_param($unit_id, P_MAX_STACK)) { |
|
| 147 | - if($unit_level >= $unit_max) { |
|
| 146 | + if ($unit_max = get_unit_param($unit_id, P_MAX_STACK)) { |
|
| 147 | + if ($unit_level >= $unit_max) { |
|
| 148 | 148 | throw new exception('{Максимальное количество юнитов данного типа уже достигнуто или будет достигнуто по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION |
| 149 | 149 | } |
| 150 | 150 | $unit_amount = max(0, min($unit_amount, $unit_max - $unit_level)); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - if($unit_amount < 1) { |
|
| 153 | + if ($unit_amount < 1) { |
|
| 154 | 154 | throw new exception('{Неправильное количество юнитов - сообщите Администрации}', ERR_ERROR); // TODO EXCEPTION |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // TODO Переделать eco_unit_busy для всех типов зданий |
| 158 | - if(get_unit_param($unit_id, P_STACKABLE)) { |
|
| 158 | + if (get_unit_param($unit_id, P_STACKABLE)) { |
|
| 159 | 159 | // TODO Поле 'max_Lot_size' для ограничения размера стэка в очереди - то ли в юниты, то ли в очередь |
| 160 | - if(in_array($unit_id, $group_missile = sn_get_groups(GROUP_STR_MISSILES))) { |
|
| 160 | + if (in_array($unit_id, $group_missile = sn_get_groups(GROUP_STR_MISSILES))) { |
|
| 161 | 161 | // TODO Поле 'container' - указывает на родительску структуру, в которой хранится данный юнит и по вместительности которой нужно применять размер юнита |
| 162 | 162 | $used_silo = 0; |
| 163 | - foreach($group_missile as $missile_id) { |
|
| 163 | + foreach ($group_missile as $missile_id) { |
|
| 164 | 164 | $missile_qued = isset($in_que[$missile_id]) ? $in_que[$missile_id] : 0; |
| 165 | 165 | $used_silo += (mrc_get_level($user, $planet, $missile_id, true, true) + $missile_qued) * get_unit_param($missile_id, P_UNIT_SIZE); |
| 166 | 166 | } |
| 167 | 167 | $free_silo = mrc_get_level($user, $planet, STRUC_SILO) * get_unit_param(STRUC_SILO, P_CAPACITY) - $used_silo; |
| 168 | - if($free_silo <= 0) { |
|
| 168 | + if ($free_silo <= 0) { |
|
| 169 | 169 | throw new exception('{Ракетная шахта уже заполнена или будет заполнена по окончанию очереди}', ERR_ERROR); // TODO EXCEPTION |
| 170 | 170 | } |
| 171 | 171 | $unit_size = get_unit_param($unit_id, P_UNIT_SIZE); |
| 172 | - if($free_silo < $unit_size) { |
|
| 172 | + if ($free_silo < $unit_size) { |
|
| 173 | 173 | throw new exception("{В ракетной шахте нет места для {$classLocale['tech'][$unit_id]}}", ERR_ERROR); // TODO EXCEPTION |
| 174 | 174 | } |
| 175 | 175 | $unit_amount = max(0, min($unit_amount, floor($free_silo / $unit_size))); |
@@ -177,9 +177,9 @@ discard block |
||
| 177 | 177 | $unit_level = $new_unit_level = 0; |
| 178 | 178 | } else { |
| 179 | 179 | $unit_amount = 1; |
| 180 | - if($que_id == QUE_STRUCTURES) { |
|
| 180 | + if ($que_id == QUE_STRUCTURES) { |
|
| 181 | 181 | $sectors_qued = is_array($in_que) ? array_sum($in_que) : 0; |
| 182 | - if($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) { |
|
| 182 | + if ($build_mode == BUILD_CREATE && eco_planet_fields_max($planet) - $planet['field_current'] - $sectors_qued <= 0) { |
|
| 183 | 183 | throw new exception('{Не хватает секторов на планете}', ERR_ERROR); // TODO EXCEPTION |
| 184 | 184 | } |
| 185 | 185 | } |
@@ -191,9 +191,9 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | $exchange = array(); |
| 193 | 193 | $market_get_autoconvert_cost = market_get_autoconvert_cost(); |
| 194 | - if($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) { |
|
| 194 | + if ($is_autoconvert && $build_data[BUILD_AUTOCONVERT]) { |
|
| 195 | 195 | $dark_matter = mrc_get_level($user, null, RES_DARK_MATTER); |
| 196 | - if(mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) { |
|
| 196 | + if (mrc_get_level($user, null, RES_DARK_MATTER) < $market_get_autoconvert_cost) { |
|
| 197 | 197 | throw new exception("{Нет хватает " . ($market_get_autoconvert_cost - $dark_matter) . "ТМ на постройки с автоконвертацией ресурсов}", ERR_ERROR); // TODO EXCEPTION |
| 198 | 198 | } |
| 199 | 199 | |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | $resource_exchange_rates = array(); |
| 204 | 204 | $resource_diff = array(); |
| 205 | 205 | $all_positive = true; |
| 206 | - foreach($resources_loot as $resource_id) { |
|
| 206 | + foreach ($resources_loot as $resource_id) { |
|
| 207 | 207 | $resource_db_name = pname_resource_name($resource_id); |
| 208 | 208 | $resource_got[$resource_id] = floor(mrc_get_level($user, $planet, $resource_id)); |
| 209 | 209 | $resource_exchange_rates[$resource_id] = classSupernova::$config->__get("rpg_exchange_{$resource_db_name}"); |
@@ -211,15 +211,15 @@ discard block |
||
| 211 | 211 | $all_positive = $all_positive && ($resource_diff[$resource_id] > 0); |
| 212 | 212 | } |
| 213 | 213 | // Нужна автоконвертация |
| 214 | - if($all_positive) { |
|
| 214 | + if ($all_positive) { |
|
| 215 | 215 | $is_autoconvert = false; |
| 216 | 216 | } else { |
| 217 | - foreach($resource_diff as $resource_diff_id => &$resource_diff_amount) { |
|
| 218 | - if($resource_diff_amount >= 0) { |
|
| 217 | + foreach ($resource_diff as $resource_diff_id => &$resource_diff_amount) { |
|
| 218 | + if ($resource_diff_amount >= 0) { |
|
| 219 | 219 | continue; |
| 220 | 220 | } |
| 221 | - foreach($resource_diff as $resource_got_id => &$resource_got_amount) { |
|
| 222 | - if($resource_got_amount <= 0) { |
|
| 221 | + foreach ($resource_diff as $resource_got_id => &$resource_got_amount) { |
|
| 222 | + if ($resource_got_amount <= 0) { |
|
| 223 | 223 | continue; |
| 224 | 224 | } |
| 225 | 225 | $current_exchange = $resource_exchange_rates[$resource_got_id] / $resource_exchange_rates[$resource_diff_id]; |
@@ -235,14 +235,14 @@ discard block |
||
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | $is_autoconvert_ok = true; |
| 238 | - foreach($resource_diff as $resource_diff_amount2) { |
|
| 239 | - if($resource_diff_amount2 < 0) { |
|
| 238 | + foreach ($resource_diff as $resource_diff_amount2) { |
|
| 239 | + if ($resource_diff_amount2 < 0) { |
|
| 240 | 240 | $is_autoconvert_ok = false; |
| 241 | 241 | break; |
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - if($is_autoconvert_ok) { |
|
| 245 | + if ($is_autoconvert_ok) { |
|
| 246 | 246 | $build_data['RESULT'][$build_mode] = BUILD_ALLOWED; |
| 247 | 247 | $build_data['CAN'][$build_mode] = $unit_amount; |
| 248 | 248 | } else { |
@@ -251,19 +251,19 @@ discard block |
||
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | $unit_amount = min($build_data['CAN'][$build_mode], $unit_amount); |
| 254 | - if($unit_amount <= 0) { |
|
| 254 | + if ($unit_amount <= 0) { |
|
| 255 | 255 | throw new exception('{Не хватает ресурсов}', ERR_ERROR); // TODO EXCEPTION |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - if($new_unit_level < 0) { |
|
| 258 | + if ($new_unit_level < 0) { |
|
| 259 | 259 | throw new exception('{Нельзя уничтожить больше юнитов, чем есть}', ERR_ERROR); // TODO EXCEPTION |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) { |
|
| 262 | + if ($build_data['RESULT'][$build_mode] != BUILD_ALLOWED) { |
|
| 263 | 263 | throw new exception('{Строительство блокировано}', ERR_ERROR); // TODO EXCEPTION |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - if($is_autoconvert) { |
|
| 266 | + if ($is_autoconvert) { |
|
| 267 | 267 | ksort($exchange); |
| 268 | 268 | ksort($resource_got); |
| 269 | 269 | db_change_resources( |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | $unit_amount_qued = 0; |
| 285 | - while($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) { |
|
| 285 | + while ($unit_amount > 0 && count($que['ques'][$que_id][$user['id']][$planet_id]) < $que_max_length) { |
|
| 286 | 286 | $place = min($unit_amount, MAX_FLEET_OR_DEFS_PER_ROW); |
| 287 | 287 | que_add_unit($unit_id, $user, $planet, $build_data, $new_unit_level, $place, $build_mode); |
| 288 | 288 | $unit_amount -= $place; |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | |
| 293 | 293 | sn_db_transaction_commit(); |
| 294 | 294 | |
| 295 | - if($redirect) { |
|
| 295 | + if ($redirect) { |
|
| 296 | 296 | sys_redirect("{$_SERVER['PHP_SELF']}?mode=" . sys_get_param_str('mode') . "&ally_id=" . sys_get_param_id('ally_id')); |
| 297 | 297 | die(); |
| 298 | 298 | } |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | 'STATUS' => ERR_NONE, |
| 302 | 302 | 'MESSAGE' => '{Строительство начато}', |
| 303 | 303 | ); |
| 304 | - } catch(Exception $e) { |
|
| 304 | + } catch (Exception $e) { |
|
| 305 | 305 | sn_db_transaction_rollback(); |
| 306 | 306 | $operation_result = array( |
| 307 | 307 | 'STATUS' => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR, |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | ); |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - if(!empty($operation_result['MESSAGE'])) { |
|
| 312 | + if (!empty($operation_result['MESSAGE'])) { |
|
| 313 | 313 | $operation_result['MESSAGE'] .= ' ' . ($unit_amount_qued ? $unit_amount_qued : $unit_amount) . 'x[' . classLocale::$lang['tech'][$unit_id] . ']'; |
| 314 | 314 | } |
| 315 | 315 | |
@@ -320,11 +320,11 @@ discard block |
||
| 320 | 320 | function que_recalculate($old_que) { |
| 321 | 321 | $new_que = array(); |
| 322 | 322 | |
| 323 | - if(!is_array($old_que['items'])) { |
|
| 323 | + if (!is_array($old_que['items'])) { |
|
| 324 | 324 | return $new_que; |
| 325 | 325 | } |
| 326 | - foreach($old_que['items'] as $row) { |
|
| 327 | - if(!isset($row) || !$row || $row['que_unit_amount'] <= 0) { |
|
| 326 | + foreach ($old_que['items'] as $row) { |
|
| 327 | + if (!isset($row) || !$row || $row['que_unit_amount'] <= 0) { |
|
| 328 | 328 | continue; |
| 329 | 329 | } |
| 330 | 330 | |
@@ -335,9 +335,9 @@ discard block |
||
| 335 | 335 | |
| 336 | 336 | $last_id = count($new_que['items']) - 1; |
| 337 | 337 | |
| 338 | - if($row['que_planet_id']) { |
|
| 338 | + if ($row['que_planet_id']) { |
|
| 339 | 339 | $new_que['planets'][$row['que_planet_id']][$row['que_type']][] = &$new_que['items'][$last_id]; |
| 340 | - } elseif($row['que_type'] == QUE_RESEARCH) { |
|
| 340 | + } elseif ($row['que_type'] == QUE_RESEARCH) { |
|
| 341 | 341 | $new_que['players'][$row['que_player_id']][$row['que_type']][] = &$new_que['items'][$last_id]; |
| 342 | 342 | } |
| 343 | 343 | $new_que['ques'][$row['que_type']][$row['que_player_id']][intval($row['que_planet_id'])][] = &$new_que['items'][$last_id]; |
@@ -375,14 +375,14 @@ discard block |
||
| 375 | 375 | $que_type = que_get_unit_que($unit_id); |
| 376 | 376 | $planet_id_origin = $planet['id'] ? $planet['id'] : 'NULL'; |
| 377 | 377 | $planet_id = $que_type == QUE_RESEARCH ? 'NULL' : $planet_id_origin; |
| 378 | - if(is_numeric($planet_id)) { |
|
| 378 | + if (is_numeric($planet_id)) { |
|
| 379 | 379 | DBStaticPlanet::db_planet_update_set_by_id( |
| 380 | 380 | $planet_id, |
| 381 | 381 | array( |
| 382 | 382 | 'que_processed' => SN_TIME_NOW, |
| 383 | 383 | ) |
| 384 | 384 | ); |
| 385 | - } elseif(is_numeric($user['id'])) { |
|
| 385 | + } elseif (is_numeric($user['id'])) { |
|
| 386 | 386 | DBStaticUser::db_user_set_by_id( |
| 387 | 387 | $user['id'], |
| 388 | 388 | array( |
@@ -417,17 +417,17 @@ discard block |
||
| 417 | 417 | $planet['id'] = $planet['id'] && $que_type !== QUE_RESEARCH ? $planet['id'] : 0; |
| 418 | 418 | $global_que = que_get($user['id'], $planet['id'], $que_type, true); |
| 419 | 419 | |
| 420 | - if(!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) { |
|
| 420 | + if (!empty($global_que['ques'][$que_type][$user['id']][$planet['id']])) { |
|
| 421 | 421 | $que = array_reverse($global_que['ques'][$que_type][$user['id']][$planet['id']]); |
| 422 | 422 | |
| 423 | - foreach($que as $que_item) { |
|
| 423 | + foreach ($que as $que_item) { |
|
| 424 | 424 | DBStaticQue::db_que_delete_by_id($que_item['que_id']); |
| 425 | 425 | |
| 426 | - if($que_item['que_planet_id_origin']) { |
|
| 426 | + if ($que_item['que_planet_id_origin']) { |
|
| 427 | 427 | $planet['id'] = $que_item['que_planet_id_origin']; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - if(!isset($planets_locked[$planet['id']])) { |
|
| 430 | + if (!isset($planets_locked[$planet['id']])) { |
|
| 431 | 431 | $planets_locked[$planet['id']] = $planet['id'] ? DBStaticPlanet::db_planet_by_id($planet['id'], true) : $planet; |
| 432 | 432 | } |
| 433 | 433 | |
@@ -443,19 +443,19 @@ discard block |
||
| 443 | 443 | ) |
| 444 | 444 | ); |
| 445 | 445 | |
| 446 | - if(!$clear) { |
|
| 446 | + if (!$clear) { |
|
| 447 | 447 | break; |
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - if(is_numeric($planet['id'])) { |
|
| 451 | + if (is_numeric($planet['id'])) { |
|
| 452 | 452 | DBStaticPlanet::db_planet_update_set_by_id( |
| 453 | 453 | $planet['id'], |
| 454 | 454 | array( |
| 455 | 455 | 'que_processed' => SN_TIME_SQL, |
| 456 | 456 | ) |
| 457 | 457 | ); |
| 458 | - } elseif(is_numeric($user['id'])) { |
|
| 458 | + } elseif (is_numeric($user['id'])) { |
|
| 459 | 459 | DBStaticUser::db_user_set_by_id( |
| 460 | 460 | $user['id'], |
| 461 | 461 | array( |
@@ -507,21 +507,21 @@ discard block |
||
| 507 | 507 | // TODO: Переделать для $que_type === false |
| 508 | 508 | $planet['id'] = $planet['id'] ? $planet['id'] : 0; |
| 509 | 509 | |
| 510 | - if(!is_array($que)) { |
|
| 510 | + if (!is_array($que)) { |
|
| 511 | 511 | $que = que_get($user['id'], $planet['id'], $que_type); |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | - if(is_array($que) && isset($que['items'])) { |
|
| 514 | + if (is_array($que) && isset($que['items'])) { |
|
| 515 | 515 | $que = $que['ques'][$que_type][$user['id']][$planet['id']]; |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | - if($que) { |
|
| 519 | - foreach($que as $que_element) { |
|
| 518 | + if ($que) { |
|
| 519 | + foreach ($que as $que_element) { |
|
| 520 | 520 | $template->assign_block_vars('que', que_tpl_parse_element($que_element, $short_names)); |
| 521 | 521 | } |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | - if($que_type == QUE_RESEARCH) { |
|
| 524 | + if ($que_type == QUE_RESEARCH) { |
|
| 525 | 525 | } |
| 526 | 526 | } |
| 527 | 527 | |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | $user = DBStaticUser::db_user_by_id($user['id'], true); |
| 546 | 546 | |
| 547 | 547 | $time_left[$user['id']][0] = max(0, $on_time - $user['que_processed']); |
| 548 | - if($planet === null && !$time_left[$user['id']][0]) { |
|
| 548 | + if ($planet === null && !$time_left[$user['id']][0]) { |
|
| 549 | 549 | return $que; |
| 550 | 550 | } |
| 551 | 551 | |
@@ -553,12 +553,12 @@ discard block |
||
| 553 | 553 | $que_type_id = $planet === null ? QUE_RESEARCH : false; |
| 554 | 554 | $planet = intval(is_array($planet) ? $planet['id'] : $planet); // В $planet у нас теперь только её ID или шаблон null/0/false |
| 555 | 555 | $que = que_get($user['id'], $planet, $que_type_id, true); |
| 556 | - if(empty($que['items'])) { |
|
| 556 | + if (empty($que['items'])) { |
|
| 557 | 557 | return $que; |
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | $planet_list = array(); |
| 561 | - if($planet !== null) { |
|
| 561 | + if ($planet !== null) { |
|
| 562 | 562 | // Если нужно изменять данные на планетах - блокируем планеты и получаем данные о них |
| 563 | 563 | // TODO - от них не надо ничего, кроме ID и que_processed |
| 564 | 564 | $planet_row = DBStaticPlanet::db_planet_list_by_user_or_planet($user['id'], $planet); |
@@ -567,20 +567,20 @@ discard block |
||
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | // Теперь в $time_left лежит время обсчета всех очередей по каждой из планеты |
| 570 | - if(array_sum($time_left[$user['id']]) == 0) { |
|
| 570 | + if (array_sum($time_left[$user['id']]) == 0) { |
|
| 571 | 571 | return $que; |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | $unit_changes = array(); |
| 575 | - foreach($que['items'] as &$que_item) { |
|
| 575 | + foreach ($que['items'] as &$que_item) { |
|
| 576 | 576 | $que_player_id = &$que_item['que_player_id']; |
| 577 | 577 | $que_planet_id = intval($que_item['que_planet_id']); |
| 578 | 578 | |
| 579 | 579 | $que_time_left = &$que['time_left'][$que_player_id][$que_planet_id][$que_item['que_type']]; |
| 580 | - if(!isset($que_time_left)) { |
|
| 580 | + if (!isset($que_time_left)) { |
|
| 581 | 581 | $que_time_left = $time_left[$que_player_id][$que_planet_id]; |
| 582 | 582 | } |
| 583 | - if($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { |
|
| 583 | + if ($que_time_left <= 0 || $que_item['que_unit_amount'] <= 0) { |
|
| 584 | 584 | continue; |
| 585 | 585 | } |
| 586 | 586 | // Дальше мы идем, если только осталось время в очереди И юниты к постройке |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | // Теперь работаем с остатком времени на юните. Оно не может быть равно или меньше нуля |
| 594 | 594 | |
| 595 | 595 | // Если времени в очереди осталось не меньше, чем время текущего юнита - значит мы достроили юнит |
| 596 | - if($que_time_left >= $que_item['que_time_left']) { |
|
| 596 | + if ($que_time_left >= $que_item['que_time_left']) { |
|
| 597 | 597 | // Увеличиваем количество отстроенных юнитов |
| 598 | 598 | $unit_processed++; |
| 599 | 599 | // Вычитаем из времени очереди потраченное на постройку время |
@@ -606,12 +606,12 @@ discard block |
||
| 606 | 606 | $que_item['que_unit_amount'] -= $unit_processed; |
| 607 | 607 | |
| 608 | 608 | // Если еще остались юниты - значит ВСЁ оставшееся время приходится на достройку следующего юнита |
| 609 | - if($que_item['que_unit_amount'] > 0) { |
|
| 609 | + if ($que_item['que_unit_amount'] > 0) { |
|
| 610 | 610 | $que_item['que_time_left'] = $que_item['que_time_left'] - $que_time_left; |
| 611 | 611 | $que_time_left = 0; |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - if($que_item['que_unit_amount'] <= 0) { |
|
| 614 | + if ($que_item['que_unit_amount'] <= 0) { |
|
| 615 | 615 | DBStaticQue::db_que_delete_by_id($que_item['que_id']); |
| 616 | 616 | } else { |
| 617 | 617 | classSupernova::$gc->cacheOperator->db_upd_record_by_id( |
@@ -626,15 +626,15 @@ discard block |
||
| 626 | 626 | ); |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - if($unit_processed) { |
|
| 629 | + if ($unit_processed) { |
|
| 630 | 630 | $unit_processed_delta = $unit_processed * ($que_item['que_unit_mode'] == BUILD_CREATE ? 1 : -1); |
| 631 | 631 | $unit_changes[$que_player_id][$que_planet_id][$que_item['que_unit_id']] += $unit_processed_delta; |
| 632 | 632 | } |
| 633 | 633 | } |
| 634 | 634 | |
| 635 | - foreach($time_left as $player_id => $planet_data) { |
|
| 636 | - foreach($planet_data as $planet_id => $time_on_planet) { |
|
| 637 | - if($planet_id) { |
|
| 635 | + foreach ($time_left as $player_id => $planet_data) { |
|
| 636 | + foreach ($planet_data as $planet_id => $time_on_planet) { |
|
| 637 | + if ($planet_id) { |
|
| 638 | 638 | // update planet |
| 639 | 639 | classSupernova::$gc->cacheOperator->db_upd_record_by_id( |
| 640 | 640 | LOC_PLANET, |
@@ -656,8 +656,8 @@ discard block |
||
| 656 | 656 | ); |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | - if(is_array($unit_changes[$player_id][$planet_id])) { |
|
| 660 | - foreach($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { |
|
| 659 | + if (is_array($unit_changes[$player_id][$planet_id])) { |
|
| 660 | + foreach ($unit_changes[$player_id][$planet_id] as $unit_id => $unit_amount) { |
|
| 661 | 661 | DBStaticUnit::dbUpdateOrInsertUnit($unit_id, $unit_amount, $user, $planet_id ? $planet_id : null); |
| 662 | 662 | } |
| 663 | 663 | } |
@@ -667,38 +667,38 @@ discard block |
||
| 667 | 667 | $que = que_recalculate($que); |
| 668 | 668 | |
| 669 | 669 | // TODO: Re-enable quests for Alliances |
| 670 | - if(!empty($unit_changes) && !$user['user_as_ally']) { |
|
| 670 | + if (!empty($unit_changes) && !$user['user_as_ally']) { |
|
| 671 | 671 | $quest_list = qst_get_quests($user['id']); |
| 672 | 672 | $quest_triggers = qst_active_triggers($quest_list); |
| 673 | 673 | $quest_rewards = array(); |
| 674 | 674 | |
| 675 | 675 | |
| 676 | 676 | $xp_incoming = array(); |
| 677 | - foreach($unit_changes as $user_id => $planet_changes) { |
|
| 678 | - foreach($planet_changes as $planet_id => $changes) { |
|
| 677 | + foreach ($unit_changes as $user_id => $planet_changes) { |
|
| 678 | + foreach ($planet_changes as $planet_id => $changes) { |
|
| 679 | 679 | $planet_this = $planet_id ? classSupernova::$gc->cacheOperator->db_get_record_by_id(LOC_PLANET, $planet_id) : array(); |
| 680 | - foreach($changes as $unit_id => $unit_value) { |
|
| 680 | + foreach ($changes as $unit_id => $unit_value) { |
|
| 681 | 681 | $que_id = que_get_unit_que($unit_id); |
| 682 | 682 | $unit_level_new = mrc_get_level($user, $planet_this, $unit_id, false, true) + $unit_value; |
| 683 | - if($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { |
|
| 683 | + if ($que_id == QUE_STRUCTURES || $que_id == QUE_RESEARCH) { |
|
| 684 | 684 | $build_data = eco_get_build_data($user, $planet_this, $unit_id, $unit_level_new - 1); |
| 685 | 685 | $build_data = $build_data[BUILD_CREATE]; |
| 686 | - foreach(sn_get_groups('resources_loot') as $resource_id) { |
|
| 686 | + foreach (sn_get_groups('resources_loot') as $resource_id) { |
|
| 687 | 687 | $xp_incoming[$que_id] += $build_data[$resource_id]; // TODO - добавить конверсию рейтов обмена |
| 688 | 688 | } |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - if(is_array($quest_triggers)) { |
|
| 691 | + if (is_array($quest_triggers)) { |
|
| 692 | 692 | // TODO: Check mutiply condition quests |
| 693 | 693 | $quest_trigger_list = array_keys($quest_triggers, $unit_id); |
| 694 | - if(is_array($quest_trigger_list)) { |
|
| 695 | - foreach($quest_trigger_list as $quest_id) { |
|
| 694 | + if (is_array($quest_trigger_list)) { |
|
| 695 | + foreach ($quest_trigger_list as $quest_id) { |
|
| 696 | 696 | $quest_unit_level = $unit_level_new; |
| 697 | - if(get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) { |
|
| 697 | + if (get_unit_param($unit_id, P_UNIT_TYPE) == UNIT_SHIPS) { |
|
| 698 | 698 | $quest_unit_level = DBStaticUnit::db_unit_count_by_user_and_type_and_snid($user_id, 0, $unit_id); |
| 699 | 699 | $quest_unit_level = $quest_unit_level[$unit_id]['qty']; |
| 700 | 700 | } |
| 701 | - if($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) { |
|
| 701 | + if ($quest_list[$quest_id]['quest_status_status'] != QUEST_STATUS_COMPLETE && $quest_list[$quest_id]['quest_unit_amount'] <= $quest_unit_level) { |
|
| 702 | 702 | $quest_rewards[$quest_id][$user_id][$planet_id] = $quest_list[$quest_id]['quest_rewards_list']; |
| 703 | 703 | $quest_list[$quest_id]['quest_status_status'] = QUEST_STATUS_COMPLETE; |
| 704 | 704 | } |
@@ -711,7 +711,7 @@ discard block |
||
| 711 | 711 | // TODO: Изменить начисление награды за квесты на ту планету, на которой происходил ресеч |
| 712 | 712 | qst_reward($user, $quest_rewards, $quest_list); |
| 713 | 713 | |
| 714 | - foreach($xp_incoming as $que_id => $xp) { |
|
| 714 | + foreach ($xp_incoming as $que_id => $xp) { |
|
| 715 | 715 | rpg_level_up($user, $que_id == QUE_RESEARCH ? RPG_TECH : RPG_STRUCTURE, $xp / 1000); |
| 716 | 716 | } |
| 717 | 717 | } |
@@ -141,6 +141,9 @@ |
||
| 141 | 141 | "); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | +/** |
|
| 145 | + * @param string $email_unsafe |
|
| 146 | + */ |
|
| 144 | 147 | function player_create($username_unsafe, $email_unsafe, $options) { |
| 145 | 148 | sn_db_transaction_check(true); |
| 146 | 149 | |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | use Vector\Vector; |
| 10 | 10 | |
| 11 | 11 | function sys_user_vacation($user) { |
| 12 | - if(sys_get_param_str('vacation') == 'leave') { |
|
| 12 | + if (sys_get_param_str('vacation') == 'leave') { |
|
| 13 | 13 | if ($user['vacation'] < SN_TIME_NOW) { |
| 14 | 14 | $user['vacation'] = 0; |
| 15 | 15 | $user['vacation_next'] = SN_TIME_NOW + classSupernova::$config->player_vacation_timeout; |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | } |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - if($user['vacation']) { |
|
| 26 | + if ($user['vacation']) { |
|
| 27 | 27 | // sn_sys_logout(false, true); |
| 28 | 28 | // core_auth::logout(false, true); |
| 29 | 29 | |
@@ -53,10 +53,10 @@ discard block |
||
| 53 | 53 | // TODO: Full rewrite |
| 54 | 54 | sn_db_transaction_start(); |
| 55 | 55 | $TheUser = DBStaticUser::db_user_by_id($UserID); |
| 56 | - if ( $TheUser['ally_id'] != 0 ) { |
|
| 56 | + if ($TheUser['ally_id'] != 0) { |
|
| 57 | 57 | $TheAlly = classSupernova::$db->doSelectFetchArray("SELECT * FROM `{{alliance}}` WHERE `id` = '" . $TheUser['ally_id'] . "';"); |
| 58 | 58 | $TheAlly['ally_members'] -= 1; |
| 59 | - if ( $TheAlly['ally_members'] > 0 ) { |
|
| 59 | + if ($TheAlly['ally_members'] > 0) { |
|
| 60 | 60 | classSupernova::$db->doUpdateRowSet( |
| 61 | 61 | TABLE_ALLIANCE, |
| 62 | 62 | array( |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | classSupernova::$gc->db->doDeleteWhere(TABLE_MESSAGES, array('message_owner' => $UserID,)); |
| 79 | 79 | classSupernova::$gc->db->doDeleteWhere(TABLE_MESSAGES, array('message_sender' => $UserID,)); |
| 80 | - classSupernova::$gc->db->doDeleteWhere(TABLE_NOTES, array('owner' => $UserID ,)); |
|
| 80 | + classSupernova::$gc->db->doDeleteWhere(TABLE_NOTES, array('owner' => $UserID,)); |
|
| 81 | 81 | FleetList::db_fleet_list_delete_by_owner($UserID); |
| 82 | - classSupernova::$gc->db->doDeleteWhere(TABLE_BUDDY, array('BUDDY_SENDER_ID' => $UserID ,)); |
|
| 83 | - classSupernova::$gc->db->doDeleteWhere(TABLE_BUDDY, array('BUDDY_OWNER_ID' => $UserID ,)); |
|
| 82 | + classSupernova::$gc->db->doDeleteWhere(TABLE_BUDDY, array('BUDDY_SENDER_ID' => $UserID,)); |
|
| 83 | + classSupernova::$gc->db->doDeleteWhere(TABLE_BUDDY, array('BUDDY_OWNER_ID' => $UserID,)); |
|
| 84 | 84 | |
| 85 | 85 | |
| 86 | 86 | classSupernova::$gc->cacheOperator->db_del_record_by_id(LOC_USER, $UserID); |
@@ -191,28 +191,28 @@ discard block |
||
| 191 | 191 | !empty($options['password_encoded_unsafe']) ? $field_set['password'] = $options['password_encoded_unsafe'] : false; |
| 192 | 192 | |
| 193 | 193 | $user_new = classSupernova::$gc->cacheOperator->db_ins_field_set(LOC_USER, $field_set); |
| 194 | - if(!($options['galaxy'] && $options['system'] && $options['planet'])) { |
|
| 194 | + if (!($options['galaxy'] && $options['system'] && $options['planet'])) { |
|
| 195 | 195 | $options['galaxy'] = classSupernova::$config->LastSettedGalaxyPos; |
| 196 | 196 | $options['system'] = classSupernova::$config->LastSettedSystemPos; |
| 197 | - $segment_size = floor(Vector::$knownPlanets/ 3); |
|
| 197 | + $segment_size = floor(Vector::$knownPlanets / 3); |
|
| 198 | 198 | $segment = floor(classSupernova::$config->LastSettedPlanetPos / $segment_size); |
| 199 | 199 | $segment++; |
| 200 | 200 | $options['planet'] = mt_rand(1 + $segment * $segment_size, ($segment + 1) * $segment_size); |
| 201 | 201 | |
| 202 | 202 | // $new_planet_id = 0; |
| 203 | - while(true) { |
|
| 204 | - if($options['planet'] > Vector::$knownPlanets) { |
|
| 203 | + while (true) { |
|
| 204 | + if ($options['planet'] > Vector::$knownPlanets) { |
|
| 205 | 205 | $options['planet'] = mt_rand(0, $segment_size - 1) + 1; |
| 206 | 206 | $options['system']++; |
| 207 | 207 | } |
| 208 | - if($options['system'] > Vector::$knownSystems) { |
|
| 208 | + if ($options['system'] > Vector::$knownSystems) { |
|
| 209 | 209 | $options['system'] = 1; |
| 210 | 210 | $options['galaxy']++; |
| 211 | 211 | } |
| 212 | - $options['galaxy'] > Vector::$knownGalaxies? $options['galaxy'] = 1 : false; |
|
| 212 | + $options['galaxy'] > Vector::$knownGalaxies ? $options['galaxy'] = 1 : false; |
|
| 213 | 213 | |
| 214 | 214 | $galaxy_row = DBStaticPlanet::db_planet_by_gspt($options['galaxy'], $options['system'], $options['planet'], PT_PLANET, true, 'id'); |
| 215 | - if(!$galaxy_row['id']) { |
|
| 215 | + if (!$galaxy_row['id']) { |
|
| 216 | 216 | classSupernova::$config->db_saveItem(array( |
| 217 | 217 | 'LastSettedGalaxyPos' => $options['galaxy'], |
| 218 | 218 | 'LastSettedSystemPos' => $options['system'], |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | db_player_name_history_replace($user_new['id'], $username_unsafe); |
| 242 | 242 | |
| 243 | - if(!empty($options['partner_id']) && ($referral_row = DBStaticUser::db_user_by_id($options['partner_id'], true))) { |
|
| 243 | + if (!empty($options['partner_id']) && ($referral_row = DBStaticUser::db_user_by_id($options['partner_id'], true))) { |
|
| 244 | 244 | db_referral_insert($options['partner_id'], $user_new['id']); |
| 245 | 245 | } |
| 246 | 246 | |
@@ -1,5 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +/** |
|
| 4 | + * @return double |
|
| 5 | + */ |
|
| 3 | 6 | function flt_fleet_speed($user, $fleet) |
| 4 | 7 | { |
| 5 | 8 | if (!is_array($fleet)) |
@@ -8,14 +8,14 @@ discard block |
||
| 8 | 8 | use Vector\Vector; |
| 9 | 9 | |
| 10 | 10 | function flt_fleet_speed($user, $fleet) { |
| 11 | - if(!is_array($fleet)) { |
|
| 11 | + if (!is_array($fleet)) { |
|
| 12 | 12 | $fleet = array($fleet => 1); |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | $speeds = array(); |
| 16 | - if(!empty($fleet)) { |
|
| 17 | - foreach($fleet as $ship_id => $amount) { |
|
| 18 | - if($amount && in_array($ship_id, classSupernova::$gc->groupFleetAndMissiles)) { |
|
| 16 | + if (!empty($fleet)) { |
|
| 17 | + foreach ($fleet as $ship_id => $amount) { |
|
| 18 | + if ($amount && in_array($ship_id, classSupernova::$gc->groupFleetAndMissiles)) { |
|
| 19 | 19 | $single_ship_data = get_ship_data($ship_id, $user); |
| 20 | 20 | $speeds[] = $single_ship_data['speed']; |
| 21 | 21 | } |
@@ -47,14 +47,14 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | $game_fleet_speed = flt_server_flight_speed_multiplier(); |
| 49 | 49 | $fleet_speed = flt_fleet_speed($user_row, $fleet_array); |
| 50 | - if(!empty($fleet_array) && $fleet_speed && $game_fleet_speed) { |
|
| 50 | + if (!empty($fleet_array) && $fleet_speed && $game_fleet_speed) { |
|
| 51 | 51 | $speed_percent = $speed_percent ? max(min($speed_percent, 10), 1) : 10; |
| 52 | 52 | $real_speed = $speed_percent * sqrt($fleet_speed); |
| 53 | 53 | |
| 54 | 54 | $duration = max(1, round((35000 / $speed_percent * sqrt($distance * 10 / $fleet_speed) + 10) / $game_fleet_speed)); |
| 55 | 55 | |
| 56 | - foreach($fleet_array as $ship_id => $ship_count) { |
|
| 57 | - if(!$ship_id || !$ship_count) { |
|
| 56 | + foreach ($fleet_array as $ship_id => $ship_count) { |
|
| 57 | + if (!$ship_id || !$ship_count) { |
|
| 58 | 58 | continue; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -82,19 +82,19 @@ discard block |
||
| 82 | 82 | function flt_bashing_check($user, $enemy, $planet_dst, $mission, $flight_duration, $fleet_group = 0) { |
| 83 | 83 | $config_bashing_attacks = classSupernova::$config->fleet_bashing_attacks; |
| 84 | 84 | $config_bashing_interval = classSupernova::$config->fleet_bashing_interval; |
| 85 | - if(!$config_bashing_attacks) { |
|
| 85 | + if (!$config_bashing_attacks) { |
|
| 86 | 86 | // Bashing allowed - protection disabled |
| 87 | 87 | return FLIGHT_ALLOWED; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | $bashing_result = FLIGHT_MISSION_ATTACK_BASHING; |
| 91 | - if($user['ally_id'] && $enemy['ally_id']) { |
|
| 91 | + if ($user['ally_id'] && $enemy['ally_id']) { |
|
| 92 | 92 | $relations = ali_relations($user['ally_id'], $enemy['ally_id']); |
| 93 | - if(!empty($relations)) { |
|
| 93 | + if (!empty($relations)) { |
|
| 94 | 94 | $relations = $relations[$enemy['ally_id']]; |
| 95 | - switch($relations['alliance_diplomacy_relation']) { |
|
| 95 | + switch ($relations['alliance_diplomacy_relation']) { |
|
| 96 | 96 | case ALLY_DIPLOMACY_WAR: |
| 97 | - if(SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= classSupernova::$config->fleet_bashing_war_delay) { |
|
| 97 | + if (SN_TIME_NOW - $relations['alliance_diplomacy_time'] <= classSupernova::$config->fleet_bashing_war_delay) { |
|
| 98 | 98 | $bashing_result = FLIGHT_MISSION_ATTACK_BASHING_WAR_DELAY; |
| 99 | 99 | } else { |
| 100 | 100 | return FLIGHT_ALLOWED; |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | // Retrieving flying fleets |
| 118 | 118 | $objFleetsBashing = FleetList::dbGetFleetListBashing($user['id'], $planet_dst); |
| 119 | - foreach($objFleetsBashing->_container as $fleetBashing) { |
|
| 119 | + foreach ($objFleetsBashing->_container as $fleetBashing) { |
|
| 120 | 120 | // Checking for ACS - each ACS count only once |
| 121 | - if($fleetBashing->group_id) { |
|
| 121 | + if ($fleetBashing->group_id) { |
|
| 122 | 122 | $bashing_list["{$user['id']}_{$fleetBashing->group_id}"] = $fleetBashing->time_arrive_to_target; |
| 123 | 123 | } else { |
| 124 | 124 | $bashing_list[] = $fleetBashing->time_arrive_to_target; |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Check for joining to ACS - if there are already fleets in ACS no checks should be done |
| 129 | - if($mission == MT_ACS && $bashing_list["{$user['id']}_{$fleet_group}"]) { |
|
| 129 | + if ($mission == MT_ACS && $bashing_list["{$user['id']}_{$fleet_group}"]) { |
|
| 130 | 130 | return FLIGHT_ALLOWED; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | $query = DBStaticFleetBashing::db_bashing_list_get($user, $planet_dst, $time_limit); |
| 134 | - while($bashing_row = db_fetch($query)) { |
|
| 134 | + while ($bashing_row = db_fetch($query)) { |
|
| 135 | 135 | $bashing_list[] = $bashing_row['bashing_time']; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -140,9 +140,9 @@ discard block |
||
| 140 | 140 | $last_attack = 0; |
| 141 | 141 | $wave = 0; |
| 142 | 142 | $attack = 1; |
| 143 | - foreach($bashing_list as &$bash_time) { |
|
| 143 | + foreach ($bashing_list as &$bash_time) { |
|
| 144 | 144 | $attack++; |
| 145 | - if($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) { |
|
| 145 | + if ($bash_time - $last_attack > $config_bashing_interval || $attack > $config_bashing_attacks) { |
|
| 146 | 146 | $attack = 1; |
| 147 | 147 | $wave++; |
| 148 | 148 | } |
@@ -159,16 +159,16 @@ discard block |
||
| 159 | 159 | //TODO: try..catch |
| 160 | 160 | global $user; |
| 161 | 161 | |
| 162 | - if($user['vacation']) { |
|
| 162 | + if ($user['vacation']) { |
|
| 163 | 163 | return $result = FLIGHT_PLAYER_VACATION_OWN; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - if(empty($fleet) || !is_array($fleet)) { |
|
| 166 | + if (empty($fleet) || !is_array($fleet)) { |
|
| 167 | 167 | return $result = FLIGHT_SHIPS_NO_SHIPS; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | $sn_groups_mission = sn_get_groups('missions'); |
| 171 | - if(!isset($sn_groups_mission[$mission])) { |
|
| 171 | + if (!isset($sn_groups_mission[$mission])) { |
|
| 172 | 172 | return $result = FLIGHT_MISSION_UNKNOWN; |
| 173 | 173 | } |
| 174 | 174 | $sn_data_mission = $sn_groups_mission[$mission]; |
@@ -187,32 +187,32 @@ discard block |
||
| 187 | 187 | $resources = 0; |
| 188 | 188 | $ship_ids = classSupernova::$gc->groupFleet; |
| 189 | 189 | $resource_ids = sn_get_groups('resources_loot'); |
| 190 | - foreach($fleet as $ship_id => $ship_count) { |
|
| 190 | + foreach ($fleet as $ship_id => $ship_count) { |
|
| 191 | 191 | $is_ship = in_array($ship_id, $ship_ids); |
| 192 | 192 | $is_resource = in_array($ship_id, $resource_ids); |
| 193 | - if(!$is_ship && !$is_resource) { |
|
| 193 | + if (!$is_ship && !$is_resource) { |
|
| 194 | 194 | // TODO Спецобработчик для Капитана и модулей |
| 195 | 195 | // return FLIGHT_SHIPS_UNIT_WRONG; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - if($ship_count < 0) { |
|
| 198 | + if ($ship_count < 0) { |
|
| 199 | 199 | return $result = $is_ship ? FLIGHT_SHIPS_NEGATIVE : FLIGHT_RESOURCES_NEGATIVE; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - if($ship_count > mrc_get_level($user, $planet_src, $ship_id)) { |
|
| 202 | + if ($ship_count > mrc_get_level($user, $planet_src, $ship_id)) { |
|
| 203 | 203 | // TODO FLIGHT_MISSION_MISSILE_NO_MISSILES |
| 204 | 204 | return $result = $is_ship ? FLIGHT_SHIPS_NOT_ENOUGH_OR_RESOURCES : FLIGHT_RESOURCES_NOT_ENOUGH; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - if($is_ship) { |
|
| 207 | + if ($is_ship) { |
|
| 208 | 208 | $single_ship_data = get_ship_data($ship_id, $user); |
| 209 | - if($single_ship_data[P_SPEED] <= 0) { |
|
| 209 | + if ($single_ship_data[P_SPEED] <= 0) { |
|
| 210 | 210 | return $result = FLIGHT_SHIPS_UNMOVABLE; |
| 211 | 211 | } |
| 212 | 212 | $ships += $ship_count; |
| 213 | 213 | $recyclers += in_array($ship_id, classSupernova::$gc->groupRecyclers) ? $ship_count : 0; |
| 214 | 214 | $spies += $ship_id == SHIP_SPY ? $ship_count : 0; |
| 215 | - } elseif($is_resource) { |
|
| 215 | + } elseif ($is_resource) { |
|
| 216 | 216 | $resources += $ship_count; |
| 217 | 217 | } |
| 218 | 218 | } |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | } |
| 224 | 224 | */ |
| 225 | 225 | |
| 226 | - if(isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) { |
|
| 226 | + if (isset($options['resources']) && $options['resources'] > 0 && !(isset($sn_data_mission['transport']) && $sn_data_mission['transport'])) { |
|
| 227 | 227 | return $result = FLIGHT_RESOURCES_FORBIDDEN; |
| 228 | 228 | } |
| 229 | 229 | |
@@ -235,78 +235,78 @@ discard block |
||
| 235 | 235 | */ |
| 236 | 236 | |
| 237 | 237 | $speed = $options['fleet_speed_percent']; |
| 238 | - if($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) { |
|
| 238 | + if ($speed && ($speed != intval($speed) || $speed < 1 || $speed > 10)) { |
|
| 239 | 239 | return $result = FLIGHT_FLEET_SPEED_WRONG; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | $travel_data = flt_travel_data($user, $planet_src, $planet_dst, $fleet, $options['fleet_speed_percent']); |
| 243 | 243 | |
| 244 | 244 | |
| 245 | - if(mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) { |
|
| 245 | + if (mrc_get_level($user, $planet_src, RES_DEUTERIUM) < $fleet[RES_DEUTERIUM] + $travel_data['consumption']) { |
|
| 246 | 246 | return $result = FLIGHT_RESOURCES_FUEL_NOT_ENOUGH; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if($travel_data['consumption'] > $travel_data['capacity']) { |
|
| 249 | + if ($travel_data['consumption'] > $travel_data['capacity']) { |
|
| 250 | 250 | return $result = FLIGHT_FLEET_TOO_FAR; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if($travel_data['hold'] < $resources) { |
|
| 253 | + if ($travel_data['hold'] < $resources) { |
|
| 254 | 254 | return $result = FLIGHT_FLEET_OVERLOAD; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | $fleet_start_time = SN_TIME_NOW + $travel_data['duration']; |
| 258 | 258 | |
| 259 | 259 | $fleet_group = $options['fleet_group']; |
| 260 | - if($fleet_group) { |
|
| 261 | - if($mission != MT_ACS) { |
|
| 260 | + if ($fleet_group) { |
|
| 261 | + if ($mission != MT_ACS) { |
|
| 262 | 262 | return $result = FLIGHT_MISSION_IMPOSSIBLE; |
| 263 | 263 | }; |
| 264 | 264 | |
| 265 | 265 | $acs = DBStaticFleetACS::db_acs_get_by_group_id($fleet_group); |
| 266 | - if(!$acs['id']) { |
|
| 266 | + if (!$acs['id']) { |
|
| 267 | 267 | return $result = FLIGHT_MISSION_ACS_NOT_EXISTS; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - if($planet_dst['galaxy'] != $acs['galaxy'] || $planet_dst['system'] != $acs['system'] || $planet_dst['planet'] != $acs['planet'] || $planet_dst['planet_type'] != $acs['planet_type']) { |
|
| 270 | + if ($planet_dst['galaxy'] != $acs['galaxy'] || $planet_dst['system'] != $acs['system'] || $planet_dst['planet'] != $acs['planet'] || $planet_dst['planet_type'] != $acs['planet_type']) { |
|
| 271 | 271 | return $result = FLIGHT_MISSION_ACS_WRONG_TARGET; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if($fleet_start_time > $acs['ankunft']) { |
|
| 274 | + if ($fleet_start_time > $acs['ankunft']) { |
|
| 275 | 275 | return $result = FLIGHT_MISSION_ACS_TOO_LATE; |
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | $flying_fleets = $options['flying_fleets']; |
| 280 | - if(!$flying_fleets) { |
|
| 280 | + if (!$flying_fleets) { |
|
| 281 | 281 | $flying_fleets = FleetList::fleet_count_flying($user['id']); |
| 282 | 282 | } |
| 283 | - if(GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) { |
|
| 283 | + if (GetMaxFleets($user) <= $flying_fleets && $mission != MT_MISSILE) { |
|
| 284 | 284 | return $result = FLIGHT_FLEET_NO_SLOTS; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | // В одиночку шпионские зонды могут летать только в миссии Шпионаж, Передислокация и Транспорт |
| 288 | - if($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) { |
|
| 288 | + if ($ships && $spies && $spies == $ships && !($mission == MT_SPY || $mission == MT_RELOCATE || $mission == MT_TRANSPORT)) { |
|
| 289 | 289 | return $result = FLIGHT_SHIPS_NOT_ONLY_SPIES; |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | // Checking for no planet |
| 293 | - if(!$planet_dst['id_owner']) { |
|
| 294 | - if($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) { |
|
| 293 | + if (!$planet_dst['id_owner']) { |
|
| 294 | + if ($mission == MT_COLONIZE && !$fleet[SHIP_COLONIZER]) { |
|
| 295 | 295 | return $result = FLIGHT_SHIPS_NO_COLONIZER; |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - if($mission == MT_EXPLORE || $mission == MT_COLONIZE) { |
|
| 298 | + if ($mission == MT_EXPLORE || $mission == MT_COLONIZE) { |
|
| 299 | 299 | return $result = FLIGHT_ALLOWED; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | return $result = FLIGHT_VECTOR_NO_TARGET; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - if($mission == MT_RECYCLE) { |
|
| 306 | - if($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) { |
|
| 305 | + if ($mission == MT_RECYCLE) { |
|
| 306 | + if ($planet_dst['debris_metal'] + $planet_dst['debris_crystal'] <= 0) { |
|
| 307 | 307 | return $result = FLIGHT_MISSION_RECYCLE_NO_DEBRIS; |
| 308 | 308 | } |
| 309 | - if($recyclers <= 0) { |
|
| 309 | + if ($recyclers <= 0) { |
|
| 310 | 310 | return $result = FLIGHT_SHIPS_NO_RECYCLERS; |
| 311 | 311 | } |
| 312 | 312 | |
@@ -314,8 +314,8 @@ discard block |
||
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | // Got planet. Checking if it is ours |
| 317 | - if($planet_dst['id_owner'] == $user['id']) { |
|
| 318 | - if($mission == MT_TRANSPORT || $mission == MT_RELOCATE) { |
|
| 317 | + if ($planet_dst['id_owner'] == $user['id']) { |
|
| 318 | + if ($mission == MT_TRANSPORT || $mission == MT_RELOCATE) { |
|
| 319 | 319 | return $result = FLIGHT_ALLOWED; |
| 320 | 320 | } |
| 321 | 321 | |
@@ -323,19 +323,19 @@ discard block |
||
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | // No, planet not ours. Cutting mission that can't be send to not-ours planet |
| 326 | - if($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) { |
|
| 326 | + if ($mission == MT_RELOCATE || $mission == MT_COLONIZE || $mission == MT_EXPLORE) { |
|
| 327 | 327 | return $result = FLIGHT_MISSION_IMPOSSIBLE; |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | $enemy = DBStaticUser::db_user_by_id($planet_dst['id_owner']); |
| 331 | 331 | // We cannot attack or send resource to users in VACATION mode |
| 332 | - if($enemy['vacation'] && $mission != MT_RECYCLE) { |
|
| 332 | + if ($enemy['vacation'] && $mission != MT_RECYCLE) { |
|
| 333 | 333 | return $result = FLIGHT_PLAYER_VACATION; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | // Multi IP protection |
| 337 | 337 | // TODO: Here we need a procedure to check proxies |
| 338 | - if(sys_is_multiaccount($user, $enemy)) { |
|
| 338 | + if (sys_is_multiaccount($user, $enemy)) { |
|
| 339 | 339 | return $result = FLIGHT_PLAYER_SAME_IP; |
| 340 | 340 | } |
| 341 | 341 | |
@@ -343,8 +343,8 @@ discard block |
||
| 343 | 343 | $enemy_points = $enemy['total_points']; |
| 344 | 344 | |
| 345 | 345 | // Is it transport? If yes - checking for buffing to prevent mega-alliance destroyer |
| 346 | - if($mission == MT_TRANSPORT) { |
|
| 347 | - if($user_points >= $enemy_points || classSupernova::$config->allow_buffing) { |
|
| 346 | + if ($mission == MT_TRANSPORT) { |
|
| 347 | + if ($user_points >= $enemy_points || classSupernova::$config->allow_buffing) { |
|
| 348 | 348 | return $result = FLIGHT_ALLOWED; |
| 349 | 349 | } else { |
| 350 | 350 | return $result = FLIGHT_PLAYER_BUFFING; |
@@ -354,66 +354,66 @@ discard block |
||
| 354 | 354 | // Only aggresive missions passed to this point. HOLD counts as passive but aggresive |
| 355 | 355 | |
| 356 | 356 | // Is it admin with planet protection? |
| 357 | - if($planet_dst['id_level'] > $user['authlevel']) { |
|
| 357 | + if ($planet_dst['id_level'] > $user['authlevel']) { |
|
| 358 | 358 | return $result = FLIGHT_PLAYER_ADMIN; |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | // Okay. Now skipping protection checks for inactive longer then 1 week |
| 362 | - if(!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) { |
|
| 363 | - if( |
|
| 362 | + if (!$enemy['onlinetime'] || $enemy['onlinetime'] >= (SN_TIME_NOW - 60 * 60 * 24 * 7)) { |
|
| 363 | + if ( |
|
| 364 | 364 | ($enemy_points <= classSupernova::$config->game_noob_points && $user_points > classSupernova::$config->game_noob_points) |
| 365 | 365 | || |
| 366 | 366 | (classSupernova::$config->game_noob_factor && $user_points > $enemy_points * classSupernova::$config->game_noob_factor) |
| 367 | 367 | ) { |
| 368 | - if($mission != MT_HOLD) { |
|
| 368 | + if ($mission != MT_HOLD) { |
|
| 369 | 369 | return $result = FLIGHT_PLAYER_NOOB; |
| 370 | 370 | } |
| 371 | - if($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && classSupernova::$config->ally_help_weak)) { |
|
| 371 | + if ($mission == MT_HOLD && !($user['ally_id'] && $user['ally_id'] == $enemy['ally_id'] && classSupernova::$config->ally_help_weak)) { |
|
| 372 | 372 | return $result = FLIGHT_PLAYER_NOOB; |
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | // Is it HOLD mission? If yes - there should be ally deposit |
| 378 | - if($mission == MT_HOLD) { |
|
| 379 | - if(mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) { |
|
| 378 | + if ($mission == MT_HOLD) { |
|
| 379 | + if (mrc_get_level($user, $planet_dst, STRUC_ALLY_DEPOSIT)) { |
|
| 380 | 380 | return $result = FLIGHT_ALLOWED; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | return $result = FLIGHT_MISSION_HOLD_NO_ALLY_DEPOSIT; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - if($mission == MT_SPY) { |
|
| 386 | + if ($mission == MT_SPY) { |
|
| 387 | 387 | return $result = $spies >= 1 ? FLIGHT_ALLOWED : FLIGHT_MISSION_SPY_NO_SPIES; |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | // Is it MISSILE mission? |
| 391 | - if($mission == MT_MISSILE) { |
|
| 391 | + if ($mission == MT_MISSILE) { |
|
| 392 | 392 | $sn_data_mip = get_unit_param(UNIT_DEF_MISSILE_INTERPLANET); |
| 393 | - if(mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) { |
|
| 393 | + if (mrc_get_level($user, $planet_src, STRUC_SILO) < $sn_data_mip[P_REQUIRE][STRUC_SILO]) { |
|
| 394 | 394 | return $result = FLIGHT_MISSION_MISSILE_NO_SILO; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - if(!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) { |
|
| 397 | + if (!$fleet[UNIT_DEF_MISSILE_INTERPLANET]) { |
|
| 398 | 398 | return $result = FLIGHT_MISSION_MISSILE_NO_MISSILES; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | $distance = abs($planet_dst['system'] - $planet_src['system']); |
| 402 | 402 | $mip_range = flt_get_missile_range($user); |
| 403 | - if($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) { |
|
| 403 | + if ($distance > $mip_range || $planet_dst['galaxy'] != $planet_src['galaxy']) { |
|
| 404 | 404 | return $result = FLIGHT_MISSION_MISSILE_TOO_FAR; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - if(isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) { |
|
| 407 | + if (isset($options['target_structure']) && $options['target_structure'] && !in_array($options['target_structure'], sn_get_groups('defense_active'))) { |
|
| 408 | 408 | return $result = FLIGHT_MISSION_MISSILE_WRONG_STRUCTURE; |
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - if($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) { |
|
| 412 | + if ($mission == MT_DESTROY && $planet_dst['planet_type'] != PT_MOON) { |
|
| 413 | 413 | return $result = FLIGHT_MISSION_IMPOSSIBLE; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - if($mission == MT_ATTACK || $mission == MT_ACS || $mission == MT_DESTROY) { |
|
| 416 | + if ($mission == MT_ATTACK || $mission == MT_ACS || $mission == MT_DESTROY) { |
|
| 417 | 417 | return $result = flt_bashing_check($user, $enemy, $planet_dst, $mission, $travel_data['duration'], $fleet_group); |
| 418 | 418 | } |
| 419 | 419 | |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | $from = $from['planet']; |
| 441 | 441 | |
| 442 | 442 | $can_attack = flt_can_attack($from, $to, $fleet_REAL_array, $mission, $options); |
| 443 | - if($can_attack != FLIGHT_ALLOWED) { |
|
| 443 | + if ($can_attack != FLIGHT_ALLOWED) { |
|
| 444 | 444 | $internal_transaction ? sn_db_transaction_rollback() : false; |
| 445 | 445 | |
| 446 | 446 | return $can_attack; |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | $travel_data = flt_travel_data($user, $from, $to, $fleet_REAL_array, $options['fleet_speed_percent']); |
| 452 | 452 | |
| 453 | 453 | $time_on_mission = 0; |
| 454 | - if($mission == MT_EXPLORE || $mission == MT_HOLD) { |
|
| 454 | + if ($mission == MT_EXPLORE || $mission == MT_HOLD) { |
|
| 455 | 455 | // TODO - include some checks about maximum and minumum stay_duration |
| 456 | 456 | $time_on_mission = $options['stay_time'] * 3600; |
| 457 | 457 | } |
@@ -473,14 +473,14 @@ discard block |
||
| 473 | 473 | $sn_group_fleet = classSupernova::$gc->groupFleet; |
| 474 | 474 | $sn_group_resources_loot = sn_get_groups('resources_loot'); |
| 475 | 475 | $planetRowFieldChanges = array(); |
| 476 | - foreach($fleet_REAL_array as $unit_id => $amount) { |
|
| 477 | - if(!$amount || !$unit_id) { |
|
| 476 | + foreach ($fleet_REAL_array as $unit_id => $amount) { |
|
| 477 | + if (!$amount || !$unit_id) { |
|
| 478 | 478 | continue; |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - if(in_array($unit_id, $sn_group_fleet)) { |
|
| 481 | + if (in_array($unit_id, $sn_group_fleet)) { |
|
| 482 | 482 | DBStaticUnit::dbUpdateOrInsertUnit($unit_id, -$amount, $user, $from['id']); |
| 483 | - } elseif(in_array($unit_id, $sn_group_resources_loot)) { |
|
| 483 | + } elseif (in_array($unit_id, $sn_group_resources_loot)) { |
|
| 484 | 484 | $planetRowFieldChanges[$unit_id] -= $amount; |
| 485 | 485 | } |
| 486 | 486 | } |
@@ -512,16 +512,16 @@ discard block |
||
| 512 | 512 | |
| 513 | 513 | $ship_data = array(); |
| 514 | 514 | $fleet_array = array(); |
| 515 | - foreach($ship_list as $transport_id => $cork) { |
|
| 515 | + foreach ($ship_list as $transport_id => $cork) { |
|
| 516 | 516 | $ship_data[$transport_id] = flt_travel_data($user, $from, $to, array($transport_id => 1), 10); |
| 517 | 517 | } |
| 518 | 518 | uasort($ship_data, 'flt_calculate_ship_to_transport_sort'); |
| 519 | 519 | |
| 520 | 520 | $fleet_capacity = 0; |
| 521 | 521 | $fuel_total = $fuel_left = mrc_get_level($user, $from, RES_DEUTERIUM); |
| 522 | - foreach($ship_data as $transport_id => &$ship_info) { |
|
| 522 | + foreach ($ship_data as $transport_id => &$ship_info) { |
|
| 523 | 523 | $ship_loaded = min($ship_list[$transport_id], ceil($resource_amount / $ship_info['hold']), floor($fuel_left / $ship_info['consumption'])); |
| 524 | - if($ship_loaded) { |
|
| 524 | + if ($ship_loaded) { |
|
| 525 | 525 | $fleet_array[$transport_id] = $ship_loaded; |
| 526 | 526 | $resource_amount -= min($resource_amount, $ship_info['hold'] * $ship_loaded); |
| 527 | 527 | $fuel_left -= $ship_info['consumption'] * $ship_loaded; |
@@ -29,6 +29,9 @@ |
||
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | +/** |
|
| 33 | + * @param string $group_name |
|
| 34 | + */ |
|
| 32 | 35 | function flt_spy_scan($target_planet, $group_name, $section_title, $target_user = array()) |
| 33 | 36 | { |
| 34 | 37 | global $lang; |
@@ -15,8 +15,8 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | // ---------------------------------------------------------------------------------------------------------------- |
| 17 | 17 | function coe_compress_add_units($unit_group, $target_planet, &$compress_data, $target_user = array()) { |
| 18 | - foreach($unit_group as $unit_id) { |
|
| 19 | - if(($unit_count = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) { |
|
| 18 | + foreach ($unit_group as $unit_id) { |
|
| 19 | + if (($unit_count = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) { |
|
| 20 | 20 | $compress_data[$unit_id] = $unit_count; |
| 21 | 21 | } |
| 22 | 22 | } |
@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | $classLocale = classLocale::$lang; |
| 27 | 27 | |
| 28 | 28 | $result = "<tr><td class=\"c\" colspan=\"4\">{$section_title}</td></tr>"; |
| 29 | - foreach(sn_get_groups($group_name) as $unit_id) { |
|
| 30 | - if(($unit_amount = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) { |
|
| 29 | + foreach (sn_get_groups($group_name) as $unit_id) { |
|
| 30 | + if (($unit_amount = mrc_get_level($target_user, $target_planet, $unit_id, false, true)) > 0) { |
|
| 31 | 31 | $result .= "<tr><td align=\"left\" colspan=\"3\">{$classLocale['tech'][$unit_id]}</td><td align=\"right\">{$unit_amount}</td></tr>"; |
| 32 | 32 | } |
| 33 | 33 | |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | $objFleet = $mission_data->fleet; |
| 58 | 58 | |
| 59 | - if(empty($target_user_row['id']) || empty($spying_user_row['id'])) { |
|
| 59 | + if (empty($target_user_row['id']) || empty($spying_user_row['id'])) { |
|
| 60 | 60 | $objFleet->markReturnedAndSave(); |
| 61 | 61 | |
| 62 | 62 | return; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | $spy_probes = $objFleet->shipsGetTotalById(SHIP_SPY); |
| 66 | - if($spy_probes > 0) { |
|
| 66 | + if ($spy_probes > 0) { |
|
| 67 | 67 | $TargetSpyLvl = GetSpyLevel($target_user_row); |
| 68 | 68 | $CurrentSpyLvl = GetSpyLevel($spying_user_row); |
| 69 | 69 | $spy_diff_empire = $CurrentSpyLvl - $TargetSpyLvl; |
@@ -87,19 +87,19 @@ discard block |
||
| 87 | 87 | $spy_message .= "<td width=220>{$classLocale['sys_deuterium']}</td><td width=220 align=right>" . pretty_number($target_planet_row['deuterium']) . "</td>"; |
| 88 | 88 | $spy_message .= "<td width=220>{$classLocale['sys_energy']}</td><td width=220 align=right>" . pretty_number($target_planet_row['energy_max']) . "</td>"; |
| 89 | 89 | $spy_message .= "</tr>"; |
| 90 | - if($spy_diff >= 2) { |
|
| 90 | + if ($spy_diff >= 2) { |
|
| 91 | 91 | $spy_message .= "<div class='spy_medium'>" . flt_spy_scan($target_planet_row, 'fleet', classLocale::$lang['tech'][UNIT_SHIPS], $target_user_row) . "</div>"; |
| 92 | 92 | coe_compress_add_units(classSupernova::$gc->groupFleet, $target_planet_row, $combat_pack[0]); |
| 93 | 93 | } |
| 94 | - if($spy_diff >= 3) { |
|
| 94 | + if ($spy_diff >= 3) { |
|
| 95 | 95 | $spy_message .= "<div class='spy_medium'>" . flt_spy_scan($target_planet_row, 'defense', classLocale::$lang['tech'][UNIT_DEFENCE], $target_user_row) . "</div>"; |
| 96 | 96 | coe_compress_add_units(sn_get_groups('defense_active'), $target_planet_row, $combat_pack[0]); |
| 97 | 97 | } |
| 98 | - if($spy_diff >= 5) { |
|
| 98 | + if ($spy_diff >= 5) { |
|
| 99 | 99 | $spy_message .= "<div class='spy_long'>" . flt_spy_scan($target_planet_row, 'structures', classLocale::$lang['tech'][UNIT_STRUCTURES], $target_user_row) . "</div>"; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if($spy_diff_empire >= 0) { |
|
| 102 | + if ($spy_diff_empire >= 0) { |
|
| 103 | 103 | $spy_message .= "<div class='spy_long'>" . flt_spy_scan($target_planet_row, 'tech', classLocale::$lang['tech'][UNIT_TECHNOLOGIES], $target_user_row) . "</div>"; |
| 104 | 104 | coe_compress_add_units(array(TECH_WEAPON, TECH_SHIELD, TECH_ARMOR), $target_planet_row, $combat_pack[0], $target_user_row); |
| 105 | 105 | } |
@@ -108,13 +108,13 @@ discard block |
||
| 108 | 108 | $simulator_link = sn_ube_simulator_encode_replay($combat_pack, 'D'); |
| 109 | 109 | |
| 110 | 110 | $target_unit_list = 0; |
| 111 | - foreach(classSupernova::$gc->groupFleet as $unit_id) { |
|
| 111 | + foreach (classSupernova::$gc->groupFleet as $unit_id) { |
|
| 112 | 112 | $target_unit_list += max(0, mrc_get_level($target_user_row, $target_planet_row, $unit_id, false, true)); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | $spy_detected = $spy_probes * $target_unit_list / 4 * pow(2, $TargetSpyLvl - $CurrentSpyLvl); |
| 116 | 116 | |
| 117 | - if(mt_rand(0, 99) > $spy_detected) { |
|
| 117 | + if (mt_rand(0, 99) > $spy_detected) { |
|
| 118 | 118 | $spy_outcome_str = sprintf(classLocale::$lang['sys_mess_spy_detect_chance'], $spy_detected); |
| 119 | 119 | $spy_detected = false; |
| 120 | 120 | } else { |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | $target_message = "{$classLocale['sys_mess_spy_ennemyfleet']} {$spying_planet_row['name']} " . uni_render_coordinates_href($spying_planet_row, '', 3); |
| 135 | 135 | $target_message .= " {$classLocale['sys_mess_spy_seen_at']} {$target_planet_row['name']} " . uni_render_coordinates($target_planet_row); |
| 136 | 136 | |
| 137 | - if($spy_detected) { |
|
| 137 | + if ($spy_detected) { |
|
| 138 | 138 | $debris_planet_id = $target_planet_row['planet_type'] == PT_PLANET ? $target_planet_row['id'] : $target_planet_row['parent_planet']; |
| 139 | 139 | |
| 140 | 140 | $spy_cost = get_unit_param(SHIP_SPY, P_COST); |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | DBStaticMessages::msg_send_simple_message($objFleet->target_owner_id, '', $objFleet->time_arrive_to_target, MSG_TYPE_SPY, classLocale::$lang['sys_mess_spy_control'], classLocale::$lang['sys_mess_spy_activity'], $target_message); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if($spy_detected) { |
|
| 159 | + if ($spy_detected) { |
|
| 160 | 160 | $objFleet->dbDelete(); |
| 161 | 161 | } else { |
| 162 | 162 | $objFleet->markReturnedAndSave(); |
@@ -26,6 +26,10 @@ |
||
| 26 | 26 | return true; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | +/** |
|
| 30 | + * @param integer $mode |
|
| 31 | + * @param integer $mercenary_id |
|
| 32 | + */ |
|
| 29 | 33 | function mrc_mercenary_hire($mode, $user, $mercenary_id) { |
| 30 | 34 | global $config, $lang, $sn_powerup_buy_discounts; |
| 31 | 35 | |
@@ -4,13 +4,13 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | function mrc_officer_accessible(&$user, $mercenary_id) { |
| 6 | 6 | $mercenary_info = get_unit_param($mercenary_id); |
| 7 | - if(classSupernova::$config->empire_mercenary_temporary || $mercenary_info[P_UNIT_TYPE] == UNIT_PLANS) { |
|
| 7 | + if (classSupernova::$config->empire_mercenary_temporary || $mercenary_info[P_UNIT_TYPE] == UNIT_PLANS) { |
|
| 8 | 8 | return true; |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | - if(isset($mercenary_info[P_REQUIRE])) { |
|
| 12 | - foreach($mercenary_info[P_REQUIRE] as $unit_id => $unit_level) { |
|
| 13 | - if(mrc_get_level($user, null, $unit_id) < $unit_level) { |
|
| 11 | + if (isset($mercenary_info[P_REQUIRE])) { |
|
| 12 | + foreach ($mercenary_info[P_REQUIRE] as $unit_id => $unit_level) { |
|
| 13 | + if (mrc_get_level($user, null, $unit_id) < $unit_level) { |
|
| 14 | 14 | return false; |
| 15 | 15 | } |
| 16 | 16 | } |
@@ -26,35 +26,35 @@ discard block |
||
| 26 | 26 | $is_permanent = $mode == UNIT_PLANS || !classSupernova::$config->empire_mercenary_temporary; |
| 27 | 27 | $cost_alliance_multiplyer = (SN_IN_ALLY === true && $mode == UNIT_PLANS ? classSupernova::$config->ali_bonus_members : 1); |
| 28 | 28 | $cost_alliance_multiplyer = $cost_alliance_multiplyer >= 1 ? $cost_alliance_multiplyer : 1; |
| 29 | - if(!in_array($mercenary_id, sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries'))) { |
|
| 29 | + if (!in_array($mercenary_id, sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries'))) { |
|
| 30 | 30 | throw new Exception(classLocale::$lang['mrc_msg_error_wrong_mercenary'], ERR_ERROR); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - if(!mrc_officer_accessible($user, $mercenary_id)) { |
|
| 33 | + if (!mrc_officer_accessible($user, $mercenary_id)) { |
|
| 34 | 34 | throw new Exception(classLocale::$lang['mrc_msg_error_requirements'], ERR_ERROR); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | $mercenary_level = sys_get_param_int('mercenary_level'); |
| 38 | - if($mercenary_level < 0 || $mercenary_level > get_unit_param($mercenary_id, P_MAX_STACK)) { |
|
| 38 | + if ($mercenary_level < 0 || $mercenary_level > get_unit_param($mercenary_id, P_MAX_STACK)) { |
|
| 39 | 39 | throw new Exception(classLocale::$lang['mrc_msg_error_wrong_level'], ERR_ERROR); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - if($mercenary_level && !array_key_exists($mercenary_period = sys_get_param_int('mercenary_period'), $sn_powerup_buy_discounts)) { |
|
| 42 | + if ($mercenary_level && !array_key_exists($mercenary_period = sys_get_param_int('mercenary_period'), $sn_powerup_buy_discounts)) { |
|
| 43 | 43 | throw new Exception(classLocale::$lang['mrc_msg_error_wrong_period'], ERR_ERROR); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | sn_db_transaction_start(); |
| 47 | 47 | |
| 48 | 48 | $mercenary_level_old = mrc_get_level($user, $planetrow, $mercenary_id, true, true); |
| 49 | - if(classSupernova::$config->empire_mercenary_temporary && $mercenary_level_old && $mercenary_level) { |
|
| 49 | + if (classSupernova::$config->empire_mercenary_temporary && $mercenary_level_old && $mercenary_level) { |
|
| 50 | 50 | throw new Exception(classLocale::$lang['mrc_msg_error_already_hired'], ERR_ERROR); // Can't hire already hired temp mercenary - dismiss first |
| 51 | - } elseif(classSupernova::$config->empire_mercenary_temporary && !$mercenary_level_old && !$mercenary_level) { |
|
| 51 | + } elseif (classSupernova::$config->empire_mercenary_temporary && !$mercenary_level_old && !$mercenary_level) { |
|
| 52 | 52 | throw new Exception('', ERR_NONE); // Can't dismiss (!$mercenary_level) not hired (!$mercenary_level_old) temp mercenary. But no error |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if($mercenary_level) { |
|
| 55 | + if ($mercenary_level) { |
|
| 56 | 56 | $darkmater_cost = eco_get_total_cost($mercenary_id, $mercenary_level); |
| 57 | - if(!classSupernova::$config->empire_mercenary_temporary && $mercenary_level_old) { |
|
| 57 | + if (!classSupernova::$config->empire_mercenary_temporary && $mercenary_level_old) { |
|
| 58 | 58 | $darkmater_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level_old); |
| 59 | 59 | $darkmater_cost[BUILD_CREATE][RES_DARK_MATTER] -= $darkmater_cost_old[BUILD_CREATE][RES_DARK_MATTER]; |
| 60 | 60 | } |
@@ -64,13 +64,13 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | $darkmater_cost *= $cost_alliance_multiplyer; |
| 66 | 66 | |
| 67 | - if(mrc_get_level($user, null, RES_DARK_MATTER) < $darkmater_cost) { |
|
| 67 | + if (mrc_get_level($user, null, RES_DARK_MATTER) < $darkmater_cost) { |
|
| 68 | 68 | throw new Exception(classLocale::$lang['mrc_msg_error_no_resource'], ERR_ERROR); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if(($darkmater_cost && $mercenary_level) || !$is_permanent) { |
|
| 71 | + if (($darkmater_cost && $mercenary_level) || !$is_permanent) { |
|
| 72 | 72 | $unit_row = db_unit_by_location($user['id'], LOC_USER, $user['id'], $mercenary_id); |
| 73 | - if(is_array($unit_row) && ($dismiss_left_days = floor((strtotime($unit_row['unit_time_finish']) - SN_TIME_NOW) / PERIOD_DAY))) { |
|
| 73 | + if (is_array($unit_row) && ($dismiss_left_days = floor((strtotime($unit_row['unit_time_finish']) - SN_TIME_NOW) / PERIOD_DAY))) { |
|
| 74 | 74 | $dismiss_full_cost = eco_get_total_cost($mercenary_id, $unit_row['unit_level']); |
| 75 | 75 | $dismiss_full_cost = $dismiss_full_cost[BUILD_CREATE][RES_DARK_MATTER]; |
| 76 | 76 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | db_unit_list_delete($user['id'], LOC_USER, $user['id'], $mercenary_id); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if($darkmater_cost && $mercenary_level) { |
|
| 86 | + if ($darkmater_cost && $mercenary_level) { |
|
| 87 | 87 | db_unit_set_insert( |
| 88 | 88 | "unit_player_id = {$user['id']}, |
| 89 | 89 | unit_location_type = " . LOC_USER . ", |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | sn_db_transaction_commit(); |
| 102 | 102 | sys_redirect($_SERVER['REQUEST_URI']); |
| 103 | - } catch(Exception $e) { |
|
| 103 | + } catch (Exception $e) { |
|
| 104 | 104 | sn_db_transaction_rollback(); |
| 105 | 105 | $operation_result = array( |
| 106 | 106 | 'STATUS' => in_array($e->getCode(), array(ERR_NONE, ERR_WARNING, ERR_ERROR)) ? $e->getCode() : ERR_ERROR, |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | $mode = in_array($mode, array(UNIT_MERCENARIES, UNIT_PLANS)) ? $mode : UNIT_MERCENARIES; |
| 119 | 119 | $is_permanent = $mode == UNIT_PLANS || !classSupernova::$config->empire_mercenary_temporary; |
| 120 | 120 | |
| 121 | - if($mercenary_id = sys_get_param_int('mercenary_id')) { |
|
| 121 | + if ($mercenary_id = sys_get_param_int('mercenary_id')) { |
|
| 122 | 122 | $operation_result = mrc_mercenary_hire($mode, $user, $mercenary_id); |
| 123 | 123 | } |
| 124 | 124 | |
@@ -126,11 +126,11 @@ discard block |
||
| 126 | 126 | |
| 127 | 127 | $template = gettemplate('mrc_mercenary_hire', true); |
| 128 | 128 | |
| 129 | - if(!empty($operation_result)) { |
|
| 129 | + if (!empty($operation_result)) { |
|
| 130 | 130 | $template->assign_block_vars('result', $operation_result); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - foreach($sn_powerup_buy_discounts as $hire_period => $hire_discount) { |
|
| 133 | + foreach ($sn_powerup_buy_discounts as $hire_period => $hire_discount) { |
|
| 134 | 134 | $template->assign_block_vars('period', array( |
| 135 | 135 | 'LENGTH' => $hire_period, |
| 136 | 136 | 'TEXT' => classLocale::$lang['mrc_period_list'][$hire_period], |
@@ -142,12 +142,12 @@ discard block |
||
| 142 | 142 | $user_dark_matter = mrc_get_level($user, null, RES_DARK_MATTER); |
| 143 | 143 | $cost_alliance_multiplyer = (SN_IN_ALLY === true && $mode == UNIT_PLANS ? classSupernova::$config->ali_bonus_members : 1); |
| 144 | 144 | $cost_alliance_multiplyer = $cost_alliance_multiplyer >= 1 ? $cost_alliance_multiplyer : 1; |
| 145 | - foreach(sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries') as $mercenary_id) { |
|
| 145 | + foreach (sn_get_groups($mode == UNIT_PLANS ? 'plans' : 'mercenaries') as $mercenary_id) { |
|
| 146 | 146 | { |
| 147 | 147 | $mercenary = get_unit_param($mercenary_id); |
| 148 | 148 | $mercenary_bonus = $mercenary['bonus']; |
| 149 | 149 | $mercenary_bonus = $mercenary_bonus >= 0 ? "+{$mercenary_bonus}" : "{$mercenary_bonus}"; |
| 150 | - switch($mercenary['bonus_type']) { |
|
| 150 | + switch ($mercenary['bonus_type']) { |
|
| 151 | 151 | case BONUS_PERCENT: |
| 152 | 152 | $mercenary_bonus = "{$mercenary_bonus}% "; |
| 153 | 153 | break; |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | $mercenary_level = mrc_get_level($user, null, $mercenary_id, false, true); |
| 165 | 165 | $mercenary_level_bonus = max(0, mrc_get_level($user, null, $mercenary_id) - $mercenary_level); |
| 166 | 166 | $total_cost_old = 0; |
| 167 | - if($is_permanent) { |
|
| 167 | + if ($is_permanent) { |
|
| 168 | 168 | $total_cost_old = eco_get_total_cost($mercenary_id, $mercenary_level); |
| 169 | 169 | $total_cost_old = $total_cost_old[BUILD_CREATE][RES_DARK_MATTER] * $cost_alliance_multiplyer; |
| 170 | 170 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | )); |
| 194 | 194 | |
| 195 | 195 | $upgrade_cost = 1; |
| 196 | - for($i = classSupernova::$config->empire_mercenary_temporary ? 1 : $mercenary_level + 1; $mercenary['max'] ? ($i <= $mercenary['max']) : $upgrade_cost <= $user_dark_matter; $i++) { |
|
| 196 | + for ($i = classSupernova::$config->empire_mercenary_temporary ? 1 : $mercenary_level + 1; $mercenary['max'] ? ($i <= $mercenary['max']) : $upgrade_cost <= $user_dark_matter; $i++) { |
|
| 197 | 197 | $total_cost = eco_get_total_cost($mercenary_id, $i); |
| 198 | 198 | $total_cost[BUILD_CREATE][RES_DARK_MATTER] *= $cost_alliance_multiplyer; |
| 199 | 199 | $upgrade_cost = $total_cost[BUILD_CREATE][RES_DARK_MATTER] - $total_cost_old; |
@@ -14,14 +14,14 @@ |
||
| 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'); |
@@ -1,6 +1,6 @@ discard block |
||
| 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 |
||
| 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"> |
@@ -1,6 +1,6 @@ discard block |
||
| 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 |
||
| 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"> |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | </script> |
| 289 | 289 | </body> |
| 290 | 290 | </html> |
| 291 | -HTML; |
|
| 291 | +html; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | function sxd_tpl_auth($error = ''){ |
@@ -350,5 +350,5 @@ discard block |
||
| 350 | 350 | </div> |
| 351 | 351 | </body> |
| 352 | 352 | </html> |
| 353 | -HTML; |
|
| 353 | +html; |
|
| 354 | 354 | } |
| 355 | 355 | \ No newline at end of file |