<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Sharecv extends CI_Controller 
{
	 function __construct() 
	 {
        parent::__construct();
        $this->load->database();
        $this->load->model('User_Model');
        $this->load->model('Common');
         $x = $this->session->userdata('logged');
         if ($x['email'] == '') 
         {
                return redirect('Welcome/index', 'refresh');
          }
    }

    public function index()
    {
        $page =(isset($_GET['page'])) ? $_GET['page'] : 0;
        $query=$this->db->select('share_cv.*')->from('share_cv')->order_by('id','desc')->limit(20,($page))->get();
        $num_rows=$this->db->order_by('id', 'desc')->get('share_cv')->num_rows();
        $data['share_cv']=$query->result_array();
        $data['links']=$this->pagi->pagination1('admin/share_cv',$num_rows,20);
        $this->load->view('share_cv/index',$data);
    }



    public function edit($id='')
    {
        if ($this->input->server('REQUEST_METHOD') == 'POST') 
        {
        $this->load->helper(array('form'));
         $this->load->library('form_validation');
         $this->form_validation->set_rules('first_name', 'First Name', 'required'); 
         $this->form_validation->set_rules('last_name', 'Last Name', 'required'); 
         $this->form_validation->set_rules('email', 'Email', 'required'); 
         $this->form_validation->set_rules('phone','Phone','required');
            if ($this->form_validation->run() == FALSE) 
             { 
                 $data['share_cv']=$this->db->where('id',$id)->get('share_cv')->row_array();
                 $this->load->view('share_cv/edit',$data);
             } 
             else 
             { 
                if($_FILES['profile']['name']!='')
                {
                     $journalName = str_replace(' ', '_', $_FILES['profile']['name']);
                $config['file_name'] = time() . $journalName;
                $config['upload_path'] = './uploads/share_cv/';
                $config['allowed_types'] = 'gif|jpg|png|JPG|JPEG|jpeg';
                $this->upload->initialize($config);
                $this->upload->do_upload('profile');
                $_POST['profile'] = $config['file_name'];
                unset($_POST['email']);

                }
                if($this->db->where('id',$id)->update('share_cv',$_POST))
                {
                    $this->session->set_flashdata('msg', 'User Successfully Updated');
                    return redirect(base_url('admin/share_cv'),'refresh');
                }
                else
                {
                    $this->session->set_flashdata('err', 'Please try Again After SomeTimes');
                    return redirect(base_url('admin/share_cv/edit/'.$id),'refresh');
                }
             }
        }
        else
        {
            $data['share_cv']=$this->db->where('id',$id)->get('share_cv')->row_array();
            $this->load->view('share_cv/edit',$data);
        }
    }

    public function view($id='')
    {
         $data['share_cv']=$this->db->where('id',$id)->get('share_cv')->row_array();
         $this->load->view('share_cv/view',$data);
    }

    public function delete($id='')
    {
        if($this->db->where('id',$id)->delete('share_cv'))
        {
            $this->session->set_flashdata('msg', 'Success Deleted share_cv');
        }
        else
        {
            $this->session->set_flashdata('err', 'Please try After Sometimes...');
        }
        return redirect(base_url('admin/share_cv'),'refresh');
    }

}
