<?php
error_reporting(0);
include_once("../include/common.php");
session_start();
islogin();
$url=$_POST["url"] ? $_POST["url"] : $_GET["url"];
$id=intval($_GET["id"]);
?>
<!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>
<script language="javascript">
function formcheck()
{
	if(document.getElementById("fenlei").value=="")
	{
		alert("请填写分类");
		return false;
	}
	else
	{
		return true;
	}
	
}
function selectbox(box)
{
	var boxall=document.getElementsByName("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.getElementsByName("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 dodel()
{
	
	document.getElementById("form2").action="func/docategory.php?category=news&action=dodel";
	if(checkselect())
	{
		if(confirm("确定要删除吗?"))
		{
			document.getElementById("form2").submit();
		}
	
	}
	else
	{
		alert("请至少选择一项");
	}

}
</script>
</head>

<body>
<?
print<<<EOT
<table width="90%" bordercolor="#cccccc" border="0" align="center" cellpadding="0" cellspacing="0" bordercolordark="#FFFFFF" class="tableborder" >
  <tr>
    <td colspan="3" width="85%" height="36" align="center" class="title">产品分类管理</td>
    <td width="15%" align="center" class="title"><a href="nfenlei.php?url=add">添加分类</a></td>
  </tr>
  <tr>
  	<td height="28" bgcolor="#F3F3F3" align="center">&nbsp;</td>
    <td height="28" bgcolor="#F3F3F3" align="center" class="normal">分类ID</td>
    <td align="center" bgcolor="#F3F3F3" class="normal">分类名称</td>
	<td width="32%" align="center" bgcolor="#F3F3F3" class="normal">操作</td>
  </tr>
<form name="form2" id="form2" method="post"> 
EOT;


$mysql->query("select * from nclass order by id asc");
	while($fenlei=$mysql->fetcharray())
	{
print<<<EOT
<tr>
    <td align="center" class="normal">
<input name="dodel[]" id="dodel" type="checkbox" value="{$fenlei["id"]}"/>
</td>
  <td align="center" class="normal">
{$fenlei["id"]}
</td>
<td align="center" class="normal">
{$fenlei["name"]}
	</td>
	<td width="32%" align="center"><a href="nfenlei.php?url=edit&id={$fenlei["id"]}">修改</a>- <a href="func/docategory.php?category=news&action=del&id={$fenlei["id"]}" onclick="return confirm('您确认要删除此分类吗?');">删除</a></td>
</tr>
EOT;
}
print<<<EOT
</form>
EOT;



if($url=="add")
{
print<<<EOT
<tr>
    <td height="36" colspan="4" align="right" class="title"><form id="form1" name="form1" method="post" action="func/docategory.php?category=news&action=add" onsubmit="return formcheck()">
      <label>
        <input type="text" name="fenlei" id="fenlei" />
      </label>
      <label>
        &nbsp;&nbsp;
        <input type="submit" name="button" id="button" value="添加分类" />
      </label>
    </form></td>
  </tr>
EOT;
}




if($url=="edit")
{
	$mysql->query("select * from nclass where id=$id");
	$arr=$mysql->fetcharray();
print<<<EOT
<tr>
    <td height="36" colspan="4" align="right" class="title"><form id="form1" name="form1" method="post" action="func/docategory.php?category=news&action=edit&id={$id}" onsubmit="return formcheck()">
      <label>
        <input type="text" name="fenlei" id="fenlei" value={$arr["name"]} />
      </label>
      <label>
        &nbsp;&nbsp;
        <input type="submit" name="button" id="button" value="修改分类" />
      </label>
    </form></td>
  </tr>
EOT;
}


print<<<EOT
<tr>
<td  colspan="4" height="39">
<a href="#" onclick="selectbox('select');">全选</a>&nbsp;&nbsp;/&nbsp;&nbsp;<a href="#" onclick="selectbox('clear');">取消全选</a> &nbsp;&nbsp; <a href="#" onclick="selectbox('fanxuan');">反选</a>   &nbsp;<a href="#"  onclick="return dodel();">全部删除</a>
</td>
</tr>
EOT;
$mysql->close();
?>
</table>
</body>
</html>