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

class Size 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['size_list'] = $this->Color_model->AllRecordWithWhere('search_sizes',array('id!='=>''));			
        
//       echo "<pre>";
//        print_r($data);
//        exit();		
		
        $this->load->view('size_list',$data);
    }
    
    public function newsize(){
        $data=array();
        $token=$this->input->post('token');
        if($token!=''){
            $data['size_row']=$this->Color_model->GetARecordWithWhereRowDESC("search_sizes",array('id'=>$token));
        }
        $this->load->view('size',$data);
    }
    public function addsize(){
        $data=$this->input->post();      
        if($data['id']!=''){
             $rest=$this->Color_model->Edit("search_sizes",$data,'id',$data['id']);
            echo $rest;
            exit;
            
        }else{
            unset($data['id']);
            $rest=$this->Color_model->Add("search_sizes",$data);
            echo $rest;
            exit;
            
        }
    }
    public function delsize(){
        $token=$this->input->post('token');
        if(!empty($token)){
            $rest=$this->Color_model->DelWhere('search_sizes',array('id'=>$token));            
        }
        redirect(base_url().'size');
    }
}