<?php
require_once(dirname(__FILE__)."/config.php");
CheckPurview('story_New');
if(!isset($action)) $action = '';
if(empty($bookid)){
	ShowMsg("参数错误！","-1");
	exit();
}

$dsql = new DedeSql(false);
$bookinfos = $dsql->GetOne("Select catid,bcatid,bookname,booktype From #@__story_books where id='$bookid' ");

if($bookinfos['booktype']==0){
	header("location:story_add_content.php?bookid={$bookid}");
	$dsql->Close();
	exit();
}

//读取所有栏目
$dsql->SetQuery("Select id,classname,pid,rank From #@__story_catalog order by rank asc");
$dsql->Execute();
$ranks = Array();
$btypes = Array();
$stypes = Array();
while($row = $dsql->GetArray()){
	if($row['pid']==0) $btypes[$row['id']] = $row['classname'];
	else $stypes[$row['pid']][$row['id']] = $row['classname'];
	$ranks[$row['id']] = $row['rank'];
}
$lastid = $row['id'];
$msg = '';
$dsql->SetQuery("Select id,chapnum,chaptername From #@__story_chapter where bookid='$bookid' order by chapnum desc");
$dsql->Execute();
$chapters = Array();
$chapnums = Array();
while($row = $dsql->GetArray()){
	$chapters[$row['id']] = $row['chaptername'];
	$chapnums[$row['id']] = $row['chapnum'];
}


$catid = $bookinfos['catid'];
$bcatid = $bookinfos['bcatid'];
$bookname = $bookinfos['bookname'];
$booktype = $bookinfos['booktype'];

require_once(dirname(__FILE__)."/templets/story_add_photo.htm");

$dsql->Close();
?>