<?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 Language extends MX_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('lang_model') ;
       checklogin();
    }

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

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

    public function add(){

        $data ="" ;
        foreach(@$this->input->post() as $key =>$value){
            if($value !=""){
                $data[$key] =$this->input->post($key);
            }
        }

        if(@@$this->input->post("is_active")=='on')
            $data['is_active'] = 'Y';
        else
            $data['is_active'] = 'N';

        unset($data['is_ajax']) ;

        if(isset($data) && $data !="" && @$data['id'] =="")
        {
            $this->lang_model->insert($data);
        }
        else if(@$data['id'])
        {
            $this->lang_model->update($data,$data['id']);
        }
    }
    public function delete_item($item=0){

//        pre($item);exit;
        if($item!=0)
        {
            $this->lang_model->delete($item);
            echo 200;
        }
        else
        {
            echo 404;
        }
    }

}