<?php
/*
* Generated by CRUDigniter v3.2
* www.crudigniter.com
*/
class Demande extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->model('Demande_model');
}
/*
* Listing of demande
*/
function index()
{
$params['limit'] = RECORDS_PER_PAGE;
$params['offset'] = ($this->input->get('per_page')) ? $this->input->get('per_page') : 0;
$config = $this->config->item('pagination');
$config['base_url'] = site_url('demande/index?');
$config['total_rows'] = $this->Demande_model->get_all_demande_count();
$this->pagination->initialize($config);
$data['demande'] = $this->Demande_model->get_all_demande($params);
$data['_view'] = 'demande/index';
$this->load->view('layouts/main',$data);
}
/*
* Adding a new demande
*/
function add()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('datedebut','Datedebut','required');
$this->form_validation->set_rules('datefin','Datefin','required');
$this->form_validation->set_rules('destination','Destination','required');
if($this->form_validation->run())
{
$params = array(
'transport_id' => $this->input->post('transport_id'),
'objetmission_id' => $this->input->post('objetmission_id'),
'typemission_id' => $this->input->post('typemission_id'),
'typeconge_id' => $this->input->post('typeconge_id'),
'objetautorisation_id' => $this->input->post('objetautorisation_id'),
'interim_id' => $this->input->post('interim_id'),
'valide' => $this->input->post('valide'),
'annule' => $this->input->post('annule'),
'type' => $this->input->post('type'),
'creationdate' => $this->input->post('creationdate'),
'datedebut' => $this->input->post('datedebut'),
'datefin' => $this->input->post('datefin'),
'destination' => $this->input->post('destination'),
'users_id' => $this->input->post('users_id'),
'depart_id' => $this->input->post('depart_id'),
'description' => $this->input->post('description'),
);
$demande_id = $this->Demande_model->add_demande($params);
redirect('demande/index');
}
else
{
$this->load->model('Transport_model');
$data['all_transport'] = $this->Transport_model->get_all_transport();
$this->load->model('Objetmission_model');
$data['all_objetmission'] = $this->Objetmission_model->get_all_objetmission();
$this->load->model('Typemission_model');
$data['all_typemission'] = $this->Typemission_model->get_all_typemission();
$this->load->model('Typeconge_model');
$data['all_typeconge'] = $this->Typeconge_model->get_all_typeconge();
$this->load->model('Objetautorisation_model');
$data['all_objetautorisation'] = $this->Objetautorisation_model->get_all_objetautorisation();
$this->load->model('User_model');
$data['all_users'] = $this->User_model->get_all_users();
$data['_view'] = 'demande/add';
$this->load->view('layouts/main',$data);
}
}
/*
* Editing a demande
*/
function edit($id)
{
// check if the demande exists before trying to edit it
$data['demande'] = $this->Demande_model->get_demande($id);
if(isset($data['demande']['id']))
{
$this->load->library('form_validation');
$this->form_validation->set_rules('datedebut','Datedebut','required');
$this->form_validation->set_rules('datefin','Datefin','required');
$this->form_validation->set_rules('destination','Destination','required');
if($this->form_validation->run())
{
$params = array(
'transport_id' => $this->input->post('transport_id'),
'objetmission_id' => $this->input->post('objetmission_id'),
'typemission_id' => $this->input->post('typemission_id'),
'typeconge_id' => $this->input->post('typeconge_id'),
'objetautorisation_id' => $this->input->post('objetautorisation_id'),
'interim_id' => $this->input->post('interim_id'),
'valide' => $this->input->post('valide'),
'annule' => $this->input->post('annule'),
'type' => $this->input->post('type'),
'creationdate' => $this->input->post('creationdate'),
'datedebut' => $this->input->post('datedebut'),
'datefin' => $this->input->post('datefin'),
'destination' => $this->input->post('destination'),
'users_id' => $this->input->post('users_id'),
'depart_id' => $this->input->post('depart_id'),
'description' => $this->input->post('description'),
);
$this->Demande_model->update_demande($id,$params);
redirect('demande/index');
}
else
{
$this->load->model('Transport_model');
$data['all_transport'] = $this->Transport_model->get_all_transport();
$this->load->model('Objetmission_model');
$data['all_objetmission'] = $this->Objetmission_model->get_all_objetmission();
$this->load->model('Typemission_model');
$data['all_typemission'] = $this->Typemission_model->get_all_typemission();
$this->load->model('Typeconge_model');
$data['all_typeconge'] = $this->Typeconge_model->get_all_typeconge();
$this->load->model('Objetautorisation_model');
$data['all_objetautorisation'] = $this->Objetautorisation_model->get_all_objetautorisation();
$this->load->model('User_model');
$data['all_users'] = $this->User_model->get_all_users();
$data['_view'] = 'demande/edit';
$this->load->view('layouts/main',$data);
}
}
else
show_error('The demande you are trying to edit does not exist.');
}
/*
* Deleting demande
*/
function remove($id)
{
$demande = $this->Demande_model->get_demande($id);
// check if the demande exists before trying to delete it
if(isset($demande['id']))
{
$this->Demande_model->delete_demande($id);
redirect('demande/index');
}
else
show_error('The demande you are trying to delete does not exist.');
}
}