<?php 
//导航程序；
//$_GET[jc_tbl]来源于主菜单GET请求；
//$_SESSION[rightId]变量为权限ID值；
//$_SESSION[jc_tbl]变量为需要操作的表名称；
session_start();
switch($_GET[jc_tbl]){
	    case "现金流量":
		    $_SESSION[rightId]=1;
			$_SESSION[jc_tbl]="jc_xjll";
			$page_title="现金流量—恩格会计软件";
			break;
		case "客户":
		    $_SESSION[rightId]=2;
			$_SESSION[jc_tbl]="jc_kh";
			$page_title="客户—恩格会计软件";
			break;
		case "个人":
		    $_SESSION[rightId]=3;
			$_SESSION[jc_tbl]="jc_gr";
			$page_title="个人—恩格会计软件";
			break;
		case "存货":
		    $_SESSION[rightId]=4;
			$_SESSION[jc_tbl]="jc_ch";
			$page_title="存货—恩格会计软件";
			break;	
		case "供应商":
		    $_SESSION[rightId]=5;
			$_SESSION[jc_tbl]="jc_gys";
			$page_title="供应商—恩格会计软件";
			break;
		case "部门":
		    $_SESSION[rightId]=6;
			$_SESSION[jc_tbl]="jc_bm";
			$page_title="部门—恩格会计软件";
			break;
		case "核算项目":
		    $_SESSION[rightId]=7;
			$_SESSION[jc_tbl]="jc_xm";
			$page_title="核算项目—恩格会计软件";
			break;
		default://当出现GET到值不正确时，中止程序的执行；
		    require("locked.php"); 
		    include("header.php");
		    echo '<div align="center">get取值不正确</div>';
			include("footer.php");
			exit();
	}

$t1=microtime(true);//页面执行起始时间；

include("header.php");
//****************************************请求权限****************************************
require("locked.php");                                                                 //*
setlocked($_SESSION[rightId]);                                             //*
//****************************************************************************************

?>
<div align="center">
<h1 id="biaoti"><?php echo $_GET[jc_tbl]; ?></h1>
<form action="" method="post" name="form1">

<select name="serach">
<option value="id">ID</option>
<option value="name" selected="selected">名称</option>
<option value="etr">录入</option>
<option value="chk">审核</option>
</select>

<select name="cp">
<option value="包含" selected="selected">包含</option>
<option value="等于">等于</option>
<option value="开头是">开头是</option>
<option value="结尾是">结尾是</option>
</select>

<input name="keyword" type="text" />
<input id="tj1" name="ok" type="submit" value="提交" />

</form>
</div>
<div align="center">
<table id="mytable1" width="95%">
<tr>
<td align="center"><img src="picture/b_fulltext.png" width="50" height="19" /></td>
<td>ID</td>
<td>名称</td>
<td>录入</td>
<td>审核</td>
</tr>
<?php
if($_SERVER['REQUEST_METHOD']=='POST' && $_POST[ok]=='提交'){
	
	include("cnn.php");
	
	//给HTML控件赋值；
	echo '<script language="javascript" type="text/javascript">
		  form1.serach.value="'.$_POST[serach].'";
		  form1.cp.value="'.$_POST[cp].'";
		  form1.keyword.value="'.$_POST[keyword].'";
		  </script>';
	
	//构造查询SQL语句；
	switch($_POST[cp]){
		case "包含":
			$strSql='select * from '.$_SESSION[jc_tbl].' where '.$_POST[serach].' like "%'.$_POST[keyword].'%" order by id desc';
			break;
		case "开头是":
		    $strSql='select * from '.$_SESSION[jc_tbl].' where '.$_POST[serach].' like "'.$_POST[keyword].'%" order by id desc';
			break;
		case "结尾是":
		    $strSql='select * from '.$_SESSION[jc_tbl].' where '.$_POST[serach].' like "%'.$_POST[keyword].'" order by id desc';
			break;
		default:
		    $strSql='select * from '.$_SESSION[jc_tbl].' where '.$_POST[serach].'="'.$_POST[keyword].'" order by id desc';
			break;
	}
	
	$strsql=$mysqli->real_escape_string($strsql);
	$sql=$mysqli->query($strSql);
	$info=$sql->fetch_array(MYSQLI_BOTH);
	$num_rows=$sql->num_rows;
	
	echo '<hr width="95%">';
	echo '<div id="ts" align="center">查找到 '.$num_rows.' 条符合条件的记录</div>';//显示查询的记录数及处理时间；
	echo '<hr width="95%">';
	
	if($info){ //如果存在数据；
		DO{
		   echo '<tr>';
		   echo '<td align="center">';
		   echo '<a href="#" onclick="openInsert()"><abbr title="新增"><img src="picture/b_insert.png" /></abbr></a>|';
		   echo '<a href="#" onclick="openEdit('.$info[id].')"><abbr title="修改"><img src="picture/b_edit.png" /></abbr></a>|';
		   echo '<a href="#" onclick="openDrop('.$info[id].')"><abbr title="删除"><img src="picture/b_drop.png" /></abbr></a>|';
		   echo '<a href="#" onclick="openCheck('.$info[id].')"><abbr title="审核"><img src="picture/b_check.png" /></abbr></a>|';
		   echo '<a href="#" onclick="openCopy('.$info[id].')"><abbr title="复制"><img src="picture/b_copy.png" /></abbr></a>';
		   echo '</td>';
		   echo '<td>'.$info[id].'</td>';
		   echo '<td>'.$info[name].'</td>';
		   echo '<td>'.$info[etr].'</td>';
		   echo '<td>'.$info[chk].'</td>';
		   echo '</tr>';
		}while($info=$sql->fetch_array(MYSQLI_BOTH));
        $sql->free();
		$mysqli->close();
	}else{
		echo '<tr>';
		echo '<td align="center" colspan="5">';
		echo '系统未检索到相关数据；<a href="#" onclick="openInsert()">新增</a></td>';
		echo '</tr>';
	}
	echo '<script language="javascript" type="text/javascript">
		  //限制频繁点击提交按钮，再次提交需要等待三秒；
		  document.getElementById("tj1").disabled=true;
		  setTimeout("getTj()",3000)
		  function getTj(){
			  document.getElementById("tj1").disabled=false;
		  }
		  </script>';
}else{
	echo '<tr>';
	echo '<td align="center" colspan="5">';
	echo '请使用提交按钮检索相关数据；<a href="#" onclick="openInsert()">新增</a></td>';
	echo '</tr>';
}
echo '</table></div>';

?>

<script language="javascript" type="text/javascript">
<!--
mytable("mytable1");
var sta="height=250,width=550,top="+(window.screen.availHeight-250)/2+",left="+(window.screen.availWidth-550)/2;
sta=sta+",toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no";
function openInsert(){
	var url="jc_Insert.php?keyword="+document.getElementById("biaoti").innerHTML;
	window.open(url,"",sta);
}
function openEdit(id){
	var url="jc_Edit.php?keyword="+id
	window.open(url,"",sta);
}
function openDrop(id){
	var url="jc_Drop.php?keyword="+id
	window.open(url,"",sta);
}
function openCheck(id){
	var url="jc_Check.php?keyword="+id
	window.open(url,"",sta);
}
function openCopy(id){
	var url="jc_Copy.php?keyword="+id
	window.open(url,"",sta);
}

//自动加载高亮显示；
HighLight();

//-->
</script>

<?php

$t2=microtime(true);//页面执行终止时间；
//给HTML控件赋值；
echo '<script language="javascript" type="text/javascript">
	  document.getElementById("ts").innerHTML+="，耗时 '.round($t2-$t1,4).' 秒。";
	  </script>';
	
include("footer.php");

?>