<?php
define('EmpireCMSAdmin','1');
$stime=microtime(true);
require("../class/connect.php");
require("../class/db_sql.php");
require("../class/functions.php");
require("../class/dpfun.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'];

$classid=(int)$_GET['classid'];
//取得栏目名
if(!$class_r[$classid][classid]||!$class_r[$classid][tbname])
{
	printerror('ErrorUrl','history.go(-1)');
}
//栏目
$thiscr=$empire->fetch1("select tbname,allinfos,infos from {$dbtbpre}enewsclass where classid='$classid'");
if(!$thiscr['tbname'])
{
	printerror('ErrorUrl','history.go(-1)');
}
$classallinfos=$thiscr['allinfos'];
$classinfos=$thiscr['infos'];
$classckinfos=$classallinfos-$classinfos;
//验证权限
$doselfinfo=CheckLevel($logininid,$loginin,$classid,"news");
//取得模型表
$fieldexp="<!--field--->";
$recordexp="<!--record-->";
//返回搜索字段列表
function ReturnSearchOptions($enter,$field,$record){
	global $modid,$emod_r;
	$r=explode($record,$enter);
	$count=count($r)-1;
	for($i=0;$i<$count;$i++)
	{
		if($i==0)
		{
			$or="";
		}
		else
		{
			$or=" or ";
		}
		$r1=explode($field,$r[$i]);
		if($r1[1]=="special.field"||strstr($emod_r[$modid]['tbdataf'],','.$r1[1].','))
		{
			continue;
		}
		if($r1[1]=="id")
		{
			$sr['searchallfield'].=$or.$r1[1]."='[!--key--]'";
			$sr['select'].="<option value=\"".$r1[1]."\">".$r1[0]."</option>";
			continue;
		}
		$sr['searchallfield'].=$or.$r1[1]." like '%[!--key--]%'";
		$sr['select'].="<option value=\"".$r1[1]."\">".$r1[0]."</option>";
	}
	return $sr;
}
$modid=(int)$class_r[$classid][modid];
$infomod_r=$empire->fetch1("select enter,tbname,sonclass,listfile from {$dbtbpre}enewsmod where mid=".$modid);
if(empty($infomod_r['tbname']))
{
	printerror("ErrorUrl","history.go(-1)");
}
$infomod_r['enter'].='发布者<!--field--->username<!--record-->ID<!--field--->id<!--record-->';
$searchoptions_r=ReturnSearchOptions($infomod_r['enter'],$fieldexp,$recordexp);
//审核表
$search='';
$addecmscheck='';
$ecmscheck=(int)$_GET['ecmscheck'];
$indexchecked=1;
if($ecmscheck)
{
	$search.='&ecmscheck='.$ecmscheck;
	$addecmscheck='&ecmscheck='.$ecmscheck;
	$indexchecked=0;
}
$infotb=ReturnInfoMainTbname($class_r[$classid]['tbname'],$indexchecked);
//导航
$url=AdminReturnBookClass($classid).'&nbsp;>&nbsp;书籍列表';
$start=0;
$page=(int)$_GET['page'];
$page=RepPIntvar($page);
$line=intval($public_r['hlistinfonum']);//每页显示
$page_line=12;
$offset=$page*$line;
$search.="&classid=$classid";
$add='';
$ewhere='';
//搜索
$sear=$_GET['sear'];
if($sear)
{
	$keyboard=RepPostVar2($_GET['keyboard']);
	$show=RepPostVar($_GET['show']);
	//关键字
	if($keyboard)
	{
		//搜索全部
		if(!$show)
		{
			$add=" and (".str_replace("[!--key--]",$keyboard,$searchoptions_r['searchallfield']).")";
		}
		//搜索字段
		elseif($show&&strstr($infomod_r['enter'],"<!--field--->".$show."<!--record-->"))
		{
			$add=$show!="id"?" and (".$show." like '%$keyboard%')":" and (".$show."='$keyboard')";
			$searchoptions_r['select']=str_replace(" value=\"".$show."\">"," value=\"".$show."\" selected>",$searchoptions_r['select']);
		}
	}
	//特殊属性
	$showspecial=$_GET['showspecial'];
	if($showspecial==1)//置顶
	{
		$add.=' and istop>0';
	}
	elseif($showspecial==2)//推荐
	{
		$add.=' and isgood>0';
	}
	elseif($showspecial==3)//头条
	{
		$add.=' and firsttitle>0';
	}
	elseif($showspecial==5)//签发
	{
		$add.=' and isqf=1';
	}
	elseif($showspecial==7)//投稿
	{
		$add.=' and ismember=1';
	}
	elseif($showspecial==8)//我的信息
	{
		$add.=" and userid='$logininid' and ismember=0";
	}
	//标题分类
	$ttid=(int)$_GET['ttid'];
	if($ttid)
	{
		$add.=" and ttid='$ttid'";
	}
	$search.="&sear=1&keyboard=$keyboard&show=$show&showspecial=$showspecial&ttid=$ttid";
}
//显示重复标题
if($_GET['showretitle']==1)
{
	$search.="&showretitle=1&srt=".$_GET['srt'];
	$addsrt="";
	$srtid="";
	$first=1;
	$srtsql=$empire->query("select id,title from ".$infotb." where classid='$classid' 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)
		{
			$add.=" and (".$addsrt.") and id not in (".$srtid.")";
		}
		else
		{
			$add.=" and (".$addsrt.")";
		}
	}
	else
	{
		printerror("HaveNotReInfo","ListBook.php?classid=$classid".$addecmscheck);
	}
}
//只能编辑自己的信息
if($doselfinfo['doselfinfo'])
{
	$add.=" and userid='$logininid' and ismember=0";
}
//优化
$yhadd='';
$yhid=$class_r[$classid][yhid];
$yhvar='hlist';
if($yhid)
{
	$yhadd=ReturnYhSql($yhid,$yhvar);
}
if(empty($yhadd))
{
	//时间范围
	$infolday=(int)$_GET['infolday'];
	if(empty($infolday))
	{
		$infolday=$public_r['infolday'];
	}
	if($infolday&&$infolday!=1)
	{
		$ckinfolday=time()-$infolday;
		$yhadd.="newstime>'$ckinfolday'";
		$search.="&infolday=$infolday";
	}
}
//单栏目单表

$ewhere=" where classid='$classid'".$add;

//统计
$totalquery="select count(*) as total from ".$infotb.$ewhere;
$totalnum=(int)$_GET['totalnum'];
if($totalnum<1)
{
	if(empty($ewhere)||$ewhere==" where classid='$classid'")
	{
		$num=$indexchecked==1?$classinfos:$classckinfos;
	}
	else
	{
		$num=$empire->gettotal($totalquery);//取得总条数
	}
}
else
{
	$num=$totalnum;
}
//排序
$myorder=$_GET['myorder'];
if($myorder==1)//时间
{$doorder="newstime desc";}
elseif($myorder==2)//评论数
{$doorder="plnum desc";}
elseif($myorder==3)//人气
{$doorder="onclick desc";}
elseif($myorder==4)//ID号
{$doorder="id desc";}
else//默认排序
{
	if(empty($thiscr['listorder']))
	{
		$doorder="id desc";
	}
	else
	{
		$doorder=$thiscr['listorder'];
	}
}
$search.="&totalnum=$num";
$search1=$search;
$search.="&myorder=$myorder";
$returnpage=page2($num,$line,$page_line,$start,$page,$search);
$phpmyself=urlencode(eReturnSelfPage(1));


//栏目链接
$classurl=ClassUrl($classid);

//转移目标栏目
$navclass='';
$ccsql=$empire->query("select classname,classid from {$dbtbpre}enewsclass where is_zt=0 and classid>$classid or classid<$classid order by myorder,classid");
while($ccr=$empire->fetch($ccsql)){
	$navclass.='<option value="'.$ccr[classid].'">'.$ccr[classname].'</option>';
}


$query="select id,classid,titleurl,havehtml,isgood,firsttitle,ismember,userid,username,totaldown,onclick,newstime,truetime,lastdotime,titlepic,title,filesize from ".$infotb.$ewhere." order by id desc 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?classid=<?=$classid?>&id='+id,'PushToSp','width=360,height=500,scrollbars=yes,left=300,top=150,resizable=yes');
}

function PushInfoToTag(form)
{
	var id='';
	id=GetSelectId(form);
	if(id=='')
	{
		alert('请选择要推送的书籍');
		return false;
	}
	window.open('tags/PushToTag.php?classid=<?=$classid?>&id='+id,'PushToTag','width=600,height=600,scrollbars=yes,left=300,top=150,resizable=yes');
}
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  <tr> 
    <td width="52%">位置： 
      <?=$url?>
    </td>
    <td width="48%"> <div align="right">[<a href="AddBookClass.php?enews=EditClass&classid=<?=$classid?>">栏目设置</a>] 
    </div></td>
  </tr>
</table>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  <form name="searchinfo" method="GET" action="ListBook.php">
    <tr> 
      <td width="35%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td width="23%"> <div align="left" class="emenubutton"> 
                <input type=button name=button value="增加书籍" onClick="self.location.href='AddBook.php?enews=AddNews&ecmsnfrom=1<?=$addecmscheck?>&classid=<?=$classid?>'">
              </div></td>
            <td width="77%" title="增加信息后使用本操作将信息显示到前台"> <div align="right"> 
                <select name="dore">
                  <option value="1">刷新当前栏目</option>
                  <option value="2">刷新当前栏目和首页</option>
                </select>
                <input type="button" name="Submit12" value="提交" onclick="self.location.href='ecmsbook.php?enews=AddInfoToReHtml<?=$addecmscheck?>&classid=<?=$classid?>&dore='+document.searchinfo.dore.value;">
              </div></td>
          </tr>
        </table>
      </td>
      <td width="65%">
<div align="right">搜索: 
          <select name="showspecial" id="showspecial">
            <option value="0"<?=$showspecial==0?' selected':''?>>不限属性</option>
            <option value="2"<?=$showspecial==2?' selected':''?>>推荐</option>
            <option value="3"<?=$showspecial==3?' selected':''?>>头条</option>
			<option value="7"<?=$showspecial==7?' selected':''?>>投稿</option>
          </select>
          <input name="keyboard" type="text" id="keyboard" value="<?=$keyboard?>" size="16">
          <select name="show">
            <option value="0" selected>不限字段</option>
            <?=$searchoptions_r['select']?>
          </select>
		  <?=$stts?>
          <input type="submit" name="Submit2" value="搜索">
          <input name="sear" type="hidden" id="sear" value="1">
          <input name="classid" type="hidden" id="classid" value="<?=$classid?>">
		  <input name="ecmscheck" type="hidden" id="ecmscheck" value="<?=$ecmscheck?>">
        </div></td>
    </tr>
  </form>
</table>
<br>
<form name="listform" method="post" action="ecmsbook.php" onsubmit="return confirm('确认要执行此操作？');">
<input type=hidden name=classid value=<?=$classid?>>
<input type=hidden name=enews value=DelNews_all>
<input type=hidden name=doing value=0>
  <input name="ecmsdoc" type="hidden" id="ecmsdoc" value="0">
  <input name="docfrom" type="hidden" id="docfrom" value="<?=$phpmyself?>">
  <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"'?> title="已发布信息总数：<?=$classinfos?>"><div align="center"><a href="ListBook.php?classid=<?=$classid?>">已发布 (<?=$classinfos?>)</a></div></td>
      <td width="20%"<?=$indexchecked==0?' class="header"':' bgcolor="#D6E4ED"'?> title="待审核信息总数：<?=$classckinfos?>"><div align="center"><a href="ListBook.php?classid=<?=$classid?>&ecmscheck=1">待审核 (<?=$classckinfos?>)</a></div></td>
      <td width="38%">&nbsp;&nbsp;<a href="AddBookDataNBID.php?classid=<?=$classid?>">章节采集</a></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="60%"><font color="#ffffff"><a href="ListBook.php?classid=<?=$classid?><?=$addecmscheck?>&sear=1&showspecial=8">我的信息</a> 
              | <a href="ListBook.php?classid=<?=$classid?><?=$addecmscheck?>&showretitle=1&srt=1" title="查询重复标题，并保留一条信息">查询重复标题A</a> 
              | <a href="ListBook.php?classid=<?=$classid?><?=$addecmscheck?>&showretitle=1&srt=0" title="查询重复标题的信息(不保留信息)">查询重复标题B</a> 
              | <a href="ecmsbook.php?classid=<?=$classid?><?=$addecmscheck?>&enews=SetAllCheckInfo" title="本栏目所有信息全设为审核状态" onclick="return confirm('确认要操作?');">审核栏目全部信息</a></font> 
            </td>
            <td width="40%"> <div align="right"><font color="#ffffff"><a href="openpage/AdminPage.php?leftfile=<?=urlencode('../file/FileNav.php')?>&mainfile=<?=urlencode('../file/ListFile.php?type=9&classid='.$classid)?>&title=<?=urlencode('管理附件')?>" target="_blank">管理附件</a> | <a href=ReHtml/ChangeData.php target=_blank>更新数据</a> | <a href="<?=$classurl?>" 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))
	{
		$index_sql=$empire->fetch1("select datanum from {$dbtbpre}ecms_bookname_index where id=$r[id] limit 1");
		//状态
		$st='';
		if($r[isgood])//推荐
		{
			$st.="<font color=red>[".$ignamer[$r[isgood]-1]."]</font>";
		}
		if($r[firsttitle])//头条
		{
			$st.="<font color=red>[".$ftnamer[$r[firsttitle]-1]."]</font>";
		}
		//时间
		$truetime=date("Y-m-d H:i:s",$r[truetime]);
		$lastdotime=date("Y-m-d H:i:s",$r[lastdotime]);
		$oldtitle=$r[title];
		$r[title]=stripSlashes(sub($r[title],0,50,false));
		//审核
		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>";
		}
		//签发
		$qf="";
		//标题图片
		$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=<?=$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"><?=$r[totaldown]?></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=<?=$classid?><?=$addecmscheck?>">修改</a> | <a href="ecmsbook.php?enews=DelNews&id=<?=$r[id]?>&classid=<?=$classid?><?=$addecmscheck?>" onClick="return confirm('确认要删除？');">删除</a>
        </div></td>
    </tr>
    <?
	}
	?>
    <tr bgcolor="#FFFFFF"> 
      <td height="25"> <div align="center">
          <input type=checkbox name=chkall value=on onClick="CheckAll(this.form)">
        </div></td>
      <td height="25" colspan="8"><div align="right">
          <input type="submit" name="Submit3" value="删除" onClick="document.listform.enews.value='DelNews_all';document.listform.action='ecmsbook.php';">
		  <?php
		  if($ecmscheck)
		  {
		  ?>
		  <input type="submit" name="Submit8" value="审核" onClick="document.listform.enews.value='CheckNews_all';document.listform.action='ecmsbook.php';">
		  <?php
		  }
		  else
		  {
		  ?>
		  <input type="submit" name="Submit9" value="取消审核" onClick="document.listform.enews.value='NoCheckNews_all';document.listform.action='ecmsbook.php';">
		  <input type="submit" name="Submit8" value="刷新" onClick="document.listform.enews.value='ReSingleInfo';document.listform.action='ecmsbook.php';">
		   <input type="button" name="Submit52" value="推送至TAG" onClick="PushInfoToTag(this.form);">
		  <?php
		  }
		  ?>
          <select name="isgood" id="isgood">
            <option value="0">不推荐</option>
			<?=$ftnr['igname']?>
          </select>
          <input type="submit" name="Submit82" value="推荐" onClick="document.listform.enews.value='GoodInfo_all';document.listform.doing.value='0';document.listform.action='ecmsbook.php';">
		  <input type="submit" name="Submit7" value="修改时间" onClick="document.listform.enews.value='EditMoreInfoTime';document.listform.action='ecmsbook.php';">		 
        </div></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="25" colspan="9"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr> 
            <td width="68%"> 
              <?=$returnpage?>
            </td>
            <td width="32%"> <div align="right">
			<select name='to_classid'>
			  <option value='0'>选择要移动的目标栏目</option>
			  <?=$navclass?>			  
			</select>
                <input type="submit" name="Submit5" value="移动" onClick="document.listform.enews.value='MoveNews_all';document.listform.action='ecmsbook.php';">
              </div></td>
          </tr>
        </table></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="25" colspan="9">
	    <?
		$et=microtime(true);
		$at=$et-$stime;
		?>
		<font color="#444444">PHP执行时间 <b><?=round($at,3)?></b> 秒</font>
	  </td>
    </tr>
  </table>
</form>
</body>
</html>

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

