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

    public function index()
    {
        $data['lists'] = $this->features_model
            ->with_product(array('with'=>array('relation'=>'category','fields'=>'title_en')))
            ->get_all();
        $this->template->write_view('content', 'feature',$data);
        $this->template->write_view('level_script', 'feature/listscript');
        $this->template->add_css('assets/css/layout-datatables.css');
        $this->template->render();
    }
    public function lists()
    {
        $data['lists'] = $this->features_model
            ->with_product(array('with'=>array('relation'=>'category','fields'=>'title_en')))
            ->get_all();

//        pre($data);exit;
        $this->template->write_view('content', 'feature',$data);
        $this->template->write_view('level_script', 'feature/listscript');
        $this->template->add_css('assets/css/layout-datatables.css');
        $this->template->render();
    }
    public function form($item_id='')
    {
        $data['item'] = $this->features_model->get($item_id);
        $data['product'] = $this->product_model->as_dropdown('title_en')->get_all();


        $this->template->write_view('content', 'featureform',$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'] =="")
        {
            $create = $this->features_model->insert($data);
        }
        else if(  @$data['id'])
            $create = $this->features_model->update($data,$data['id']) ;


    }

}