<?php
/*
* Generated by CRUDigniter v3.2
* www.crudigniter.com
*/
class Planning extends FrontApplication{
function __construct()
{
parent::__construct();
$this->load->model('Planning_model');
}
/*
* Listing of planning
*/
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('planning/index?');
$config['total_rows'] = $this->Planning_model->get_all_planning_count();
$this->pagination->initialize($config);
$this->data['planning'] = $this->Planning_model->get_all_planning($params);
$this->data['_view'] = 'planning/index';
$this->load->view('layouts/main',$this->data);
}
/*
* Adding a new date
*/
function add()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('libelle','Libelle','required');
$this->form_validation->set_rules('actif','Actif','required');
$this->form_validation->set_rules('typeplanning','Typeplanning','required');
if($this->form_validation->run())
{
$params = array(
'actif' => $this->input->post('actif'),
'libelle' => $this->input->post('libelle'),
'typeplanning' => $this->input->post('typeplanning'),
);
$planning_id = $this->Planning_model->add_planning($params);
redirect('planning/index');
}
else
{
$this->data['_view'] = 'planning/add';
$this->load->view('layouts/main',$this->data);
}
}
function addecriture(){
$debut = $this->input->post('datedebut');
$fin = $this->input->post('datefin');
$jours =array();
$jours[] = date('Y-m-d', strtotime($debut));
$day = $debut;
$date1 = new DateTime($debut);
$date2 = new DateTime($fin);
$interval = $date1->diff($date2);
for($i=1;$i<=$interval->days;$i++){
$day = date('Y-m-d', strtotime('+1 day', strtotime($day)));
$jours[]= $day;
}
foreach($jours as $item){
$number = date("N", strtotime($item));
$params = array(
'jour' => $item,
'tempdebut' => $this->input->post('tempdebut'.$number),
'tempfin' => $this->input->post('tempfin'.$number),
'pausedebut' =>$this->input->post('pausedebut'.$number),
'pausefin' =>$this->input->post('pausefin'.$number),
'type' =>($this->Planning_model->isferie($item))?3:$this->input->post('type'.$number),
'planning_id' =>$this->input->post('planning_id'),
"datedebut"=>$debut,
"datefin"=>$fin
);
$planning_id = $this->Planning_model->add_ecriture($params);
}
redirect("Planning/indexecriture");
}
function indexecriture(){
$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('planning/indexecriture?');
$config['total_rows'] = $this->Planning_model->get_all_ecriture_count();
$this->pagination->initialize($config);
$this->data['planning'] = $this->Planning_model->get_all_ecriture($params);
$this->data['_view'] = 'planning/indexecriture';
$this->load->view('layouts/main',$this->data);
}
/*
* Editing a planning
*/
function edit($id)
{
// check if the planning exists before trying to edit it
$this->data['planning'] = $this->Planning_model->get_planning($id);
if(isset($this->data['planning']['id']))
{
$this->load->library('form_validation');
$this->form_validation->set_rules('libelle','Libelle','required');
$this->form_validation->set_rules('actif','Actif','required');
$this->form_validation->set_rules('typeplanning','Typeplanning','required');
if($this->form_validation->run())
{
$params = array(
'libelle' => $this->input->post('libelle'),
'typeplanning' => $this->input->post('typeplanning'),
'actif' => $this->input->post('actif'),
);
$this->Planning_model->update_planning($id,$params);
redirect('planning/index');
}
else
{
// $this->load->model('Typeplanning_model');
//$this->data['all_typeplanning'] = $this->Typeplanning_model->get_all_typeplanning();
$this->data['_view'] = 'planning/edit';
$this->load->view('layouts/main',$this->data);
}
}
else
show_error('The planning you are trying to edit does not exist.');
}
/*
* Deleting planning
*/
function remove($id)
{
$planning = $this->Planning_model->get_planning($id);
// check if the planning exists before trying to delete it
if(isset($planning['id']))
{
$this->Planning_model->delete_planning($id);
redirect('planning/index');
}
else
show_error('The planning you are trying to delete does not exist.');
}
function removeecriture($id)
{
$this->Planning_model->delete_by_planning($id);
redirect('planning/indexecriture');
}
function removeperiode()
{
$this->Planning_model->delete_by_periode($this->input->post("datedebut"),$this->input->post("datefin"));
redirect('planning/indexecriture');
}
function detail(){
$this->data['planning'] = $this->Planning_model->get_all_planning();
$this->data['_view'] = "planning/delail";
$this->load->view('layouts/main',$this->data);
}
function getIntervalDate($debut,$fin){
$jours =array();
$jours[] = date('Y-m-d', strtotime($debut));
$day = $debut;
$date1 = new DateTime($debut);
$date2 = new DateTime($fin);
$interval = $date1->diff($date2);
for($i=1;$i<=$interval->days;$i++){
$day = date('Y-m-d', strtotime('+1 day', strtotime($day)));
$jours[]= $day;
}
$this->data["jours"]=$jours;
echo $this->load->view("planning/table",$this->data,true);
}
function Plan(){
$this->data['planning'] = $this->Planning_model->get_all_planning();
$this->data['_view'] = "planning/calendar";
$this->load->view('layouts/main',$this->data);
}
function calendar($idplanning){
$calendar = array();
foreach($this->db->query("select * from jourferie")->result() as $value){
$itemconge=array(
"title"=>$value->libelle,
"start"=>$value->date,
"end"=>$value->date,
"backgroundColor"=>"#f20962",
"borderColor"=>"#f20962",
);
$calendar[]= $itemconge;
}
foreach($this->db->query("select * from ecritureplanning where type!=3 && planning_id=".$idplanning)->result() as $value){
if($value->type==1){
$daynumber=date("N", strtotime($value->jour));
if($daynumber==6){
$itemconge=array(
"title"=>"1ère Periode de la journée",
"start"=>$value->jour." ".$value->tempdebut,
"end"=>$value->jour." ".$value->tempfin,
"backgroundColor"=>"#040d8c",
"borderColor"=>"#040d8c",
);
$calendar[]= $itemconge;
/* $itemconge=array(
"title"=>"Repos Hebdomadaire",
"start"=>$value->jour." ".$value->tempfin,
"end"=>$value->jour." 23:59",
"backgroundColor"=>"#f44242",
"borderColor"=>"#f44242",
);
$calendar[]= $itemconge;*/
}else{
$itemconge=array(
"title"=>"1ère Periode de la journée",
"start"=>$value->jour." ".$value->tempdebut,
"end"=>$value->jour." ".$value->pausedebut,
"backgroundColor"=>"#040d8c",
"borderColor"=>"#040d8c",
);
$calendar[]= $itemconge;
if($value->pausedebut."" != "00:00:00" && $value->pausefin."" != "00:00:00"){
$itemconge=array(
"title"=>"Pause de la journée",
"start"=>$value->jour." ".$value->pausedebut,
"end"=>$value->jour." ".$value->pausefin,
"backgroundColor"=>"#03a1c4",
"borderColor"=>"#03a1c4",
);
$calendar[]= $itemconge;
$itemconge=array(
"title"=>"2ème Periode de la journée",
"start"=>$value->jour." ".$value->pausefin,
"end"=>$value->jour." ".$value->tempfin,
"backgroundColor"=>"#040d8c",
"borderColor"=>"#040d8c",
);
$calendar[]= $itemconge;
}
}
}else if($value->type==2){
$itemconge=array(
"title"=>"Repos Hebdomadaire",
"start"=>$value->jour,
"end"=>$value->jour,
"backgroundColor"=>"#c61f3b",
"borderColor"=>"#c61f3b",
);
$calendar[]= $itemconge;
}
}
echo json_encode($calendar);
}
}