<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class AppendAction extends MemberAction
{
    public function run()
    {
        $id = S::gp('id','G',2);
        $diary = $this->db()->select()->from(Diary::table())->where('id='.S::sqlEscape($id))->find(true);
        if (empty($diary))
        {
            throw new iSystemException('不存在的日志');
        }
        if ($this->uid() != $diary['uid'])
        {
            throw new iSystemException('非法操作');
        }
        
        if (isset($_POST['content']))
        {
            $content = '[br]'.S::gp('content','P');
            $sql = 'UPDATE '.DiaryData::table().' SET `content` = CONCAT(`content`, '.S::sqlEscape($content).') WHERE did='.S::sqlEscape($id);
            $this->db()->query($sql);
            
            iforward(url('system',array('s'=>'member','c'=>'diary','a'=>'read','id'=>$id)));
        }
        $this->getController()->render('append', array(
                'id' => $id,
                'diary' => $diary,
            )
        );
    }
}