public function insert_topic()
{
$this->db->trans_begin();
$topic_data = array(
'forum_id' => $this->input->get('fid'),
'user_id' => $this->session->userdata('user_id'),
'title' => $this->input->post('subject'),
'message' => $this->input->post('message'),
'date_created' => time()
);
$this->db->set($topic_data);
$this->db->insert($this->db->dbprefix . 'topics');
$topic_id = $this->db->insert_id();
$forum_data = array(
'lastpostdate' => time(),
'lastpostid' => $topic_id,
'lastpostuserid' => $this->session->userdata('user_id'),
'lastpostby' => '',
'lastpostsubject' => $this->input->post('subject')
);
$this->db->where('forum_id', $this->input->get('fid'));
$this->db->update($this->db->dbprefix . 'forum', $forum_data);
$forumsread_data = array(
'forum_id' => $this->input->get('fid'),
'user_id' => $this->session->userdata('user_id'),
'date_created' => time()
);
$this->db->insert($this->db->dbprefix . 'forumsread', $forumsread_data);
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
}
else
{
$this->db->trans_commit();
}
}