<?php $title = '《'.$chapter['chaptername'].'》章节续传内容管理 - ' . setting('webname');?>
<?php include_once tpl('header');?>
<link rel="stylesheet" type="text/css" href="<?php echo getCssFile('author.css');?>" />
<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>
<?php if (false !== $cron):?><div class="help">此章将在 <?php echo $cron;?> 自动发布，您可以点击<?php echo ilink('<span class="rs">取消定时</span>', url('system', array('s'=>'author','c'=>'chapter','a'=>'cc','bid'=>$book['bookid'],'cid'=>$chapter['chapterid'])));?>删除发布任务！</div><div class="clear"></div><div class="brbr"></div> <?php endif;?>
<style type="text/css">
.dlist { width: 800px; }
</style>

<script type="text/javascript">
$(function(){
    $('a.dEdit, a.dCreate, a#cron').fancybox({'titleShow':false,'scrolling':false,'mouseEnabled':false,'gallery':false});
    $('#eDraft #save').live("click", function(obj) {
        var id = $('#did').val();
        sData = checkData();
        $.ajax({
            type: 'POST',
            url: '<?php echo url('system', array('s'=>'author','c'=>'draft','a'=>'edit','cid'=>$chapter['chapterid']));?>'+'&id='+id,
            data: 'subject='+sData.subject+'&content='+sData.content,
            dataType: 'json',
            beforeSend: function(obj) {
                $('#sMsg').html('数据提中，请稍后...');
            },
            success: function(response) {
                alert(response.msg);
                if (1 == response.status) {
                    $.fancybox.close();
                }
            }
        });
    });
    $('#cDraft #save').live("click", function(obj) {
        sData = checkData();
        $.ajax({
            type: 'POST',
            url: '<?php echo url('system', array('s'=>'author','c'=>'draft','a'=>'create','cid'=>$chapter['chapterid']));?>',
            data: 'subject='+sData.subject+'&content='+sData.content,
            dataType: 'json',
            beforeSend: function(obj) {
                $('#sMsg').html('数据提中，请稍后...');
            },
            success: function(response) {
                alert(response.msg);
                if (1 == response.status) {
                    $.fancybox.close();
                    location.reload();
                }
            }
        });
    });
    $('#sCron').live('click', function() {
        var year = $('#year').val();
        var month = $('#month').val();
        var day = $('#day').val();
        var hour = $('#hour').val();
        $.ajax({
            type: 'POST',
            url: '<?php echo url('system', array('s'=>'author','c'=>'chapter','a'=>'cron','bid'=>$book['bookid'],'cid'=>$chapter['chapterid']));?>',
            data: 'year='+year+'&month='+month+'&day='+day+'&hour='+hour,
            dataType: 'json',
            success: function(response) {
                alert(response.msg);
                if (1 == response.status) {
                    $.fancybox.close();
                    location.reload();
                }
            }
        });
    });
});

function checkData() {
    var Data = [];
    var subject = $('#subject').val();
    var content = $('#content').val();
    if ('' == subject) {
        alert('请输入备注');
        exit;
    }
    if ('' == content) {
        alert('请输入内容');
        exit;
    }
    Data.subject = subject;
    Data.content = content;

    return Data;
}
function deleteDraft(id, cid, self) {
    if (!confirm('确定要删除吗？')) {
        return false;
    }
    
    $.ajax({
        type: 'GET',
        url: '<?php echo url('system', array('s'=>'author','c'=>'draft','a'=>'delete'));?>',
        data: 'id='+id+'&cid='+cid,
        dataType: 'json',
        success: function(response) {
            alert(response.msg);
            if (1 == response.status) {
                $(self).parent().parent().remove();
            }
        }
    });
}
</script>
<?php if (!empty($drafts)):?>
    <form action="<?php echo $this->url('system', array('s'=>'author','c'=>'draft','a'=>'sort','cid'=>$chapter['chapterid']));?>" method="post">
    <table id="booklist" class="dlist">
        <thead>
            <th>排序</th>
            <th>备注</th>
            <th>字数</th>
            <th>操作</th>
        </thead>
        <tbody>
	<?php foreach ($drafts as $draft):?>
        <tr>
            <td><input type='text' size='2' name='sort_<?php echo $draft['id'];?>' value='<?php echo $draft['sort'];?>' /></td>
            <td class="subject"><?php echo ilink($draft['subject'],$this->url('system',array('s'=>'author','c'=>'draft','a'=>'detail','cid'=>$chapter['chapterid'],'id'=>$draft['id'])));?></td>
            <td><?php echo $draft['size'];?></td>
            <td><a href="<?php echo $this->url('system',array('s'=>'author','c'=>'draft','a'=>'edit','cid'=>$chapter['chapterid'],'id'=>$draft['id']));?>" class="dEdit">修改</a> <a href="javascript:;" onclick="deleteDraft(<?php echo $draft['id'];?>, <?php echo $draft['chapterid'];?>, this);">删除</a></td>
        </tr>
	<?php endforeach;?>
        <tr>
            <td colspan="4"><input type="submit" value="提交新排序" />  <a href="<?php echo url('system', array('s'=>'author','c'=>'draft','a'=>'create','cid'=>$chapter['chapterid']));?>" class="dCreate">增加新内容</a> <a href="<?php echo $this->url('system',array('s'=>'author','c'=>'draft','a'=>'publish','cid'=>$chapter['chapterid']));?>">立刻发布该章节</a> <a href="<?php echo url('system', array('s'=>'author','c'=>'chapter','a'=>'cron','do'=>'draft','bid'=>$chapter['bookid'],'cid'=>$chapter['chapterid']));?>" id="cron">定时发布该章节</a></td>
        </tr>
        </tbody>
	</table>

    </form>

    <div class="brbr"></div>
    <div class="help">
        <span class="rs">*</span> 点击“立刻发布该章节”链接，当前章节将会直接发表到网站上去，其他书友马上就能阅读到
        <br/>
        <span class="rs">*</span> 点击“定时发布该章节”链接，当前章节不会立即发表到网站上，您可以在这里设定一个时间，系统将会在您设定的时间点将章节发表到网站上，这样方便各位作者存稿，而不用像以前老忘记发布！
    </div>
<?php else:?>
	本章节暂无草稿内容，现在<a href="<?php echo $this->url('system',array('s'=>'author','c'=>'draft','a'=>'create','cid'=>$chapter['chapterid']));?>" class="dCreate"><span style="color:red;">添加</span></a>？
<?php endif;?>
<?php include_once tpl('footer');?>