<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Type extends CI_Controller {
    
    public function __construct() {
        parent::__construct();
         if (! $this->session->userdata ( 'user_logged_in' ) || !company_url($this->session->userdata ('company_slag'))) {
            redirect ( 'login', 'refresh' );
        }
        $this->load->vars ( array (
                'global' => 'Available to all views',
                'header' => 'common/header',
                'left' => 'common/left',
                'footer' => 'common/footer' 
        ) );
        $this->load->model('Design_model');
        
    }
    
    public function index(){
          $data['list'] = $this->Design_model->AllRecordWithWhere('types',array('status'=>1));			
        
       //echo "<pre>";
        //print_r($data);
        //exit();		
		
        $this->load->view('master/type_list',$data);
    }

    
    public function new(){
        $data=array();
        $token=$this->input->post('token');
        if($token!=''){
            $data['type_row']=$this->Design_model->GetARecordWithWhereRowDESC("types",array('id'=>$token));
        }
        $this->load->view('master/new_type',$data);
    }



    public function add_type(){
        $data=$this->input->post();      
        if($data['id']!=''){
             $rest=$this->Design_model->Edit("types",$data,'id',$data['id']);
            echo $rest;
            exit;
            
        }else{
            unset($data['id']);
            $rest=$this->Design_model->Add("types",$data);
            echo $rest;
            exit;
            
        }
    }
    public function del_type(){
        $token=$this->input->post('token');
        if(!empty($token)){
            $rest=$this->Design_model->DelWhere('types',array('id'=>$token));            
        }
        redirect(base_url().'type');
    }
}