<?php include $this->admin_tpl('meta');?>
<title>数据备份 - YzmCMS内容管理系统</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 数据管理 <span class="c-gray en">&gt;</span> 数据备份 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<form method="post" name="myform" id="myform" action="<?php echo U('export_list');?>">
	<input type="hidden" name="dosubmit" value="1">
	<div class="cl pd-5 bg-1 bk-gray"> 
	<span class="l">
	<input class="btn btn-primary radius" onclick="yzm_export()" value="立即备份" type="button">
	<input class="btn btn-success radius" onclick="yzm_ajax('<?php echo U('public_optimize');?>')" value="优化表" type="button">
	<input class="btn btn-warning radius" onclick="yzm_ajax('<?php echo U('public_repair');?>')" value="修复表" type="button">
	</span>
	</div>
	<table class="table table-border table-bordered table-bg table-hover">
		<thead>
			<tr class="text-c">
				<th><input type="checkbox" checked></th>
				<th>表名</th>
				<th>类型</th>
				<th>编码</th>
				<th>数据量</th>
				<th>数据大小</th>
				<th>创建时间</th>
				<th>碎片</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<?php 
			   foreach($data as $val){
			 ?>
			<tr class="text-c">
				<td><input type="checkbox" value="<?php echo $val['Name']?>" name="tables[]" checked></td>
				<td><?php echo $val['Name'];?></td>
				<td><?php echo $val['Engine'];?></td>
				<td><?php echo $val['Collation'];?></td>
				<td><?php echo $val['Rows'];?></td>
				<td><?php echo sizecount($val['Data_length']);?></td>
				<td><?php echo $val['Create_time'];?></td>
				<td><?php echo $val['Data_free'];?></td>
				<td class="td-manage"> 
					<a title="优化表" href="javascript:;" onclick="yzm_ajax('<?php echo U('public_optimize');?>', '<?php echo $val['Name'];?>')" class="btn-mini btn-secondary">优化</a> 
					<a title="修复表" href="javascript:;" onclick="yzm_ajax('<?php echo U('public_repair');?>', '<?php echo $val['Name'];?>')" class="btn-mini btn-warning ml-5">修复</a> 
					<a title="表结构" href="javascript:;" onclick="yzm_open('表 <?php echo $val['Name'];?> 结构','<?php echo U('public_datatable_structure',array('table'=>$val['Name']));?>', 700, 500)" class="btn-mini btn-success ml-5">结构</a>
				</td>
			</tr>
			<?php 
			   }		 
			?>	
		</tbody>
	</table>
	</form>
</div>
<?php include $this->admin_tpl('footer');?>
<script>
	function yzm_ajax(url) {
		var table = arguments[1] || 0;
		var data = table ? {"tables":table} : $("#myform").serialize();
		if (table==0 && $("input[name='tables[]']:checked").length<1){
		   layer.alert('请先勾选表！');
		   return false;
		}
		$.ajax({
	        type: 'POST',
	        url: url, 
	        data: data,
		    dataType: "json", 
	        success: function (msg) {
				if(msg.status == 1){
					layer.msg(msg.message, {icon:1,time:1500},function(){
						window.location.reload();
					});
			    }else{
			    	layer.alert(msg.message, {icon:2});
				}
	        }
	    })
	}

	function yzm_export() {
		if ($("input[name='tables[]']:checked").length<1){
		   layer.alert('请先勾选表！');
		   return false;
		}
		layer.msg('<span id="yzm_message">开始请求服务器……</span>', {icon:16, shade:0.21, shadeClose:true, time:false});
		$.ajax({
			type: 'POST',
			url: '<?php echo U('export_list');?>', 
			data: $("#myform").serialize(),
			dataType: "json", 
			success: function (msg) {
				if(msg.status == 1){
					$("#yzm_message").html(msg.message);
					yzm_dorequest(msg.tab.id, msg.tab.start);
				}else{
					layer.alert(msg.message, {icon:2});
				}
			}
		}) 
	}

	function yzm_dorequest(id, start) {
		$.ajax({
	        type: 'POST',
	        url: '<?php echo U('export_list');?>', 
	        data: {"id":id, "start":start, "yzm_csrf_token":yzm_csrf_token},
		    dataType: "json", 
	        success: function (msg) {
				if(msg.status == 1){
					layer.msg(msg.message, {icon:1, time:1500}, function(){
						window.location.href = msg.url;
					});
			    }else if(msg.status == 2){
			    	$("#yzm_message").html(msg.message);
					yzm_dorequest(msg.tab.id, msg.tab.start);
				}else{
					layer.alert(msg.message, {icon:2});
				}
	        }
	    })
	}
</script>
</body>
</html>