<?php require "_header.php";
 require "commonincludefiles.php";
    $tables = array();
    $result = dbQuery('SHOW TABLES');
    while($row = dbRows($result))
    {
      $tables[] = $row[0];
    }
  
  
  foreach($tables as $table)
  {
	$result = dbQuery('SELECT * FROM '.$table);
    $num_fields = dbFields($result);
    
    $return.= 'DROP TABLE IF EXISTS '.$table.';';
    $row2 = dbRows(dbQuery('SHOW CREATE TABLE '.$table));
    $return.= "\n\n".$row2[1].";\n\n";
    
    for ($i = 0; $i < $num_fields; $i++) 
    {
      while($row = dbRows($result))
      {
        $return.= '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])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
          if ($j<($num_fields-1)) { $return.= ','; }
        }
        $return.= ");\n";
      }
    }
    $return.="\n\n\n";
  }
  $filename.="db-backup-";
  $filename.=date("j-M-Y-g-i-s-a");
  $filename.=".sql";
  if(!is_dir("aum_backup/")){
			
			 mkdir("aum_backup/",0777);
			 chmod("aum_backup/", 0777);
			 
			  mkdir("aum_backup/db/",0777);
			 chmod("aum_backup/db/", 0777);
  }
  $path = 'aum_backup/db/'.$filename;
 
  $handle = fopen($path,'w+');
  fwrite($handle,$return);
  fclose($handle); 
  ?>
<div id="main-content">
<div id="abcd"></div> 

<script language="javascript" type="text/javascript">
Ext.onReady(function(){
	Ext.QuickTips.init();
   Ext.MessageBox.show({
							title: 'Message',
							msg: 'Backup process complete successfully.',
							buttons: Ext.MessageBox.OK,
							icon:Ext.MessageBox.INFO
							
						});
});
</script>
</div>
<?php require "_footer.php"; ?>