<?php
	include "db_connection/db_connection.php";
	include "config/config.php";
	
	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='index.php';</script>";
	}
	$SLCT	=	"SELECT * FROM admin WHERE admin_id = '$_SESSION[admin_login_id]'";
	$QRY	=	mysqli_query($connect,$SLCT);
	$FTCH	=	mysqli_fetch_object($QRY);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title><?php echo $PROJECT_TITLE ?></title>

<!--<script type="text/javascript" src="js/design_add_JS.js"></script>-->
 <script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<!--[if IE]> <link href="css/ie.css" rel="stylesheet" type="text/css"> <![endif]-->

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>

<script type="text/javascript" src="js/plugins/forms/ui.spinner.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.mousewheel.js"></script>
 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

<script type="text/javascript" src="js/plugins/charts/excanvas.min.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.orderBars.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.pie.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.resize.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.sparkline.min.js"></script>

<script type="text/javascript" src="js/plugins/tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/plugins/tables/jquery.sortable.js"></script>
<script type="text/javascript" src="js/plugins/tables/jquery.resizable.js"></script>

<script type="text/javascript" src="js/plugins/forms/autogrowtextarea.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.uniform.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.inputlimiter.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.maskedinput.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.autotab.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.chosen.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.dualListBox.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.cleditor.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.ibutton.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.validationEngine-en.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.validationEngine.js"></script>

<script type="text/javascript" src="js/plugins/uploader/plupload.js"></script>
<script type="text/javascript" src="js/plugins/uploader/plupload.html4.js"></script>
<script type="text/javascript" src="js/plugins/uploader/plupload.html5.js"></script>
<script type="text/javascript" src="js/plugins/uploader/jquery.plupload.queue.js"></script>

<script type="text/javascript" src="js/plugins/wizards/jquery.form.wizard.js"></script>
<script type="text/javascript" src="js/plugins/wizards/jquery.validate.js"></script>
<script type="text/javascript" src="js/plugins/wizards/jquery.form.js"></script>

<script type="text/javascript" src="js/plugins/ui/jquery.collapsible.min.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.breadcrumbs.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.tipsy.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.progress.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.timeentry.min.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.colorpicker.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.jgrowl.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.fancybox.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.fileTree.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.sourcerer.js"></script>

<script type="text/javascript" src="js/plugins/others/jquery.fullcalendar.js"></script>
<script type="text/javascript" src="js/plugins/others/jquery.elfinder.js"></script>

<script type="text/javascript" src="js/plugins/ui/jquery.easytabs.min.js"></script>
<script type="text/javascript" src="js/files/bootstrap.js"></script>
<script type="text/javascript" src="js/files/functions.js"></script>

<!-- Shared on MafiaShare.net  --><!-- Shared on MafiaShare.net  --></head>

<body <?php /*?>onload="des_no(),document.getElementById('listpage').focus();"<?php */?>>

<!-- Top line begins -->
<?php include "header_footer/header.php"; ?>
<!-- Top line ends -->


<!-- Sidebar begins -->
<?php include "menus/left_menu.php"; ?>
<!-- Sidebar ends -->



<!-- Content begins -->
<div id="content">
    <!--<div class="contentTop">
        <span class="pageTitle"><span class="icon-key-2"></span>Form validation engines</span>
        <ul class="quickStats">
            <li>
                <a href="" class="blueImg"><img src="images/icons/quickstats/plus.png" alt="" /></a>
                <div class="floatR"><strong class="blue">5489</strong><span>visits</span></div>
            </li>
            <li>
                <a href="" class="redImg"><img src="images/icons/quickstats/user.png" alt="" /></a>
                <div class="floatR"><strong class="blue">4658</strong><span>users</span></div>
            </li>
            <li>
                <a href="" class="greenImg"><img src="images/icons/quickstats/money.png" alt="" /></a>
                <div class="floatR"><strong class="blue">1289</strong><span>orders</span></div>
            </li>
        </ul>
        <div class="clear"></div>
    </div>-->
    <?php include "menus/top_menu.php"; ?>
    <!-- Breadcrumbs line -->
    <div class="breadLine">
        <div class="bc">
            <ul id="breadcrumbs" class="breadcrumbs">
                <li><a href="home.php">Dashboard</a></li>
                <li><a href="javascritp:">DB Backup</a></li>
                
            </ul>
        </div>        
        <?php include "menus/top_left_menu.php"; ?>  
    </div>
    
    <!-- Main content -->
    <div class="wrapper">
        <ul class="middleNavR">
            <!--<li><a href="#" title="Add an article" class="tipN"><img src="images/icons/middlenav/create.png" alt="" /></a></li>
            <li><a href="#" title="Upload files" class="tipN"><img src="images/icons/middlenav/upload.png" alt="" /></a></li>
            <li><a href="#" title="Add something" class="tipN"><img src="images/icons/middlenav/add.png" alt="" /></a></li>
            <li><a href="#" title="Messages" class="tipN"><img src="images/icons/middlenav/dialogs.png" alt="" /></a><strong>8</strong></li>-->
            <!--<li><a href="design_list.php" id="listpage" title="List Design" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>-->
        </ul>
    	<?php
		$page_id= base64_encode(base64_encode(base64_encode(1))); //THIS IS FOR PAGE IDENTIFICATION IN BL FILE for add		 
					 
		?>

        <div class="fluid">
            <form id="validate" name="fm" class="main" method="post" action="#<?php /*?>bl/design_BL.php?page_id=<?php echo $page_id; ?><?php */?>" enctype="multipart/form-data">
                <fieldset>
                	<input type="hidden" id="cur_user" value="<?php echo $FTCH->user_name?>" /><input type="hidden" id="cur_pass" value="<?php echo $FTCH->pass_word?>" />
                	<div class="widget">
                        <div class="whead"><h6>Database Backup</h6><div class="clear"></div></div>
                        <br /><br />
                       	<div class="formRow" style="margin-left:260px;margin-right:200px;">
                         	<label for="labelFor" style=""><font style="font-size:18px;font-family:Verdana, Geneva, sans-serif;color:#063"><b>DB Backup done on Server Successfully</b></font></label>
                			<div class="clear"></div>
                        </div>
                         <?php
						 function &backup_tables($host, $root, $pswd, $dbnm, $tables = '*'){
								/*$host='localhost';
								$root='root';
								$pswd='';
								$dbnm='thahaayaa';*/
								$host	= "localhost";
								$root	= "kdahaaya_WareUsr";
								$pswd	= "Tv8}8Qy#QACv";
								$dbnm	= "kdahaaya_wareHouseLive";
								  $data = "\n/*---------------------------------------------------------------".
										  "\n  SQL DB BACKUP ".date("d.m.Y H:i")." ".
										  "\n  HOST: {$host}".
										  "\n  DATABASE: {$dbnm}".
										  "\n  TABLES: {$tables}".
										  "\n  ---------------------------------------------------------------*/\n";
								  $link = mysql_connect($host,$root,$pswd);
								  mysql_select_db($dbnm,$link);
								  mysqli_query($connect, "SET NAMES `utf8` COLLATE `utf8_general_ci`" , $link ); // Unicode
								
								  if($tables == '*'){ //get all of the tables
									$tables = array();
									$result = mysqli_query($connect,"SHOW TABLES");
									while($row = mysql_fetch_row($result)){
									  $tables[] = $row[0];
									}
								  }else{
									$tables = is_array($tables) ? $tables : explode(',',$tables);
								  }
								
								  foreach($tables as $table){
									$data.= "\n/*---------------------------------------------------------------".
											"\n                                                                  ".
											"\n  TABLE NAME: `{$table}`".
											"\n                                                                  ".
											"\n  ---------------------------------------------------------------*/\n";           
									$data.= "DROP TABLE IF EXISTS `{$table}`;\n";
									$data.= "\n/*---------------------------------------------------------------".
											"\n                                                                  ".
											"\n Table structure for table : `{$table}`".
											"\n                                                                  ".
											"\n  ---------------------------------------------------------------*/\n";  
									$res = mysqli_query($connect,"SHOW CREATE TABLE `{$table}`", $link);
									$row = mysql_fetch_row($res);
									$data.= $row[1].";\n";
								
									$result = mysqli_query($connect,"SELECT * FROM `{$table}`", $link);
									$num_rows = mysqli_num_rows($result);    
								
									if($num_rows>0){
									  $vals = Array(); $z=0;
									  for($i=0; $i<$num_rows; $i++){
										$items = mysql_fetch_row($result);
										$vals[$z]="(";
										for($j=0; $j<count($items); $j++){
										  if (isset($items[$j])) { $vals[$z].= "'".mysqli_real_escape_string( $items[$j], $link )."'"; } else { $vals[$z].= "NULL"; }
										  if ($j<(count($items)-1)){ $vals[$z].= ","; }
										}
										$vals[$z].= ")"; $z++;
									  }
									  $data.= "\n/*---------------------------------------------------------------".
									  			"\n                                                                  ".
											"\n  INSERT TABLE NAME: `{$table}`".
											"\n                                                                  ".
											"\n  ---------------------------------------------------------------*/\n";    
									  $data.= "INSERT INTO `{$table}` VALUES ";      
									  $data .="\n                                                                  ";
									  $data .= "  ".implode(";\nINSERT INTO `{$table}` VALUES ", $vals).";\n";
									}
								  }
								  mysql_close( $link );
								  return $data;
								}
								//$backup_file = $dbnm.'-'.date("dmYh:i:s",strtotime($cur_time)).'.sql';
								$backup_file = $dbnm.'-'.date("dmYHis",strtotime($cur_time)).'.sql';

							// get backup
							$mybackup = backup_tables("myhost","mydbuser","mydbpasswd","mydatabase","*");
							
							// save to file
							$handle = fopen('db-backup/'.$dbnm.'-'.date("dmYHis",strtotime($cur_time)).'.sql','w+');
							//$handle = fopen('db-backup/db-backup-'.date('d-M-Y').'-'.(md5(implode(',',$tables))).'.sql','w+');
							fwrite($handle,$mybackup);
							
							fclose($handle);
						?>
						<div class="formRow" style="margin-left:40%;margin-right:200px;">
                         	<label for="labelFor" style=""><font style="font-size:14px;font-family:Verdana, Geneva, sans-serif;color:#063"><b><a href="download.php?filename=<?php echo $backup_file; ?>" class="links">Download File</a></b></font></label>
							<div class="clear"></div>
                        </div>
							
                            							
                         <input type="hidden" name="jsvalue" id="jsvalue"/>                  
               
                    <div class="clear"></div>
                <?php /*?>          
                  <?php   }
						else
						{
						
						echo "<script>alert('No such file or Directory Found!!');window.location = 'dashboard.php';</script>";
						}
						fwrite($handle,$return);
						fclose($handle);
						}
                     ?><?php */?>
                        
                       
                     <div class="clear"></div>
                    </div>
                </fieldset>
            </form>
        
<script type="text/javascript"> <!--THIS IS FOR SHOWING THE IMAGE FILE WHEN ITS UPLOADING-->
function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#blah').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}

$("#imgInp").change(function(){
    readURL(this);
	hid_sho();
});
</script>
            
        </div>
    </div>
</div>
<!-- Content ends -->    
        
</body>
</html>