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

$bookid=(int)$_GET['bookid'];
$classid=(int)$_GET['classid'];
$bk=GetBN($bookid);
//取得栏目名
if(!$bookid)
{
	printerror('ErrorUrl','history.go(-1)');
}
//书籍
$thisbr=$empire->fetch1("select tid,datanum,cknum,checked,ln from {$dbtbpre}ecms_bookname_index where id='$bookid'");
if(!$thisbr[checked]){
	printerror("EmptyCk",'history.go(-1)');
}
$tid=$thisbr[tid];
$tbname=$emod_r[$tid][tbname];
$classallinfos=$thisbr['datanum']; //总数
$classinfos=$thisbr['cknum']; //已审核数
$classckinfos=$classallinfos-$classinfos; //未审核数
$ls=$thisbr[ln];
$width=floor(100/$ls);
//验证权限
$doselfinfo=CheckLevel($logininid,$loginin,$classid,"news");
//取得模型表
$fieldexp="<!--field--->";
$recordexp="<!--record-->";
$modid=(int)$tid;
$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-->';
//审核表
$search='';
$addecmscheck='';
$ecmscheck=(int)$_GET['ecmscheck'];
$indexchecked=1;
if($ecmscheck)
{
	$search.='&ecmscheck='.$ecmscheck;
	$addecmscheck='&ecmscheck='.$ecmscheck;
	$indexchecked=0;
}
$infotb=ReturnInfoMainTbname($tbname,$indexchecked);
//导航
$url=AdminReturnBookClass($classid).'&nbsp;>&nbsp;<a href="ListBookData.php?bookid='.$bookid.'&classid='.$classid.'">《'.$bk[title].'》</a>&nbsp;>&nbsp;章节列表';

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

$vr=$empire->fetch1("select allvid from {$dbtbpre}ecms_bookname where id=$bookid limit 1");
$len=strlen($vr[allvid]);
$str=substr($vr[allvid],0,-1);
$z=explode('|',$str);


$enews=$_GET[enews];
if($enews=='editln'){
	$reurl="ListBookData.php?bookid=$bookid&classid=$classid";
	if(!$thisbr[checked]){
		printerror("EmptyCk",$reurl);
	}
	$ln=(int)$_GET[ln];
	if($ln>4 || $ln<1){
		printerror("ErrorUrl",$reurl);
	}
	$sql=$empire->query("update {$dbtbpre}ecms_bookname_index set ln=$ln where id=$bookid");
	if($sql){
		printerror("EdSuc",$reurl);
	}else{
		printerror("DbError",$reurl);
	}
}

$v_str='';
$v_sql=$empire->query("select vid,vname from {$dbtbpre}enewsvolume where bookid=$bookid order by myorder,vid");
while($v_r=$empire->fetch($v_sql))
{
	$v_str.="<option value='".$v_r[vid]."'>".$v_r[vname]."</option>";
}

?>
<!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 PushInfoToZt(form)
{
	var id='';
	id=GetSelectId(form);
	if(id=='')
	{
		alert('请选择要推送的信息');
		return false;
	}
	window.open('special/PushToZt.php?classid=<?=$classid?>&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">
  <tr> 
    <td width="52%">位置： 
      <?=$url?>
    </td>
    <td width="48%"> <div align="right">[<a href="AddBook.php?enews=EditNews&id=<?=$bookid?>&classid=<?=$classid?>">书籍设置</a>] 
        [<a href="ecmsbookdata.php?enews=ReBNum&bookid=<?=$bookid?>">更新章节数</a>] 
        [<a href="ecmsbookdata.php?enews=ReBDOne&bookid=<?=$bookid?>" target="_blank">刷新本书章节</a>]</div></td>
  </tr>
</table>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  <form name="searchinfo" method="GET" action="ListBookData.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='AddBookData.php?enews=AddNews&ecmsnfrom=1<?=$addecmscheck?>&bookid=<?=$bookid?>&classid=<?=$classid?>'">
              </div></td>
            <td width="77%" title="增加信息后使用本操作将信息显示到前台"> <div align="">&nbsp;
                <select name="dore">
                  <option value="1">刷新当前书籍</option>
                  <option value="2">刷新当前书籍和栏目</option>
                  <option value="3">刷新首页</option>
                </select>
                <input type="button" name="Submit12" value="提交" onclick="self.location.href='ecmsbookdata.php?enews=AddInfoToReHtml<?=$addecmscheck?>&classid=<?=$classid?>&bookid=<?=$bookid?>&dore='+document.searchinfo.dore.value;">
              </div></td>
          </tr>
        </table>
      </td>
      <td width="65%">
<div align="right"><a href="<?=$bk[titleurl]?>" target=_blank>预览书籍</a> | <a href="<?=$classurl?>" target=_blank>预览栏目</a> | <a href=../../ target=_blank>预览首页</a>
        </div></td>
    </tr>
  </form>
</table>
<br>

<table width="100%" border="0" cellspacing="1" cellpadding="0">
  <form name="v" method="GET" action="ListBookData.php">
  <input type=hidden name=classid value=<?=$classid?>>
  <input type=hidden name=bookid value=<?=$bookid?>>
  <input type=hidden name=enews value=editln>
    <tr>
      <td width="20%" height="25"<?=$indexchecked==1?' class="header"':' bgcolor="#D6E4ED"'?> title="已发布信息总数：<?=$classinfos?>"><div align="center"><a href="ListBookData.php?bookid=<?=$bookid?>&classid=<?=$classid?>">已发布 (<?=$classinfos?>)</a></div></td>
      <td width="20%"<?=$indexchecked==0?' class="header"':' bgcolor="#D6E4ED"'?> title="待审核信息总数：<?=$classckinfos?>"><div align="center"><a href="ListBookData.php?bookid=<?=$bookid?>&classid=<?=$classid?>&ecmscheck=1">待审核 (<?=$classckinfos?>)</a></div></td>
      <td width="20%">&nbsp;&nbsp;<a href="AddVolume.php?enews=AddVolume&bookid=<?=$bookid?>&classid=<?=$classid?>">[增加分卷]</a>&nbsp;&nbsp;<a href="ListVolume.php?bookid=<?=$bookid?>&classid=<?=$classid?>">[管理分卷]</a>&nbsp;&nbsp;
	  <? 
	  if($indexchecked){
	  ?>
	  <a href="#ecms" onclick="window.open('ListBookData_order.php?bookid=<?=$bookid?>&classid=<?=$classid?><?=$addecmscheck?>','','width=600,height=350,scrollbars=yes,top=270,left=270,resizable=yes');">[修改顺序]</a>
	  <?
	  }
	  ?>
	  </td>

      <td width="30%" align=right>本书每行显示
	  <select name="ln">
         <option value="1"<?=$ls==1?' selected':''?>>1</option>
         <option value="2"<?=$ls==2?' selected':''?>>2</option>
         <option value="3"<?=$ls==3?' selected':''?>>3</option>
         <option value="4"<?=$ls==4?' selected':''?>>4</option>
     </select>
	  个章节
	  <input type="submit" name="Submit1223" value="提交">
	  </td>
	 
    </tr>
  </form>
</table>

<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
<form name="listform" method="post" action="ecmsbookdata.php" style="padding:0;marging:0;" onsubmit="return confirm('确认要执行此操作？');">
<input type=hidden name=classid value=<?=$classid?>>
<input type=hidden name=bookid value=<?=$bookid?>>
<input type=hidden name=bclassid value=<?=$bclassid?>>
<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?>">

    <?php
if($len<2){ //不存在分卷
	?>

	<tr>
	  <td colspan="2">
		<table width="100%" border="0" cellspacing="0" cellpadding="0"  bgcolor="#FFFFFF">
		  <tr bgcolor="#FFFFFF">	
	<?
	$i=0;
	$query="select id,titleurl,title,havehtml from ".$infotb." where bookid=$bookid  order by myorder,id";
	$sql=$empire->query($query);
	while($r=$empire->fetch($sql))
	{
		$sell='';
		$index_r=$empire->fetch1("select * from {$dbtbpre}ecms_".$tbname."_index where id=$r[id]");
		if($index_r[sell]){
			$sell='<a title="出售"><font color="#ff0000">V</font></a>';
		}
		$i+=1;
		$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=GotoGetBDUrl($bookid,$r[id]);
		}
		//未生成
		$myid="<a href='ecmsbookdata.php?enews=ReSingleInfo&bookid=$bookid&id[]=".$r[id]."'>".$r['id']."</a>";
		if(empty($r[havehtml]))
		{
			$myid="<a href='ecmsbookdata.php?enews=ReSingleInfo&bookid=$bookid&id[]=".$r[id]."' title='未生成'><b>".$r[id]."</b></a>";
		}
	?>
    
      <td  height="30" width="<?=$width?>%"> 
          <input name="id[]" type="checkbox" id="id[]" value="<?=$r[id]?>"<?=$checked?>>
		  <input name="infoid[]" type="hidden" value="<?=$r['id']?>">
		  <?=$myid?>
		  <a href='<?=$titleurl?>' target=_blank title="<?=$oldtitle?>"><?=$r[title]?></a><?=$sell?>
		  <a href="AddBookData.php?enews=EditNews&id=<?=$r[id]?>&classid=<?=$classid?>&bookid=<?=$bookid?><?=$addecmscheck?>">[修改]</a> <a href="ecmsbookdata.php?enews=DelNews&id=<?=$r[id]?>&classid=<?=$classid?>&bookid=<?=$bookid?><?=$addecmscheck?>" onClick="return confirm('确认要删除？');">[删除]</a>
      </td>
	  
    <?
	   if($i%$ls==0){echo '</tr><tr bgcolor="#FFFFFF">';}
	}
	?>
		  </tr>
	    </table>
	  </td>
	</tr>
<?
}else{
?>
    <!-- 没有分卷的章节 -->
    <tr height="25" class=header><td align="center" colspan="2"><b>正文</b></td></tr>
	<tr>
	  <td colspan="2">
	    <table width="100%" border="0" cellspacing="0" cellpadding="0"  bgcolor="#FFFFFF">
		  <tr bgcolor="#FFFFFF">
		  <?
		  $i=0;

		  $sql=$empire->query("select id,titleurl,title,havehtml from ".$infotb." where bookid=$bookid and vid=0  order by myorder,id");
	      while($r=$empire->fetch($sql)){
			$i+=1;
			$oldtitle=$r[title];
			$r[title]=stripSlashes(sub($r[title],0,50,false));
			$sell='';
			$index_r=$empire->fetch1("select * from {$dbtbpre}ecms_".$tbname."_index where id=$r[id]");
			if($index_r[sell]){
				$sell='<a title="出售"><font color="#ff0000">V</font></a>';
			}
			//审核
			if(empty($indexchecked))
			{
				$checked=" title='未审核' style='background:#99C4E3'";
				$titleurl="ShowInfo.php?classid=$r[classid]&id=$r[id]".$addecmscheck;
			}
			else
			{
				$checked="";
				$titleurl=GotoGetBDUrl($bookid,$r[id]);
			}
			//未生成
			$myid="<a href='ecmsbookdata.php?enews=ReSingleInfo&bookid=$bookid&id[]=".$r[id]."'>".$r['id']."</a>";
			if(empty($r[havehtml]))
			{
				$myid="<a href='ecmsbookdata.php?enews=ReSingleInfo&bookid=$bookid&id[]=".$r[id]."' title='未生成'><b>".$r[id]."</b></a>";
			}
		  ?>
		  <td  height="30" width="<?=$width?>%"> 
            <input name="id[]" type="checkbox" id="id[]" value="<?=$r[id]?>"<?=$checked?>>
		    <input name="infoid[]" type="hidden" value="<?=$r['id']?>">
		    <?=$myid?>
		    <a href='<?=$titleurl?>' target=_blank title="<?=$oldtitle?>"><?=$r[title]?></a><?=$sell?>
		    <a href="AddBookData.php?enews=EditNews&id=<?=$r[id]?>&classid=<?=$classid?>&bookid=<?=$bookid?><?=$addecmscheck?>">[修改]</a> <a href="ecmsbookdata.php?enews=DelNews&id=<?=$r[id]?>&classid=<?=$classid?>&bookid=<?=$bookid?><?=$addecmscheck?>" onClick="return confirm('确认要删除？');">[删除]</a>
		  </td>
		  <?
	          if($i%$ls==0){echo '</tr><tr bgcolor="#FFFFFF">';}
	      }
		  ?>
		  </tr>
		</table>
	  </td>
	</tr>

	<!-- 增加的分卷 -->
	<?
	for($n=0;$n<count($z);$n++){
		$vn=$empire->fetch1("select vid,vname from {$dbtbpre}enewsvolume where vid=$z[$n] and bookid=$bookid limit 1");
	?>
		<tr height="25"><td align="center" colspan="2"><b><?=$vn[vname]?></b></td></tr>
		<tr>
		  <td colspan="2">
			<table width="100%" border="0" cellspacing="0" cellpadding="0"  bgcolor="#FFFFFF">
			  <tr bgcolor="#FFFFFF">
		<?	
		$vnsql=$empire->query("select id,bookid,title,titleurl,havehtml from ".$infotb." where bookid=$bookid and vid=$vn[vid] order by myorder,id");
		$t=0;
		while($vr=$empire->fetch($vnsql)){
			$t+=1;

			$voldtitle=$vr[title];
			$vr[title]=stripSlashes(sub($vr[title],0,50,false));
			$sell2='';
			$index_r2=$empire->fetch1("select * from {$dbtbpre}ecms_".$tbname."_index where id=$vr[id]");
			if($index_r2[sell]){
				$sell2='<a title="出售"><font color="#ff0000">V</font></a>';
			}
			//审核
			if(empty($indexchecked))
			{
				$vchecked=" title='未审核' style='background:#99C4E3'";
				$vtitleurl="ShowInfo.php?classid=$r[classid]&id=$r[id]".$addecmscheck;
			}
			else
			{
				$vchecked="";
				$vtitleurl=GotoGetBDUrl($bookid,$vr[id]);
			}
			//未生成
			$vmyid="<a href='ecmsbookdata.php?enews=ReSingleInfo&bookid=$bookid&id[]=".$vr[id]."'>".$vr['id']."</a>";
			if(empty($vr[havehtml]))
			{
				$vmyid="<a href='ecmsbookdata.php?enews=ReSingleInfo&bookid=$bookid&id[]=".$vr[id]."' title='未生成'><b>".$vr[id]."</b></a>";
			}

		?>
		  <td  height="30" width="<?=$width?>%"> 
            <input name="id[]" type="checkbox" id="id[]" value="<?=$vr[id]?>"<?=$vchecked?>>
		    <input name="infoid[]" type="hidden" value="<?=$vr['id']?>">
		    <?=$vmyid?>
		    <a href='<?=$vr[titleurl]?>' target=_blank title="$voldtitle"><?=$vr[title]?></a><?=$sell2?>
		    <a href="AddBookData.php?enews=EditNews&id=<?=$vr[id]?>&classid=<?=$classid?>&bookid=<?=$bookid?><?=$addecmscheck?>">[修改]</a> <a href="ecmsbookdata.php?enews=DelNews&id=<?=$vr[id]?>&classid=<?=$classid?>&bookid=<?=$bookid?><?=$addecmscheck?>" onClick="return confirm('确认要删除？');">[删除]</a>
		  </td>
		<?
			if($t%$ls==0){echo '</tr><tr bgcolor="#FFFFFF">';}
		}
		?>
			</tr>
		  </table>
		</td>
	  </tr>

	<?
	}
	?>


<?
}	
?>



    <tr bgcolor="#FFFFFF"> 
      <td height="25"> <div align="">
          <input type=checkbox name=chkall value=on onClick="CheckAll(this.form)">全选
        </div></td>
      <td height="25"><div align="right">
          <input type="submit" name="Submit3" value="删除" onClick="document.listform.enews.value='DelNews_all';document.listform.action='ecmsbookdata.php';">
		  <?php
		  if($ecmscheck)
		  {
		  ?>
		  <input type="submit" name="Submit8" value="审核" onClick="document.listform.enews.value='CheckNews_all';document.listform.action='ecmsbookdata.php';">
		  <?php
		  }
		  else
		  {
		  ?>
		  <input type="submit" name="Submit9" value="取消审核" onClick="document.listform.enews.value='NoCheckNews_all';document.listform.action='ecmsbookdata.php';">
		  <input type="submit" name="Submit8" value="刷新" onClick="document.listform.enews.value='ReSingleInfo';document.listform.action='ecmsbookdata.php';">
		  <?php
		  }
		  ?>
        </div></td>
    </tr>
	<tr bgcolor="#FFFFFF"> 
      <td height="25"> 
		<?
		$et=microtime(true);
		$at=$et-$st;
		?>
		<font color="#444444">PHP执行时间 <b><?=round($at,3)?></b> 秒</font>
	  </td>
      <td height="25" align=right> 
        <select name="vid">
          <option>移动到分卷</option>
		  <?=$v_str?>
        </select>
		<input type="submit" name="Submit5" value="移动" onClick="document.listform.enews.value='MoveBD';document.listform.action='ecmsbookdata.php';">
	  </td>
    </tr>
	</form>
  </table>
</body>
</html>

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