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

class Color 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('Color_model');
        
    }
    
    public function index(){
          $data['color_list'] = $this->Color_model->AllRecordWithWhere('color',array('status'=>1));			
        
//       echo "<pre>";
//        print_r($data);
//        exit();		
		
        $this->load->view('color_list',$data);
    }
    
    public function newcolor(){
        $data=array();
        $token=$this->input->post('token');
        if($token!=''){
            $data['color_row']=$this->Color_model->GetARecordWithWhereRowDESC("color",array('id'=>$token));
        }
        $this->load->view('newcolor',$data);
    }
    public function addcolor(){
        $data=$this->input->post();      
        if($data['id']!=''){
             $rest=$this->Color_model->Edit("color",$data,'id',$data['id']);
            echo $rest;
            exit;
            
        }else{
            unset($data['id']);
            $rest=$this->Color_model->Add("color",$data);
            echo $rest;
            exit;
            
        }
    }
    public function delcolor(){
        $token=$this->input->post('token');
        if(!empty($token)){
            $rest=$this->Color_model->DelWhere('color',array('id'=>$token));            
        }
        redirect(base_url().'color');
    }
}