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

class Quality 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['quality_list'] = $this->Color_model->AllRecordWithWhere('rugs_qualities',array('id!='=>''));			
        
//       echo "<pre>";
//        print_r($data);
//        exit();		
		
        $this->load->view('quality_list',$data);
    }
    
    public function newquality(){
        $data=array();
        $token=$this->input->post('token');
        if($token!=''){
            $data['quality_row']=$this->Color_model->GetARecordWithWhereRowDESC("rugs_qualities",array('id'=>$token));
        }
        $this->load->view('quality',$data);
    }
    public function addquality(){
        $data=$this->input->post();      
        if($data['id']!=''){
             $rest=$this->Color_model->Edit("rugs_qualities",$data,'id',$data['id']);
            echo $rest;
            exit;
            
        }else{
            unset($data['id']);
            $rest=$this->Color_model->Add("rugs_qualities",$data);
            echo $rest;
            exit;
            
        }
    }
    public function delquality(){
        $token=$this->input->post('token');
        if(!empty($token)){
            $rest=$this->Color_model->DelWhere('rugs_qualities',array('id'=>$token));            
        }
        redirect(base_url().'quality');
    }
}