<?php
require_once(dirname(__FILE__)."/config.php");
CheckRank(0,0);
require_once(dirname(__FILE__)."/../include/inc_photograph.php");
require_once(dirname(__FILE__)."/../include/pub_oxwindow.php");
require_once(dirname(__FILE__)."/./inc/inc_archives_functions.php");

if(!isset($iscommend)) $iscommend = 0;

if($catid==0){
	ShowMsg("请指定图书所属栏目！","-1");
	exit();
}

$dsql = new DedeSql(false);
//获得父栏目
$nrow = $dsql->GetOne("Select * From #@__story_catalog where id='$catid' ");
$bcatid = $nrow['pid'];
$booktype = $nrow['booktype'];

$pubdate = GetMkTime($pubdate);

$bookname = cn_substr($bookname,50);

if($keywords!="") $keywords = trim(cn_substr($keywords,60));

//处理上传的缩略图
$litpic = GetUpImage('litpic',$litpicname,0);

$userip = getip();

//自动摘要
if($description=="" && $cfg_auot_description>0){
	$description = stripslashes(cn_substr(html2text($body),$cfg_auot_description));
	$description = addslashes($description);
}

if($cfg_book_ifcheck == 'Y'){
	$ischeck = 0;
}else{
	$ischeck = 1;
}
//----------------------------------
$inQuery = "
INSERT INTO `#@__story_books`(`catid`,`bcatid`,`booktype`,`iscommend`,`click`,`freenum`,`bookname`,
`author`,`memberid`,`litpic`,`pubdate`,`ischeck`,`status`,
`lastpost`,`postnum`,`lastfeedback`,`feedbacknum`,`weekcc`,`monthcc`,`weekup`,`monthup`,
`description`,`body`,`keywords`,`userip`,`senddate` )
VALUES ('$catid','$bcatid','$booktype', '$iscommend', '0', '$freenum', '$bookname',
 '$author', '{$cfg_ml->M_ID}', '$litpic', '$pubdate', '$ischeck', '0',
 '0', '0', '0', '0', '0', '0', '0', '0',
  '$description' , '$body' , '$keywords', '$userip','".mytime()."');
";


if(!$dsql->ExecuteNoneQuery($inQuery)){
	$gerr = $dsql->GetError();
	$dsql->Close();
	ShowMsg("把数据保存到数据库时出错，请检查！".$gerr."<hr>".$inQuery,"javascript:;");
	exit();
}

$arcID = $dsql->GetLastID();

$dsql->Close();

//生成HTML
//---------------------------------
if($cfg_book_ifcheck == 'N'){
	require_once(dirname(__FILE__).'/../include/inc_arcbook_view.php');
	$bv = new BookView($arcID,'book');
	$artUrl = $bv->MakeHtml();
	$bv->Close();
}else{
	$artUrl = "../book/book.php?id=$arcID";
}
//---------------------------------
//返回成功信息
//----------------------------------
$msg = "
　　请选择你的后续操作：
<a href='story_add.php?catid=$catid'><u>继续发布图书</u></a>
&nbsp;&nbsp;
<a href='$artUrl' target='_blank'><u>查看图书</u></a>
&nbsp;&nbsp;
<a href='story_add_content.php?bookid={$arcID}'><u>增加图书内容</u></a>
&nbsp;&nbsp;
<a href='story_books.php'><u>管理图书</u></a>
";

$wintitle = "成功发布图书！";
$wecome_info = "连载管理::发布图书";
$win = new OxWindow();
$win->AddTitle("成功发布一本图书：");
$win->AddMsgItem($msg);
$winform = $win->GetWindow("hand","&nbsp;",false);
$win->Display();

?>