public function grid()
{
$iTotal = $this->db->count_all('articles');
$this->db->start_cache();
//$this->db->select('user_id, user_ip, user_first_name, user_last_name, user_email, user_username, user_group, user_join_date, user_last_login');
$this->db->from('articles');
// User Level
if ($this->session->userdata('user_group') == 4) {
$this->db->where('article_author', $this->session->userdata['userid']);
}
/* Searching */
if ($this->input->post('sSearch') != '') {
$q = $this->input->post('sSearch', TRUE);
$this->db->orlike('article_title', $q);
$this->db->orlike('article_short_desc', $q);
$this->db->orlike('article_description', $q);
$this->db->orlike('article_uri', $q);
}
/* Sorting */
if ($this->input->post('iSortCol_0')) {
$sort_col = $this->input->post('iSortCol_0');
for ($i = 0; $i < $sort_col; $i++) {
$this->db->order_by($this->_column_to_field($this->input->post('iSortCol_' . $i)), $this->input->post('iSortDir_' . $i));
}
} else {
$this->db->order_by('article_modified', 'desc');
}
$this->db->stop_cache();
$iFilteredTotal = $this->db->count_all_results();
$this->db->start_cache();
/* Limit */
if ($this->input->post('iDisplayStart') && $this->input->post('iDisplayLength') != '-1') {
$this->db->limit($this->input->post('iDisplayLength'), $this->input->post('iDisplayStart'));
} elseif ($this->input->post('iDisplayLength')) {
$this->db->limit($this->input->post('iDisplayLength'));
}
$query = $this->db->get();
$output = '{';
$output .= '"sEcho": ' . $this->input->post('sEcho') . ', ';
$output .= '"iTotalRecords": ' . $iTotal . ', ';
$output .= '"iTotalDisplayRecords": ' . $iFilteredTotal . ', ';
$output .= '"aaData": [ ';
foreach ($query->result_array() as $row) {
$cat = '';
// Here we are flushing cache because of the "get_cats" query.
$this->db->flush_cache();
$cats = $this->articles_model->get_cats_by_article($row['article_id']);
foreach ($cats->result_array() as $item) {
$cat .= anchor('admin/categories/edit/' . $item['cat_id'], $item['cat_name']) . ', ';
}
$status = '<span class="not_active">' . lang('lang_not_active') . '</span>';
if ($row['article_display'] == 'y') {
$status = '<span class="active">' . lang('lang_active') . '</span>';
}
$title = anchor('admin/kb/articles/edit/' . $row['article_id'], $row['article_title']);
$output .= "[";
$output .= '"' . addslashes($title) . '",';
$output .= '"' . addslashes(reduce_multiples($cat, ", ", TRUE)) . '",';
$output .= '"' . addslashes(date($this->config->item('short_date_format'), $row['article_date'])) . '",';
$output .= '"' . addslashes(date($this->config->item('short_date_format'), $row['article_modified'])) . '",';
$output .= '"' . addslashes($status) . '",';
$output .= '"<input type=\\"checkbox\\" name=\\"article_id[]\\" value=\\"' . $row['article_id'] . '\\" />"';
$output .= "],";
}
$output = substr_replace($output, "", -1);
$output .= '] }';
echo $output;
}