<?php
defined('BASEPATH') OR exit('No direct script access allowed');
Class Component Extends MY_Controller{
	function __construct()
	{
		parent::__construct();	
		$this->load->model('admin_api/Component_model');
		$this->config->load('my_constants');
	}

	public function add_component()
	{
		$data['active_component'] = 'open';
		$data['title'] = 'component List';
		$data['header_title'] = 'component';
		$data['component_info'] = $this->Component_model->get_component_list();
		$data['category_info'] = $this->Component_model->get_category_list();
		$data['heading'] = $this->Component_model->get_heading_list();
		//print_r($data['package_info']);exit();
		$data['main_content'] = 'admin/Component/add_component';
        $this->load->view('admin/includes/template', $data);
	}

	
	
	public function save_component()
	{
		$post_data = $this->input->post();
			$query=$this->Component_model->save_component($post_data);
			if($query){
				$this->session->set_flashdata('success_message', 'component Added successfully!');

				redirect('admin/Component/add_component','refresh');
			}else{
				$this->session->set_flashdata('failure_message', 'You are fail to Add component!');
				redirect('admin/Component/add_component','refresh');
			}
	}
	
public function update_component()
	{
		$post_data = $this->input->post();
			$query=$this->Component_model->update_component($post_data);
			if($query){
				$this->session->set_flashdata('success_message', 'component Updated successfully!');

				redirect('admin/Component/add_component','refresh');
			}else{
				$this->session->set_flashdata('failure_message', 'You are fail to Update component!');
				redirect('admin/Component/add_component','refresh');
			}
	}
	
	public function delete_component($id=NULL)
	{
	
	//	$post_data = $this->input->post();
			$query=$this->Component_model->delete_component($id);
			if($query){
				$this->session->set_flashdata('success_message', 'component Deleted successfully!');

				redirect('admin/Component/add_component','refresh');
			}else{
				$this->session->set_flashdata('failure_message', 'You are fail to Delete component!');
				redirect('admin/Component/add_component','refresh');
			}
	}	
	
	public function auo_product3()
	{
		$search_id = $_POST['search_id'];
	//echo $search_id;


		$db = get_instance()->db->conn_id;
		// $output = array();
		$sql = "SELECT * FROM category where master_product='$search_id' and IsActive='0'";
		$result = mysqli_query($db, $sql);
		while ($row = mysqli_fetch_assoc($result)) {
			// echo $district->id;
			// echo $district->district_name;
			$id=$row['category_no'];
		
			$output .= "<option value='$id'>".$row['category']."</option>";
		}

		echo $output; 
	
	}
		
	public function auo_product4()
	{
		$search_id = $_POST['search_id'];
	//echo $search_id;


		$db = get_instance()->db->conn_id;
		// $output = array();
		$sql = "SELECT * FROM headingmaster where master_product='$search_id' and IsActive='0'";
		$result = mysqli_query($db, $sql);
		while ($row = mysqli_fetch_assoc($result)) {
			// echo $district->id;
			// echo $district->district_name;
			$id=$row['heading_no'];
			$output .= "<option value='$id'>".$row['heading']."</option>";
		}

		echo $output; 
	
	}
	
	

}?>