<?php


class Front_model extends CI_Model
{
   function get_slider_by_id($id)
    {
        $this->db->where('slider_id', $id);
        return $this->db->get('frontend_slider')->row();
    }

    function update_slider($id) 
    {
        $data['slider_heading'] = $this->input->post('slider_heading');
        $data['slider_sub_heading'] = $this->input->post('slider_sub_heading');
        $data['block_1_heading'] = $this->input->post('block_1_heading');
        $data['block_1_sub_heading'] = $this->input->post('block_1_sub_heading');

        if(!empty($_FILES['slider_image']['name']))
        {
            $image = $this->get_slider_by_id($id);
            if(file_exists($image->slider_image))
            {
                unlink($image->slider_image);
            }
            $_FILES['file']['name'] = $_FILES['slider_image']['name'];
            $_FILES['file']['type'] = $_FILES['slider_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['slider_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['slider_image']['error'];
            $_FILES['file']['size'] = $_FILES['slider_image']['size'];

            // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '5000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['slider_image']['name'];
            $this->upload->initialize($config);
            //Load upload library
            $this->load->library('upload',$config); 

            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['slider_image'] = 'uploads/' . $filename;

                }
            }
            
        }

        if(!empty($_FILES['shape_1_image']['name']))
        {
            $image = $this->get_slider_by_id($id);
            if(file_exists($image->shape_1_image))
            {
                unlink($image->shape_1_image);
            }
            $_FILES['file']['name'] = $_FILES['shape_1_image']['name'];
            $_FILES['file']['type'] = $_FILES['shape_1_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['shape_1_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['shape_1_image']['error'];
            $_FILES['file']['size'] = $_FILES['shape_1_image']['size'];

            // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '5000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['shape_1_image']['name'];
            $this->upload->initialize($config);
            //Load upload library
            $this->load->library('upload',$config); 

            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['shape_1_image'] = 'uploads/' . $filename;

                }
            }
            
        }

      

        $this->db->where('slider_id', $id);
        return $this->db->update('frontend_slider', $data);
        
    }

    function get_our_service_image()
    {
        $this->db->where('os_image_id', 1);
        return $this->db->get('our_service_image')->row();        
    }

    function get_all_our_service()
    {
        return $this->db->get('our_service')->result(); 
    }

    function update_our_service_image_section()
    {
        $data = [
            'os_image_heading' => $this->input->post('os_image_heading'),
            'os_image_sub_heading' => $this->input->post('os_image_sub_heading'), 
        ];
        if(!empty($_FILES['os_image_image']['name']))
        {
            $image = $this->get_our_service_image();
            if(file_exists($image->os_image_image))
            {
                unlink($image->os_image_image);
            }
            $_FILES['file']['name'] = $_FILES['os_image_image']['name'];
            $_FILES['file']['type'] = $_FILES['os_image_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['os_image_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['os_image_image']['error'];
            $_FILES['file']['size'] = $_FILES['os_image_image']['size'];

            // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '5000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['os_image_image']['name'];
            $this->upload->initialize($config);
            //Load upload library
            $this->load->library('upload',$config); 

            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['os_image_image'] = 'uploads/' . $filename;

                }
            }
        }
        if(!empty($_FILES['os_extra_image_image_1']['name']))
        {
            $image = $this->get_our_service_image();
            if(file_exists($image->os_extra_image_image_1))
            {
                unlink($image->os_extra_image_image_1);
            }
            $_FILES['file']['name'] = $_FILES['os_extra_image_image_1']['name'];
            $_FILES['file']['type'] = $_FILES['os_extra_image_image_1']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['os_extra_image_image_1']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['os_extra_image_image_1']['error'];
            $_FILES['file']['size'] = $_FILES['os_extra_image_image_1']['size'];

            // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '5000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['os_extra_image_image_1']['name'];
            $this->upload->initialize($config);
            //Load upload library
            $this->load->library('upload',$config); 

            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['os_extra_image_image_1'] = 'uploads/' . $filename;

                }
            }
        }
        if(!empty($_FILES['os_extra_image_image_2']['name']))
        {
            $image = $this->get_our_service_image();
            if(file_exists($image->os_extra_image_image_2))
            {
                unlink($image->os_extra_image_image_2);
            }
            $_FILES['file']['name'] = $_FILES['os_extra_image_image_2']['name'];
            $_FILES['file']['type'] = $_FILES['os_extra_image_image_2']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['os_extra_image_image_2']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['os_extra_image_image_2']['error'];
            $_FILES['file']['size'] = $_FILES['os_extra_image_image_2']['size'];

            // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '5000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['os_extra_image_image_2']['name'];
            $this->upload->initialize($config);
            //Load upload library
            $this->load->library('upload',$config); 

            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['os_extra_image_image_2'] = 'uploads/' . $filename;

                }
            }
        }
        if(!empty($_FILES['os_extra_image_image_3']['name']))
        {
            $image = $this->get_our_service_image();
            if(file_exists($image->os_extra_image_image_3))
            {
                unlink($image->os_extra_image_image_3);
            }
            $_FILES['file']['name'] = $_FILES['os_extra_image_image_3']['name'];
            $_FILES['file']['type'] = $_FILES['os_extra_image_image_3']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['os_extra_image_image_3']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['os_extra_image_image_3']['error'];
            $_FILES['file']['size'] = $_FILES['os_extra_image_image_3']['size'];

            // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '5000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['os_extra_image_image_3']['name'];
            $this->upload->initialize($config);
            //Load upload library
            $this->load->library('upload',$config); 

            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['os_extra_image_image_3'] = 'uploads/' . $filename;

                }
            }
        }
        $this->db->where('os_image_id', 1);
        return $this->db->update('our_service_image', $data);
    }

    function add_new_service()
    {
        $data = [
            'os_heading' => $this->input->post('os_heading'),
            'os_sub_heading' => $this->input->post('os_sub_heading'), 
        ];
        if(!empty($_FILES['os_image']['name']))
        {
            $_FILES['file']['name'] = $_FILES['os_image']['name'];
            $_FILES['file']['type'] = $_FILES['os_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['os_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['os_image']['error'];
            $_FILES['file']['size'] = $_FILES['os_image']['size'];

            // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '5000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['os_image']['name'];
            $this->upload->initialize($config);
            //Load upload library
            $this->load->library('upload',$config); 

            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['os_image'] = 'uploads/' . $filename;

                }
            }
        }
        return $this->db->insert('our_service', $data);
    }

    function get_our_service_by_id($id)
    {
        $this->db->where('os_id', $id);
        return $this->db->get('our_service')->row();
    }

    function update_our_service_section($id)
    {
        $data = [
            'os_heading' => $this->input->post('os_heading'),
            'os_sub_heading' => $this->input->post('os_sub_heading'), 
        ];
        if(!empty($_FILES['os_image']['name']))
        {
            $image = $this->get_our_service_by_id($id);
            if(file_exists($image->os_image))
            {
                unlink($image->os_image);
            }
            $_FILES['file']['name'] = $_FILES['os_image']['name'];
            $_FILES['file']['type'] = $_FILES['os_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['os_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['os_image']['error'];
            $_FILES['file']['size'] = $_FILES['os_image']['size'];

            // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '5000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['os_image']['name'];
            $this->upload->initialize($config);
            //Load upload library
            $this->load->library('upload',$config); 

            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['os_image'] = 'uploads/' . $filename;

                }
            }
        }
        $this->db->where('os_id', $id);
        return $this->db->update('our_service', $data);
    }

    function delete_our_service($id)
    {
        $image = $this->get_our_service_by_id($id);
        if(file_exists($image->os_image))
        {
            unlink($image->os_image);
        }
        $this->db->where('os_id', $id);
        return $this->db->delete('our_service');
    }

    function get_all_banner_heading()
    {
        $this->db->where('banner_heading_id', 1);
        return $this->db->get('banner_heading')->row();
    }

    function update_banner_heading()
    {
        $data = [
            'banner_heading_title' => $this->input->post('banner_heading_title'), 
            'banner_heading_sub_title' => $this->input->post('banner_heading_sub_title')
        ];

        if(!empty($_FILES['banner_bg_image']['name']))
        {
            $image = $this->get_all_banner_heading();
            if(file_exists($image->banner_bg_image))
            {
                unlink($image->banner_bg_image);
            }
            $_FILES['file']['name'] = $_FILES['banner_bg_image']['name'];
            $_FILES['file']['type'] = $_FILES['banner_bg_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['banner_bg_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['banner_bg_image']['error'];
            $_FILES['file']['size'] = $_FILES['banner_bg_image']['size'];

            // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '5000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['banner_bg_image']['name'];
            $this->upload->initialize($config);
            //Load upload library
            $this->load->library('upload',$config); 

            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['banner_bg_image'] = 'uploads/' . $filename;

                }
            }
            
        }

        $this->db->where('banner_heading_id', 1);
        return $this->db->update('banner_heading', $data);
    }

    // About Us Section Start

    function get_all_about_us_content_1() 
    {
        $this->db->where('id', 1);
        return $this->db->get('about_us_1')->row();
    }

    function add_about_us_section_1() 
    {
        $data = array(
            'heading' => $this->input->post('heading'), 
            'sub_heading' => $this->input->post('sub_heading'), 
            'content' => $this->input->post('content'), 
            'video_or_image' => $this->input->post('video_or_image'), 
            'video' => $this->input->post('video'), 
        );

         if(!empty($_FILES['image']['name']))
        {
            $data1 = $this->get_all_about_us_content_1();
            if(file_exists($data1->image))
            {
                unlink($data1->image);
            }
          $_FILES['file']['name'] = $_FILES['image']['name'];
          $_FILES['file']['type'] = $_FILES['image']['type'];
          $_FILES['file']['tmp_name'] = $_FILES['image']['tmp_name'];
          $_FILES['file']['error'] = $_FILES['image']['error'];
          $_FILES['file']['size'] = $_FILES['image']['size'];

          // Set preference
          $config['upload_path'] = 'uploads/'; 
          $config['allowed_types'] = 'jpg|jpeg|png|gif';
          $config['max_size'] = '5000'; // max_size in kb
          $config['file_name'] = uniqid().$_FILES['image']['name'];
          $this->upload->initialize($config);
          //Load upload library
          $this->load->library('upload',$config); 

          // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['image']= 'uploads/' . $filename;

                }

            }
        }
        $this->db->where('id', 1);
        return $this->db->update('about_us_1', $data);
    }

    function get_all_about_us_content_2_i() 
    {
        $this->db->where('id', 1);
        return $this->db->get('about_us_2_i')->row();
    }

    function add_about_us_section_2_i() 
    {
        $data = array(
            'heading' => $this->input->post('heading'), 
            'sub_heading' => $this->input->post('sub_heading'), 
        );
        $this->db->where('id', 1);
        return $this->db->update('about_us_2_i', $data);
    }

    function add_about_us_section_2_ii() 
    {
        $data = array(
            'heading' => $this->input->post('heading'), 
            'des' => $this->input->post('des'), 
        );
          $_FILES['file']['name'] = $_FILES['image']['name'];
          $_FILES['file']['type'] = $_FILES['image']['type'];
          $_FILES['file']['tmp_name'] = $_FILES['image']['tmp_name'];
          $_FILES['file']['error'] = $_FILES['image']['error'];
          $_FILES['file']['size'] = $_FILES['image']['size'];

          // Set preference
          $config['upload_path'] = 'uploads/'; 
          $config['allowed_types'] = 'jpg|jpeg|png|gif';
          $config['max_size'] = '5000'; // max_size in kb
          $config['file_name'] = uniqid().$_FILES['image']['name'];
          $this->upload->initialize($config);
          //Load upload library
          $this->load->library('upload',$config); 

          // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['image'] = 'uploads/' . $filename;

                }

            }
        return $this->db->insert('about_us_2_ii', $data);
    }

    function get_all_about_us_content_2_ii() 
    {

        return $this->db->get('about_us_2_ii')->result();
    }

    function get_all_about_us_content_2_ii_by_id($id) 
    {
        $this->db->where('id', $id);
        return $this->db->get('about_us_2_ii')->row();
    }

    function delete_section_2_content($id) 
    {
        $data = $this->get_all_about_us_content_2_ii_by_id($id);
        if(file_exists($data->image))
        {
            unlink($data->image);
        }
        $this->db->where('id', $id);
        return $this->db->delete('about_us_2_ii');
    }

    function update_about_us_section_2_ii() 
    {
        $data = array(
            'heading' => $this->input->post('heading'), 
            'des' => $this->input->post('des'), 

        );
        
        if(!empty($_FILES['image']['name']))
        {
            $data1 = $this->get_all_about_us_content_2_ii_by_id($this->input->post('id'));
            if(file_exists($data1->image))
            {
                unlink($data1->image);
            }
          $_FILES['file']['name'] = $_FILES['image']['name'];
          $_FILES['file']['type'] = $_FILES['image']['type'];
          $_FILES['file']['tmp_name'] = $_FILES['image']['tmp_name'];
          $_FILES['file']['error'] = $_FILES['image']['error'];
          $_FILES['file']['size'] = $_FILES['image']['size'];

          // Set preference
          $config['upload_path'] = 'uploads/'; 
          $config['allowed_types'] = 'jpg|jpeg|png|gif';
          $config['max_size'] = '5000'; // max_size in kb
          $config['file_name'] = uniqid().$_FILES['image']['name'];
          $this->upload->initialize($config);
          //Load upload library
          $this->load->library('upload',$config); 

          // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['image']= 'uploads/' . $filename;

                }

            }
        }
        
        $this->db->where('id', $this->input->post('id'));
        return $this->db->update('about_us_2_ii', $data);
    }

    function add_about_us_section_3() 
    {
        $data = array(
            'heading' => $this->input->post('heading'), 
            'sub_heading' => $this->input->post('sub_heading'), 
            'button_name' => $this->input->post('button_name'), 
        );
        $this->db->where('id', 1);
        return $this->db->update('about_3', $data);
    }

    function get_all_about_us_content_3() 
    {
        $this->db->where('id', 1);
        return $this->db->get('about_3')->row();
    }

    function get_all_about_us_content_4_i() 
    {
        $this->db->where('id', 1);
        return $this->db->get('about_us_4_i')->row();
    }
    function add_about_us_section_4_i() 
    {
        $data = array(
            'heading' => $this->input->post('heading'), 
            'sub_heading' => $this->input->post('sub_heading'), 

        );

        if(!empty($_FILES['image']['name']))
        {
            $data1 = $this->get_all_about_us_content_4_i();
            if(file_exists($data1->image))
            {
                unlink($data1->image);
            }
          $_FILES['file']['name'] = $_FILES['image']['name'];
          $_FILES['file']['type'] = $_FILES['image']['type'];
          $_FILES['file']['tmp_name'] = $_FILES['image']['tmp_name'];
          $_FILES['file']['error'] = $_FILES['image']['error'];
          $_FILES['file']['size'] = $_FILES['image']['size'];

          // Set preference
          $config['upload_path'] = 'uploads/'; 
          $config['allowed_types'] = 'jpg|jpeg|png|gif';
          $config['max_size'] = '5000'; // max_size in kb
          $config['file_name'] = uniqid().$_FILES['image']['name'];
          $this->upload->initialize($config);
          //Load upload library
          $this->load->library('upload',$config); 

          // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['image'] = 'uploads/' . $filename;

                }

            }
        }
        
        
        $this->db->where('id', 1);
        return $this->db->update('about_us_4_i', $data);
    }

    function get_all_about_us_content_4_ii() 
    {
        return $this->db->get('about_us_4_ii')->result();
    }

     function add_about_us_section_4_ii() 
    {
        $data = array(
            'heading' => $this->input->post('heading'), 
            'sub_heading' => $this->input->post('sub_heading'), 
            'color' => $this->input->post('color'), 
            'icon' => $this->input->post('icon'), 
        );
        return $this->db->insert('about_us_4_ii', $data);
    }

    function delete_section_4_content($id) 
    {
        $this->db->where('id', $id);
        return $this->db->delete('about_us_4_ii');
    }

    function update_about_us_section_4_ii() 
    {
        $data = array(
            'heading' => $this->input->post('heading'), 
            'sub_heading' => $this->input->post('sub_heading'), 
            'color' => $this->input->post('color'), 
            'icon' => $this->input->post('icon'), 
        );
         $this->db->where('id', $this->input->post('id'));
        return $this->db->update('about_us_4_ii', $data);
    }

    function get_all_about_us_content_5() 
    {
        return $this->db->get('about_us_5')->result();
    }

    function add_about_us_section_5() 
    {
        $data = array(
            'heading' => $this->input->post('heading'), 
            'number' => $this->input->post('number'), 
            'icon' => $this->input->post('icon'), 
        );
        return $this->db->insert('about_us_5', $data);
    }

    function delete_section_5_content($id) 
    {
        $this->db->where('id', $id);
        return $this->db->delete('about_us_5');
    }

    function update_about_us_section_5() 
    {
        $data = array(
            'heading' => $this->input->post('heading'), 
            'number' => $this->input->post('number'), 
            'icon' => $this->input->post('icon'),  
        );
         $this->db->where('id', $this->input->post('id'));
        return $this->db->update('about_us_5', $data);
    }

    function get_all_about_us_content_6_i() 
    {
        $this->db->where('id', 1);
        return $this->db->get('about_us_6_i')->row();
    }

    function add_about_us_section_6_i() 
    {
        $data = array(
            'heading' => $this->input->post('heading'), 
            'sub_heading' => $this->input->post('sub_heading'), 
        );
         $this->db->where('id', 1);
        return $this->db->update('about_us_6_i', $data);
    }

    function add_about_us_section_6_ii() 
    {
        $data = array(
            'name' => $this->input->post('name'), 
            'designation' => $this->input->post('designation'), 
            'year' => $this->input->post('year'),
            'des' => $this->input->post('des'),
        );
          $_FILES['file']['name'] = $_FILES['image']['name'];
          $_FILES['file']['type'] = $_FILES['image']['type'];
          $_FILES['file']['tmp_name'] = $_FILES['image']['tmp_name'];
          $_FILES['file']['error'] = $_FILES['image']['error'];
          $_FILES['file']['size'] = $_FILES['image']['size'];

          // Set preference
          $config['upload_path'] = 'uploads/'; 
          $config['allowed_types'] = 'jpg|jpeg|png|gif';
          $config['max_size'] = '5000'; // max_size in kb
          $config['file_name'] = uniqid().$_FILES['image']['name'];
          $this->upload->initialize($config);
          //Load upload library
          $this->load->library('upload',$config); 

          // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['image'] = 'uploads/' . $filename;

                }

            }
        return $this->db->insert('about_us_6_ii', $data);
    }

     function get_all_about_us_content_6_ii() 
    {
        return $this->db->get('about_us_6_ii')->result();
    }

    function delete_section_6_ii_content($id) 
    {
        $this->db->where('id', $id);
        return $this->db->delete('about_us_6_ii');
    }

    function get_section_6_ii_content($id) 
    {
        $this->db->where('id', $id);
        return $this->db->get('about_us_6_ii')->row();
    }

    function update_about_us_section_6_ii() 
    {
        $data['name'] = $this->input->post('name');
        $data['designation'] = $this->input->post('designation');
        $data['year'] = $this->input->post('year');
        $data['des'] = $this->input->post('des');
        if(!empty($_FILES['image']['name']))
        {
            $data1 = $this->get_section_6_ii_content($this->input->post('id'));
            if(file_exists($data1->image))
            {
                unlink($data1->image);
            }
          $_FILES['file']['name'] = $_FILES['image']['name'];
          $_FILES['file']['type'] = $_FILES['image']['type'];
          $_FILES['file']['tmp_name'] = $_FILES['image']['tmp_name'];
          $_FILES['file']['error'] = $_FILES['image']['error'];
          $_FILES['file']['size'] = $_FILES['image']['size'];

          // Set preference
          $config['upload_path'] = 'uploads/'; 
          $config['allowed_types'] = 'jpg|jpeg|png|gif';
          $config['max_size'] = '5000'; // max_size in kb
          $config['file_name'] = uniqid().$_FILES['image']['name'];
          $this->upload->initialize($config);
          //Load upload library
          $this->load->library('upload',$config); 

          // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['image'] = 'uploads/'.$filename;

                }

            }
        }
        $this->db->where('id', $this->input->post('id'));
        return $this->db->update('about_us_6_ii', $data);
    }

    function add_about_us_section_timeline() 
    {
        $data = array(
            'time_line_year' => $this->input->post('time_line_year'), 
            'time_line_title' => $this->input->post('time_line_title'), 
            'time_line_description' => $this->input->post('time_line_description'),
        );

        return $this->db->insert('about_us_time_line', $data);
    }

     function get_all_about_us_content_timeline() 
    {
        $this->db->order_by('time_line_year', 'ASC');
        return $this->db->get('about_us_time_line')->result();
    }

    function delete_section_timeline_content($id) 
    {
        $this->db->where('time_line_id', $id);
        return $this->db->delete('about_us_time_line');
    }

    function update_about_us_section_timeline($id) 
    {
        $data = array(
            'time_line_year' => $this->input->post('time_line_year'), 
            'time_line_title' => $this->input->post('time_line_title'), 
            'time_line_description' => $this->input->post('time_line_description'),
        );

        $this->db->where('time_line_id', $id);
        return $this->db->update('about_us_time_line', $data);
    }

    function update_brain_behind()
    {
        $data = array(
          'brain_behind_title' => $this->input->post('brain_behind_title'), 
          'brain_behind_description' => $this->input->post('brain_behind_description'),
        );
        if(!empty($_FILES['brain_behind_image']['name']))
        {
            $_FILES['file']['name'] = $_FILES['brain_behind_image']['name'];
            $_FILES['file']['type'] = $_FILES['brain_behind_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['brain_behind_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['brain_behind_image']['error'];
            $_FILES['file']['size'] = $_FILES['brain_behind_image']['size'];

              // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '20000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['brain_behind_image']['name'];
            $this->load->library('upload',$config); 
            $this->upload->initialize($config);
            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['brain_behind_image'] = 'uploads/' . $filename;

                }
            }      
        }
        $this->db->where('brain_behind_id', 1);
        return $this->db->update('about_us_brain_behind', $data);
    }

    function get_brain_behiend()
    {
        $this->db->where('brain_behind_id', 1);
        return $this->db->get('about_us_brain_behind')->row();
    }

    function add_about_us_section_award() 
    {
        $data = array(
            'awards_title' => $this->input->post('awards_title'), 
            'awards_description' => $this->input->post('awards_description'), 
            'awards_date' => $this->input->post('awards_date'),
            'awards_place' => $this->input->post('awards_place'),
        );
        if(!empty($_FILES['awards_image']['name']))
        {
            $_FILES['file']['name'] = $_FILES['awards_image']['name'];
            $_FILES['file']['type'] = $_FILES['awards_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['awards_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['awards_image']['error'];
            $_FILES['file']['size'] = $_FILES['awards_image']['size'];

              // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '20000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['awards_image']['name'];
            $this->load->library('upload',$config); 
            $this->upload->initialize($config);
            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['awards_image'] = 'uploads/' . $filename;

                }
            }      
        }
        return $this->db->insert('about_us_awards', $data);
    }

     function get_all_about_us_content_award() 
    {
        return $this->db->get('about_us_awards')->result();
    }

    function delete_section_award_content($id) 
    {
        $this->db->where('awards_id', $id);
        return $this->db->delete('about_us_awards');
    }

    function update_about_us_section_award($id) 
    {
        $data = array(
            'awards_title' => $this->input->post('awards_title'), 
            'awards_description' => $this->input->post('awards_description'), 
            'awards_date' => $this->input->post('awards_date'),
            'awards_place' => $this->input->post('awards_place'),
        );
        if(!empty($_FILES['awards_image']['name']))
        {
            $_FILES['file']['name'] = $_FILES['awards_image']['name'];
            $_FILES['file']['type'] = $_FILES['awards_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['awards_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['awards_image']['error'];
            $_FILES['file']['size'] = $_FILES['awards_image']['size'];

              // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '20000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['awards_image']['name'];
            $this->load->library('upload',$config); 
            $this->upload->initialize($config);
            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['awards_image'] = 'uploads/' . $filename;

                }
            }      
        }
        $this->db->where('awards_id', $id);
        return $this->db->update('about_us_awards', $data);
    }
    
    // About Us Section End

    public function get_all_slider_block()
    {
        $this->db->where('block_id', 1);
        return $this->db->get('slider_block')->row();
    }

    public function update_slider_block()
    {
        $data = array(
            'block_1_icon'          => $this->input->post('block_1_icon'),
            'block_1_heading'       => $this->input->post('block_1_heading'),
            'block_1_sub_heading'   => $this->input->post('block_1_sub_heading'),
            'block_2_icon'          => $this->input->post('block_2_icon'),
            'block_2_heading'       => $this->input->post('block_2_heading'),
            'block_2_sub_heading'   => $this->input->post('block_2_sub_heading'),
            'block_3_icon'          => $this->input->post('block_3_icon'),
            'block_3_heading'       => $this->input->post('block_3_heading'),
            'block_3_sub_heading'   => $this->input->post('block_3_sub_heading'),
            'block_4_icon'          => $this->input->post('block_4_icon'),
            'block_4_heading'       => $this->input->post('block_4_heading'),
            'block_4_sub_heading'   => $this->input->post('block_4_sub_heading')
        );

        $this->db->where('block_id', 1);
        return $this->db->update('slider_block', $data);
    }

    function get_all_testimonial()
    {
        return $this->db->get('testimonials')->result();
    }

    function add_new_testimonials()
    {
        $data = [
            'test_name' => $this->input->post('test_name'),
            'test_position' => $this->input->post('test_position'), 
            'test_review' => $this->input->post('test_review'), 
            'test_description' => $this->input->post('test_description'), 
        ];
        if(!empty($_FILES['test_image']['name']))
        {
            $_FILES['file']['name'] = $_FILES['test_image']['name'];
            $_FILES['file']['type'] = $_FILES['test_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['test_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['test_image']['error'];
            $_FILES['file']['size'] = $_FILES['test_image']['size'];

            // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '5000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['test_image']['name'];
            $this->upload->initialize($config);
            //Load upload library
            $this->load->library('upload',$config); 

            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['test_image'] = 'uploads/' . $filename;

                }
            }
            
        }
        return $this->db->insert('testimonials', $data);
    }

    function get_testimonials_details_by_id($id)
    {
        $this->db->where('test_id', $id);
        return $this->db->get('testimonials')->row();
    }

    function delete_testmonials($id)
    {
        $image = $this->get_testimonials_details_by_id($id);
        if(file_exists($image->test_image))
        {
            unlink($image->test_image);
        }
        $this->db->where('test_id', $id);
        return $this->db->delete('testimonials');
    }

    function update_testimonials($id)
    {
        $data = [
            'test_name' => $this->input->post('test_name'),
            'test_position' => $this->input->post('test_position'), 
            'test_review' => $this->input->post('test_review'), 
            'test_description' => $this->input->post('test_description'), 
        ];
        if(!empty($_FILES['test_image']['name']))
        {
            $image = $this->get_testimonials_details_by_id($id);
            if(file_exists($image->test_image))
            {
                unlink($image->test_image);
            }
            $_FILES['file']['name'] = $_FILES['test_image']['name'];
            $_FILES['file']['type'] = $_FILES['test_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['test_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['test_image']['error'];
            $_FILES['file']['size'] = $_FILES['test_image']['size'];

            // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '5000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['test_image']['name'];
            $this->upload->initialize($config);
            //Load upload library
            $this->load->library('upload',$config); 

            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['test_image'] = 'uploads/' . $filename;

                }
            }
        }
        $this->db->where('test_id', $id);
        return $this->db->update('testimonials', $data);
    }

    function get_all_placement_logo()
    {
        return $this->db->get('placement_logo')->result();
    }
    function add_new_placement_logo()
    {
        $data = [
            'placement_name' => $this->input->post('placement_name'), 
        ];
        if(!empty($_FILES['placement_image']['name']))
        {
            $_FILES['file']['name'] = $_FILES['placement_image']['name'];
            $_FILES['file']['type'] = $_FILES['placement_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['placement_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['placement_image']['error'];
            $_FILES['file']['size'] = $_FILES['placement_image']['size'];

            // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '5000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['placement_image']['name'];
            $this->upload->initialize($config);
            //Load upload library
            $this->load->library('upload',$config); 

            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['placement_image'] = 'uploads/' . $filename;

                }
            }
        }
        return $this->db->insert('placement_logo', $data);
    }

    function get_placement_logo_by_id($id)
    {
        $this->db->where('placement_id', $id);
        return $this->db->get('placement_logo')->row();
    }

    function update_new_placement_logo($id)
    {
        $data = [
            'placement_name' => $this->input->post('placement_name'), 
        ];
        if(!empty($_FILES['placement_image']['name']))
        {
            $image = $this->get_placement_logo_by_id($id);
            if(file_exists($image->placement_image))
            {
                unlink($image->placement_image);
            }
            $_FILES['file']['name'] = $_FILES['placement_image']['name'];
            $_FILES['file']['type'] = $_FILES['placement_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['placement_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['placement_image']['error'];
            $_FILES['file']['size'] = $_FILES['placement_image']['size'];

            // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '5000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['placement_image']['name'];
            $this->upload->initialize($config);
            //Load upload library
            $this->load->library('upload',$config); 

            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['placement_image'] = 'uploads/' . $filename;

                }
            }
        }
        $this->db->where('placement_id', $id);
        return $this->db->update('placement_logo', $data);
    }

    function delete_placement_logo($id)
    {
        $image = $this->get_placement_logo_by_id($id);
        if(file_exists($image->placement_image))
        {
            unlink($image->placement_image);
        }
        $this->db->where('placement_id', $id);
        return $this->db->delete('placement_logo');
    }

    function get_page_by_id($id) 
    {
        $this->db->where('id', $id);
        return $this->db->get('extra_page')->row();
    }

    function get_page_by_id_for_sign_up_page($id) 
    {
        $this->db->select('name, slug');
        $this->db->where('id', $id);
        return $this->db->get('extra_page')->row();
    }

    function get_all_page_for_footer() 
    {
        $this->db->select('name, slug, showing, id');
        return $this->db->get('extra_page')->result();
    }

    function get_page_by_slug($slug) 
    {
        $this->db->where('slug', $slug);
        return $this->db->get('extra_page')->row();
    }

    function page_add() 
    {
        if($this->input->post('slug'))
        {
            $slug = $this->input->post('slug');
        }
        else
        {
            $slug = slug($this->input->post('name'));
        }
        $data = array(
          'name' => $this->input->post('name'), 
          'slug' => $slug, 
          'content' => $this->input->post('content'),
          'meta_title' => $this->input->post('meta_title'), 
          'meta_descrition' => $this->input->post('meta_descrition'),
          'meta_keyword' => $this->input->post('meta_keyword'),
          'status' => $this->input->post('status'),
          'showing' => $this->input->post('showing'),
          'date' => date('Y-m-d')
        );
        if(!empty($_FILES['image']['name']))
        {
            $_FILES['file']['name'] = $_FILES['image']['name'];
            $_FILES['file']['type'] = $_FILES['image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['image']['error'];
            $_FILES['file']['size'] = $_FILES['image']['size'];

              // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '20000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['image']['name'];
            $this->load->library('upload',$config); 
            $this->upload->initialize($config);
            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['image'] = 'uploads/' . $filename;

                }

            }
                  
        }
        return $this->db->insert('extra_page', $data);
    }

    function update_page() 
    {
        if($this->input->post('slug'))
        {
            $slug = $this->input->post('slug');
        }
        else
        {
            $slug = slug($this->input->post('name'));
        }
        $data = array(
          'name' => $this->input->post('name'), 
          'slug' => $slug, 
          'content' => $this->input->post('content'),
          'meta_title' => $this->input->post('meta_title'),
          'meta_descrition' => $this->input->post('meta_descrition'),
          'meta_keyword' => $this->input->post('meta_keyword'),
          'status' => $this->input->post('status'),
          'showing' => $this->input->post('showing'),
        );
        if(!empty($_FILES['image']['name']))
        {
            $page = $this->get_page_by_id($this->input->post('page_id'));
            if(file_exists($page->image))
            {
                unlink($page->image);
            }
            $_FILES['file']['name'] = $_FILES['image']['name'];
            $_FILES['file']['type'] = $_FILES['image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['image']['error'];
            $_FILES['file']['size'] = $_FILES['image']['size'];

              // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '20000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['image']['name'];
            $this->load->library('upload',$config); 
            $this->upload->initialize($config);
            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['image'] = 'uploads/' . $filename;

                }

            }   
        }
        $this->db->where('id', $this->input->post('page_id'));
        return $this->db->update('extra_page', $data);
    }

    function get_all_page()
    {
        return $this->db->get('extra_page')->result();
    }

    
    function delete_page($id) 
    {
        $page = $this->get_page_by_id($id);
        if(file_exists($page->image))
        {
            unlink($page->image);
        }
        $this->db->where('id', $id);
        return $this->db->delete('extra_page');
    }

    function get_front_top_notification()
    {
        $this->db->where('notification_id', 1);
        return $this->db->get('top_notification')->row();
    }

    function get_front_top_notification_for_home_page()
    {
        // $this->db->where('notification_last_date >', date('Y-m-d'));
        $this->db->where('notification_id', 1);
        return $this->db->get('top_notification')->row();
    }

    function update_notification()
    {
        $data = [
            'notification_content' => $this->input->post('notification_content'),
            'notification_url' => $this->input->post('notification_url'),
            'notification_last_date' => $this->input->post('notification_last_date'),
        ];

        $this->db->where('notification_id', 1);
         return $this->db->update('top_notification', $data);
    }


    // Gallery Start

    public function get_all_gallery_category()
    {
        return $this->db->get('gallery_category')->result();
    }

    public function get_gallery_category_by_id($id)
    {
        $this->db->where('gc_id', $id);
        return $this->db->get('gallery_category')->row();
    }

    public function add_gallery_category()
    {
        $data = array(
            'gc_name' => $this->input->post('gc_name') 
        );

        return $this->db->insert('gallery_category', $data);
    }

    public function update_gallery_category($id)
    {
        $data = array(
            'gc_name' => $this->input->post('gc_name') 
        );

        $this->db->where('gc_id', $id);
        return $this->db->update('gallery_category', $data);
    }

    public function delete_gallery_category($id)
    {
        $this->db->where('gallery_category', $id);
        $is_avl = $this->db->get('gallery')->num_rows();
        if(!$is_avl)
        {
            $this->db->where('gc_id', $id);
            return $this->db->delete('gallery_category');
        }
        else
        {
            return 2;
        }
    }

    public function get_all_gellery()
    {
        return $this->db->get('gallery')->result();
    }

    public function get_all_gellery_with_category()
    {
        $this->db->select('a.*, b.*');
        $this->db->from('gallery a');
        $this->db->join('gallery_category b', 'b.gc_id = a.gallery_category');
        return $this->db->get()->result();
    }

    public function get_gallery_by_id($id)
    {
        $this->db->where('gallery_id', $id);
        return $this->db->get('gallery')->row();
    }

    public function get_gallery_by_mode($id)
    {
        $this->db->select('a.*, b.*');
        $this->db->from('gallery a');
        $this->db->join('gallery_category b', 'b.gc_id = a.gallery_category');
        $this->db->where('a.gallery_video_or_image', $id);
        return $this->db->get()->result();
    }

    public function add_gallery_image()
    {
        $data = array(
            'gallery_category' => $this->input->post('gallery_category'),
            'gallery_video_or_image' => $this->input->post('gallery_video_or_image'),
            'gallery_video_iframe' => $this->input->post('gallery_video_iframe'),
        );
        if(!empty($_FILES['gallery_image']['name']))
        {
            $_FILES['file']['name'] = $_FILES['gallery_image']['name'];
            $_FILES['file']['type'] = $_FILES['gallery_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['gallery_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['gallery_image']['error'];
            $_FILES['file']['size'] = $_FILES['gallery_image']['size'];

              // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '20000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['gallery_image']['name'];
            $this->load->library('upload',$config); 
            $this->upload->initialize($config);
            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['gallery_image'] = 'uploads/' . $filename;

                }
            }   
        }

        return $this->db->insert('gallery', $data);
    }

    public function update_gallery($id)
    {
        $data = array(
            'gallery_category' => $this->input->post('gallery_category'),
            'gallery_video_or_image' => $this->input->post('gallery_video_or_image'),
            'gallery_video_iframe' => $this->input->post('gallery_video_iframe'),
        );
        if(!empty($_FILES['gallery_image']['name']))
        {
            $page = $this->get_gallery_by_id($id);
            if(file_exists($page->gallery_image))
            {
                unlink($page->gallery_image);
            }
            $_FILES['file']['name'] = $_FILES['gallery_image']['name'];
            $_FILES['file']['type'] = $_FILES['gallery_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['gallery_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['gallery_image']['error'];
            $_FILES['file']['size'] = $_FILES['gallery_image']['size'];

              // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '20000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['gallery_image']['name'];
            $this->load->library('upload',$config); 
            $this->upload->initialize($config);
            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['gallery_image'] = 'uploads/' . $filename;

                }
            }   
        }

        $this->db->where('gallery_id', $id);
        return $this->db->update('gallery', $data);
    }

    public function delete_gallery($id)
    {
        $page = $this->get_gallery_by_id($id);
        if(file_exists($page->gallery_image))
        {
            unlink($page->gallery_image);
        }
        $this->db->where('gallery_id', $id);
        return $this->db->delete('gallery');
    }

    public function get_ebook_data()
    {
        $this->db->where('ebook_id', 1);
        return $this->db->get('ebook')->row();
    }

    public function update_ebook()
    {
        $data = array(
            'ebook_heading'         => $this->input->post('ebook_heading'),
            'ebook_description'     => $this->input->post('ebook_description'),
            'ebook_status'          => $this->input->post('ebook_status') == 1 ? 1 : 0,
        );

        if(!empty($_FILES['ebook_pdf']['name']))
        {
            $page = $this->get_ebook_data();
            if(file_exists($page->ebook_pdf))
            {
                unlink($page->ebook_pdf);
            }
            $_FILES['file']['name'] = $_FILES['ebook_pdf']['name'];
            $_FILES['file']['type'] = $_FILES['ebook_pdf']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['ebook_pdf']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['ebook_pdf']['error'];
            $_FILES['file']['size'] = $_FILES['ebook_pdf']['size'];

              // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'pdf';
            $config['max_size'] = '20000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['ebook_pdf']['name'];
            $this->load->library('upload',$config); 
            $this->upload->initialize($config);
            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['ebook_pdf'] = 'uploads/' . $filename;

                }
            }   
        }

        if(!empty($_FILES['ebook_image']['name']))
        {
            $page = $this->get_ebook_data();
            if(file_exists($page->ebook_image))
            {
                unlink($page->ebook_image);
            }
            $_FILES['file']['name'] = $_FILES['ebook_image']['name'];
            $_FILES['file']['type'] = $_FILES['ebook_image']['type'];
            $_FILES['file']['tmp_name'] = $_FILES['ebook_image']['tmp_name'];
            $_FILES['file']['error'] = $_FILES['ebook_image']['error'];
            $_FILES['file']['size'] = $_FILES['ebook_image']['size'];

              // Set preference
            $config['upload_path'] = 'uploads/'; 
            $config['allowed_types'] = 'jpg|jpeg|png|gif';
            $config['max_size'] = '20000'; // max_size in kb
            $config['file_name'] = uniqid().$_FILES['ebook_image']['name'];
            $this->load->library('upload',$config); 
            $this->upload->initialize($config);
            // File upload
            if($this->upload->do_upload('file'))
            {
                // Get data about the file
                $uploadData = $this->upload->data();
                $filename = $uploadData['file_name'];

                 if (isset($filename)) 
                {
                    $data['ebook_image'] = 'uploads/' . $filename;

                }
            }   
        }

        $this->db->where('ebook_id', 1);
        return $this->db->update('ebook', $data);
    }
}   
