<?php
define('EmpireCMSAdmin','1');
require('../class/connect.php');
require('../class/db_sql.php');
require('../class/functions.php');
require LoadLang("pub/fun.php");
require("../data/dbcache/class.php");
$link=db_connect();
$empire=new mysqlquery();
//验证用户
$lur=is_login();
$logininid=$lur['userid'];
$loginin=$lur['username'];
$loginrnd=$lur['rnd'];
$loginlevel=$lur['groupid'];
$loginadminstyleid=$lur['adminstyleid'];
//取得数据表
$tid=(int)$public_r['tid'];
$tbname=$_GET['tbname']?$_GET['tbname']:$public_r['tbname'];
$tbname=RepPostVar($tbname);
$changetbs='';
$havetb=0;
$tbsql=$empire->query("select tid,tbname,tname from {$dbtbpre}enewstable order by tid");
while($tbr=$empire->fetch($tbsql))
{
	$selected='';
	if($tbname==$tbr[tbname])
	{
		$tid=$tbr[tid];
		$selected=' selected';
		$havetb=1;
	}
	$changetbs.="<option value='".$tbr[tbname]."'".$selected.">".$tbr[tname]."(".$tbr[tbname].")</option>";
}
if($havetb==0)
{
	printerror('ErrorUrl','');
}
//取得相应的信息
$user_r=$empire->fetch1("select groupid,adminclass from {$dbtbpre}enewsuser where userid='$logininid'");
//取得用户组
$gr=$empire->fetch1("select doall,doselfinfo from {$dbtbpre}enewsgroup where groupid='$user_r[groupid]'");
//管理员
$where='';
$and='';
$ewhere='';
$search="&tbname=$tbname";
$ecmscheck=(int)$_GET['ecmscheck'];
$addecmscheck='';
$indexchecked=1;
if($ecmscheck)
{
	$search.='&ecmscheck='.$ecmscheck;
	$addecmscheck='&ecmscheck='.$ecmscheck;
	$indexchecked=0;
}
$infotb=ReturnInfoMainTbname($tbname,$indexchecked);
//优化
$modid=$etable_r[$tbname][mid];
$yhadd='';
$yhvar='hlist';
$yhid=$etable_r[$tbname][yhid];
if($yhid)
{
	$yhadd=ReturnYhSql($yhid,$yhvar);
	if($yhadd)
	{
		$and=$where?' and ':' where ';
		$where.=$and.$yhadd;
	}
}
if(empty($yhadd))
{
	//时间范围
	$infolday=(int)$_GET['infolday'];
	if(empty($infolday))
	{
		$infolday=$public_r['infolday'];
	}
	if($infolday&&$infolday!=1)
	{
		$ckinfolday=time()-$infolday;
		$and=$where?' and ':' where ';
		$where.=$and."newstime>'$ckinfolday'";
		$search.="&infolday=$infolday";
	}
}
if(!$gr['doall'])
{
	$cids='';
	$a=explode("|",$user_r['adminclass']);
	for($i=1;$i<count($a)-1;$i++)
	{
		$dh=',';
		if(empty($cids))
		{
			$dh='';
		}
		$cids.=$dh.$a[$i];
	}
	if($cids=='')
	{
		$cids=0;
	}
	$and=$where?' and ':' where ';
	$where.=$and.'classid in ('.$cids.')';
}
//只能编辑自己的信息
if($gr['doselfinfo'])
{
	$and=$where?' and ':' where ';
	$where.=$and."userid='$logininid' and ismember=0";
}
$url="<a href=ListAllBook.php?tbname=".$tbname.$addecmscheck.">管理书籍</a>";
$start=0;
$page=(int)$_GET['page'];
$page=RepPIntvar($page);
$line=intval($public_r['hlistinfonum']);//每页显示
$page_line=21;
$offset=$page*$line;
//栏目ID
$classid=intval($_GET['classid']);
if($classid)
{
	$and=$where?' and ':' where ';
	if($class_r[$classid][islast])
	{
		$where.=$and."classid='$classid'";
	}
	else
	{
		$where.=$and."(".ReturnClass($class_r[$classid][sonclass]).")";
	}
	$search.="&classid=$classid";
}
//模型
$infomod_r=$empire->fetch1("select mid,listfile from {$dbtbpre}enewsmod where mid='$modid'");
//标题分类
$ttid=(int)$_GET['ttid'];
if($ttid)
{
	$and=$where?' and ':' where ';
	$where.=$and."ttid='$ttid'";
	$search.="&ttid=$ttid";
}
//搜索
$sear=$_GET['sear'];
if($sear)
{
	$and=$where?' and ':' where ';
	$showspecial=$_GET['showspecial'];
	if($showspecial==1)//置顶
	{
		$where.=$and.'istop>0';
	}
	elseif($showspecial==2)//推荐
	{
		$where.=$and.'isgood>0';
	}
	elseif($showspecial==3)//头条
	{
		$where.=$and.'firsttitle>0';
	}
	elseif($showspecial==5)//签发
	{
		$where.=$and.'isqf=1';
	}
	elseif($showspecial==7)//投稿
	{
		$where.=$and.'ismember=1';
	}
	elseif($showspecial==8)//我的信息
	{
		$where.=$and."userid='$logininid' and ismember=0";
	}
	$and=$where?' and ':' where ';
	if($_GET['keyboard'])
	{
		$keyboard=RepPostVar2($_GET['keyboard']);
		$show=$_GET['show'];
		if($show==0)//搜索全部
		{
			$where.=$and."(title like '%$keyboard%' or username like '%$keyboard%' or id='$keyboard')";
		}
		elseif($show==1)//搜索标题
		{
			$where.=$and."(title like '%$keyboard%')";
		}
		elseif($show==3)//ID
		{
			$where.=$and."(id='$keyboard')";
		}
		else
		{
			$where.=$and."(username like '%$keyboard%')";
		}
	}
	$search.="&sear=1&keyboard=$keyboard&show=$show&showspecial=$showspecial";
}
//显示重复标题
if($_GET['showretitle']==1)
{
	$and=$where?' and ':' where ';
	$search.="&showretitle=1&srt=".$_GET['srt'];
	$addsrt="";
	$srtid="";
	$first=1;
	$srtsql=$empire->query("select id,title from ".$infotb." group by title having(count(*))>1");
	while($srtr=$empire->fetch($srtsql))
	{
		if($first==1)
		{
			$addsrt.="title='".addslashes($srtr['title'])."'";
			$srtid.=$srtr['id'];
			$first=0;
		}
		else
		{
			$addsrt.=" or title='".addslashes($srtr['title'])."'";
			$srtid.=",".$srtr['id'];
		}
	}
	if(!empty($addsrt))
	{
		if($_GET['srt']==1)
		{
			$where.=$and."(".$addsrt.") and id not in (".$srtid.")";
		}
		else
		{
			$where.=$and."(".$addsrt.")";
		}
	}
	else
	{
		printerror("HaveNotReInfo","ListAllBook.php?tbname=".$tbname.$addecmscheck);
	}
}
//排序
$orderby=$_GET['orderby'];
$doorderby=$orderby?'asc':'desc';
$myorder=$_GET['myorder'];
if($myorder==1)//ID号
{$doorder="id";}
elseif($myorder==2)//时间
{$doorder="newstime";}
elseif($myorder==5)//评论数
{$doorder="plnum";}
elseif($myorder==3)//人气
{$doorder="onclick";}
elseif($myorder==4)//下载
{$doorder="totaldown";}
else//默认排序
{$doorder="id";}
$doorder.=' '.$doorderby;
$search.="&myorder=$myorder&orderby=$orderby";
$totalquery="select count(*) as total from ".$infotb.$where;
//表信息数
$tbinfos=eGetTableRowNum("{$dbtbpre}ecms_".$tbname);
$tbckinfos=eGetTableRowNum("{$dbtbpre}ecms_".$tbname."_check");
//取得总条数
$totalnum=intval($_GET['totalnum']);
if($totalnum<1)
{
	if(empty($where))
	{
		$num=$indexchecked==1?$tbinfos:$tbckinfos;
	}
	else
	{
		$num=$empire->gettotal($totalquery);
	}
}
else
{
	$num=$totalnum;
}
$search1=$search;
$search.="&totalnum=$num";
$returnpage=page2($num,$line,$page_line,$start,$page,$search);
$phpmyself=urlencode(eReturnSelfPage(1));







//查询SQL，如果要显示自定义字段记得在SQL里增加查询字段
$query="select id,classid,titleurl,havehtml,isgood,firsttitle,ismember,userid,username,totaldown,onclick,newstime,truetime,lastdotime,titlepic,title,filesize from ".$infotb.$where." order by ".$doorder." limit $offset,$line";
$sql=$empire->query($query);
//返回头条和推荐级别名称
$ftnr=ReturnFirsttitleNameList(0,0);
$ftnamer=$ftnr['ftr'];
$ignamer=$ftnr['igr'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="adminstyle/<?=$loginadminstyleid?>/adminstyle.css" type="text/css">
<title>管理信息</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;
    }
  }

function GetSelectId(form)
{
  var ids='';
  var dh='';
  for (var i=0;i<form.elements.length;i++)
  {
	var e = form.elements[i];
	if (e.name == 'id[]')
	{
	   if(e.checked==true)
	   {
       		ids+=dh+e.value;
			dh=',';
	   }
	}
  }
  return ids;
}

function PushInfoToSp(form)
{
	var id='';
	id=GetSelectId(form);
	if(id=='')
	{
		alert('请选择要推送的信息');
		return false;
	}
	window.open('sp/PushToSp.php?tid=<?=$tid?>&id='+id,'PushToSp','width=360,height=500,scrollbars=yes,left=300,top=150,resizable=yes');
}

function PushInfoToZt(form)
{
	var id='';
	id=GetSelectId(form);
	if(id=='')
	{
		alert('请选择要推送的信息');
		return false;
	}
	window.open('special/PushToZt.php?tid=<?=$tid?>&id='+id,'PushToZt','width=360,height=500,scrollbars=yes,left=300,top=150,resizable=yes');
}
</script>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
<form name="AddNewsForm" method="get">
  <tr> 
    <td width="24%">位置： 
      <?=$url?>
    </td>
    <td width="76%"><div align="right" class="emenubutton">
          <input type="button" name="Submit4" value="刷新首页" onclick="self.location.href='ecmschtml.php?enews=ReIndex'">
        </div></td>
  </tr>
</form>
</table>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  <form name="SearchForm" method="GET" action="ListAllBook.php">
    <tr> 
      <td width="100%"> <div align="right">&nbsp;搜索： 
          <select name="showspecial" id="showspecial">
            <option value="0"<?=$showspecial==0?' selected':''?>>不限属性</option>
            <option value="2"<?=$showspecial==2?' selected':''?>>推荐</option>
          </select>
          <input name="keyboard" type="text" id="keyboard" value="<?=$keyboard?>">
          <select name="show">
            <option value="0"<?=$show==0?' selected':''?>>不限字段</option>
            <option value="1"<?=$show==1?' selected':''?>>标题</option>
            <option value="2"<?=$show==2?' selected':''?>>发布者</option>
			<option value="3"<?=$show==3?' selected':''?>>ID</option>
          </select>
		  <?=$stts?>
		  <span id="searchclassnav"></span>
          <select name="myorder" id="myorder">
            <option value="1"<?=$myorder==1?' selected':''?>>按信息ID</option>
            <option value="2"<?=$myorder==2?' selected':''?>>按发布时间</option>
            <option value="3"<?=$myorder==3?' selected':''?>>按点击率</option>
            <option value="4"<?=$myorder==4?' selected':''?>>按下载数</option>
          </select>
          <select name="orderby" id="orderby">
            <option value="0"<?=$orderby==0?' selected':''?>>降序排序</option>
            <option value="1"<?=$orderby==1?' selected':''?>>升序排序</option>
          </select>
          <select name="infolday" id="infolday">
            <option value="1"<?=$infolday==1?' selected':''?>>全部时间</option>
            <option value="86400"<?=$infolday==86400?' selected':''?>>1 天</option>
            <option value="172800"<?=$infolday==172800?' selected':''?>>2 天</option>
            <option value="604800"<?=$infolday==604800?' selected':''?>>一周</option>
            <option value="2592000"<?=$infolday==2592000?' selected':''?>>1 个月</option>
            <option value="7948800"<?=$infolday==7948800?' selected':''?>>3 个月</option>
            <option value="15897600"<?=$infolday==15897600?' selected':''?>>6 
            个月</option>
            <option value="31536000"<?=$infolday==31536000?' selected':''?>>1 
            年</option>
          </select>
          <input type="submit" name="Submit2" value="搜索">
          <input name="tbname" type="hidden" value="<?=$tbname?>">
          <input name="ecmscheck" type="hidden" id="ecmscheck" value="<?=$ecmscheck?>">
          <input name="sear" type="hidden" value="1">
        </div></td>
    </tr>
  </form>
</table>
<br>
<form name="listform" method="post" action="ecmsbook.php" onsubmit="return confirm('确认要执行此操作？');">
  <input type=hidden name=enews value=DelNews_all>
  <input name=mid type=hidden id="mid" value=<?=$mid?>>
  <input type=hidden name=doing value=0>
  <input name="ecmscheck" type="hidden" id="ecmscheck" value="<?=$ecmscheck?>">
  <table width="100%" border="0" cellspacing="1" cellpadding="0">
    <tr>
      <td width="20%" height="25"<?=$indexchecked==1?' class="header"':' bgcolor="#D6E4ED"'?>><div align="center"><a href="ListAllBook.php?tbname=<?=$tbname?>" title="已发布信息总数：<?=$tbinfos?>">已发布 (<?=$tbinfos?>)</a></div></td>
      <td width="20%"<?=$indexchecked==0?' class="header"':' bgcolor="#D6E4ED"'?> title="待审核信息总数：<?=$tbckinfos?>"><div align="center"><a href="ListAllBook.php?tbname=<?=$tbname?>&ecmscheck=1">待审核 (<?=$tbckinfos?>)</a></div></td>
      <td width="10%">&nbsp;</td>
      <td width="38%">&nbsp;</td>
      <td width="6%">&nbsp;</td>
      <td width="6%">&nbsp;</td>
    </tr>
  </table>
  <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
    <tr class="header"> 
      <td height="25" colspan="9"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td width="25%"></td>
            <td width="75%"> <div align="right"><font color="#ffffff"><a href="ListAllBook.php?tbname=<?=$tbname?><?=$addecmscheck?>&showretitle=1&srt=1" title="查询重复标题，并保留一条信息">查询重复标题A</a> 
                | <a href="ListAllBook.php?tbname=<?=$tbname?><?=$addecmscheck?>&showretitle=1&srt=0" title="查询重复标题的信息(不保留信息)">查询重复标题B</a> 
                | <a href="ReHtml/ChangeData.php" target=_blank>更新数据</a> | <a href="../../" target=_blank>预览首页</a></font></div></td>
          </tr>
        </table></td>
    </tr>
    <tr> 
      <td width="3%"><div align="center"></div></td>
      <td width="6%" height="25"><div align="center">ID</div></td>
      <td width="30%" height="25"> <div align="center">书名</div></td>
	  <td width="6%" height="25"> <div align="center">章节数</div></td>
	  <td width="7%" height="25"><div align="center">点击数</div></td>
	  <td width="6%"><div align="center">下载数</div></td>
      <td width="12%" height="25"><div align="center">发布者</div></td>
      <td width="16%" height="25"> <div align="center">发布时间</div></td>      
      <td width="14%" height="25"> <div align="center">操作</div></td>
    </tr>
    <?php
	while($r=$empire->fetch($sql))
	{
		if($r[filesize]){
			$down=$r[totaldown];
		}else{
			$down='无附件';
		}
		$index_sql=$empire->fetch1("select datanum from {$dbtbpre}ecms_bookname_index where id=$r[id] limit 1");
		//状态
		$st='';
		if($r[istop])//置顶
		{
			$st.="<font color=red>[顶".$r[istop]."]</font>";
		}
		if($r[isgood])//推荐
		{
			$st.="<font color=red>[".$ignamer[$r[isgood]-1]."]</font>";
		}
		if($r[firsttitle])//头条
		{
			$st.="<font color=red>[".$ftnamer[$r[firsttitle]-1]."]</font>";
		}
		$oldtitle=$r[title];
		$r[title]=stripSlashes(sub($r[title],0,36,false));
		//时间
		$truetime=date("Y-m-d H:i:s",$r[truetime]);
		$lastdotime=date("Y-m-d H:i:s",$r[lastdotime]);
		//审核
		if(empty($indexchecked))
		{
			$checked=" title='未审核' style='background:#99C4E3'";
			$titleurl="ShowInfo.php?classid=$r[classid]&id=$r[id]".$addecmscheck;
		}
		else
		{
			$checked="";
			$titleurl=sys_ReturnBqTitleLink($r);
		}
		//会员投稿
		if($r[ismember])
		{
			$r[username]="<a href='member/AddMember.php?enews=EditMember&userid=".$r[userid]."' target='_blank'><font color=red>".$r[username]."</font></a>";
		}
		//取得类别名
		$do=$r[classid];
		//标题图片
		$showtitlepic="";
		if($r[titlepic])
		{
			$showtitlepic="<a href='".$r[titlepic]."' title='预览标题图片' target=_blank><img src='../data/images/showimg.gif' border=0></a>";
		}
		//未生成
		$myid="<a href='ecmsbook.php?enews=ReSingleInfo&classid=$r[classid]&id[]=".$r[id]."'>".$r['id']."</a>";
		if(empty($r[havehtml]))
		{
			$myid="<a href='ecmsbook.php?enews=ReSingleInfo&classid=$r[classid]&id[]=".$r[id]."' title='未生成'><b>".$r[id]."</b></a>";
		}
		if(empty($addecmscheck)){
			$lbtxt=' <a href="'.$titleurl.'" title="预览" target=_blank><img src="../data/images/ad.gif" border=0></a>';
		}else{
			$lbtxt='';
		}
	?>
    <tr bgcolor="#FFFFFF" onmouseout="this.style.backgroundColor='#ffffff'" onmouseover="this.style.backgroundColor='#E2E9EA'" id=news<?=$r[id]?>> 
      <td><div align="center"> 
          <input name="id[]" type="checkbox" id="id[]" value="<?=$r[id]?>"<?=$checked?>>
		  <input name="infoid[]" type="hidden" value="<?=$r['id']?>">
        </div></td>
      <td height="32"> <div align="center"> 
          <?=$myid?>
        </div></td>
      <td height="25"> <div align="left"> 
          <?=$st?>
          <?=$showtitlepic?>
          <a href='ListBookData.php?bookid=<?=$r[id]?>&classid=<?=$r[classid]?>' title="进入章节列表"> 
          《<?=$r[title]?>》<?=$lbtxt?>
          </a> 
          <?=$qf?>
        </div></td>
      <td height="25"> <div align="center"> 
          <?=$index_sql[datanum]?>
        </div></td>
      <td><div align="center"><?=$r[onclick]?></div></td>
      <td height="25"> <div align="center"><?=$down?></div></td>
      <td height="25"> <div align="center"> 
          <?=$r[username]?>
        </div></td>
      <td height="25" title="<? echo"增加时间：".$truetime."\r\n最后修改：".$lastdotime;?>"> <div align="center"> 
		  <input name="newstime[]" type="text" value="<?=date("Y-m-d H:i:s",$r[newstime])?>" size="20">
        </div></td>

      <td height="25"> <div align="center"><a href="AddBook.php?enews=EditNews&id=<?=$r[id]?>&classid=<?=$r[classid]?><?=$addecmscheck?>">修改</a> | <a href="ecmsbook.php?enews=DelNews&id=<?=$r[id]?>&classid=<?=$r[classid]?><?=$addecmscheck?>" onClick="return confirm('确认要删除？');">删除</a>
        </div></td>
    </tr>
    <?
	}
	?>
 
    <tr bgcolor="#FFFFFF"> 
      <td height="25" colspan="9"> 
        <?=$returnpage?>
      　 </td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="25" colspan="9"> <font color="#666666">备注：多选框蓝色为未审核信息；发布者红色为会员投稿；信息ID粗体为未生成,点击ID可刷新页面.</font></td>
    </tr>
  </table>
</form>
<IFRAME frameBorder="0" id="showclassnav" name="showclassnav" scrolling="no" src="ShowClassNav.php?ecms=2&classid=<?=$classid?>" style="HEIGHT:0;VISIBILITY:inherit;WIDTH:0;Z-INDEX:1"></IFRAME>
</body>
</html>



<?
db_close();
$empire=null;
?>