<?php $title = '《'.$book['bookname'].'》章节管理 - ' . setting('webname');?>
<?php include_once tpl('header');?>
<script type="text/javascript" src="<?php echo getJsFile('book.js');?>"></script>
<link rel="stylesheet" type="text/css" href="<?php echo getJsFile('jquery/fancybox/jquery.fancybox-1.3.4.css');?>" media="screen" />
<script type="text/javascript" src="<?php echo getJsFile('jquery/fancybox/jquery.fancybox-1.3.4.js');?>"></script>
<script type="text/javascript" src="<?php echo getJsFile('jquery/fancybox/jquery.mousewheel-3.0.4.pack.js');?>"></script>
<style type="text/css">
#bookname {text-align: center;font-size: 16px;font-weight: bold;}
.isview {color:blue;}
</style>
<script type="text/javascript">
$(function(){
    $('a#edit, a#create').fancybox({'titleShow':false,'scrolling':false,'mouseEnabled':false,'gallery':false});
    $('#cSave').live('click', function() {
        checkChapterSubmit();
        var chapterId = $('#cid').val();
        var chapterName = $('#chaptername').val();
        $.ajax({
            type: 'POST',
            url: '<?php echo url('system', array('s'=>'author','c'=>'chapter','a'=>'edit','bid'=>$book['bookid']));?>'+'&cid='+chapterId,
            data: 'chaptername='+chapterName,
            dataType: 'json',
            success: function(response) {
                alert(response.msg);
                if (1 == response.status) {
                    $('#c'+chapterId).html(chapterName);
                    $.fancybox.close();
                }
            }
        });
    });

    $('#cCreate').live('click', function() {
        checkChapterSubmit();
        var chapterId = $('#cid').val();
        var chapterName = $('#chaptername').val();
        $.ajax({
            type: 'POST',
            url: '<?php echo url('system', array('s'=>'author','c'=>'chapter','a'=>'create','bid'=>$book['bookid']));?>',
            data: 'chaptername='+chapterName,
            dataType: 'json',
            success: function(response) {
                alert(response.msg);
                if (1 == response.status) {
                    $.fancybox.close();
                    location.reload();
                }
            }
        });
    });
});
function deleteChapter(id, self) {
	if (!confirm('确定要删除吗？')) {
		return false;
	}
	$.ajax({
		type: 'GET',
        dataType: 'json',
		url: '<?php echo $this->url('system',array('s'=>'author','c'=>'chapter','a'=>'delete','confirm'=>1,'bid'=>$book['bookid']));?>'+'&cid='+id,
		success:function(response) {
            alert(response.msg);
			if (1 == response.status) {
				$(self).parent().remove();
			}
		}
	});
}
</script>
<div class="clist">
	<div id="bookname">《<?php echo $book['bookname'];?>》<br/><a href="<?php echo $this->url('system',array('s'=>'author','c'=>'chapter','a'=>'create','bid'=>$book['bookid']));?>" id="create">添加新章节</a> <?php echo $this->link('返回作者中心', $this->url('system',array('s'=>'author')));?></div>
	<ul>
		<?php foreach ($chapters as $chapter):?>
			<li><?php if ($chapter['isvip']):?><span class="vipchapter">[vip]</span><?php endif;?><a href="<?php echo $this->url('system',array('s'=>'author','c'=>'draft','cid'=>$chapter['chapterid']));?>" target="_blank" title="发表:<?php echo $chapter['createdate'];?> 字数:<?php echo $chapter['size'];?>" id="c<?php echo $chapter['chapterid'];?>"><?php echo $chapter['chaptername'];?></a> <?php if ($chapter['display']):?><span class="isview">已发布</span><?php else:?><span class="vipchapter">未发布</span><?php endif;?> [<a href="<?php echo $this->url('system',array('s'=>'author','c'=>'chapter','a'=>'edit','bid'=>$chapter['bookid'],'cid'=>$chapter['chapterid']));?>" id="edit">修改</a> <a href="javascript:void(0);" onclick="return deleteChapter('<?php echo $chapter['chapterid'];?>', this);">删除</a> <a href="<?php echo url('read', array('bid'=>$chapter['bookid'],'cid'=>$chapter['chapterid']));?>" target="_blank">查看</a>]</li>
		<?php endforeach;?>
	</ul>
</div>

<?php if (1 < count($chapters)):?>
<div class="clear"></div>
<div class="brbr"></div>
<div class="brbr"></div>
<div id="sort">
	<form action="<?php echo $this->url('system',array('s'=>'author','c'=>'chapter','a'=>'sort','bid'=>$book['bookid']));?>" method="post">
	<table>
		<tr>
			<td colspan="2">章节排序</td>
		</tr>
		<tr>
			<td width="50">将</td>
			<td>
			<select name="fromid">
				<?php foreach ($chapters as $chapter):?>
						<option value="<?php echo $chapter['sort'];?>"><?php echo $chapter['chaptername'];?></option>
				<?php endforeach;?>
			</select>
			</td>
		</tr>
		<tr>
			<td>移动到</td>
			<td>
			<select name="toid">
				<option value="0">--最前面--</option>
				<?php foreach ($chapters as $chapter):?>
						<option value="<?php echo $chapter['sort'];?>"><?php echo $chapter['chaptername'];?></option>
				<?php endforeach;?>
			</select>之后</td>
		</tr>
		<tr>
			<td></td>
			<td><input type="submit" value="重新排序" /></td>
		</tr>
	</table>
	</form>
</div>
<?php endif;?>
<?php include_once tpl('footer');?>