<?php
class Insert_data extends CI_Model {
    
    
    function set_slider()
    {
        $data = array(
        's_title' => $this->input->post('s_title'),
        //'s_content' => $this->input->post('s_content')
        );
       
        $this->db->insert('slider', $data);
        $id = $this->db->insert_id();        
        $image = $this->input->post('s_title');	       
        move_uploaded_file($_FILES['s_image']['tmp_name'], 'assets/uploads/slider/'.$image.'_'.$id.'.jpg');
    }
	function set_team()
	{
		$data = array (
			't_name'=>$this->input->post('t_name'),
			't_post'=>$this->input->post('t_post'),
			't_status' =>'1'
	 	);
		$this->db->insert('team',$data);
		$id=$this->db->insert_id();
		move_uploaded_file($_FILES['t_image']['tmp_name'], 'assets/uploads/team/t_'.$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/clients/client_'.$id.'.jpg');
	}
	
	/*function setproduct()
	{
	    
	   //$p_image_count = 0; 
	   //$p_image = 0;	 
	   $p_image = 1;
	   $p_image_count = count($_FILES['p_image']['tmp_name']);
	   $count = $_FILES['p_image']['tmp_name'];
	   //echo count($count);
	   //die();
		$data = array(			
			'p_name'=> $this->input->post('p_name'),	
			'p_description'=>$this->input->post('p_description'),
			'p_image' => $p_image,
			'p_image_count' => $p_image_count,
			'p_status'=>1
		);
		//print_r($data); die();
		$this->db->insert('sub_product',$data);
		$p_id = $this->db->insert_id();
		//$p_id = mysql_insert_id();
		
		$i = 0;
		foreach($_FILES['p_image']['tmp_name'] as $key => $tmp_name)
		{
			$i++;
			$file_tmp =$_FILES['p_image']['tmp_name'][$key];			
			move_uploaded_file($file_tmp,"assets/uploads/news/product_".$p_id."_".$i.'.jpg');
		    //move_uploaded_file($_FILES['p_image']['tmp_name'],'assets/uploads/news/product_'.$id.'.jpg');
		}
	}*/
	
	
	
	function set_service()
    {
        $data = array(
        //'pt_id' => $this->input->post('pt_id'),
        's_name' => $this->input->post('s_name'),
        's_description' => $this->input->post('s_description'),
        's_status' => '1'
        );
        //print_r($data);die();
        $this->db->insert('service', $data);
        $s_id = $this->db->insert_id();
        move_uploaded_file($_FILES['s_image']['tmp_name'], 'assets/uploads/services/service_'.$s_id.'.jpg');
		$source_path = "assets/uploads/services/service_".$s_id.".jpg";
	 	$thumb_path = 'assets/uploads/services/thumbnail/ser_'.$s_id.'.jpg';
		$this->upload_thumbnail($source_path,$thumb_path,'150','150');
    }
	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/gallery/gallery_'.$g_id.'.jpg');
    }
  
	function set_gtype()
	{
		$data = array(
			'gt_type'=>$this->input->post('gt_type'),
			'gt_status' =>'1'
		);
		$this->db->insert('gallery_type',$data);
		
	}
   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'    => false,
			   'width'             => $width,
			   'height'            => $height
			   );

	 $this->image_lib->initialize($config);
	 $this->image_lib->resize();
	 if (!$this->image_lib->resize()) {
	 echo $this->image_lib->display_errors();
	 }
}

}
