<?php include $this->admin_tpl('meta');?>
<title>SQL命令行 - YzmCMS内容管理系统</title>
</head>
<body>
<nav class="breadcrumb"><i class="yzm-iconfont yzm-iconai-home"></i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> SQL命令行 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="yzm-iconfont yzm-iconshuaxin"></i></a></nav>
<div class="page-container">
    <div class="explain explain-error light"> 
    	<p><span class="yzm-iconfont yzm-iconshuoming"></span>执行SQL将直接操作数据库，请谨慎使用，（表前缀可用“yzmcms_”代替）.</p>
    </div>
	<div class="formdoby_normal mt-15"> 
		<form method="post" action="<?php echo U('do_sql');?>" name="myform" id="myform" onsubmit="return check_all()">
			<ul>
				 <li>
				  	<textarea class="textarea" name="sqlstr" placeholder="请输入SQL命令" style="height:300px" ><?php if(isset($sqlstr)) echo $sqlstr;?></textarea>
				  	<input type="hidden" name="action" value="many" id="action">
				 </li>
				 <li>
					 <input class="dosubmit w_120 btn-primary radius" name="single" onclick="setacton('single')" type="submit" value="执行单条SQL">
					 <input class="dosubmit w_120 btn-success radius" name="many" onclick="setacton('many')" type="submit" value="执行多条SQL"> 
				 </li>
			</ul>
		</form>
		<?php if(isset($str)){?>
		<div class="mt-20">
		<?php 
		if(is_array($result)){
			if(!empty($result)){
		?>
			<table class="table table-border table-bg table-hover">
				<thead>
				<tr>
					<?php 
					$keys = array_keys($result[0]);
					foreach($keys as $val){
						echo '<th>'.$val.'</th>';
					}
					
					?>
				</tr>
				</thead>
				<tbody>				
				<?php 
				foreach($result as $row){
					echo '<tr>';
					foreach($row as $val){
						echo '<td>'.$val.'</td>';
					}
					echo '</tr>';
				}
				?>				
				</tbody>
			</table>
		<?php
			}else{
				echo '<p class="c-red">查询结果为空！</p>';
			}
		}else{
			echo $str;
		}
		?>
		</div>
		<?php }?>
	</div>
</div>
<?php include $this->admin_tpl('footer');?>
<script type="text/javascript">
function setacton(action){
		document.getElementById('action').value = action;
}

function check_all(){
		var sqlstr = document.myform.sqlstr.value;
		if(sqlstr==""){
			layer.msg("请输入SQL命令！", {icon:2});
			return false;
		}
		var reg = /^delete/i;	
		var reg2 = /^(.*)where(.*)/i;	
		if(reg.test(sqlstr) && !reg2.test(sqlstr) ){
			layer.confirm('检测到delete语句没有加where条件，是否继续？', {title:"操作提示",icon:0}, function(index){
				document.getElementById('myform').submit();
			});
			return false;
		}		
		return true;
}
</script>

</body>
</html>