<?php
error_reporting(0);
//加载常用函数
include_once("../include/common.php");
//加载分页函数
include_once("../include/page.inc.php");
session_start();
islogin();
$url=$_POST["url"] ? $_POST["url"] : $_GET["url"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style/index.css" />
<title></title>
</head>
<script language="javascript">
function selectbox(box)
{
	var boxall=document.form1.dodel;
	if(box=="select")
	{
		for(var i=0;i<boxall.length;i++)
		{
				boxall[i].checked=true;
		}
	}
	if(box=="clear")
	{
		for(var i=0;i<boxall.length;i++)
		{
			boxall[i].checked=false;
		}
	}
	
	if(box=="fanxuan")
	{
		for(var i=0;i<boxall.length;i++)
		{
			if(boxall[i].checked==false)
			{
				boxall[i].checked=true;
			}
			else
			{
				boxall[i].checked=false;
			}
		}
	}
}

function checkselect()
{
	
	var boxall=document.form1.dodel;
	var biaoji=0;
	for(var i=0;i<boxall.length;i++)
	{
		if(boxall[i].checked==false)
		{
			
			biaoji+=0;
		}
		else
		{
			biaoji+=1;
		}
	}
	if(biaoji==0)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function del()
{
	//document.write("test ok");
	document.getElementById("form1").action="func/pfunc.php?action=dodel";
	if(checkselect())
	{
		if(confirm("确定要全部删除吗,所有的附件及内容将要全部删除?"))
		{
			document.getElementById("form1").submit();
		}
	
	}
	else
	{
		alert("请至少选择一项");
	}

}

function submitform()
{
	
	document.getElementById("form1").action="func/pfunc.php?action=move";
	if(checkselect())
	{
		if(confirm("确定要批量设置分类吗?"))
		{
			document.getElementById("form1").submit();
		}
	
	}
	else
	{
		alert("请至少选择一项");
	}

}
</script>
<body>
<form name="form1" id="form1" method="post">
<table width="90%"  border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC" bordercolordark="#FFFFFF" class="tableborder">
  <tr>
    <td height="53" colspan="7" align="center" class="title">产品管理</td>
  </tr>
  <tr>
    <td width="5%">&nbsp;</td>
    <td width="14%" align="center" bgcolor="#F3F3F3" class="normal">ID</td>
    <td width="15%" align="center" bgcolor="#F3F3F3" class="normal">标题</td>
    <td width="15%" align="center" bgcolor="#F3F3F3" class="normal">分类</td>
    <td width="15%" align="center" bgcolor="#F3F3F3" class="normal">时间</td>
    <td width="14%" align="center" bgcolor="#F3F3F3" class="normal">附件数</td>
    <td width="22%" align="center" bgcolor="#F3F3F3" class="normal">操作</td>
  </tr>

<?
//分页数
$pageid=intval($_GET["pageid"]);

$pagesize=15;

$pageurl=$_SERVER["PHP_SELF"]."?";

if(!$pageid)
{
	$pageid=1;
}
$offset=($pageid-1)*$pagesize;
if($offset<=0)
{
	$offset=0;
}

$total=$mysql->rownums("select a.id,a.title,b.name,a.time from product  a left join pclass b on a.bigclassid=b.id");


$mysql->query("select a.id,a.title,b.name,a.time from product  a left join pclass b on a.bigclassid=b.id order by id desc limit $offset,$pagesize ");

//获取总记录数

while($arr=$mysql->fetcharray())
{
	//print_r($arr);
//统计附件数
$attach=$mysql->rownums("select * from product a left join attachment b on b.aid=a.id where b.aid=$arr[0] ");
print<<<EOT
  <tr>
    <td align="center"><label>
      <input type="checkbox" name="dodel[]" id="dodel" value="{$arr[0]}" />
    </label></td>
    <td align="center" class="normal">{$arr[0]}</td>
    <td align="center" class="normal">{$arr[1]}</td>
    <td align="center" class="normal">{$arr[2]}</td>
    <td align="center" class="normal">{$arr[3]}</td>
    <td align="center" class="normal">{$attach}</td>
    <td align="center" class="normal"><a href="pedit.php?id={$arr[0]}">修改</a> - <a href="func/pfunc.php?action=del&id={$arr[0]}" onclick="return confirm('您确认要删除吗,程序将要删除数据库内容以及附件?')">删除</a></td>
  </tr>
EOT;
}
?>
 
 <tr>
    <td height="37" colspan="5" align="left">&nbsp;<a href="#" onclick="selectbox('select')">全选</a> &nbsp;/ &nbsp;<a href="#" onclick="selectbox('clear')">取消全选</a>&nbsp;&nbsp;<a href="#" onclick="selectbox('fanxuan')">反选</a>&nbsp;&nbsp;<a href="#" onclick="del()">全部删除</a></td>
    <td colspan="2" align="center" class="normal">批量分类:&nbsp;&nbsp;
      <label>
  <select name="category" id="category" onchange="submitform()">
  <option selected="selected" value=0>--选择分类--</option>
        <?
		$result=$mysql->query("select * from pclass");
		while($arr=$mysql->fetcharray($result))
		{
			echo "<option value=".$arr["id"].">".$arr['name']."</option>";
		}
		?>
        </select>
      </label></td>
  </tr>
 <tr>
   <td colspan="7" align="center" class="normal"><? 
   //echo $total.$pagesize.$pageurl;
  echo page($total,$pagesize,$pageurl);
   
   ?></td>
 </tr>
</table>
</form> 
</body>
</html>