<?php
class Insert_data extends CI_Model {
 function __construct()
    {
	 parent::__construct();
	 $this->load->helper(array('html','language','form','text'));
     $this->load->helper('my_helper');
	 $this->load->model('Common_model');

    }
	 
	function set_image()
	 {
		 $data = array(
		 'p_id' => trim($this->input->post('p_id')),
		  'a_status' => '1'
		 );
		 $this->db->insert('add_image', $data);
		 $id = $this->db->insert_id();
		 move_uploaded_file($_FILES['add_image']['tmp_name'], 'assets/uploads/Images/image_'.$id.'.jpg');
	 }
		 
	 function set_pvideo()
	 {
		 $data = array(
		 'p_id' => trim($this->input->post('p_id')),
		 'v_link' => trim($this->input->post('v_link')),
		 'v_status' => '1'
		 );
		 $this->db->insert('add_video', $data);
		 $id = $this->db->insert_id();	
	 }
		 
	 function set_slider()
	 {
		 $data = array(
		 's_title' => $this->input->post('s_title'),
		 's_status' => '1'
		 );
		 $this->db->insert('slider', $data);
		 $id = $this->db->insert_id();
		 move_uploaded_file($_FILES['s_image']['tmp_name'], 'assets/uploads/slider/slider_'.$id.'.jpg'); 
	 }

	function set_article()
    {
        $data = array(
        'a_title' => $this->input->post('a_title'),
		'description' => $this->input->post('description')
        );
        //print_r($data);die();
        $this->db->insert('articles', $data);
		$id = $this->db->insert_id();
		move_uploaded_file($_FILES['a_image']['tmp_name'], 'assets/uploads/articles/'.$id.'.jpg'); 
    }

	function set_client()
	{
		$data = array (
			'c_name'=>$this->input->post('c_name'),
			'c_status' =>'1'
	 	);
		$this->db->insert('client',$data);
		$id=$this->db->insert_id();
		move_uploaded_file($_FILES['c_image']['tmp_name'], 'assets/uploads/news/client_'.$id.'.jpg');
	}

	function setproject()
	{
		$data = array(
			'p_name' => $this->input->post('p_name'),
			'p_description'=>$this->input->post('p_description'),
			'p_status'=>'1'
		 );
		$this->db->insert('projects',$data);
		$id=$this->db->insert_id();

		 move_uploaded_file($_FILES['p_image']['tmp_name'], 'assets/uploads/projects/project_'.$id.'.jpg');
		
	}
	
	function set_projectimage()
	 {
		 $data = array(
		 'p_id' => trim($this->input->post('p_id')),
		  'a_status' => '1'
		 );
		 $this->db->insert('project_images', $data);
		 $id = $this->db->insert_id();
		 move_uploaded_file($_FILES['add_image']['tmp_name'], 'assets/uploads/projects/image_'.$id.'.jpg');
	 }
	 
	function setproduct()
	{
		$data = array(
			'p_name' => $this->input->post('p_name'),
			'p_description'=>$this->input->post('p_description'),
			'p_status'=>'1'
		 );
		$this->db->insert('product',$data);
		$id=$this->db->insert_id();

		 move_uploaded_file($_FILES['p_image']['tmp_name'], 'assets/uploads/products/product_'.$id.'.jpg');
		 move_uploaded_file($_FILES['p_file']['tmp_name'], 'assets/uploads/products/brochure_'.$id.'.pdf');
	}

	function set_gallery()
    {
        $data = array(
        'gt_id' => $this->input->post('gt_id'),
        'g_name' => $this->input->post('g_name'),

        'g_status' => '1'
        );
        //print_r($data);die();
        $this->db->insert('gallery', $data);
        $g_id = $this->db->insert_id();
        move_uploaded_file($_FILES['g_image']['tmp_name'], 'assets/uploads/news/gallery_'.$g_id.'.jpg');
    }
	
	function set_infra()
    {
        $data = array(
        'name' => $this->input->post('name'),
        );
        //print_r($data);die();
        $this->db->insert('infrastructure', $data);
        $id = $this->db->insert_id();
        move_uploaded_file($_FILES['s_image']['tmp_name'], 'assets/uploads/infra/'.$id.'.jpg');
    }

	function set_enquiry()
    {
	  $data = array(
	   'name' => $this->input->post('name'),
	   'mobile' => $this->input->post('mobile'),
	   'email' => $this->input->post('email'),
	   'message' => $this->input->post('message'),
      );
      $this->db->insert('enquiry', $data);
    }

	function set_gtype()
	{
	   $data = array(
		'gt_type'=>$this->input->post('gt_type'),
		'gt_status' =>'1'
	   );
	   $this->db->insert('gallery_type',$data);
	}
	
	function set_video()
	{
	  $data = array(
	   'v_name'=>$this->input->post('v_name'),
	   'v_link'=>$this->input->post('v_link'),
	   'v_status' =>'1'
	  );
	  $this->db->insert('video',$data);
	}
	
	function set_test()
    {
        $data = array(
		
        't_comment' => $this->input->post('t_comment'),
        't_name' => $this->input->post('t_name'),
        't_status' => '1'
        );
        //print_r($data);die();
        $this->db->insert('testimonials', $data);
        $t_id = $this->db->insert_id();
        move_uploaded_file($_FILES['t_image']['tmp_name'], 'assets/uploads/testimonial/'.$t_id.'.jpg');
    }

		function set_news()
    {
        $data = array(
        'n_title' => $this->input->post('n_title'),
        'n_description' => $this->input->post('n_description'),

        'n_status' => '1'
        );
        //print_r($data);die();
        $this->db->insert('news', $data);
        $n_id = $this->db->insert_id();
        move_uploaded_file($_FILES['n_image']['tmp_name'], 'assets/uploads/news/news_'.$n_id.'.jpg');
    }


   function set_pdf()
   {
	  $data = array(
		 'p_name' =>$this->input->post('p_name'),
		 'p_status' => '1'
	  );
	  $this->db->insert('pdf',$data);
	  $p_id=$this->db->insert_id();
	  move_uploaded_file($_FILES['p_pdf']['tmp_name'], 'assets/uploads/gallery/broucher_'.$p_id.'.pdf');
   }


   function upload_thumbnail($source_path,$thumb_path,$width,$height)
 	{
 	  $this->load->library('image_lib');
 		$config = array(
 				   'source_image'      => $source_path,
 				   'new_image'         => $thumb_path,
 				   'maintain_ratio'    => true,
 				   'width'             => $width,
 				   'height'            => $height,
 					 'quality'           => 90
 				   );

 		$this->image_lib->initialize($config);
 		$this->image_lib->resize();
 	}
}
