<?php
class CalenderModel extends CI_Model {
    public function update_holiday($holiday_date,$data_update,$table){
        $info =array();	
        $this->db->where("holiday_date",$holiday_date);
        $info= $this->db->update($table,$data_update);
        return $info;    
    }

    public function insert_holiday($data,$table){
        $this->db->insert($table,$data);
        return $this->db->insert_id();	      
    }

    public function check_holiday($holiday_date,$table){
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('holiday_date',$holiday_date);
        $this->db->order_by('id',"DESC");
        $info=$this->db->get()->result_array();
        return $info;     
    }    

    public function check_holiday_date($list_day,$month,$year){
        $table='school_calender';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('day',$list_day);
        $this->db->where('month',$month);
        $this->db->where('year',$year);
        $this->db->order_by('id',"DESC");
        $info=$this->db->get()->result_array();
        return $info;         
    }   
    
    public function get_holidays(){
        $table='school_calender';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        // $this->db->where('batch',$yy);
        $this->db->order_by('id',"DESC");
        $info=$this->db->get()->result_array();
        return $info;
    }
    
    public function get_acedemic_session_holidays($acedemic_session){
        $table='school_calender';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);	
        $this->db->where('academic_session',$acedemic_session);
        $this->db->order_by('id',"DESC");
        $info=$this->db->get()->result_array();
        return $info;
    }


    public function get_holidays_in_month($month,$year){
        $table='school_calender';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('month',$month);
        $this->db->where('year',$year);
        $this->db->order_by('id',"DESC");
        $info=$this->db->get()->result_array();
        return $info;    
    }

    public function check_day_holiday($day,$month,$year){
        $table='school_calender';
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('day',$day);
        $this->db->where('month',$month);
        $this->db->where('year',$year);
        $this->db->order_by('id',"DESC");
        $info=$this->db->get()->result_array();
        return $info;    
    }
    
    public function check_sunday($list_day,$month,$year){

        // $day=$this->uri->segment('3') + 1;
        // $month=$this->uri->segment('4');
        // $year=$this->uri->segment('5');
        $d=unixtojd(mktime(0,1,0,$month,$list_day ,$year));
        // print_r(cal_from_jd($d,CAL_GREGORIAN));
        $ddd=array(cal_from_jd($d,CAL_GREGORIAN));
        foreach($ddd as $dd){
            return $daystr=date('D',strtotime($dd['date']));
            // echo $daystr=date('D',strtotime($log_date));
            // if($daystr =="Sun"){
            // return 1;
            // }else{
            // return 0;    
            // }
            // echo $log_date;
        }

    
    }
    
    
    public function get_item_data($id,$table){
        $info=array();
        $this->db->select('*');
        $this->db->from($table);
        $this->db->where('id',$id);
        $info=$this->db->get()->result_array();
        return $info;        
    }
}
?>