<?php
class Update_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 up_test($t_id)
    {
	    $check = $this->input->post('check');
		  $data = array(
		  't_comment' => $this->input->post('t_comment'),
		  't_name' => $this->input->post('t_name'),
		  );
		  $this->db->where('t_id',$t_id);
		  $this->db->update('testimonials', $data);
		  
	    if($check == 'on')
        {
           move_uploaded_file($_FILES['t_image']['tmp_name'], 'assets/uploads/testimonial/'.$t_id.'.jpg');
		}
    }

    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_password($u_id)
    {
        $data = array(
        'u_password' => $this->input->post('u_password')

        );

        $this->db->where('u_id',$u_id);
        $this->db->update('user', $data);
    }

	function up_article($a_id)
    {
	 $check = $this->input->post('check');
        $data = array(
        'a_title'=>$this->input->post('a_title'),
		'description'=>$this->input->post('description')
        );
        //print_r($data);die();
        $this->db->where('a_id',$a_id);
        $this->db->update('articles',$data);
		
		if($check == 'on')
        {
            move_uploaded_file($_FILES['a_image']['tmp_name'], 'assets/uploads/articles/'.$a_id.'.jpg');
        }
    }

	function up_slider($s_id)
    {
	    $check = $this->input->post('check');
        $data = array(
        's_title'=>$this->input->post('s_title'),

        );
        //print_r($data);die();
        $this->db->where('s_id',$s_id);
        $this->db->update('slider',$data);
		if($check == 'on')
        {
            move_uploaded_file($_FILES['s_image']['tmp_name'], 'assets/uploads/slider/slider_'.$s_id.'.jpg');
        }
    }

	function up_news($n_id)
    {
	    $check = $this->input->post('check');
        $data = array(
        'n_title'=>$this->input->post('n_title'),
		'n_date'=>$this->input->post('n_date'),
		'n_description'=>$this->input->post('n_description')
        );
        //print_r($data);die();
        $this->db->where('n_id',$n_id);
        $this->db->update('news',$data);
		if($check == 'on')
        {
            move_uploaded_file($_FILES['n_image']['tmp_name'], 'assets/uploads/news/news_'.$n_id.'.jpg');
        }
    }
	
     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/services/about_'.$a_id.'.jpg');
        }
    }
	
	function up_case($p_id)
    {
        $check = $this->input->post('check');
        $data = array(
        'p_title' => $this->input->post('p_title'),
        'p_description' => $this->input->post('p_description')
        );
        $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/case_'.$p_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('product',$data);
        if($check == 'on')
        {
            move_uploaded_file($_FILES['p_image']['tmp_name'], 'assets/uploads/products/product_'.$p_id.'.jpg');
        }
	    if($check2 == 1)
        {
            move_uploaded_file($_FILES['p_file']['tmp_name'], 'assets/uploads/products/brochure_'.$p_id.'.pdf');
        }

    }

    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'    => true,
            'width'             => $width,
            'height'            => $height,
            'quality'           => 90
            );

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



}
