<?php
$page = @$_GET['page'];
$pagesize = 10;
if(!$page){$page=1;}
$pagenum = ($page-1)*$pagesize;
mysql_select_db($dbname, $conn);          //选择数据库
if($a=="del"){
$arr = explode(",",$_GET['ids']);
	foreach($arr as $id){		//循环验证权限
		if($id==""){break;}//ID为空就跳出循环
		$sql = "delete FROM `".$qz."order` WHERE `id` =".$id;
		mysql_query($sql);
		$sql = "OPTIMIZE TABLE  `".$qz."order`";	//优化表
		mysql_query($sql);
	}
	header("location:?m=alist");
	die;
}
$sql = "SELECT * FROM  `".$qz."order` ORDER BY `id` desc LIMIT ".$pagenum." , ".$pagesize;

$rs = mysql_query($sql);
if(!$rs){die(mysql_error());}
$content = array();
while($row = mysql_fetch_array($rs)){
	// 给数组赋值
	$content[] = $row;
}
?>
<div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="./">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">信息管理</span></div>
        </div>
<!--         <div class="search-wrap">
            <div class="search-content">
                <form action="/jscss/admin/design/index" method="post">
                    <table class="search-tab">
                        <tr>
                            <th width="120">选择分类:</th>
                            <td>
                                <select name="search-sort" id="">
                                    <option value="">全部</option>
                                    <option value="19">精品界面</option><option value="20">推荐界面</option>
                                </select>
                            </td>
                            <th width="70">关键字:</th>
                            <td><input class="common-text" placeholder="关键字" name="keywords" value="" id="" type="text"></td>
                            <td><input class="btn btn-primary btn2" name="sub" value="查询" type="submit"></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div> -->
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a id="echocheck" href="javascript:;"><i class="icon-font"></i>批量删除</a><div class="tips right">Tips：如果出现乱码请将前台form里加入： <strong>accept-charset="UTF-8"</strong> &nbsp; <a href="http://jingyan.baidu.com/article/fb48e8be31f26b6e622e141f.html" target="_blank">详细</a></div>
                    </div>
                </div>
                <div class="result-content">
                    <table class="result-tab" width="100%">
                        <tr>
                            <th class="tc" width="10px"><input id="checkedAll" class="allChoose" type="checkbox"></th>
                            <th width="80px">ID</th>
                            <th>详细</th>
							<th width="105px">IP</th>
							<th width="150px">来源</th>
							<th width="120px">提交时间</th>
                            <th width="80px">操作</th>
                        </tr>
<?php
for($temp = 0;$temp < count($content);$temp++){

$iid=$content[$temp]["id"];
	echo '<tr>
                            <td class="tc"><input name="check" value="'.$iid.'" type="checkbox"></td>
                            <td>'.$iid.'</td>
                            <td>'.base64_decode($content[$temp]["content"]).'</td>
							<td>'.$content[$temp]["ip"].'</td>
							<td>'.base64_decode($content[$temp]["from"]).'</td>
							<td>'.date('Y-m-d H:i',$content[$temp]["time"]).'</td>
                            <td><a class="link-del" href="javascript:;" onclick="del(\''.$iid.'\')"><i class="icon-font">&#xe019;</i> 删除</a></td>
                        </tr>';
}
//取得分页条数/总条数
	$sql = "select id from ".$qz."order";
	$result=mysql_query($sql);
	$num=mysql_num_rows($result);	//获取总条数
	if($num < $pagesize){$page_count = 1;}	//$page_count -> 总页数
	if($num % $pagesize){$page_count = (int)($num / $pagesize) + 1;}else{$page_count = $num / $pagesize;}
	
?>

                    </table>
                    <div class="list-page"> 
					<?php
					$prepage=1;
					if($page>1){$prepage=$page-1;}
					if($page_count>1 && $page<$page_count){$nextpage=$page+1;}else{$nextpage=$page;}
					$pagetext = $num." 条 ".$page."/".$page_count." 页";
					echo'<ul><li><a href="?m=alist&page=1" target="_self">首页</a></li><li><a href="?m=alist&page='.$prepage.'" target="_self">上一页</a></li><li><a href="?m=alist&page='.$nextpage.'" target="_self">下一页</a></li><li><a href="?m=alist&page='.$page_count.'" target="_self">尾页</a></li><li><span class="bartext">'.$pagetext.'</span></li>';
					?>
					</ul>
					</div>
                </div>
            </form>
        </div>
    </div>
<script type="text/javascript">
    $(document).ready(function () {

        $("#checkedAll").click(function () {

            if ($(this).attr("checked")) { // 全选 
                $("input[name='check']").each(function () {
                    $(this).attr("checked", true);
                });
            }else{ // 取消全选 
                $("input[name='check']").each(function () {
                    $(this).attr("checked", false);
                });
            }
        });

    }); 
	
$("#echocheck").click(function () {
	var str=document.getElementsByName("check");
	var objarray=str.length;
	var chestr="";
	for (i=0;i<objarray;i++){
	  if(str[i].checked == true){
	   chestr+=str[i].value+",";
	  }
	}
	if(chestr == ""){
	  alert("请最少选中一个！");
	}else{
		del(chestr);
	}
});

function del(ids){
		if(window.confirm('确定要删除？')){
                 //("确定");
				 document.location="?m=alist&a=del&ids="+ids;
                 return true;
              }else{
                 //("取消");
                 return false;
         }
}
</script>
<?php
mysql_close($conn);
?>