<?php
class Direction  extends CI_Controller{
    function __construct() {
        parent::__construct();
        $this->Is_Connected();

      }

      public function Is_Connected()
       {
       if (empty($this->session->userdata('SOCAR_ID_USER')))
        {
         redirect(base_url('Login/'));
        }
       }

        


  
    public function index()
    {

      $data['title']='Direction';
      $this->load->view('Direction_Add_View',$data);

    }



    public function add()
    {

  // $ACCORDE_CONGE=$this->input->post('ACCORDE_CONGE');
  $DESCRIPTION=$this->input->post('DESCRIPTION');
    
  $this->form_validation->set_rules('DESCRIPTION', 'Description', 'required');

   if ($this->form_validation->run() == FALSE){
    $message = "<div class='alert alert-danger'>
                            Direction non enregistr&eacute;
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
    $this->session->set_flashdata(array('message'=>$message));
    $data['title']='Direction';
  $this->load->view('Direction_Add_View',$data);
   }
   else{

    
    $datas=array('DESCRIPTION'=>$DESCRIPTION);
    $this->Model->insert_last_id('organigramme_direction',$datas);

    $message = "<div class='alert alert-success' id='message'>
                            Direction enregistr&eacute; avec succés
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
    $this->session->set_flashdata(array('message'=>$message));
      redirect(base_url('organigramme/Direction/listing'));  
   }

    }

    

    public function listing()
    {

      $data['resultat']=$this->Model->getRequete('SELECT STATUS, ID_DIRECTION, DESCRIPTION FROM `organigramme_direction` WHERE 1');
      $tabledata=array();

      $data['title']='Direction';
        $this->load->view('Direction_List_View',$data);

    }


    public function index_update($id)
    {

      $data['title']='Direction';
      $data['data']=$this->Model->getRequeteOne('SELECT * FROM organigramme_direction WHERE ID_DIRECTION = '.$id.'');
      $this->load->view('Direction_Update_View',$data);

    }



    public function update()
    {

      // $ACCORDE_CONGE=$this->input->post('ACCORDE_CONGE');
      $DESCRIPTION=$this->input->post('DESCRIPTION');
      $ID_DIRECTION=$this->input->post('ID_DIRECTION');
        
      $this->form_validation->set_rules('DESCRIPTION', 'Description', 'required');
    
       if ($this->form_validation->run() == FALSE){
        $message = "<div class='alert alert-danger'>
                                Direction non modifi&eacute;
                                <button type='button' class='close' data-dismiss='alert'>&times;</button>
                          </div>";
        $this->session->set_flashdata(array('message'=>$message));
        $data['title']='Direction';
      $this->load->view('Direction_Update_View',$data);
       }
       else{
    
        
        $datas=array('DESCRIPTION'=>$DESCRIPTION);
        $this->Model->update('organigramme_direction',array('ID_DIRECTION'=>$ID_DIRECTION),$datas);
    
        $message = "<div class='alert alert-success' id='message'>
                                Direction modifi&eacute; avec succés
                                <button type='button' class='close' data-dismiss='alert'>&times;</button>
                          </div>";
        $this->session->set_flashdata(array('message'=>$message));
          redirect(base_url('organigramme/Direction/listing'));  
       }
     

    }


    public function desactiver($id)
    {
      $this->Model->update('organigramme_direction',array('ID_DIRECTION'=>$id),array('STATUS'=>0));
      $message = "<div class='alert alert-success' id='message'>
                              Direction désactivé avec succés
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
      $this->session->set_flashdata(array('message'=>$message));
      redirect(base_url('organigramme/Direction/listing'));  
    }

  public function reactiver($id)
    {
      $this->Model->update('organigramme_direction',array('ID_DIRECTION'=>$id),array('STATUS'=>1));
      $message = "<div class='alert alert-success' id='message'>
                            Direction Réactivé avec succés
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
      $this->session->set_flashdata(array('message'=>$message));
      redirect(base_url('organigramme/Direction/listing'));  
    }

    
    


}