<?
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/adm_check.php';
include_once '../sys/inc/user.php';
user_access('adm_panel_show',null,'/index.php?'.SID);
include 'system.php';
$set['title'] = 'Профессиоальная защита для вашего сайта '.$systems_bleik['title'].'';
include_once '../sys/inc/thead.php';
title();
err();
aut();
?>
<link rel="stylesheet" href="style.css" type="text/css" />
<?

base($set['mysql_host'],$set['mysql_user'],$set['mysql_pass'],$set['mysql_db_name'], '*');
function base($host,$user,$pass,$name,$tables)
{
    $link = mysql_connect($host,$user,$pass);
    mysql_select_db($name,$link);
    if($tables == '*')
    {
        $tables = array();
        $result = mysql_query('SHOW TABLES');
        while($row = mysql_fetch_row($result))
        {
        $tables[] = $row[0];
        }
    }
    else
    {
        $tables = is_array($tables) ? $tables : explode(',',$tables);
    }
    foreach($tables as $table)
    {
        $result = mysql_query('SELECT * FROM '.$table);
        $num_fields = mysql_num_fields($result);
        $mysq_back.= 'DROP TABLE '.$table.';';
        $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
        $mysq_back.= "\n\n".$row2[1].";\n\n";
        for ($i = 0; $i < $num_fields; $i++)
        {
            while($row = mysql_fetch_row($result))
            {
                $mysq_back.= 'INSERT INTO '.$table.' VALUES(';
                for($j=0; $j<$num_fields; $j++)
				{
				    $row[$j] = addslashes($row[$j]);
                    $row[$j] = ereg_replace("\n","\\n",$row[$j]);
                    if (isset($row[$j])) { $mysq_back.= '"'.$row[$j].'"' ; } else { $mysq_back.= '""'; }
                    if ($j<($num_fields-1)) { $mysq_back.= ','; }
                }
                $mysq_back.= ");\n";
            }
        }
		$mysq_back.="\n\n\n/*Бэкап сделан на движке SHCMS Engine*/\n\n\n";}
$s = mkdir('Backup',0777,true);
    $handle = fopen('Backup/'.$_SERVER['HTTP_HOST'].'_'.date('d.m.y'). '.sql','w+');
    fwrite($handle,$mysq_back);
    fclose($handle);

	$file = "";
	$person = '';
	file_put_contents($file,$person,FILE_APPEND | LOCK_EX);
}
echo '<div class="msg"><center>Бэкап успешно создан и сохранен в папке Backup</center></div>';
linbSAleik();
include_once '../sys/inc/tfoot.php';
?>