<?php
class Type_Bouteille  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']='Taille bouteille';
      $this->load->view('Type_Bouteille_Add_View',$data);

    }



    public function add()
    {

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


  $this->form_validation->set_rules('DESCRIPTION', 'Taille de la bouteille', 'required');
  $this->form_validation->set_rules('LIMITE_VIDE', 'Limite Vide', 'required');
  $this->form_validation->set_rules('LIMITE_PLEIN', 'Limite Plein', 'required');

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

    
    
    
    $datas=array('DESCRIPTION'=>$DESCRIPTION,'LIMITE_VIDE'=>$LIMITE_VIDE,'LIMITE_PLEIN'=>$LIMITE_PLEIN);
    $this->Model->insert_last_id('syst_taille_bouteille',$datas);

    $message = "<div class='alert alert-success' id='message'>
                            Taille de la bouteille 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('configuration/Type_Bouteille/listing'));  
   }

    }

    

    public function listing()
    {
      

      $data['resultat']=$this->Model->getRequete('SELECT * FROM `syst_taille_bouteille` ');
      $tabledata=array();
      
      

      $data['title']='Taille de bouteille';
        $this->load->view('Type_Bouteille_List_View',$data);

    }



    public function index_update($id)
    {

      $data['title']='Taille de bouteille';
      $data['data']=$this->Model->getRequeteOne('SELECT * FROM syst_taille_bouteille WHERE ID_TAILLE_BOUTEILLE = '.$id.'');
      $this->load->view('Type_Bouteille_Update_View',$data);

    }



    public function update()
    {
      $ID_TAILLE_BOUTEILLE=$this->input->post('ID_TAILLE_BOUTEILLE');  
      $DESCRIPTION=$this->input->post('DESCRIPTION');  
      $LIMITE_VIDE=$this->input->post('LIMITE_VIDE');      
      $LIMITE_PLEIN=$this->input->post('LIMITE_PLEIN');
      
      
      $this->form_validation->set_rules('DESCRIPTION', 'Taille de la bouteille', 'required');
      $this->form_validation->set_rules('LIMITE_VIDE', 'Limite Vide', 'required');
      $this->form_validation->set_rules('LIMITE_PLEIN', 'Limite Plein', 'required');
    
       if ($this->form_validation->run() == FALSE){
        $message = "<div class='alert alert-danger'>
                                Type de bouteille non modifi&eacute;
                                <button type='button' class='close' data-dismiss='alert'>&times;</button>
                          </div>";
        $this->session->set_flashdata(array('message'=>$message));
        $data['title']='Taille de bouteille';
        $data['data']=$this->Model->getRequeteOne('SELECT * FROM syst_taille_bouteille WHERE ID_TAILLE_BOUTEILLE = '.$ID_TAILLE_BOUTEILLE.'');
        $this->load->view('Type_Bouteille_Update_View',$data);
       }
       else{
        
        $datas=array(
          'DESCRIPTION'=>$DESCRIPTION,
          'LIMITE_VIDE'=>$LIMITE_VIDE,
          'LIMITE_PLEIN'=>$LIMITE_PLEIN
        );
        $this->Model->update('syst_taille_bouteille',array('ID_TAILLE_BOUTEILLE'=>$ID_TAILLE_BOUTEILLE),$datas);
    
        $message = "<div class='alert alert-success' id='message'>
                                Type de bouteille 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('configuration/Type_Bouteille/listing'));  
       }

    }


    public function desactiver($id)
    {
      $this->Model->update('syst_taille_bouteille',array('ID_TAILLE_BOUTEILLE'=>$id),array('ID_STATUS'=>2));
      $message = "<div class='alert alert-success' id='message'>
                            Type de bouteille 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('configuration/Type_Bouteille/listing'));  
    }

  public function reactiver($id)
    {
      $this->Model->update('syst_taille_bouteille',array('ID_TAILLE_BOUTEILLE'=>$id),array('ID_STATUS'=>1));
      $message = "<div class='alert alert-success' id='message'>
                            Type de bouteille 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('configuration/Type_Bouteille/listing'));  
    }


    public function testmail()
    {
      // echo "string";
      $mail = 'gigigen03@gmail.com';
      $obj = 'Objet de test';
      $message = 'Corp du message de Test news';
      $this->notifications->newsend_mail($mail,$obj,NULL,$message,NULL);



    }


    public function newtestmail(){
      

      $this->email->from('gigigen03@gmail.com', 'Ghislain F');
      $this->email->to('ghislain@mediabox.bi');
      $this->email->subject('Email Test');
      $this->email->message('Testing the email class.');
      // $this->email->send();

      if (!$this->email->send())
        {
        // Generate error
          $this->email->print_debugger(array('headers'));
        }
    
    }

    
    public function newtest()
    {
      


      // require 'vendor/autoload.php';
  // use \Mailjet\Resources;
  $mj = new \Mailjet\Client('*********1234','***********abcd',true,['version' => 'v3.1']);
  $body = [
    'Messages' => [
      [
        'From' => [
          'Email' => "mvuyekurejustin@gmail.com",
          'Name' => "Justin"
        ],
        'To' => [
          [
            'Email' => "mvuyekurejustin@gmail.com",
            'Name' => "Justin"
          ]
        ],
        'Subject' => "Greetings from Mailjet.",
        'TextPart' => "My first Mailjet email",
        'HTMLPart' => "<h3>Dear passenger 1, welcome to <a href='https://www.mailjet.com/'>Mailjet</a>!</h3><br />May the delivery force be with you!",
        'CustomID' => "AppGettingStartedTest"
      ]
    ]
  ];
  $response = $mj->post(Resources::$Email, ['body' => $body]);
  $response->success() && var_dump($response->getData());


  
    }    
    


}