<?php
/*
* Generated by CRUDigniter v3.2
* www.crudigniter.com
*/
class User extends FrontApplication{
function __construct()
{
parent::__construct();
$this->load->model('User_model');
}
function pdf()
{
$this->load->model('Service_model');
$this->data['services']= $this->Service_model->get_all_service();
$this->data['users'] = $this->User_model->get_all_users();
$this->load->library("html2pdf/HTML2PDF");
$this->load->view("user/pdf",$this->data);
}
/*
* Listing of users
*/
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('user/index?');
$config['total_rows'] = $this->User_model->get_all_users_count();
$this->pagination->initialize($config);
$this->data['users'] = $this->User_model->get_all_users($params);
$this->data['_view'] = 'user/index';
$this->load->view('layouts/main',$this->data);
}
/*
* Adding a new user
*/
function add()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('password','Password','required');
$this->form_validation->set_rules('matricule','Matricule','required');
$this->form_validation->set_rules('login','Login','required');
$this->form_validation->set_rules('nom','Nom','required');
$this->form_validation->set_rules('prenom','Prenom','required');
$this->form_validation->set_rules('active','Active','required');
if($this->form_validation->run())
{
$params = array(
'active' => $this->input->post('active'),
'responsable_id' => $this->input->post('responsable_id'),
'interim_id' => $this->input->post('interim_id'),
'type' => $this->input->post('type'),
'password' => $this->input->post('password'),
'matricule' => $this->input->post('matricule'),
'login' => $this->input->post('login'),
'nom' => $this->input->post('nom'),
'prenom' => $this->input->post('prenom'),
'tel'=>$this->input->post('tel'),
'email'=>$this->input->post('email'),
'adresse'=>$this->input->post('adresse'),
'typehoraire'=>$this->input->post('typehoraire')
);
$user_id = $this->User_model->add_user($params);
redirect('user/index');
}
else
{
$user = $this->session->userdata("auth");
if(in_array($this->data["readException"], $this->data["access"]["User"]->actions)){
$this->data['all_users'] = $this->User_model->get_all_users();
}else{
$this->data['all_users'] = $this->User_model->get_all_users_same_service($user["service_id"]);
}
$this->data['_view'] = 'user/add';
$this->load->view('layouts/main',$this->data);
}
}
/*
* Editing a user
*/
function edit($id)
{
// check if the user exists before trying to edit it
$this->data['editeduser'] = $this->User_model->get_user($id);
if(isset($this->data['editeduser']['id']))
{
$this->load->library('form_validation');
$this->form_validation->set_rules('password','Password','required');
$this->form_validation->set_rules('matricule','Matricule','required');
$this->form_validation->set_rules('login','Login','required');
$this->form_validation->set_rules('nom','Nom','required');
$this->form_validation->set_rules('prenom','Prenom','required');
$this->form_validation->set_rules('active','Active','required');
if($this->form_validation->run())
{
$params = array(
'active' => $this->input->post('active'),
'responsable_id' => $this->input->post('responsable_id'),
'interim_id' => $this->input->post('interim_id'),
'type' => $this->input->post('type'),
'password' => $this->input->post('password'),
'matricule' => $this->input->post('matricule'),
'login' => $this->input->post('login'),
'nom' => $this->input->post('nom'),
'prenom' => $this->input->post('prenom'),
'tel'=>$this->input->post('tel'),
'email'=>$this->input->post('email'),
'adresse'=>$this->input->post('adresse')
);
$this->User_model->update_user($id,$params);
redirect('user/index');
}
else
{
$this->data['all_users'] = $this->User_model->get_all_users();
$this->data['_view'] = 'user/edit';
$this->load->view('layouts/main',$this->data);
}
}
else
show_error('The user you are trying to edit does not exist.');
}
/*
* Deleting user
*/
function remove($id)
{
$user = $this->User_model->get_user($id);
// check if the user exists before trying to delete it
if(isset($user['id']))
{
$this->User_model->delete_user($id);
redirect('user/index');
}
else
show_error('The user you are trying to delete does not exist.');
}
function getForList(){
echo json_encode($this->User_model->getForList());
}
function getForListCustom(){
$user =$this->session->userdata("auth");
if($user["type"]==2){
echo json_encode($this->User_model->getForList());
}else{
echo json_encode($this->User_model->getForListResponsable());
}
}
}