<?
error_reporting(0);

require("../include/common.php");

include_once(ROOT.'include/page.inc.php');

session_start();
islogin();
?>
<!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.getElementsByName("attach");
	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("attach");
	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("form1").action="func/afunc.php?action=dodel";
	if(checkselect())
	{
		if(confirm("确定要全部删除吗,所有的附件及内容将要全部删除?"))
		{
			document.getElementById("form1").submit();
		}
	
	}
	else
	{
		alert("请至少选择一项");
	}

}

function show(name,id)
{
	var name="show"+name;
	if(id=="1")
	{
	document.getElementById(name).style.display="block";
	}
	if(id=="0")
	{
	document.getElementById(name).style.display="none";
	}
}
</script>
<body>
<table width="90%"  border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC" bordercolordark="#FFFFFF" class="tableborder">
  <tr>
    <td height="38" colspan="7" align="center" class="title">附件管理</td>
  </tr>
  <tr>
    <td width="3%">&nbsp;</td>
    <td width="6%" align="center" bgcolor="#F3F3F3" class="normal">ID</td>
    <td width="37%" align="center" bgcolor="#F3F3F3" class="normal">附件URL</td>
    <td width="15%" align="center" bgcolor="#F3F3F3" class="normal">附件类型</td>
    <td width="18%" align="center" bgcolor="#F3F3F3" class="normal">附件大小</td>
    <td width="15%" align="center" bgcolor="#F3F3F3" class="normal">关联文章ID </td>
    <td  align="center" bgcolor="#F3F3F3" class="normal">操作</td>
  </tr>
  
<form id="form1" name="form1" method="post"> 
<?
$pagesize=15;
$page=intval($_GET["pageid"]);
if($page<=0 && !$page)
{
	$page=1;
}
$offset=($page-1)*$pagesize;
if($offset<0)
{
	$offset=0;
}
//计算总记录数
$total=$mysql->rownums("select * from attachment");
//获得当前页面路径
$url=$_SERVER['PHP_SELF']."?";

$mysql->query("select * from attachment order by id desc limit $offset,$pagesize");

while($arr=$mysql->fetcharray())
{
$filesize=ceil(intval($arr["filesize"])/1024);	
print<<<EOT
  <tr>
  <td align="center"><label>
      <input type="checkbox" name="attach[]" id="attach" value="{$arr['id']}" />
    </label></td>
    <td align="center">{$arr["id"]}</td>
    <td align="center"><a href="{$arr['attach']}" target="_blank" onmouseover="show('{$arr["id"]}','1')" onmouseout="show('{$arr["id"]}','0')">{$arr["attach"]}</a><div id="show{$arr["id"]}" style="position:absolute;display:none;padding-left:20%;"><img width="300" src="{$arr["attach"]}"/></div></td>
    <td align="center">{$arr["filetype"]}</td>
    <td align="center">{$filesize}&nbsp;Kb</td>
    <td align="center">{$arr["aid"]}</td>
	<td align="center" width="10%"><a href="func/afunc.php?action=del&id={$arr["id"]}" onclick="return confirm('确认要删除吗?')">删除</a></td>
 </tr>
EOT;
}
?>
</form>

<tr>
<td height="20" colspan="7"><a href="#" onclick="selectbox('select')">全选</a> &nbsp;/&nbsp;<a href="#" onclick="selectbox('clear')">&nbsp;取消全选</a>&nbsp;&nbsp;<a href="#" onclick="selectbox('fanxuan')">反选</a>&nbsp;&nbsp;<a href="#" onclick="dodel();">全部删除</a></td>
</tr>
<tr>
  <td height="20" colspan="7" align="center" class="normal"><? echo page($total,$pagesize,$url);?></td>
  </tr>
</table>
</body>
</html>