<?php
/*
* Generated by CRUDigniter v3.2
* www.crudigniter.com
*/
class Contrat extends FrontApplication{
function __construct()
{
parent::__construct();
$this->load->model('Contrat_model');
}
/*
* Listing of contrat
*/
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('contrat/index?');
$config['total_rows'] = $this->Contrat_model->get_all_contrat_count();
$this->pagination->initialize($config);
$this->data['contrat'] = $this->Contrat_model->get_all_contrat($params);
$this->data['_view'] = 'contrat/index';
$this->load->view('layouts/main',$this->data);
}
/*
* Adding a new contrat
*/
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('active','Active','required');
$this->form_validation->set_rules('users_id','Users Id','required');
$this->form_validation->set_rules('typecontrat_id','Typecontrat Id','required');
$this->form_validation->set_rules('soldeconge','Soldeconge','required');
$this->form_validation->set_rules('soldeautorisation','Soldeautorisation','required');
if($this->form_validation->run())
{
$params = array(
'active' => $this->input->post('active'),
'users_id' => $this->input->post('users_id'),
'typecontrat_id' => $this->input->post('typecontrat_id'),
'datedebut' => date("Y-m-d",strtotime($this->input->post('datedebut'))),
'datefin' =>date("Y-m-d",strtotime($this->input->post('datefin'))) ,
'soldeconge' => $this->input->post('soldeconge'),
'soldeautorisation' => $this->input->post('soldeautorisation'),
);
$contrat_id = $this->Contrat_model->add_contrat($params);
redirect('contrat/index');
}
else
{
$this->load->model('User_model');
$this->data['all_users'] = $this->User_model->getForList();
$this->load->model('Typecontrat_model');
$this->data['all_typecontrat'] = $this->Typecontrat_model->get_all_typecontrat();
$this->data['_view'] = 'contrat/add';
$this->load->view('layouts/main',$this->data);
}
}
/*
* Editing a contrat
*/
function edit($id)
{
// check if the contrat exists before trying to edit it
$this->data['contrat'] = $this->Contrat_model->get_contrat($id);
if(isset($this->data['contrat']['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('active','Active','required');
$this->form_validation->set_rules('typecontrat_id','Typecontrat Id','required');
$this->form_validation->set_rules('soldeconge','Soldeconge','required');
$this->form_validation->set_rules('soldeautorisation','Soldeautorisation','required');
if($this->form_validation->run())
{
$params = array(
'active' => $this->input->post('active'),
'typecontrat_id' => $this->input->post('typecontrat_id'),
'datedebut' => date("Y-m-d",strtotime($this->input->post('datedebut'))),
'datefin' =>date("Y-m-d",strtotime($this->input->post('datefin'))) ,
'soldeconge' => $this->input->post('soldeconge'),
'soldeautorisation' => $this->input->post('soldeautorisation'),
);
$this->Contrat_model->update_contrat($id,$params);
redirect('contrat/index');
}
else
{
$this->load->model('User_model');
$this->data['all_users'] = $this->User_model->get_all_users();
$this->load->model('Typecontrat_model');
$this->data['all_typecontrat'] = $this->Typecontrat_model->get_all_typecontrat();
$this->data['_view'] = 'contrat/edit';
$this->load->view('layouts/main',$this->data);
}
}
else
show_error('The contrat you are trying to edit does not exist.');
}
/*
* Deleting contrat
*/
function remove($id)
{
$contrat = $this->Contrat_model->get_contrat($id);
// check if the contrat exists before trying to delete it
if(isset($contrat['id']))
{
$this->Contrat_model->delete_contrat($id);
redirect('contrat/index');
}
else
show_error('The contrat you are trying to delete does not exist.');
}
}