<?php



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



class Requirement 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('requirement.*')->from('requirement')->order_by('id','desc')->limit(20,($page))->get();

        $num_rows=$this->db->order_by('id', 'desc')->get('requirement')->num_rows();

        $data['requirement']=$query->result_array();

        $data['links']=$this->pagi->pagination1('admin/requirement',$num_rows,20);

        $this->load->view('requirement/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('salary', 'Salary', 'required'); 


            if ($this->form_validation->run() == FALSE) 

             { 

                 $data['requirement']=$this->db->where('id',$id)->get('requirement')->row_array();

                 $this->load->view('requirement/edit',$data);

             } 

             else 

             { 

               

                if($this->db->where('id',$id)->update('requirement',$_POST))

                {

                    $this->session->set_flashdata('msg', 'User Successfully Updated');

                    return redirect(base_url('admin/requirement'),'refresh');

                }

                else

                {

                    $this->session->set_flashdata('err', 'Please try Again After SomeTimes');

                    return redirect(base_url('admin/requirement/edit/'.$id),'refresh');

                }

             }

        }

        else

        {

            $data['requirement']=$this->db->where('id',$id)->get('requirement')->row_array();

            $this->load->view('requirement/edit',$data);

        }

    }



    public function view($id='')

    {

         $data['requirement']=$this->db->where('id',$id)->get('requirement')->row_array();

         $this->load->view('requirement/view',$data);

    }



    public function delete($id='')

    {

        if($this->db->where('id',$id)->delete('requirement'))

        {

            $this->session->set_flashdata('msg', 'Success Deleted requirement');

        }

        else

        {

            $this->session->set_flashdata('err', 'Please try After Sometimes...');

        }

        return redirect(base_url('admin/requirement'),'refresh');

    }



    public function status_change()

    {

        $this->db->where('id',$_POST['id'])->update('requirement',$_POST);

        $this->session->set_flashdata('msg', 'Successfully Status Updated');

        return redirect(base_url('admin/requirement'),'refresh');

    }



}

