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

class Size extends CI_Controller {
	// Session Authoriesed
	public function __construct() {
		parent::__construct();
		
		$admin = $this->session->userdata('admin');
		$column['id'] = $admin['id'];
		$table = 'tbl_user';
		
	    // loading common model
	    $this->load->model('Common_model');
		$result = $this->Common_model->Result($column,$table);
		if($result['password'] == $admin['password']){
		    $login = true;
		} else {
		    $login = false;
		}
		
		if (empty($admin) || $login==false) {
			$this->session->set_flashdata('msg','Your Session Has Been Expired');
			redirect(base_url().'master/login/index');
		}
		
	   // loading common model
	    $this->load->model('Common_model');
	}

	public function index()
	{
        // we are setting data for get site data
		$column['id'] = '1';
		$table = 'tbl_settings';
		
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
        // we are setting result in data array as $data
		$data['data'] = $result;
		$data['page'] = 'Size';
		
		$table = 'tbl_size';
        // we are getting results from common modal
		$result = $this->Common_model->Results($table);
		
		$data['size'] = $result;
		
        // we are loading admin dashboard
		$this->load->view('master/size/list',$data);	
	}


	public function edit($id)
	{
        // we are setting data for get site data
		$column['id'] = '1';
		$table = 'tbl_settings';
		
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
        // we are setting result in data array as $data
		$data['data'] = $result;
		$data['page'] = 'Size';
		
		$table1 = 'tbl_size';
		$column1['size_id'] = $id;
        // we are getting results from common modal
		$result1 = $this->Common_model->Result($column1,$table1);
		
		$data['size'] = $result1;
		
        // we are loading admin dashboard
		$this->load->view('master/size/edit',$data);	
	}

	public function create()
	{
        // we are setting data for get site data
		$column['id'] = '1';
		$table = 'tbl_settings';
		
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
        // we are setting result in data array as $data
		$data['data'] = $result;
		$data['page'] = 'Size';
		
		
        // we are getting results from common modal
		$result = $this->Common_model->Results($table);
		
		$data['size'] = $result;
		
        // we are loading admin dashboard
		$this->load->view('master/size/create',$data);	
	}
	
	public function edit_content($id){
        $data = [];
        foreach ($_POST as $key => $value) {
            if($key == 'table'){$table = $value;}
            if($key == 'page'){$page = $value;}
            if($key != 'status'){
                if (empty($value)) {
                    $this->session->set_flashdata('error',''.strtoupper("$key").' Can not be Empty.');
    			    redirect(base_url('master/'.$page));
    			    exit();
                }
            }
            if($key != 'table' && $key != 'page' && $key != 'column'){
                $data[$key] = $value;
            }
        }
        $column['size_id'] = $id;
                
        // we are updating data from tbl_p_type
        $result  = $this->Common_model->Edit($column,$data,$table);
        if($result == true){
            $this->session->set_flashdata('success','SUCCESS!! Data is Updated Successfully.');
		    redirect(base_url('master/'.$page));
		    exit();
        } else{
            $this->session->set_flashdata('error','Something went Wrong .');
		    redirect(base_url('master/'.$page));
		    exit();
        }
           
	}


	
}

?>