<?php
class Type_Documents  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']='Demande interne';      
      $this->load->view('Type_Documents_Add_View',$data);

    }



      public function add()
    {
           
      $DESCRIPTION=$this->input->post('DESCRIPTION');

      $this->form_validation->set_rules('DESCRIPTION', 'Nom du type de document', 'required');
  
   if ($this->form_validation->run() == FALSE){
    $message = "<div class='alert alert-danger'>
                              Type de document non enregistr&eacute;
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
    $this->session->set_flashdata(array('message'=>$message));
    $data['title']='Demande interne';
      $this->load->view('Type_Documents_Add_View',$data); 
   }
   else{

    $data=array('DESCRIPTION'=>$DESCRIPTION);    
    $ID_DOC_INTERNE = $this->Model->insert_last_id('doc_interne_type',$data);

    $message = "<div class='alert alert-success' id='message'>
                            Type de document 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('document_interne/Type_Documents/listing'));  
   }

    }


      public function listing()
    {            
       $statusc = ' ';
              
      $data['resultat']=$this->Model->getRequete('SELECT * FROM `doc_interne_type` WHERE 1');

      $data['title']='Demande interne';
        $this->load->view('Type_Documents_List_View',$data);
    }

    public function desactiver($id)
    {
      $this->Model->update('doc_interne_type',array('ID_TYPE_DOC_INTERNE'=>$id),array('STATUS'=>0));
      
      $message = "<div class='alert alert-primary' id='message'>
                            Type de document interne 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('document_interne/Type_Documents/listing'));  
    }

  public function reactiver($id)
    {
      $this->Model->update('doc_interne_type',array('ID_TYPE_DOC_INTERNE'=>$id),array('STATUS'=>1));
      $message = "<div class='alert alert-primary' id='message'>
                            Type de document interne 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('document_interne/Type_Documents/listing'));  
    }


    
    public function index_update($ID_TYPE_DOC_INTERNE)
    {

      $data['title']='Demande interne';     
      $data['data']=$this->Model->getRequeteOne('SELECT * FROM `doc_interne_type` WHERE 1 AND ID_TYPE_DOC_INTERNE = '.$ID_TYPE_DOC_INTERNE.''); 
      $this->load->view('Type_Documents_Update_View',$data);

    }


    public function update()
    {

       $DESCRIPTION=$this->input->post('DESCRIPTION');
       $ID_TYPE_DOC_INTERNE=$this->input->post('ID_TYPE_DOC_INTERNE');

      $this->form_validation->set_rules('DESCRIPTION', 'Nom du type de document', 'required');
  
   if ($this->form_validation->run() == FALSE){
    $message = "<div class='alert alert-danger'>
                              Type de document non modifi&eacute;
                            <button type='button' class='close' data-dismiss='alert'>&times;</button>
                      </div>";
    $this->session->set_flashdata(array('message'=>$message));
    $data['title']='Demande interne';
    $data['data']=$this->Model->getRequeteOne('SELECT * FROM `doc_interne_type` WHERE 1 AND ID_TYPE_DOC_INTERNE = '.$ID_TYPE_DOC_INTERNE.'');
      $this->load->view('Type_Documents_Update_View',$data); 
   }
   else{

    $data=array('DESCRIPTION'=>$DESCRIPTION);    
    $this->Model->update('doc_interne_type',array('ID_TYPE_DOC_INTERNE'=>$ID_TYPE_DOC_INTERNE),$data);

    $message = "<div class='alert alert-success' id='message'>
                            Type de document 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('document_interne/Type_Documents/listing'));  
   }

    }


}