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

$enews=$_GET['enews'];
$classid=(int)$_GET['classid'];
$bookid=(int)$_GET['bookid'];
if(empty($class_r[$classid][classid]))
{
	printerror("ErrorUrl","history.go(-1)");
}
$bk=GetBN($bookid);
//验证权限
$doselfinfo=CheckLevel($logininid,$loginin,$classid,"news");
$fun_r['AdminBook']='管理书籍';
//附件验证码
if($enews=="AddNews")
{
	if(!$doselfinfo['doaddinfo'])//增加权限
	{
		printerror("NotAddInfoLevel","history.go(-1)");
	}
	$filepass=time();
	$word='增加章节';
	$ecmsfirstpost=1;
}
else
{
	if(!$doselfinfo['doeditinfo'])//编辑权限
	{
		printerror("NotEditInfoLevel","history.go(-1)");
	}
	$filepass=$id;
	$word='修改章节';
	$ecmsfirstpost=0;
}
//审核
$ecmscheck=(int)$_GET['ecmscheck'];
$addecmscheck='';
$indexchecked=1;
if($ecmscheck)
{
	$addecmscheck='&ecmscheck='.$ecmscheck;
	$indexchecked=0;
}
//模型
$bindex=$empire->fetch1("select tid,checked from {$dbtbpre}ecms_bookname_index where id=$bookid limit 1");
$modid=$bindex[tid];
$tbname=$emod_r[$modid]['tbname'];
$enter=$emod_r[$modid]['enter'];
if(!$bindex[checked]){
	printerror("EmptyCk","history.go(-1)");
}
//导航
$url=AdminReturnBookClass($classid).'&nbsp;>&nbsp;<a href="ListBookData.php?bookid='.$bookid.'&classid='.$classid.$addecmscheck.'">《'.$bk[title].'》</a>&nbsp;>&nbsp;'.$word;
//会员组
$sql1=$empire->query("select groupid,groupname from {$dbtbpre}enewsmembergroup order by level");
while($l_r=$empire->fetch($sql1))
{
	$ygroup.="<option value=".$l_r[groupid].">".$l_r[groupname]."</option>";
}
if($enews=="AddNews")
{
	$group=str_replace(" value=".$class_r[$classid][groupid].">"," value=".$class_r[$classid][groupid]." selected>",$ygroup);
}
//初始化数据
$r=array();
$newstime=time();
$r[newstime]=date("Y-m-d H:i:s");
$todaytime=$r[newstime];
$r[checked]=1;
$r[newspath]=date($class_r[$classid][newspath]);
$r[onclick]=0;
$r[userfen]=0;
$titlefontb="";
$titlefonti="";
$titlefonts="";
$voteeditnum=8;
$voter[width]=500;
$voter[height]=300;
$voter[dotime]='0000-00-00';
$r[dokey]=1;
$titleurl='';
if($public_r['onclickrnd'])
{
	$onclick_rndr=explode(',',$public_r['onclickrnd']);
	$r[onclick]=rand(intval($onclick_rndr[0]),intval($onclick_rndr[1]));
	$r[totaldown]=$r[onclick];
}
else
{
	$r[totaldown]=0;
	$r[onclick]=0;
}
//----------- 特殊模型初始化 -----------
//html编辑器
if($emod_r[$modid]['editorf']&&$emod_r[$modid]['editorf']!=',')
{
	include('ecmseditor/infoeditor/fckeditor.php');
}



//-----------------------------------------修改信息
if($enews=="EditNews")
{
	$id=$_GET[id];
	//索引表
	$index_r=$empire->fetch1("select id,checked,bookid,sell from {$dbtbpre}ecms_".$tbname."_index where id='$id' limit 1");
	if(!$index_r['id']||$index_r['bookid']!=$bookid)
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	//返回表
	$infotb=ReturnInfoMainTbname($tbname,$index_r['checked']);
	//主表
	$r=$empire->fetch1("select * from ".$infotb." where id='$id' limit 1");
	//返回表信息
	$infodatatb=ReturnInfoDataTbname($tbname,$index_r['checked'],$r['stb']);
	//副表
	//时间
	$r['checked']=$index_r['checked'];
	$newstime=$r['newstime'];
	$r['newstime']=date("Y-m-d H:i:s",$r['newstime']);
	//链接地址
	$titleurl=$r['titleurl'];
	if(!$r['isurl'])
	{
		$r['titleurl']='';
	}
	if($r[vid]){
		$vl=$empire->fetch1("select vname from {$dbtbpre}enewsvolume where vid=$r[vid]");
		$vname=$vl[vname];
	}
	//会员组
	$group=str_replace(" value=".$r[groupid].">"," value=".$r[groupid]." selected>",$ygroup);
	//内容存文本
	$savetxtf=$emod_r[$modid]['savetxtf'];
	$newstext_url='';
	if($savetxtf)
	{
		$newstext_url=$r[$savetxtf];
		$r[$savetxtf]=GetTxtFieldText($r[$savetxtf]);
    }
	//标题属性
	if(strstr($r[titlefont],','))
	{
		$tfontr=explode(',',$r[titlefont]);
		$r[titlecolor]=$tfontr[0];
		$r[titlefont]=$tfontr[1];
	}
	if(strstr($r[titlefont],"b|"))
	{
		$titlefontb=" checked";
	}
	if(strstr($r[titlefont],"i|"))
	{
		$titlefonti=" checked";
	}
	if(strstr($r[titlefont],"s|"))
	{
		$titlefonts=" checked";
	}

}

//表单文件
$modfile="../data/html/".$modid.".php";
//栏目链接
$getcurlr['classid']=$classid;
$classurl=sys_ReturnBqClassname($getcurlr,9);
//当前使用的模板组
$thegid=GetDoTempGid();
$phpmyself=urlencode(eReturnSelfPage(1));
//返回头条和推荐级别名称
$ftnr=ReturnFirsttitleNameList($r['firsttitle'],$r['isgood']);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?=$word?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="adminstyle/<?=$loginadminstyleid?>/adminstyle.css" type="text/css">
<link id="luna-tab-style-sheet" type="text/css" rel="stylesheet" href="adminstyle/<?=$loginadminstyleid?>/tab.winclassic.css" disabled="disabled" /> 
<!-- the id is not needed. It is used here to be able to change css file at runtime -->
<style type="text/css"> 
   .dynamic-tab-pane-control .tab-page { 
          width:                100%;
 } 
  .dynamic-tab-pane-control .tab-page .dynamic-tab-pane-control .tab-page { 
         height:                150px; 
 } 
  form { 
         margin:        0; 
         padding:        0; 
 } 
  /* over ride styles from webfxlayout */ 
  .dynamic-tab-pane-control h2 { 
         font-size:12px;
		 font-weight:normal;
		 text-align:        center; 
         width:                auto;
		 height:            20; 
 } 
   .dynamic-tab-pane-control h2 a { 
         display:        inline; 
         width:                auto; 
 } 
  .dynamic-tab-pane-control a:hover { 
         background: transparent; 
 } 
  </style>
 <script type="text/javascript" src="../data/images/tabpane.js"></script> <script type="text/javascript"> 
  function setLinkSrc( sStyle ) { 
         document.getElementById( "luna-tab-style-sheet" ).disabled = sStyle != "luna"; 
  
         //document.documentElement.style.background = "";
         //document.body.style.background = sStyle == "webfx" ? "white" : "ThreeDFace"; 
 } 
function chgBg(obj,color){
 if (document.all || document.getElementById)
   obj.style.backgroundColor=color;
 else if (document.layers)
   obj.bgColor=color;
}
  setLinkSrc( "luna" ); 
</script>
<script>
function dovoteadd(){
	var i;
	var str="";
	var oldi=0;
	var j=0;
	oldi=parseInt(document.add.v_editnum.value);
	for(i=1;i<=document.add.v_vote_num.value;i++)
	{
		j=i+oldi;
		str=str+"<tr><td width='9%' height=20> <div align=center>"+j+"</div></td><td width='65%'> <div align=center><input type=text name=vote_name[] size=30></div></td><td width='26%'> <div align=center><input type=text name=vote_num[] value=0 size=6></div></td></tr>";
	}
	document.getElementById('addvote').innerHTML="<table width='100%' border=0 cellspacing=1 cellpadding=3>"+str+"</table>";
}

function doSpChangeFile(name,url,filesize,filetype,idvar){
	document.getElementById(idvar).value=url;
	if(document.add.filetype!=null)
	{
		if(document.add.filetype.value=='')
		{
			document.add.filetype.value=filetype;
		}
	}
	if(document.add.filesize!=null)
	{
		if(document.add.filesize.value=='')
		{
			document.add.filesize.value=filesize;
		}
	}
}

function SpOpenChFile(type,field){
	window.open('ecmseditor/FileMain.php?classid=<?=$classid?>&infoid=<?=$id?><?=$addecmscheck?>&filepass=<?=$filepass?>&type='+type+'&sinfo=1&tranfrom=2&field='+field,'','width=700,height=550,scrollbars=yes');
}
</script>
<script src="ecmseditor/fieldfile/setday.js"></script>
<script src="../data/html/postinfo.js"></script>
<script>
function bs(){
	var f=document.add;
	if(f.title.value.length==0){alert("标题还没写");f.title.focus();return false;}
}
function foreColor(){
  if(!Error())	return;
  var arr = showModalDialog("../data/html/selcolor.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0");
  if (arr != null) document.add.titlecolor.value=arr;
  else document.add.titlecolor.focus();
}
function FieldChangeColor(obj){
  if(!Error())	return;
  var arr = showModalDialog("../data/html/selcolor.html", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0");
  if (arr != null) obj.value=arr;
  else obj.focus();
}
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" onload="document.add.title.focus();">
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  <tr> 
    <td width="62%" height="25">位置： 
      <?=$url?>
    </td>
    <td width="38%"><div align="right">
      </div></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="1" cellpadding="3" class="tableborder">
  <form name="searchinfo" method="GET" action="ListNews.php">
    <tr> 
      <td width="42%" title="增加信息后使用本操作将信息显示到前台"> <select name="dore">
          <option value="1">刷新当前栏目</option>
          <option value="2">刷新首页</option>
          <option value="3">刷新父栏目</option>
          <option value="4">刷新当前栏目与父栏目</option>
          <option value="5">刷新父栏目与首页</option>
          <option value="6" selected>刷新当前栏目、父栏目与首页</option>
        </select> <input type="button" name="Submit12" value="提交" onclick="self.location.href='ecmsbookdata.php?enews=AddInfoToReHtml<?=$addecmscheck?>&classid=<?=$classid?>&dore='+document.searchinfo.dore.value;"> 
      </td>
      <td width="58%"><div align="right">[<font color="#ffffff"><a href=../../ target=_blank>预览首页</a></font>] 
          [<font color="#ffffff"><a href="<?=$classurl?>" target=_blank>预览栏目</a></font>] 
          [<font color="#ffffff"><a href="file/ListFile.php?type=9&classid=<?=$classid?>">附件管理</a></font>] 
          [<a href="AddClass.php?enews=EditClass&classid=<?=$classid?>">栏目设置</a>] 
          [<a href="ecmschtml.php?enews=ReAllNewsJs&from=<?=$phpmyself?>">刷新所有信息JS</a>] 
        </div></td>
    </tr>
	</form>
</table>
<br>
<form name="add" method="post" enctype="multipart/form-data" action="ecmsbookdata.php" onsubmit="return EmpireCMSInfoPostFun(document.add,'<?=$modid?>');">
<div class="tab-pane" id="TabPane1">
	<script type="text/javascript">
	tb1 = new WebFXTabPane( document.getElementById( "TabPane1" ) );
	</script>
     

		<table width="100%" align="center" cellpadding="3" cellspacing="1" class="tableborder">
			<tr class="header"> 
				<td width="16%" height="25">
					<div align="left"><?=$word?></div>
				</td>
				<td>
					<input type="submit" name="addnews2" value="提交"> <input type="reset" name="Submit23" value="重置">
					<input type=hidden value=<?=$enews?> name=enews> <input type=hidden value=<?=$classid?> name=classid> 
					<input type=hidden value=<?=$bookid?> name=bookid> <input name=id type=hidden value=<?=$id?>> 
					<input type=hidden value="<?=$filepass?>" name=filepass> <input type=hidden value="<?=$r[username]?>" name=username> 
					<input name="oldfilename" type="hidden" value="<?=$r[filename]?>">  
					<input name="oldgroupid" type="hidden" value="<?=$r[groupid]?>"> 
					<input name="oldchecked" type="hidden" value="<?=$r[checked]?>">  
					<input name="newstext_url" type="hidden" value="<?=$newstext_url?>">
					<input name="ecmsfrom" type="hidden" value="<?=$_SERVER['HTTP_REFERER']?>">
					<input name="ecmsnfrom" type="hidden" value="<?=$_GET['ecmsnfrom']?>">
					<input name="fstb" type="hidden" value="<?=$r[fstb]?>">
					<input name="oldttid" type="hidden" value="<?=$r[ttid]?>">
					<input name="ecmscheck" type="hidden" id="ecmscheck" value="<?=$ecmscheck?>">
            <input name="ztids" type="hidden" id="ztids">
            <input name="zcids" type="hidden" id="zcids">
            <input name="oldztids" type="hidden" id="oldztids">
            <input name="oldzcids" type="hidden" id="oldzcids"></td>
			</tr>
		</table>

		<table width='100%' align=center cellpadding=3 cellspacing=1 bgcolor='#DBEAF5'><tr><td width='16%' height=25 bgcolor='ffffff'>标题</td><td bgcolor='ffffff'>
		<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#DBEAF5">
		<tr> 
			<td height="25" bgcolor="#FFFFFF">	
			<input type=text name=title value="<?=ehtmlspecialchars(stripSlashes($r[title]))?>" size="60"> 
			<input name="checked" type="checkbox" value="1"<?=$r[checked]?' checked':''?>>
			审核 
			<input name="sell" type="checkbox" value="1"<?=$index_r[sell]?' checked':''?>>
			出售 (<?=$public_r[docnewsnum]?>点/千字 <a href="pay/SetPayFen.php">修改</a>) 
			</td>
		</tr>
		</table>
		</td></tr>

		<tr><td width='16%' height=25 bgcolor='ffffff'>分卷</td><td bgcolor='ffffff'>
<?php
$writer_sql=$empire->query("select vid,vname from {$dbtbpre}enewsvolume where bookid=$bookid");
while($w_r=$empire->fetch($writer_sql))
{
	$ee='';
	if($r[vid]==$w_r[vid]){$ee=' selected';};
	$w_class.="<option value='".$w_r[vid]."' ".$ee.">".$w_r[vname]."</option>";
}
?>
方式一：手动填写 <input type=text name=vname value="<?=$ecmsfirstpost==1?"":ehtmlspecialchars(stripSlashes($vname))?>" size="">，
方式二：选择
        <select name="vid" id="vid">
          <option>选择分卷</option>
		  <?=$w_class?>
        </select>
<a href="ListVolume.php?bookid=<?=$bookid?>">管理分卷</a><br>
<font color="gray">(“选择”优先于“手动填写”。修改时“手动填写”无效。)</font>
</td></tr><tr><td height=25 colspan=2 bgcolor='ffffff'><div align=left>正文</div></td></tr></table>
<div style='background-color:#D0D0D0'>
<?=ECMS_ShowEditorVar("newstext",$ecmsfirstpost==1?"":stripSlashes($r[newstext]),"BookData","","300","100%")?>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#DBEAF5">
          <tr> 
            <td bgcolor="#FFFFFF"> <input name="copyimg" type="checkbox" id="copyimg" value="1">
      远程保存图片(
      <input name="mark" type="checkbox" id="mark" value="1">
      <a href="SetEnews.php" target="_blank">加水印</a>)</td>
          </tr>

        </table>
</div><table width='100%' align=center cellpadding=3 cellspacing=1 bgcolor='#DBEAF5'></table>


	</div>


  <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
    <tr>
      <td width="16%">&nbsp;</td>
      <td><input type="submit" name="addnews" value=" 提 交 "> &nbsp;&nbsp;&nbsp;<input type="reset" name="Submit2" value="重置"></td>
    </tr>
  </table>
</form>
<?=$copyclassidshowiframe?>
</body>
</html>
<?php
db_close();
$empire=null;
?>