<?php
define('EmpireCMSAdmin','1');
require("../../class/connect.php");
require("../../class/db_sql.php");
require("../../class/functions.php");
require("../../class/t_functions.php");
require("../../class/tag.php");
require("../../class/dpfun.php");
require "../".LoadLang("pub/fun.php");
$link=db_connect();
$empire=new mysqlquery();
$editor=1;
//验证用户
$lur=is_login();
$logininid=$lur['userid'];
$loginin=$lur['username'];
$loginrnd=$lur['rnd'];
$loginlevel=$lur['groupid'];
$loginadminstyleid=$lur['adminstyleid'];
//验证权限
CheckLevel($logininid,$loginin,$classid,"tags");



$enews=$_POST['enews'];
if(empty($enews))
{$enews=$_GET['enews'];}
if($enews=="AddTags")//增加TAGS
{
	AddTags($_POST,$logininid,$loginin);
}
elseif($enews=="EditTags")//修改TAGS
{
	EditTags($_POST,$logininid,$loginin);
}
elseif($enews=="DelTags")//删除TAGS
{
	DelTags($_GET,$logininid,$loginin);
}
elseif($enews=="PushInfoToTag")//推送书籍至tag
{
	PushInfoToTag($_POST,$logininid,$loginin);
}
elseif($enews=="DelBfromT")//书籍从tag中移除
{
	$tid=(int)$_GET[tid];
	DelBfromT($tid,$logininid,$loginin);
}
elseif($enews=="SetTags")//设置TAGS
{
	SetTags($_POST,$logininid,$loginin);
}
elseif($enews=="ReTagOne")//刷新单一tag
{
	$tagid=(int)$_GET[tagid];
	ReTagOne($tagid,$logininid,$loginin);
}
elseif($enews=="ReAllTag")//刷新所有tag
{
	$start=(int)$_GET[start];
	ReAllTag($start,$logininid,$loginin);
}
elseif($enews=="ZhengliOne")//整理单一tag
{
	$tagid=(int)$_GET[tagid];
	ZhengliOne($tagid,$logininid,$loginin);
}
elseif($enews=="Zhengli")//整理所有tag
{
	$start=(int)$_GET[start];
	Zhengli($start,$logininid,$loginin);
}
else
{}

$page=(int)$_GET['page'];
$page=RepPIntvar($page);
$start=0;
$line=30;//每页显示条数
$page_line=20;//每页显示链接数
$offset=$page*$line;//总偏移量
//搜索
$add='';
$search='';
//关键字
if($_GET['keyboard'])
{
	$keyboard=RepPostVar($_GET['keyboard']);
	$show=(int)$_GET['show'];
	if($show==1)
	{
		$add.=" and tagid='$keyboard'";
	}
	else
	{
		$add.=" and tagname like '%$keyboard%'";
	}
	$search.="&show=$show&keyboard=$keyboard";
}
//排序
$orderby=$_GET['orderby'];
if($orderby==1)//按TAGID升序排序
{$doorder='tagid asc';}
elseif($orderby==2)//按信息数降序排序
{$doorder='num desc';}
elseif($orderby==3)//按信息数升序排序
{$doorder='num asc';}
elseif($orderby==4)//按信息数升序排序
{$doorder='isgood';}
elseif($orderby==5)//按信息数升序排序
{$doorder='isgood desc';}
else//按TAGID降序排序
{$doorder='tagid desc';}
$search.="&orderby=$orderby";
$add=$add?' where '.substr($add,5):'';
$query="select * from {$dbtbpre}enewstags".$add;
$totalquery="select count(*) as total from {$dbtbpre}enewstags".$add;
$num=$empire->gettotal($totalquery);//取得总条数
$query=$query." order by ".$doorder." limit $offset,$line";
$sql=$empire->query($query);

$returnpage=page2($num,$line,$page_line,$start,$page,$search);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../adminstyle/<?=$loginadminstyleid?>/adminstyle.css" rel="stylesheet" type="text/css">
<title>管理TAGS</title>
<script>
function CheckAll(form)
  {
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.name != 'chkall')
       e.checked = form.chkall.checked;
    }
  }
</script>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  <tr> 
    <td width="40%" height="25">位置：<a href=ListTags.php>管理TAGS</a></td>
    <td width="60%" align=right>
	  <a href="ListTags.php?enews=ReAllTag" target="_blank">[刷新全部TAG]</a> 
	  <a href="ListTags.php?enews=Zhengli" target="_blank">[整理全部TAG]</a>
	</td>
  </tr>
</table>
  <table width="100%" border="0" cellspacing="1" cellpadding="3">
  <form name="searchform" method="GET" action="ListTags.php">
    <tr> 
      <td height="25" width="70%">搜索：
        <select name="show" id="show">
          <option value="0"<?=$show==0?' selected':''?>>TAG名称</option>
		  <option value="1"<?=$show==1?' selected':''?>>TAGID</option>
        </select> 
        <input name="keyboard" type="text" id="keyboard" value="<?=$keyboard?>">
        <select name="orderby" id="orderby">
          <option value="0"<?=$orderby==0?' selected':''?>>按TAGID降序排序</option>
		  <option value="1"<?=$orderby==1?' selected':''?>>按TAGID升序排序</option>
          <option value="2"<?=$orderby==2?' selected':''?>>按信息数降序排序</option>
		  <option value="3"<?=$orderby==3?' selected':''?>>按信息数升序排序</option>
		  <option value="4"<?=$orderby==4?' selected':''?>>推荐等级升序</option>
		  <option value="5"<?=$orderby==5?' selected':''?>>推荐等级降序</option>
        </select> 
        <input type="submit" name="Submit2" value="显示"></td>
		<td width="30%"><div align="right" class="emenubutton">
        <input type="button" name="Submit" value="增加TAGS" onclick="self.location.href='AddTags.php?enews=AddTags';">&nbsp;
        <input type="button" name="Submit42" value="设置TAGS" onclick="self.location.href='SetTags.php';">&nbsp;
      </div></td>
    </tr>
  </form>
  </table>
<br>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  <form name="listform" method="post" action="ListTags.php" onsubmit="return confirm('确认要操作?');">
    <tr class="header"> 
      <td width="5%" height="25"> <div align="center">ID</div></td>
      <td width="20%" height="25"> <div align="center">TAG名称</div></td>
	  <td width="10%" height="25"> <div align="center">推荐等级</div></td>
      <td width="15%" height="25"> <div align="center">书籍数</div></td>
      <td width="22%"><div align="center">管理</div></td>
      <td width="28%" height="25"> <div align="center">操作</div></td>
    </tr>
    <?
  while($r=$empire->fetch($sql))
  {
	$tagsurl=$public_r[newsurl].'tags/'.$r[tagid].'/';
  ?>
    <tr bgcolor="#FFFFFF" onmouseout="this.style.backgroundColor='#ffffff'" onmouseover="this.style.backgroundColor='#E2E9EA'"> 
      <td height="25"> <div align="center"> 
          <?=$r[tagid]?>
        </div></td>
      <td height="25">&nbsp;&nbsp; 
        <a href="<?=$tagsurl?>" target="_blank">
        <?=$r[tagname]?>
        </a> </td>
      <td height="25"> <div align="center">
          <?=$r[isgood]?>
        </div></td>
      <td height="25"> <div align="center">
          <?=$r[num]?>
        </div></td>
      <td><div align="center">
          <a href="ListTagBook.php?tagid=<?=$r[tagid]?>">书籍管理</a>
        </div></td>
      <td height="25"> <div align="center"><a href="ListTags.php?enews=ReTagOne&tagid=<?=$r[tagid]?>" >[刷新]</a>&nbsp;&nbsp;<a href="ListTags.php?enews=ZhengliOne&tagid=<?=$r[tagid]?>" >[整理]</a>&nbsp;&nbsp;[<a href="AddTags.php?enews=EditTags&tagid=<?=$r[tagid]?>&fcid=<?=$cid?>">修改</a>]&nbsp;&nbsp;[<a href="ListTags.php?enews=DelTags&tagid=<?=$r[tagid]?>&fcid=<?=$cid?>" onclick="return confirm('确认要删除？');">删除</a>]</div></td>
    </tr>
    <?
  }
  ?>
    <tr bgcolor="#FFFFFF">
      <td height="25" colspan="6">
        <?=$returnpage?>
      </td>
    </tr>
  </form>
</table>
</body>
</html>
<?
db_close();
$empire=null;
?>