<?php
/*
* Generated by CRUDigniter v3.2
* www.crudigniter.com
*/
class Ecritureplanning extends FrontApplication{
function __construct()
{
parent::__construct();
$this->load->model('Ecritureplanning_model');
}
function add(){
$this->load->library('form_validation');
$this->form_validation->set_rules('planning_id','Planning Id','required');
$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;
}
if($this->form_validation->run()){
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->Ecritureplanning_model->isferie($item))?3:$this->input->post('type'.$number),
'planning_id' =>$this->input->post('planning_id'),
"datedebut"=>$debut,
"datefin"=>$fin
);
if(!$this->Ecritureplanning_model->is_ecriture_exist($item)){
$ecritureplanning_id = $this->Ecritureplanning_model->add_ecriture($params);
}else{
redirect("ecritureplanning/index/1");
}
}
redirect("ecritureplanning/index/");
}
else{
$this->load->model('Planning_model');
$this->data['all_planning'] = $this->Planning_model->get_all_planning();
$this->data['_view'] = "ecritureplanning/add";
$this->load->view('layouts/main',$this->data);
}
}
function index($msg =null){
$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('ecritureplanning/index?');
$config['total_rows'] = $this->Ecritureplanning_model->get_all_ecriture_count();
$this->pagination->initialize($config);
$this->data['ecritureplanning'] = $this->Ecritureplanning_model->get_all_ecriture($params);
if($msg!=null){
$this->data['msg']="Des ecritures planning sont déja existants";
}
$this->data['_view'] = 'ecritureplanning/index';
$this->load->view('layouts/main',$this->data);
}
function remove($id)
{
$this->Ecritureplanning_model->delete_by_planning($id);
redirect('ecritureplanning/index');
}
function removeperiode()
{
$this->Ecritureplanning_model->delete_by_periode($this->input->post("datedebut"),$this->input->post("datefin"));
redirect('ecritureplanning/index');
}
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("ecritureplanning/add",$this->data,true);
}
function Plan(){
$this->data['planning'] = $this->Planning_model->get_all_planning();
$this->data['_view'] = "timeschedule/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"=>"#673072",
"borderColor"=>"#673072",
);
$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"=>"#726f6e",
"borderColor"=>"#726f6e",
);
$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"=>"#726f6e",
"borderColor"=>"#726f6e",
);
$calendar[]= $itemconge;
$itemconge=array(
"title"=>"Pause de la journée",
"start"=>$value->jour." ".$value->pausedebut,
"end"=>$value->jour." ".$value->pausefin,
"backgroundColor"=>"#39577c",
"borderColor"=>"#39577c",
);
$calendar[]= $itemconge;
$itemconge=array(
"title"=>"2ème Periode de la journée",
"start"=>$value->jour." ".$value->pausefin,
"end"=>$value->jour." ".$value->tempfin,
"backgroundColor"=>"#726f6e",
"borderColor"=>"#726f6e",
);
$calendar[]= $itemconge;
}
}else if($value->type==2){
$itemconge=array(
"title"=>"Repos Hebdomadaire",
"start"=>$value->jour,
"end"=>$value->jour,
"backgroundColor"=>"#ddad90",
"borderColor"=>"#ddad90",
);
$calendar[]= $itemconge;
}
}
echo json_encode($calendar);
}
function IsInTimeDemande(){
$date = $this->input->post("date");
$user = $this->session->userdata("auth");
echo json_encode(
array('success' => $this->Ecritureplanning_model->IsInTimeDemande($date,$user["planning_id"])));
}
function get_count_ferie_in_periode($debut,$fin){
echo json_encode(["count"=> $this->Ecritureplanning_model->get_count_ferie_in_periode($debut,$fin).""]);
}
}