<?php
class Update_data extends CI_Model{
    
    
    function up_profile($c_id)
    {
        $data = array(
        'c_name' => $this->input->post('c_name'),
        'c_phone' => $this->input->post('c_phone'),
        'c_mobile' => $this->input->post('c_mobile'),
        'c_contactperson' => $this->input->post('c_contactperson'),
        'c_address' => $this->input->post('c_address'),
        'c_email' => $this->input->post('c_email'),
        'c_facebook' => $this->input->post('c_facebook'),
        'c_linkedin' => $this->input->post('c_linkedin'),
        'c_google' => $this->input->post('c_google'),
        );
        //print_r($data); die();
        $this->db->where('c_id',$c_id);
        $this->db->update('company_profile', $data);
    }
     function up_about($a_id)
    {
        $check = $this->input->post('check');        
        $data = array(
        'a_title' => $this->input->post('a_title'),
        'a_description' => $this->input->post('a_description')
        );
        $this->db->where('a_id',$a_id);
        $this->db->update('about', $data);
        
        if($check == 'on')
        {
            move_uploaded_file($_FILES['a_image']['tmp_name'], 'assets/uploads/about/about_'.$a_id.'.jpg');
        }
    }
	 function up_director($p_id)
    {
        $check = $this->input->post('check');        
        $data = array(
        'p_title' => $this->input->post('p_title'),
        'p_description' => $this->input->post('p_description'),
		//'p_name' => 'Vission'
        );
        $this->db->where('p_id',$p_id);
        $this->db->update('pages', $data);
        
        if($check == 'on')
        {
            move_uploaded_file($_FILES['p_image']['tmp_name'], 'assets/uploads/about/director_'.$p_id.'.jpg');
        }
    }
	 function up_quality($p_id)
    {
        $check = $this->input->post('check');        
        $data = array(
        'p_title' => $this->input->post('p_title'),
        'p_description' => $this->input->post('p_description'),
		//'p_name' => 'Vission'
        );
        $this->db->where('p_id',$p_id);
        $this->db->update('pages', $data);
        
        if($check == 'on')
        {
            move_uploaded_file($_FILES['p_image']['tmp_name'], 'assets/uploads/about/qualitypolicy_'.$p_id.'.jpg');
        }
    }
	 function up_company($p_id)
    {
        $check = $this->input->post('check');        
        $data = array(
        'p_title' => $this->input->post('p_title'),
        'p_description' => $this->input->post('p_description'),
		//'p_name' => 'Company Profile'
        );
        $this->db->where('p_id',$p_id);
        $this->db->update('pages', $data);
        
        if($check == 'on')
        {
            move_uploaded_file($_FILES['p_image']['tmp_name'], 'assets/uploads/services/company_'.$p_id.'.jpg');
        }
    }
     function up_service($s_id)
    {
        $check = $this->input->post('check');
        $data = array(
       // 'pt_id' =>$this->input->post('pt_id'),
        's_name' => $this->input->post('s_name'),
        's_description' => $this->input->post('s_description')
        );
        //print_r($data); die();        
        $this->db->where('s_id',$s_id);
        $this->db->update('service', $data);
        
         if($check == 'on')
        {
            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 up_product_cat($pt_id)
    {
        
	    $check = $this->input->post('check');
        $data = array(
        
       // 'pt_id'=>$this->input->post('pt_id'),
        'pt_name'=>$this->input->post('pt_name'),
        'pt_description' =>$this->input->post('pt_description')
        
        );
        //print_r($data);die();
        $this->db->where('pt_id',$pt_id);
        $this->db->update('product',$data);
        if($check == 'on')
        {
            move_uploaded_file($_FILES['pt_image']['tmp_name'], 'assets/uploads/news/ptype_'.$pt_id.'.jpg');
        }
       
    }
	  function up_product($p_id)
    {
        
	    $check = $this->input->post('check');
		$check2 = $this->input->post('check2');
        $data = array(
        
        
        'p_name'=>$this->input->post('p_name'),
        'p_description' =>$this->input->post('p_description')
        
        );
        //print_r($data);die();
        $this->db->where('p_id',$p_id);
        $this->db->update('sub_product',$data);
        if($check == 'on')
        {
            move_uploaded_file($_FILES['p_image']['tmp_name'], 'assets/uploads/news/product_'.$p_id.'.jpg');
        }
       /* if($check2 == '1')
        {
            move_uploaded_file($_FILES['bro_image']['tmp_name'], 'assets/uploads/news/product_'.$p_id.'.pdf');
        }*/
    }
	
	  function up_subproduct($p_id)
    {
        $check = $this->input->post('check');
        $data = array(
        'pt_id' =>$this->input->post('pt_id'),
        'p_name' => $this->input->post('p_name'),
        'p_description' => $this->input->post('p_description')
        );
        //print_r($data); die();        
        $this->db->where('p_id',$p_id);
        $this->db->update('sub_product', $data);
        
         if($check == 'on')
        {
            move_uploaded_file($_FILES['p_image']['tmp_name'], 'assets/uploads/services/subproduct_'.$p_id.'.jpg');
        }
       
    }
  /*  function up_subservices($su_id)
    {
       
	    $su_image = 1;
		$su_image_count = count($_FILES['su_image']['tmp_name']);
	    $count = $_FILES['su_image']['tmp_name'];
          
        $data = array(
        //'se_id' =>$this->input->post('se_id'),
        'su_title' => $this->input->post('su_title'),
        'su_description' => $this->input->post('su_description'),
        'su_image' =>$su_image,
        'su_image_count' => $su_image_count
        );
        //print_r($data); die();        
        $this->db->where('su_id',$su_id);
        $this->db->update('sub_service', $data);
        
         $i = 0;
	   foreach($_FILES['su_image']['tmp_name'] as $key => $tmp_name)
	   {
		$i++;
        $file_tmp =$_FILES['su_image']['tmp_name'][$key];
		move_uploaded_file($file_tmp,"assets/uploads/services/subservices_".$su_id."_".$i.'.jpg');
        //move_uploaded_file($_FILES['p_image']['tmp_name'],'assets/uploads/news/product_'.$p_id.'.jpg');
       }
        
       
    }*/
      
    function up_gallery($g_id)
    {
        $check = $this->input->post('check');
        $data = array(
       // 'pt_id' =>$this->input->post('pt_id'),
        'g_name' => $this->input->post('g_name'),
        'g_description' => $this->input->post('g_description')
        );
        //print_r($data); die();        
        $this->db->where('g_id',$g_id);
        $this->db->update('gallery', $data);
        
         if($check == 'on')
        {
            move_uploaded_file($_FILES['g_image']['tmp_name'], 'assets/uploads/news/gallery_'.$g_id.'.jpg');
        }
       
    }
    
    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();
	 }
}
    
}
