<?
include("../includes/config.php");
$adminuser = @mysql_db_query("$dbName", "select *  from admin where  admin_id = '1'") ;
while  ($ab = mysql_fetch_array($adminuser)){
$adminu = $ab['admin_name'];
$adminp = $ab['admin_password'];
}
$loguser= $_COOKIE['adminuser'];
$logipass= $_COOKIE['adminpassword'];



if ( $adminp == $logipass  && $adminu == $loguser ){

 $tables = $_POST['check'];
$outta = "";
foreach($tables as $table)
{
    $query = @mysql_query("SHOW CREATE TABLE ". $table); //الاستعلام عن كود انشاء الجدول
    $que = @mysql_fetch_array($query);
    $outta .= $que['Create Table'] . "\r\n";// طباعة كود انشاء الجدول
    $query2 = @mysql_query("SELECT * FROM `$que[Table]`");// ايجاد جميع الصفوف في الجدول
    while($result = @mysql_fetch_array($query2))
    {
        while($res = current($result))
        {
            $fields[] .= "`".key($result)."`";
            $values[] .= "'$res'";
            next($result);
        }
        $fields = join(", ", $fields);
        $values = join(", ", $values);
        $q = "INSERT INTO `$que[Table]` ($fields) VALUES ($values);";
        $outta .= $q . "\r\n";
        unset($fields);
        unset($values);
    }
}
header("Content-length: " . strlen($outta));
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=poem.sql");
echo $outta;
exit;



}else {
echo"<META HTTP-EQUIV='Refresh' CONTENT='0; url=login.php'>";
	}?>