<?php
class MoveAction extends ForumAction
{
    public function run()
    {
        $this->isManager();
        
        $chat = Chat::single($this->id());
        $cid = S::gp('cid','G',2);
    	$sql = 'SELECT uid,username,message FROM ' . $chat->table() . ' WHERE id = ' . $cid;
    	$record = $this->db()->setQueryString($sql)->find(true);
    	if (empty($record))
    	{
    		throw new iSystemException('不存在的记录');
    	}
    
    	$data = array(
    	    'message' => $record['message'],
    	    'uid' => $record['uid'],
    	    'username' => $record['username'],
    	);
    	BookPost::single()->create($this->id(), $data);
        $chat->delete($cid);
        
        iforward($this->getController()->url('system',array('s'=>'forum','c'=>'chat','id'=>$this->id())));
    }
}