<?php
/**
 * Created by PhpStorm.
 * User: CHALONG LATEX
 * Date: 14-Sep-16
 * Time: 4:22 PM
 */
if(!defined('BASEPATH')) exit('No direct script access allowed');

class Content extends MX_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('content_model') ;
        $this->load->model('lang_model') ;
       checklogin();
    }

    public function index()
    {
        $data['lists'] = $this->content_model->get_all();
        $this->template->write_view('content', 'content',$data);
        $this->template->write_view('level_script', 'content/listscript');
        $this->template->add_css('assets/css/layout-datatables.css');
        $this->template->render();
    }
    public function lists()
    {
        $data['lists'] = $this->content_model->get_all();
        $this->template->write_view('content', 'content',$data);
        $this->template->write_view('level_script', 'content/listscript');
        $this->template->add_css('assets/css/layout-datatables.css');
        $this->template->render();
    }
    public function form($item_id='')
    {
        $data['item'] = $this->content_model->get($item_id);
        $data['langs'] = $this->lang_model->where("is_active",'Y')->get_all();

        $this->template->write_view('content', 'contentform',$data);
        $this->template->add_js('assets/js/progress.js');
        $this->template->render();
    }

    public function add(){

        $data ="" ;
        foreach(@$_POST as $key =>$value){
            if($value !=""){
                $data[$key] =$value ;
            }
        }
        unset($data['is_ajax']) ;

        if(isset($data) && $data !="" && @$data['id'] =="")
        {
            $this->content_model->insert($data);
        }
        else if(@$data['id'])
        {
            $this->content_model->update($data,$data['id']);
        }
    }

}