<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class DeleteAction extends AuthorAction
{
    public function run()
    {
        $id = S::gp('id','G',2);
        $chapter = $this->getController()->getChapter();
    	$draft = $this->db()->select()->from(Draft::table())->where(array('id'=>$id))->find(true);
    	if (empty($draft))
    	{
    		$this->_showMessage('不存在的续传信息');
    	}
    	if ($draft['chapterid'] != $chapter['chapterid'])
    	{
    	    $this->_showMessage('非法删除，已禁止');
    	}
    	if ($draft['authorid'] != $this->getAuthorId())
    	{
    		$this->_showMessage('此段章节不属于您，不能删除');
    	}

    	$this->db()->update(Draft::table())->value(array('deleted'=>1))->where(array('id'=>$id))->q();

        if ($this->getController()->isAjaxRequest())
        {
            $this->_showMessage('删除成功！', 1);
        }
    	iforward($this->getController()->url('system',array('s'=>'author','c'=>'draft','cid'=>$draft['chapterid'])));
    }
}