<?php
require("../class/connect.php");
require("../class/db_sql.php");
require("../class/q_functions.php");
require("../class/qinfofun.php");
require("../member/class/user.php");
require("../data/dbcache/class.php");
require("../class/dpfun.php");
require("../data/dbcache/MemberLevel.php");
$link=db_connect();
$empire=new mysqlquery();
if($public_r['addnews_ok'])//关闭投稿
{
	printerror("NotOpenCQInfo","",1);
}
//验证本时间允许操作
eCheckTimeCloseDo('info');
//验证IP
eCheckAccessDoIp('postinfo');
$bookid=(int)$_GET['bookid'];
//书索引表
$b_in=$empire->fetch1("select * from {$dbtbpre}ecms_bookname_index where id=$bookid limit 1");
$mid=$b_in[tid];
//书主表
$bk=$empire->fetch1("select * from {$dbtbpre}ecms_bookname where id=$bookid limit 1");
$classid=$b_in[classid];
$tbname=$emod_r[$b_in[tid]][tbname];
if($bookid!=$b_in[id])
{
	printerror("EmptyQinfoCid","",1);
}
$enews=$_GET['enews'];
if(empty($enews))
{
	$enews="MAddInfo";
}
$r=array();
$memberinfor=array();
$muserid=(int)getcvar('mluserid');
$musername=RepPostVar(getcvar('mlusername'));
$mrnd=RepPostVar(getcvar('mlrnd'));
$newstime=time();
$r[newstime]=date("Y-m-d H:i:s");
$todaytime=$r[newstime];
$showkey="";
$r['newstext']="";
//验证会员信息
$mloginauthr=qCheckLoginAuthstr();

$user=islogin();
$r=ReturnUserInfo($muserid);
$groupid=$r[groupid];
$cr=DoQCheckAddLevel($classid,$muserid,$musername,$mrnd,0,1);

//取得登陆会员资料
if($muserid&&$mloginauthr['islogin'])
{
	$memberinfor=$empire->fetch1("select ".eReturnSelectMemberF('*','u.').",ui.* from ".eReturnMemberTable()." u LEFT JOIN {$dbtbpre}enewsmemberadd ui ON u.".egetmf('userid')."=ui.userid where u.".egetmf('userid')."='$muserid' limit 1");
}
//增加
if($enews=="AddBd")
{
	$cr=DoQCheckAddLevel($classid,$muserid,$musername,$mrnd,0,1);
	$mr=$empire->fetch1("select qenter,qmname from {$dbtbpre}enewsmod where mid='$mid'");
	if(empty($mr['qenter']))
	{
		//printerror("NotOpenCQInfo","history.go(-1)",1);
	}
	//IP发布数限制
	$check_ip=egetip();
	$check_checked=$cr['wfid']?0:$cr['checkqadd'];
	eCheckIpAddInfoNum($check_ip,'bookdata',$mid,$check_checked);
	//初始变量
	$word="增加信息";
	$ecmsfirstpost=1;
	$rechangeclass="&nbsp;[<a href='ChangeBook.php?mid=".$mid."'>重新选择</a>]";
	//验证码
	if($cr['qaddshowkey'])
	{
		$showkey="<tr bgcolor=\"#FFFFFF\">
      <td width=\"11%\" height=\"25\">验证码</td>
      <td height=\"25\"><input name=\"key\" type=\"text\" size=\"6\">
        <img src=\"../ShowKey/?v=info\"></td></tr>";
	}
	//图片
	$imgwidth=0;
	$imgheight=0;
	//文件验证码
	$filepass=time();
}
else
{
	$word="修改信息";
	$ecmsfirstpost=0;
	$id=(int)$_GET['id'];
	if(empty($id))
	{
		printerror("EmptyQinfoCid","",1);
	}
	$mr=$empire->fetch1("select qenter,qmname from {$dbtbpre}enewsmod where mid='$mid'");
	if(empty($mr['qenter']))
	{
		printerror("NotOpenCQInfo","history.go(-1)",1);
	}
	$r=CheckQdob($classid,$id,$muserid,$musername,$bookid);
	//检测时间
	if($public_r['qeditinfotime'])
	{
		if(time()-$r['truetime']>$public_r['qeditinfotime']*60)
		{
			printerror("QEditInfoOutTime","history.go(-1)",1);
		}
	}
	$newstime=$r['newstime'];
	$r['newstime']=date("Y-m-d H:i:s",$r['newstime']);
	//图片
	$imgwidth=170;
	$imgheight=120;
	//文件验证码
	$filepass=$id;
}
$tbname='bookdata';
esetcookie("qeditinfo","dgcms");
//栏目
$classurl=sys_ReturnBqClassname($cr,9);
$postclass=$class_r[$classid][classname].' > 《'.$bk[title].'》';
//html编辑器
if($emod_r[$mid]['editorf']&&$emod_r[$mid]['editorf']!=',')
{
	include('../data/ecmseditor/infoeditor/fckeditor.php');
}
if(empty($musername))
{
	printerror('未登录','',8,1,1);
}
$modfile="../data/html/q".$mid.".php";


$public_diyr['pagetitle']=$word;
$url="<a href='../../'>首页</a>&nbsp;>&nbsp;<a href='../member/cp/'>会员中心</a>&nbsp;>&nbsp;<a href='ListInfo.php?mid=".$mid."'>管理信息</a>&nbsp;>&nbsp;".$word."&nbsp;(".$mr[qmname].")";
//require(ECMS_PATH.'e/template/incfile/header.php');

?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?=$thispagetitle?></title>
<link href="<?=$public_r[newsurl]?>skin/v3/t.css" rel="stylesheet" />
</head>

<body leftmargin="0" topmargin="0">
<br>
<script src="../data/html/setday.js"></script>
<script>
function bs(){
	var f=document.add
	if(f.title.value.length==0){alert("标题还没写");f.title.focus();return false;}
	if(f.classid.value==0){alert("请选择栏目");f.classid.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>
<script src="../data/html/postinfo.js"></script>
<div class="w98">
<form name="add" method="POST" enctype="multipart/form-data" action="ecms.php" onsubmit="return EmpireCMSQInfoPostFun(document.add,'<?=$mid?>');">
  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="tableborder">
          <tr class="header"> 
            <td height="25" colspan="2"> 
              <?=$word?>
              <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 id="id" value=<?=$id?>> <input type=hidden value="<?=$filepass?>" name=filepass> 
              <input name=mid type=hidden id="mid" value=<?=$mid?>></td>
          </tr>
          <tr bgcolor="#FFFFFF">
            <td height="25">提交者</td>
            <td>&nbsp;<b>
              <?=$musername?>
              </b></td>
          </tr>
          <tr bgcolor="#FFFFFF"> 
            <td width="16%" height="25">书籍</td>
            <td>&nbsp;
              <?=$postclass?>
			</td>
          </tr>
		  <tr bgcolor="#FFFFFF"> 
            <td height="25" bgcolor="#FFFFFF">是否出售: </td>
			<td>&nbsp;
			  <input type="radio" name="sell" value="1"<?=$r[sell]==1?' checked':''?>>
        是 
        <input type="radio" name="sell" value="0"<?=$r[sell]==0?' checked':''?>>
        否
			</td>
          </tr>

		<tr><td width='16%' height=25 bgcolor='ffffff'>分卷</td><td bgcolor='ffffff'>&nbsp;
<?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>";
}
?>
        <select name="vid" id="vid">
          <option>选择分卷</option>
		  <?=$w_class?>
        </select>
&nbsp;<a href="ListVolume.php?bookid=<?=$bookid?>" target="_blank">管理分卷</a></font>
</td></tr>


        </table>
  <?php
  @include($modfile);
  ?>
  <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  	<?=$showkey?>
    <tr class="header"> 
      <td width="16%">&nbsp;</td>
      <td><input type="submit" name="addnews" value="提交"> <input type="reset" name="Submit2" value="重置"></td>
    </tr>
  </table>
</form>
</div>
<?php
if($enews=="AddBd"){
	require(ECMS_PATH.'e/template/incfile/footer.php');
}
db_close();
$empire=null;
?>