<?php defined("BASEPATH")or exit("NO DIRECT ACCESS IS ALLOWED"); ?>
<?php

class TeacherModel extends CI_Model{
    protected $limit, $offset;
  public function __construct(){
    parent::__construct();
    //$this->db->simple_query('SET SESSION group_concat_max_len=100000');
	error_reporting(0);
  }

  /*public function user_profile($ts_id){

      $id          =    substr($ts_id, 16);
      $hashtag     =    substr($ts_id, 0,16);
      $query       =    $this->db->select(['first_name','last_name','email','category','info','profile_image'])->from('master_user')
      ->where('id',$id)->where('hashtag',$hashtag)->where('category','1')->get();
      return $query->row();
      //echo "<pre>";print_r($query->row());die;
      //echo $this->db->last_query();die;
  }*/
    public function user_profile($ts_id){

      $id          =    substr($ts_id, 16);
      $hashtag     =    substr($ts_id, 0,16);
      $query       =    $this->db->select(['first_name','last_name','email','category','info','profile_image'])->from('master_user')
      ->where('id',$id)->where('hashtag',$hashtag)->where('category','1')->get();
      return $query->row();
      //echo "<pre>";print_r($query->row());die;
      //echo $this->db->last_query();die;
    }


    /* Date: 21-06-18  */
    public function basic_information($userid){

    $query=$this->db->select(['master_user.*','mu_teacher_basic.upload_resume','mu_teacher_basic.screenshot_speed','mu_teacher_basic.dob','mu_teacher_basic.aadhar_id','mu_teacher_basic.pan_id',
    'mu_teacher_basic.zip_code','mu_teacher_basic.country_id','mu_teacher_basic.state_id','mu_teacher_basic.city_id',
    '(select name from countries where countries.id=mu_teacher_basic.country_id) as countries',
    '(select name from cities where cities.id=mu_teacher_basic.city_id) as cities',
    '(select name from states where states.id=mu_teacher_basic.state_id) as states'
    ])
    ->from('master_user')
    ->join('mu_teacher_basic','mu_teacher_basic.user_id=master_user.id')
    ->where('user_id',$userid)
    ->get();
    return $query->row();
    //echo "<pre>";print_r($query->row());die;
    //echo $this->db->last_query();die;
}

    /* Date: 21-06-18  */
  public function qualification_details($userid){
    $query=$this->db->select(['*'
    ])
    ->from('mu_teacher_qualfication')
    ->where('user_id',$userid)
    ->get();
    return $query->result();
        //echo "<pre>";print_r($query->row());die;
        //echo $this->db->last_query();die;
    }

    /* Date: 21-06-18  */
    public function preferred_classes($userid){

        $query=$this->db->select(['*'])
        ->from('mu_teacher_pf_class')
        ->where('user_id',$userid)
        ->get();
        return $query->result();

        }

    /* Date: 21-06-18  */
    public function bank_details($userid){

        $query=$this->db->select(['mu_teacher_bank_detail.bank_name','mu_teacher_bank_detail.branch_name',
		'mu_teacher_bank_detail.account_holder_name','mu_teacher_bank_detail.ifsc_code','mu_teacher_bank_detail.micr_code'
		])
		->from('mu_teacher_bank_detail')
        ->where('user_id',$userid)
		->get();
		//echo $this->db->last_query();die;
	   // $query=$this->db->select(['*'])->from('master_user')->where('category','1')->where('master_user.id',$list_id)->get();
		return $query->row();
    }

    /* Date: 21-06-18  */
    public function network_info($userid){

        $query=$this->db->select(['mu_teacher_extra_info.current_occupation','mu_teacher_extra_info.days_available',
		'mu_teacher_extra_info.hours_week_ends_available','mu_teacher_extra_info.available_timings','mu_teacher_extra_info.total_teaching_experience','mu_teacher_extra_info.type_of_connection',
		'mu_teacher_extra_info.down_internet_conn_speed','mu_teacher_extra_info.up_internet_conn_speed','mu_teacher_extra_info.association_with_gurukul','mu_teacher_extra_info.come_to_know_tog_status'
		])
		->from('mu_teacher_extra_info')
        ->where('user_id',$userid)

    	->limit($limit, $offset)
		->get();
		//echo $this->db->last_query();die;
	 	return $query->row();
    }

  public function find_course_key_id($course_id_tag){
      $query        =   $this->db->select(['id'])->from('v2_course_new')->where('course_id_tag',$course_id_tag)->get();
      $course_id    =   $query->row();
      return $course_id->id;
  }

  public function v2_faculty_list($userid){
      $query        =   $this->db->select(['v2_faculty.id'])->from('v2_faculty')->where('teacher_id',$userid)->get();
      $res          =   $query->result_array();
    //print_r($res);die;
	  if(count($res)>0){
          foreach($res as $bs){
              $z[] =   $bs['id'];
          }
          //print_r($z);die;
		  return $z;
	  }else{
		  return null;
	  }
  }


  public function teacher_crs_enrld_list($limit,$offset,$facultyid){
      $offset = ($offset-1)*$limit;
      $this->db->simple_query('SET sql_mode=(SELECT REPLACE(@@sql_mode,"ONLY_FULL_GROUP_BY",""))');
      $query  = $this->db->select(['v2_course_class_detail.id','course_id',
          '(select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date',
          '(select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date',
          '(select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag',
          '(select CONCAT(first_name, " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty',
          '(select category from category where category.id=v2_course_class_detail.category_id)as category_id',
          '(select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id',
          '(select class from class where class.id=v2_course_class_detail.class_id)as class_id','subject_code',
          'class_start_time','class_end_time','class_duration_min','class_extend_time_min','time_zone'])
          ->from('v2_course_class_detail')
          ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
          ->where_in('class_presenter',$facultyid)
          ->group_by('course_id')
          ->order_by("v2_course_class_detail.id","asc")->limit($limit, $offset)->get();
         // echo $this->db->last_query();die;
          return $query->result();
  }
  public function teacher_crs_enrld_list_num_row($facultyid){
      $this->db->simple_query('SET sql_mode=(SELECT REPLACE(@@sql_mode,"ONLY_FULL_GROUP_BY",""))');
      $query  = $this->db->select(['v2_course_class_detail.id','course_id',
          '(select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date',
          '(select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date',
          '(select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag',
          '(select CONCAT(first_name, " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty',
          '(select category from category where category.id=v2_course_class_detail.category_id)as category_id',
          '(select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id',
          '(select class from class where class.id=v2_course_class_detail.class_id)as class_id','subject_code',
          'class_start_time','class_end_time','class_duration_min','class_extend_time_min','time_zone'])
          ->from('v2_course_class_detail')
          ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
          ->where_in('class_presenter',$facultyid)
          ->group_by('course_id')
          ->order_by("v2_course_class_detail.id","asc")->get();
          //echo $this->db->last_query();die;
          return $query->num_rows();
  }
  public function teacher_crs_enrld_list_num_row_running($facultyid){
      $this->db->simple_query('SET sql_mode=(SELECT REPLACE(@@sql_mode,"ONLY_FULL_GROUP_BY",""))');
      $query  = $this->db->select(['v2_course_class_detail.id'])
          ->from('v2_course_class_detail')
          ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
          ->join('v2_course_new as v2','v2.id=v2_course_class_detail.course_id')
          ->where_in('class_presenter',$facultyid)
          ->where("DATE(v2.course_start_date)<=DATE(NOW())")
          ->where("DATE(v2.course_end_date)>=DATE(NOW())")
            ->where('v2_course_class_detail.method','create')
          ->group_by('course_id')
          ->order_by("v2_course_class_detail.id","asc")->get();
          //echo $this->db->last_query();die;
          return $query->num_rows();
  }
  public function teacher_crs_enrld_list_num_row_completed($facultyid){
      $this->db->simple_query('SET sql_mode=(SELECT REPLACE(@@sql_mode,"ONLY_FULL_GROUP_BY",""))');
      $query  = $this->db->select(['v2_course_class_detail.id'])
          ->from('v2_course_class_detail')
          ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
          ->join('v2_course_new as v2','v2.id=v2_course_class_detail.course_id')
          ->where_in('class_presenter',$facultyid)
          ->where("DATE(v2.course_end_date)<DATE(NOW())")
            ->where('v2_course_class_detail.method','create')
          ->group_by('course_id')
          ->order_by("v2_course_class_detail.id","asc")->get();
          //echo $this->db->last_query();die;
          return $query->num_rows();
  }

  public function teacher_crs_enrld_cl_list($limit,$offset,$facultyid,$courseid){
      $offset = ($offset-1)*$limit;
      $query  = $this->db->select(['v2_course_class_detail.id','course_id','class_tag_id','class_date','v2_course_class_detail.recording_url',
          '(select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date',
          '(select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date',
          '(select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag',
          'class_strength','recording_url','method',
          '(select CONCAT(first_name, " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty',
          '(select category from category where category.id=v2_course_class_detail.category_id)as category_id',
          '(select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id',
          '(select class from class where class.id=v2_course_class_detail.class_id)as class_id','subject_code',
          'class_start_time','class_end_time','class_duration_min','class_extend_time_min','time_zone','presenter_url'])
          ->from('v2_course_class_detail')
          ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
          ->where_in('class_presenter',$facultyid)
          ->where('v2_course_class_detail.course_id',$courseid)
            ->where('v2_course_class_detail.method','create')
          ->order_by("v2_course_class_detail.id","asc")->limit($limit, $offset)->get();
          // echo $this->db->last_query();die;
          return $query->result();
  }
  public function teacher_crs_enrld_cl_list_num_row($facultyid,$courseid){
      $query  = $this->db->select(['v2_course_class_detail.id','course_id','class_tag_id','class_date','v2_course_class_detail.recording_url',
          '(select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date',
          '(select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date',
          '(select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag',
          'class_strength','recording_url','method',
          '(select CONCAT(first_name, " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty',
          '(select category from category where category.id=v2_course_class_detail.category_id)as category_id',
          '(select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id',
          '(select class from class where class.id=v2_course_class_detail.class_id)as class_id','subject_code',
          'class_start_time','class_end_time','class_duration_min','class_extend_time_min','time_zone','presenter_url'])
          ->from('v2_course_class_detail')
          ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
          ->where_in('class_presenter',$facultyid)
          ->where('v2_course_class_detail.course_id',$courseid)
          ->where('v2_course_class_detail.method','create')
          ->order_by("v2_course_class_detail.id","asc")->get();
          //echo $this->db->last_query();die;
          return $query->num_rows();
  }

  public function subject_approved_list($limit,$offset,$userid){
      $offset = ($offset-1)*$limit;
      $query  = $this->db->select(['v2_faculty.*','master_user.first_name','master_user.last_name','category.category','category.category_code',
          'class.class','class.class_code','subject.subject','subject.subject_code'])
          ->from('v2_faculty')->join('master_user','v2_faculty.teacher_id   =   master_user.id')
          ->join('category','v2_faculty.category_id=category.id')
          ->join('class','v2_faculty.class_id=class.id')
          ->join('subject','v2_faculty.subject_id=subject.id')
          ->where('teacher_id',$userid)->limit($limit, $offset)->get();
          // echo $this->db->last_query();die;
          return $query->result();
  }
  public function subject_approved_list_num_row($userid){
      $query  = $this->db->select(['v2_faculty.*','master_user.first_name','master_user.last_name','category.category','category.category_code',
          'class.class','class.class_code','subject.subject','subject.subject_code'])
      ->from('v2_faculty')->join('master_user','v2_faculty.teacher_id   =   master_user.id')
      ->join('category','v2_faculty.category_id=category.id')
      ->join('class','v2_faculty.class_id=class.id')
      ->join('subject','v2_faculty.subject_id=subject.id')
      ->where('teacher_id',$userid)->get();
      // echo $this->db->last_query();die;
      return $query->num_rows();
  }


  public function recent_classes_15_days_list($limit,$offset,$facultyid){
    //  print_r($facultyid);die;
      $offset = ($offset-1)*$limit;
      $date  =   date("Y-m-d");
      foreach($facultyid as $fs){$fs1.="'".$fs."',";}
      $fs    =   rtrim($fs1,",");
        $array  = array('create','modify');
	  if(!empty($facultyid)){
      $this->db->simple_query("SET time_zone='UTC+05:30'");
      $sql="select v2_course_class_detail.id,course_id,class_tag_id,class_date,v2_course_class_detail.recording_url,
          (select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date,
          (select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date,
          (select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag,
          class_strength,recording_url,method,
          (select CONCAT(first_name, ' ', last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty,
          (select category from category where category.id=v2_course_class_detail.category_id)as category_id,
          (select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id,
          (select class from class where class.id=v2_course_class_detail.class_id)as class_id,subject_code,
          class_start_time,class_end_time,class_duration_min,class_extend_time_min,time_zone,presenter_url from v2_course_class_detail
          join v2_course_presenter_data on v2_course_presenter_data.class_id=v2_course_class_detail.id
          where DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) AND class_date  < NOW() + INTERVAL 15 DAY
          and class_presenter in($fs) and v2_course_class_detail.method in('create','modify')
          order by DATE(class_date),TIME(class_start_time) asc  LIMIT $offset,$limit
        ";

         $res  = $this->db->query($sql)->result();
       // echo $this->db->last_query();die;
         //where (class_date) >= NOW() - INTERVAL 10 DAY AND class_date  < NOW() + INTERVAL 10 DAY
         //DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) and DATE_ADD(NOW(), INTERVAL +1 MONTH)
          return $res;
	  }
	  else{
		  return null;
	  }
  }
  public function recent_classes_15_days_num_row($facultyid){
      $date  =   date("Y-m-d");
      foreach($facultyid as $fs){$fs1.="'".$fs."',";}
      $fs    =   rtrim($fs1,",");
	  if(!empty($facultyid)){
      $this->db->simple_query("SET time_zone='UTC+05:30'");
      $sql="select v2_course_class_detail.id,course_id,class_tag_id,class_date,v2_course_class_detail.recording_url,
          (select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date,
          (select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date,
          (select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag,
          class_strength,recording_url,method,
          (select CONCAT(first_name, ' ', last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty,
          (select category from category where category.id=v2_course_class_detail.category_id)as category_id,
          (select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id,
          (select class from class where class.id=v2_course_class_detail.class_id)as class_id,subject_code,
          class_start_time,class_end_time,class_duration_min,class_extend_time_min,time_zone,presenter_url from v2_course_class_detail
          join v2_course_presenter_data on v2_course_presenter_data.class_id=v2_course_class_detail.id
          where DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) AND class_date  < NOW() + INTERVAL 15 DAY
          and class_presenter in($fs) and v2_course_class_detail.method in('create','modify')
          order by DATE(class_date),TIME(class_start_time) asc
        ";
          //echo $this->db->last_query();die;
      $res  = $this->db->query($sql)->num_rows();
      //echo $this->db->last_query();die;
      return $res;
	  }
	  else{
		  return 0;
	  }
  }



  public function recent_classes_past_days_list($limit,$offset,$facultyid){
    //  print_r($facultyid);die;
      $offset = ($offset-1)*$limit;
      $date  =   date("Y-m-d");
      foreach($facultyid as $fs){$fs1.="'".$fs."',";}
      $fs    =   rtrim($fs1,",");
    if(!empty($facultyid)){
      $this->db->simple_query("SET time_zone='UTC+05:30'");
      $sql="select v2_course_class_detail.id,course_id,class_tag_id,class_date,v2_course_class_detail.recording_url,
          (select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date,
          (select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date,
          (select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag,
          class_strength,recording_url,method,
          (select CONCAT(first_name, ' ', last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty,
          (select category from category where category.id=v2_course_class_detail.category_id)as category_id,
          (select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id,
          (select class from class where class.id=v2_course_class_detail.class_id)as class_id,subject_code,
          class_start_time,class_end_time,class_duration_min,class_extend_time_min,time_zone,presenter_url from v2_course_class_detail
          join v2_course_presenter_data on v2_course_presenter_data.class_id=v2_course_class_detail.id
         where  TIMESTAMP(class_date,class_start_time) <= NOW()  and class_presenter in($fs)
         and v2_course_class_detail.method in('create','modify') order by timestamp(class_date,class_start_time) desc  LIMIT $offset,$limit
        ";

         $res  = $this->db->query($sql)->result();
       // echo $this->db->last_query();die;
         //where (class_date) >= NOW() - INTERVAL 10 DAY AND class_date  < NOW() + INTERVAL 10 DAY
         //DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) and DATE_ADD(NOW(), INTERVAL +1 MONTH)
          return $res;
    }
    else{
      return null;
    }
  }
  public function recent_classes_past_days_num_row($facultyid){
      $date  =   date("Y-m-d");
      foreach($facultyid as $fs){$fs1.="'".$fs."',";}
      $fs    =   rtrim($fs1,",");
    if(!empty($facultyid)){
      $this->db->simple_query("SET time_zone='UTC+05:30'");
      $sql="select v2_course_class_detail.id,course_id,class_tag_id,class_date,v2_course_class_detail.recording_url,
          (select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date,
          (select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date,
          (select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag,
          class_strength,recording_url,method,
          (select CONCAT(first_name, ' ', last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty,
          (select category from category where category.id=v2_course_class_detail.category_id)as category_id,
          (select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id,
          (select class from class where class.id=v2_course_class_detail.class_id)as class_id,subject_code,
          class_start_time,class_end_time,class_duration_min,class_extend_time_min,time_zone,presenter_url from v2_course_class_detail
          join v2_course_presenter_data on v2_course_presenter_data.class_id=v2_course_class_detail.id
          where  TIMESTAMP(class_date,class_start_time) <= NOW()  and class_presenter in($fs)
          and v2_course_class_detail.method in('create','modify') order by DATE(class_date),TIME(class_start_time) desc
        ";
          //echo $this->db->last_query();die;
      $res  = $this->db->query($sql)->num_rows();
      //echo $this->db->last_query();die;
      return $res;
    }
    else{
      return 0;
    }
  }


  public function recent_classes_15_days_list_api($facultyid){
   //  print_r($facultyid);die;

      $date  =   date("Y-m-d");
      foreach($facultyid as $fs){$fs1.="'".$fs."',";}
      $fs    =   rtrim($fs1,",");
	  if(!empty($facultyid)){
      $this->db->simple_query("SET time_zone='UTC+05:30'");
      $sql="select v2_course_class_detail.id,course_id,class_tag_id,class_date,v2_course_class_detail.recording_url,
          (select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date,
          (select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date,
          (select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag,
          class_strength,recording_url,method,
          (select CONCAT(first_name, ' ', last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty,
          (select category from category where category.id=v2_course_class_detail.category_id)as category_id,
          (select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id,
          (select class from class where class.id=v2_course_class_detail.class_id)as class_id,subject_code,
          class_start_time,class_end_time,class_duration_min,class_extend_time_min,time_zone,presenter_url from v2_course_class_detail
          join v2_course_presenter_data on v2_course_presenter_data.class_id=v2_course_class_detail.id
          where DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) AND class_date  < NOW() + INTERVAL 15 DAY
          and class_presenter in($fs) and v2_course_class_detail.method in('create','modify')
          order by DATE(class_date),TIME(class_start_time) asc
        ";

         $res  = $this->db->query($sql)->result();
       // echo $this->db->last_query();die;
         //where (class_date) >= NOW() - INTERVAL 10 DAY AND class_date  < NOW() + INTERVAL 10 DAY
         //DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) and DATE_ADD(NOW(), INTERVAL +1 MONTH)
          return $res;
	  }
	  else{
		  return null;
	  }
  }
  /*
  public function recent_classes_15_days_list($limit,$offset,$facultyid){
      $offset = ($offset-1)*$limit;
      $date  =   date("Y-m-d");
      foreach($facultyid as $fs){$fs1.="'".$fs."',";}
      $fs    =   rtrim($fs1,",");
      $this->db->simple_query("SET time_zone='UTC+05:30'");
      $sql="select v2_course_class_detail.id,course_id,class_tag_id,class_date,
          (select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date,
          (select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date,
          (select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag,
          class_strength,recording_url,method,
          (select CONCAT(first_name, ' ', last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty,
          (select category from category where category.id=v2_course_class_detail.category_id)as category_id,
          (select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id,
          (select class from class where class.id=v2_course_class_detail.class_id)as class_id,subject_code,
          class_start_time,class_end_time,class_duration_min,class_extend_time_min,time_zone,presenter_url from v2_course_class_detail
          join v2_course_presenter_data on v2_course_presenter_data.class_id=v2_course_class_detail.id
          where DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) AND class_date  < NOW() + INTERVAL 15 DAY
          and class_presenter in($fs)
          order by DATE(class_date),TIME(class_start_time) asc  LIMIT $offset,$limit
        ";
         $res  = $this->db->query($sql)->result();
       //  echo $this->db->last_query();die;
         //where (class_date) >= NOW() - INTERVAL 10 DAY AND class_date  < NOW() + INTERVAL 10 DAY
         //DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) and DATE_ADD(NOW(), INTERVAL +1 MONTH)
          return $res;
  }
  public function recent_classes_15_days_num_row($facultyid){
      $date  =   date("Y-m-d");
      foreach($facultyid as $fs){$fs1.="'".$fs."',";}
      $fs    =   rtrim($fs1,",");
      $this->db->simple_query("SET time_zone='UTC+05:30'");
      $sql="select v2_course_class_detail.id,course_id,class_tag_id,class_date,
          (select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date,
          (select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date,
          (select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag,
          class_strength,recording_url,method,
          (select CONCAT(first_name, ' ', last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty,
          (select category from category where category.id=v2_course_class_detail.category_id)as category_id,
          (select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id,
          (select class from class where class.id=v2_course_class_detail.class_id)as class_id,subject_code,
          class_start_time,class_end_time,class_duration_min,class_extend_time_min,time_zone,presenter_url from v2_course_class_detail
          join v2_course_presenter_data on v2_course_presenter_data.class_id=v2_course_class_detail.id
          where DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) AND class_date  < NOW() + INTERVAL 15 DAY
          and class_presenter in($fs)
          order by DATE(class_date),TIME(class_start_time) asc
        ";
          //echo $this->db->last_query();die;
      $res  = $this->db->query($sql)->num_rows();
      //echo $this->db->last_query();die;
      return $res;
  }*/
  public function total_session($facultyid){
      /* $date  =   date("Y-m-d"); foreach($facultyid as $fs){$fs1.="'".$fs."',";}$fs    =   rtrim($fs1,",");
      $this->db->simple_query("SET time_zone='UTC+05:30'");
      $sql="select v2_course_class_detail.id from v2_course_class_detail join v2_course_presenter_data on v2_course_presenter_data.class_id=v2_course_class_detail.id
          where class_presenter in($fs)";$res  = $this->db->query($sql)->num_rows();return $res; */
      $query  = $this->db->select(['pt.id'])
      ->from('v2_course_presenter_data as pt')
      ->join('v2_course_class_detail as clsd','clsd.id=pt.class_id')
      ->where_in('pt.class_presenter',$facultyid)
      ->get();
      ///echo $this->db->last_query();die;
      return $query->num_rows();
  }
  public function current_class_counter($facultyid){
      $query  = $this->db->select(['clsd.class_date','clsd.class_start_time','clsd.class_end_time','st.presenter_url'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("DATE(clsd.class_date)=CURDATE()")
      ->where("TIME(clsd.class_end_time)>=CURRENT_TIME()")
      ->where("TIME(clsd.class_start_time)<=CURRENT_TIME()")
      ->order_by('clsd.class_date','asc')
      ->get();
     // echo $this->db->last_query();die;
      return $query->row();
  }
  public function total_class_today_rows($facultyid){
      $query  = $this->db->select(['clsd.id','clsd.class_date','clsd.class_start_time','clsd.class_end_time','st.presenter_url'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("DATE(clsd.class_date)=CURDATE()")
      ->where("TIME(clsd.class_end_time)>=CURRENT_TIME()")
      ->order_by('TIME(clsd.class_start_time)','asc')
      ->get();
     // echo $this->db->last_query();die;
      return $query->result();
  }
  public function current_class_rows($facultyid){
      $query  = $this->db->select(['clsd.id','clsd.class_date','clsd.class_start_time','clsd.class_end_time','st.presenter_url'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("DATE(clsd.class_date)=CURDATE()")
      ->where("TIME(clsd.class_end_time)>=CURRENT_TIME()")
      ->order_by('TIME(clsd.class_start_time)','asc')
      ->limit('1')
      ->get();
     //echo $this->db->last_query();die;
      return $query->row();
  }
  public function next_class_rows($facultyid){
      $query  = $this->db->select(['clsd.id','clsd.class_date','clsd.class_start_time','clsd.class_end_time','st.presenter_url'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("DATE(clsd.class_date)=CURDATE()")
      ->where("TIME(clsd.class_start_time)>=CURRENT_TIME()")
      ->order_by('TIME(clsd.class_start_time)','asc')
      ->limit('1')
      ->get();
      //echo $this->db->last_query();die;
      return $query->row();
  }
  public function total_class_today($facultyid){
      $query  = $this->db->select(['st.id'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("DATE(clsd.class_date)=CURDATE()")
      ->order_by('clsd.class_date','asc')
      ->get();
      ///echo $this->db->last_query();die;
      return $query->num_rows();
  }
  public function total_class_today_remaining($facultyid){
      $query  = $this->db->select(['st.id'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("TIME(clsd.class_end_time)>CURRENT_TIME()")
      ->where("DATE(clsd.class_date)=CURDATE()")
      ->order_by('clsd.class_date','asc')
      ->get();
      ///echo $this->db->last_query();die;
      return $query->num_rows();
  }
  public function total_class_today_completed($facultyid){
      $query  = $this->db->select(['st.id'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("TIME(clsd.class_end_time)<CURRENT_TIME()")
      ->where("DATE(clsd.class_date)=CURDATE()")
      ->order_by('clsd.class_date','asc')
      ->get();
      ///echo $this->db->last_query();die;
      return $query->num_rows();
  }

  public function total_class_this_week($facultyid){
      $query  = $this->db->select(['st.id'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("WEEKOFYEAR(clsd.class_date)= WEEKOFYEAR(NOW())")
      ->order_by('clsd.class_date','asc')
      ->get();
      ///echo $this->db->last_query();die;
      return $query->num_rows();
  }
  public function total_class_this_week_completed($facultyid){
      $query  = $this->db->select(['st.id'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("WEEKOFYEAR(clsd.class_date)= WEEKOFYEAR(NOW())")
      ->where("TIME(clsd.class_end_time)<NOW()")
      ->where("DATE(clsd.class_date)<=CURDATE()")
      ->order_by('clsd.class_date','asc')
      ->get();
      ///echo $this->db->last_query();die;
      return $query->num_rows();
  }
  public function total_class_this_week_remaining($facultyid){
      $query  = $this->db->select(['st.id'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("WEEKOFYEAR(clsd.class_date)= WEEKOFYEAR(NOW())")
      ->where("TIME(clsd.class_start_time)>NOW()")
      ->where("DATE(clsd.class_date)>=CURDATE()")
      ->order_by('clsd.class_date','asc')
      ->get();
      ///echo $this->db->last_query();die;
      return $query->num_rows();
  }
  public function total_class_next_week($facultyid){
      $query  = $this->db->select(['st.id'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("WEEKOFYEAR(clsd.class_date)= WEEKOFYEAR(NOW())+1")
      ->order_by('clsd.class_date','asc')
      ->get();
      ///echo $this->db->last_query();die;
      return $query->num_rows();
  }


  public function total_class_this_month($facultyid){
      $query  = $this->db->select(['st.id'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("MONTH(clsd.class_date)= MONTH(NOW())")
      ->order_by('clsd.class_date','asc')
      ->get();
      ///echo $this->db->last_query();die;
      return $query->num_rows();
  }
  public function total_class_this_month_completed($facultyid){
      $query  = $this->db->select(['st.id'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("MONTH(clsd.class_date)= MONTH(NOW())")
      ->where("DATE(clsd.class_date)<CURDATE()")
      ->order_by('clsd.class_date','asc')
      ->get();
      ///echo $this->db->last_query();die;
      return $query->num_rows();
  }
  public function total_class_this_month_remaining($facultyid){
      $query  = $this->db->select(['st.id'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("MONTH(clsd.class_date)= MONTH(NOW())")
      ->where("DATE(clsd.class_date)>=CURDATE()")
      ->order_by('clsd.class_date','asc')
      ->get();
      ///echo $this->db->last_query();die;
      return $query->num_rows();
  }

  public function total_class_next_month($facultyid){
      $query  = $this->db->select(['st.id'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("MONTH(clsd.class_date)= MONTH(NOW())+1")
      ->order_by('clsd.class_date','asc')
      ->get();
      ///echo $this->db->last_query();die;
      return $query->num_rows();
  }
  public function total_class_this_year($facultyid){
      $query  = $this->db->select(['st.id'])
      ->from('v2_course_presenter_data as st')
      ->join('v2_course_class_detail as clsd','clsd.id=st.class_id')
      ->where_in('st.class_presenter',$facultyid)
      ->where("YEAR(clsd.class_date)= YEAR(NOW())")
      ->order_by('clsd.class_date','asc')
      ->get();
      ///echo $this->db->last_query();die;
      return $query->num_rows();
  }



  ///////////////////////////////
  public function earnings($limit,$offset,$facultyid){
      $offset = ($offset-1)*$limit;
      foreach($facultyid as $fs){$fs1.="'".$fs."',";}
      $fs    =   rtrim($fs1,",");
      $this->db->simple_query("SET time_zone='UTC+05:30'");
      $query  = $this->db->select(['course_id','class_date',
          '(select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date',
          '(select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date',
          '(select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag',

          '(select CONCAT(first_name, " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty',
          '(select category from category where category.id=v2_course_class_detail.category_id)as category_id',
          '(select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id',
          '(select class from class where class.id=v2_course_class_detail.class_id)as class_id','subject_code',
          'class_start_time','class_end_time','class_duration_min','class_extend_time_min','time_zone','sum(per_class_earning)as total_earn'])
          ->from('v2_course_class_detail')
          ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
          ->where_in('class_presenter',$facultyid)
          ->group_by('course_id')
          ->order_by("v2_course_class_detail.id","asc")->limit($limit, $offset)->get();
         // echo $this->db->last_query();die;
          return $query->result();
     //$res  = $this->db->query($sql)->result();
     // echo $this->db->last_query();die;
      //where DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) AND class_date  < NOW() + INTERVAL 15 DAY
      //where (class_date) >= NOW() - INTERVAL 10 DAY AND class_date  < NOW() + INTERVAL 10 DAY
      //DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) and DATE_ADD(NOW(), INTERVAL +1 MONTH)
      //return $res;
  }
  public function earnings_num_row($facultyid){

      foreach($facultyid as $fs){$fs1.="'".$fs."',";}
      $fs    =   rtrim($fs1,",");
      $this->db->simple_query("SET time_zone='UTC+05:30'");
      $query  = $this->db->select(['course_id','class_date',
      '(select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date',
      '(select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date',
      '(select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag',

      '(select CONCAT(first_name, " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty',
      '(select category from category where category.id=v2_course_class_detail.category_id)as category_id',
      '(select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id',
      '(select class from class where class.id=v2_course_class_detail.class_id)as class_id','subject_code',
      'class_start_time','class_end_time','class_duration_min','class_extend_time_min','time_zone','sum(per_class_earning)as total_earn'])
      ->from('v2_course_class_detail')
      ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
      ->where_in('class_presenter',$facultyid)
      ->group_by('course_id')
      ->order_by("v2_course_class_detail.id","asc")->get();
          // echo $this->db->last_query();die;

      $res  = $query->num_rows();
      return $res;
  }





  public function earnings_list($limit,$offset,$courseid,$facultyid){
    $offset = ($offset-1)*$limit;
      foreach($facultyid as $fs){$fs1.="'".$fs."',";}
      $fs    =   rtrim($fs1,",");
      $this->db->simple_query("SET time_zone='UTC+05:30'");
$this->db->simple_query('SET sql_mode=(SELECT REPLACE(@@sql_mode,"ONLY_FULL_GROUP_BY","STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"))');
      $query  = $this->db->select(['course_id','class_date',
          '(select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date',
          '(select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date',
          '(select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag',
          '(select CONCAT(first_name, " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty',
          '(select category from category where category.id=v2_course_class_detail.category_id)as category_id',
          '(select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id',
          '(select class from class where class.id=v2_course_class_detail.class_id)as class_id','subject_code',
          'class_start_time','class_end_time','class_duration_min','class_extend_time_min','time_zone','v2_course_presenter_data.per_class_earning','sum(v2_course_presenter_data.per_class_earning)as total_earning'  ])
          ->from('v2_course_class_detail')
          ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
          ->where_in('class_presenter',$facultyid)
          ->where('v2_course_class_detail.course_id',$courseid)
          ->order_by("v2_course_class_detail.id","asc")->limit($limit, $offset)->get();
          //echo $this->db->last_query();die;
          return $query->result();

}
public function earnings_list_num_row($courseid,$facultyid){

     $this->db->simple_query("SET time_zone='UTC+05:30'");
$this->db->simple_query('SET sql_mode=(SELECT REPLACE(@@sql_mode,"ONLY_FULL_GROUP_BY","STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"))');
      $query  = $this->db->select(['course_id','class_date',
          '(select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date',
          '(select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date',
          '(select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag',
          '(select CONCAT(first_name, " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty',
          '(select category from category where category.id=v2_course_class_detail.category_id)as category_id',
          '(select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id',
          '(select class from class where class.id=v2_course_class_detail.class_id)as class_id','subject_code',
          'class_start_time','class_end_time','class_duration_min','class_extend_time_min','time_zone','v2_course_presenter_data.per_class_earning','sum(v2_course_presenter_data.per_class_earning)as total_earning'  ])
          ->from('v2_course_class_detail')
          ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
          ->where_in('class_presenter',$facultyid)
          ->where('v2_course_class_detail.course_id',$courseid)
          ->order_by("v2_course_class_detail.id","asc")->limit($limit, $offset)->get();

      $res  = $query->num_rows();
      return $res;
}



  public function class_scheduled_list($user_id){
      $query  = $this->db->select(['teacher_course_enrolled.course_id','teacher_course_enrolled.user_id',
          'teacher_course_enrolled.course_time', 'teacher_course_enrolled.course_end_time',
          'teacher_course_enrolled.course_duration', 'teacher_course_enrolled.course_running_hours',
          'class_mgmt.class_date','class_mgmt.class_id','class_mgmt.info','class_mgmt.presenter_url',
          '(select course.student_count from course where class_mgmt.course_id=course.id)as student_count',
          '(select subject from subject where subject.id=(select subject_id from course where course.id=class_mgmt.course_id))as subject',
          '(select CONCAT(first_name, " ", last_name) from master_user where master_user.id=(select user_id from teacher_course_enrolled where teacher_course_enrolled.course_id=class_mgmt.course_id))as teacher',
          '(select class from class join subject on subject.class_id=class.id where subject.id=(select subject_id from course where course.id=class_mgmt.course_id))as class'
      ])
      ->from('class_mgmt')->join('teacher_course_enrolled','class_mgmt.course_id=teacher_course_enrolled.course_id')->where('user_id',$user_id)->order_by('class_mgmt.id','desc')->get();

      return $query->result();
  }

  public function class_scheduled_list_num_rows($user_id){
      $query  = $this->db->select(['teacher_course_enrolled.course_id','teacher_course_enrolled.user_id',
          'teacher_course_enrolled.course_time', 'teacher_course_enrolled.course_end_time',
          'teacher_course_enrolled.course_duration', 'teacher_course_enrolled.course_running_hours',
          'class_mgmt.class_date','class_mgmt.class_id','class_mgmt.info',
          '(select subject from subject where subject.id=(select subject_id from course where course.id=class_mgmt.course_id))as subject',
          '(select CONCAT(first_name, " ", last_name) from master_user where master_user.id=(select user_id from teacher_course_enrolled where teacher_course_enrolled.course_id=class_mgmt.course_id))as teacher',
          '(select class from class join subject on subject.class_id=class.id where subject.id=(select subject_id from course where course.id=class_mgmt.course_id))as class'
      ])
      ->from('class_mgmt')->join('teacher_course_enrolled','class_mgmt.course_id=teacher_course_enrolled.course_id')->where('user_id',$user_id)->get();
      //echo $this->db->last_query();die;
      return $query->num_rows();
  }

  public function complete_profile_teacher($id,$data_remarks){

		$this->db->where('id',$id);
		$this->db->set('info', $data_remarks);
    $this->db->update('master_user');
		return true;
	}


  public function update_profile_pic($id,$path){
  //  echo $id.$path;die;
      $this->db->set('profile_image', $path);
      $this->db->where('id', $id);
      $this->db->update('master_user');
      return true;
  }

  public function activity_list($limit, $offset){

		$offset = ($offset-1)*$limit;
		$query=$this->db->select(['*'])->from('activity')
		//->order_by("activity", "asc")
    	->limit($limit, $offset)
		->get();
		//echo $this->db->last_query();die;
		return $query->result();
	}

	public function num_rows(){

		$user_id = $this->session->userdata('user_id');
		$query=$this->db->select(['*'])->from('activity')->get();
		return $query->num_rows();
	}
	public function insert_activity($data_activity){

		$this->db->insert('activity', $data_activity);
		$data_activity['id'] = $this->db->insert_id();
    	return $data_activity['id'];
	}



	public function view_activity($list_id){

		$query=$this->db->select(['*'])->from('activity')->where('id',$list_id)->get();
		return $query->row();
	}
	public function count_activity($activity){

		$query=$this->db->select(['*'])->from('activity')->where('activity',$activity)->get();
		return $query->num_rows();
	}

	public function delete_activity($list_id){

		$this->db->where('id', $list_id);
		$this->db->delete('activity');
		}

	public function chapter_lister(){
		$query=$this->db->select(['chapter.id','chapter.subject_id','chapter.chapter'])->from('chapter')
		//->join("topic", "topic.chapter_id=chapter.id",'left')
		->limit($limit, $offset)
		->get();//echo $this->db->last_query();die;
		return $query->result();
	}
	public function chapter_num_rows(){
		$query=$this->db->select(['*'])->from('chapter')->get();
		return $query->num_rows();
	}
	public function course_num_rows(){
		$query=$this->db->select(['*'])->from('course')->get();
		return $query->num_rows();
	}
	public function course_list($limit, $offset){
		$offset = ($offset-1)*$limit;
		$query=$this->db->select(['course.id','course.course_hash',
		'(select subject from subject where subject.id=course.subject_id )as subject_id',
		'(select class.class from subject join class on class.id=subject.class_id where subject.id=course.subject_id )as class_id',
		'course.course_time','course_from','course_to','course_duration','extend_duration','course.student_count'])
		->from('course')//->order_by("activity", "asc")
    	->limit($limit, $offset)
		->get();//echo $this->db->last_query();die;
		return $query->result();
	}

	public function subject_code_lists(){
    $query		=	  $this->db->select(['subject.id','subject.subject','subject.subject_code','class.class_code',
    'category.category_code'])
    ->from('subject')
    ->join('category','category.id=subject.category_id')
    ->join('class','class.id=subject.class_id')
    ->order_by("subject.id", "asc")->get();
	//echo "<pre>"; print_r($query->result_array());die;
    $return 	= 	array();
    if($query->num_rows() > 0) {
        $return[''] = ('Select subject code');
        foreach($query->result_array() as $row) {
            $return[$row['id']] = strtoupper($row['category_code'].$row['class_code'].$row['subject_code']);
        }
    }
    return $return;
	}


	function getcategory(){
    $response = array();
    $this->db->select('*')->where("id", '1');
    $q = $this->db->get('category');
   //echo $this->db->last_query();die;
    $response = $q->result_array();
    return $response;
	}


	function getclass(){
		$response = array();
		$this->db->select('*');
		$q = $this->db->get('class');
		$response = $q->result_array();
		return $response;
	}
	function get_category_class($postData){
		$response = array();
		$this->db->select('*');
		$this->db->where('category_id', $postData['category']);
		$q = $this->db->get('class');
		$response = $q->result_array();
		return $response;
	}
	function get_class_subject($postData){
		$response = array();
		$this->db->select('*');
		$this->db->where('class_id', $postData['classes']);
		$q = $this->db->get('subject');
		$response = $q->result_array();
		return $response;
	}
	// Get City departments
	function get_subject_chapter($postData){
		$response = array();
		$this->db->select('*');
		$this->db->where('subject_id', $postData['subject']);
		$q = $this->db->get('chapter');
		$response = $q->result_array();
		return $response;
	}
	function get_chapter_topic($postData){
		$response = array();
		$this->db->select('*');
		$this->db->where('chapter_id', $postData['chapter']);
		$q = $this->db->get('topic');
		$response = $q->result_array();
		return $response;
	}

	 function get_class_subject_course_maded_list($postData){
		  // echo "<pre>";print_r($postData['subject']);die;
		  $response     = array();
		  $query  = $this->db->select(['v2_course_new.*','category.category','class.class','subject.subject'])
			  ->from('v2_course_new')
			  ->join('category','v2_course_new.category_id=category.id')
			  ->join('class','v2_course_new.class_id=class.id')
			  ->join('subject','v2_course_new.subject_id=subject.id')
			  ->where('subject_id', $postData['subject'])->get();
			  // $this->db->select('*');
			  // $this->db->where('subject_id', $postData['subject']);
			  //$q            = $this->db->get('v2_faculty');
			  $response     = $query->result_array();
			  return $response;
	  }


	 public function subject_approved_list_search($teacherid,$data_taskpo){

	      $query  = $this->db->select(['v2_faculty.*','category.category','category.category_code',
          'class.class','class.class_code','subject.subject','subject.subject_code'])
		  ->join('category','v2_faculty.category_id=category.id')
          ->join('class','v2_faculty.class_id=class.id')
          ->join('subject','v2_faculty.subject_id=subject.id')
          ->from('v2_faculty')->where('v2_faculty.teacher_id',$teacherid);

        if(!empty($data_taskpo['category'])){
            $this->db->where('v2_faculty.category_id',$data_taskpo['category']);
        }
        if(!empty($data_taskpo['class'])){
            $this->db->where('v2_faculty.class_id', $data_taskpo['class']);
        }
        if(!empty($data_taskpo['subject'])){
            $this->db->where('v2_faculty.subject_id', $data_taskpo['subject']);
        }
        $query=$this->db->get();
         //echo $this->db->last_query();die;
        if($query->num_rows()>0){
            return $query->result();
        }
        else{
            return $query->result();
        }
    }

    public function subject_approved_list_search2($teacherid,$subject_code1){
          $query  = $this->db->select(['v2_faculty.*','category.category','category.category_code',
          'class.class','class.class_code','subject.subject','subject.subject_code'])
		  ->join('category','v2_faculty.category_id=category.id')
          ->join('class','v2_faculty.class_id=class.id')
          ->join('subject','v2_faculty.subject_id=subject.id')
          ->from('v2_faculty')->where('v2_faculty.subject_id',$subject_code1)->where('v2_faculty.teacher_id',$teacherid);
        //echo "<pre>"; print_r($query->result_array());die;
			$query=$this->db->get();
		//echo $this->db->last_query();die;
	        if($query->num_rows()>0){
                return $query->result();
            }
            else{
	            return $query->result();
	        }

    }

	public function teacher_course_enrolled_list_search($facultyid,$data_taskpo){

	       $query  = $this->db->select(['v2_course_new.id','v2_course_new.course_id_tag','v2_course_new.course_start_date','v2_course_new.course_end_date',
		   'v2_course_new.class_start_time','v2_course_new.class_end_time','v2_course_new.class_duration_min',
		   'v2_course_new.class_extend_time_min','v2_course_new.per_class_amount',
		   'v2_course_new.class_count','v2_course_new.faculty_code','v2_course_new.course_week_days','v2_course_new.time_zone',
		   'v2_course_new.course_duration','v2_course_new.course_furthur_extended',
		   'category.category','category.category_code',
          'class.class','class.class_code','subject.subject','CONCAT(category.category_code,class.class_code,subject.subject_code) AS subject_code',
		  '(select category from category where category.id=v2_course_new.category_id)as category_id',
          '(select subject from subject where subject.id=v2_course_new.subject_id)as subject_id',
          '(select class from class where class.id=v2_course_new.class_id)as class_id',

		  '(select CONCAT(first_name, " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_new.faculty_code=v2_faculty.id) as faculty'
		  ])
		  ->join('category','v2_course_new.category_id=category.id')
          ->join('class','v2_course_new.class_id=class.id')
          ->join('subject','v2_course_new.subject_id=subject.id')
          ->from('v2_course_new')->where_in('v2_course_new.faculty_code',$facultyid);

        if(!empty($data_taskpo['category'])){
            $this->db->where('v2_course_new.category_id',$data_taskpo['category']);
        }
        if(!empty($data_taskpo['class'])){
            $this->db->where('v2_course_new.class_id', $data_taskpo['class']);
        }
        if(!empty($data_taskpo['subject'])){
            $this->db->where('v2_course_new.subject_id', $data_taskpo['subject']);
        }
        $query=$this->db->get();
		//echo $this->db->last_query();die;
        if($query->num_rows()>0){
            return $query->result();
        }
        else{
            return $query->result();
        }
    }

    public function teacher_course_enrolled_list_search2($facultyid,$subject_code1){
          $query  = $this->db->select(['v2_course_new.id','v2_course_new.course_id_tag','v2_course_new.course_start_date','v2_course_new.course_end_date',
		   'v2_course_new.class_start_time','v2_course_new.class_end_time','v2_course_new.class_duration_min',
		   'v2_course_new.class_extend_time_min','v2_course_new.per_class_amount',
		   'v2_course_new.class_count','v2_course_new.faculty_code','v2_course_new.course_week_days','v2_course_new.time_zone',
		   'v2_course_new.course_duration','v2_course_new.course_furthur_extended',
		   'category.category','category.category_code','CONCAT(category.category_code,class.class_code,subject.subject_code) AS subject_code',
          'class.class','class.class_code','subject.subject',
		  '(select category from category where category.id=v2_course_new.category_id)as category_id',
          '(select subject from subject where subject.id=v2_course_new.subject_id)as subject_id',
          '(select class from class where class.id=v2_course_new.class_id)as class_id',
		   '(select CONCAT(first_name,  " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_new.faculty_code=v2_faculty.id) as faculty'

           ])

		  ->join('category','v2_course_new.category_id=category.id')
          ->join('class','v2_course_new.class_id=class.id')
          ->join('subject','v2_course_new.subject_id=subject.id')

          ->from('v2_course_new')->where('v2_course_new.subject_id',$subject_code1)->where_in('v2_course_new.faculty_code',$facultyid);
        //echo "<pre>"; print_r($query->result_array());die;
        $query=$this->db->get();
	   //echo $this->db->last_query();die;
	        if($query->num_rows()>0){
                return $query->result();
            }
            else{
	            return $query->result();
	        }

    }

	public function recent_classes_15_days_search($facultyid, $data_taskpo){
			  $offset = ($offset-1)*$limit;
      $date  =   date("Y-m-d");
      foreach($facultyid as $fs){$fs1.="'".$fs."',";}
      $fs    =   rtrim($fs1,",");
	  if(!empty($facultyid)){
      $this->db->simple_query("SET time_zone='UTC+05:30'");
	      $query="select v2_course_class_detail.id,course_id,class_tag_id,class_date,
          (select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date,
          (select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date,
          (select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag,
          class_strength,recording_url,method,
          (select CONCAT(first_name, ' ', last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty,
          (select category from category where category.id=v2_course_class_detail.category_id)as category_id,
          (select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id,
          (select class from class where class.id=v2_course_class_detail.class_id)as class_id,subject_code,
          class_start_time,class_end_time,class_duration_min,class_extend_time_min,time_zone,presenter_url from v2_course_class_detail
          join v2_course_presenter_data on v2_course_presenter_data.class_id=v2_course_class_detail.id
          where DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) AND class_date  < NOW() + INTERVAL 15 DAY
          and class_presenter in($fs)
          order by DATE(class_date),TIME(class_start_time) asc  LIMIT $offset,$limit
        ";

        if(!empty($data_taskpo['category'])){
            $this->db->where('v2_course_class_detail.category_id',$data_taskpo['category']);
        }
        if(!empty($data_taskpo['class'])){
            $this->db->where('v2_course_class_detail.class_id', $data_taskpo['class']);
        }
        if(!empty($data_taskpo['subject'])){
            $this->db->where('v2_course_class_detail.subject_id', $data_taskpo['subject']);
        }
		if(!empty($data_taskpo['course_id'])){
            $this->db->where('v2_course_class_detail.course_id', $data_taskpo['course_id']);
        }


        $query=$this->db->get();
		//echo $this->db->last_query();die;
        if($query->num_rows()>0){
            return $query->result();
        }
        else{
            return $query->result();
        }
		}
	  else{
		  return 0;
	  }
    }

	public function recent_classes_15_days_search2($facultyid,$subject_code1){

      $offset = ($offset-1)*$limit;
      $date  =   date("Y-m-d");
      foreach($facultyid as $fs){$fs1.="'".$fs."',";}
      $fs    =   rtrim($fs1,",");
	  if(!empty($facultyid)){
      $this->db->simple_query("SET time_zone='UTC+05:30'");
      $sql="select v2_course_class_detail.id,course_id,class_tag_id,class_date,
          (select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date,
          (select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date,
          (select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag,
          class_strength,recording_url,method,
          (select CONCAT(first_name, ' ', last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty,
          (select category from category where category.id=v2_course_class_detail.category_id)as category_id,
          (select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id,
          (select class from class where class.id=v2_course_class_detail.class_id)as class_id,subject_code,
          class_start_time,class_end_time,class_duration_min,class_extend_time_min,time_zone,presenter_url from v2_course_class_detail
          join v2_course_presenter_data on v2_course_presenter_data.class_id=v2_course_class_detail.id
          where DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) AND class_date  < NOW() + INTERVAL 15 DAY
          and class_presenter in($fs) and v2_course_class_detail.subject_id=$subject_code1
          order by DATE(class_date),TIME(class_start_time) asc  LIMIT $offset,$limit
        ";

         $res  = $this->db->query($sql)->result();
       //  echo $this->db->last_query();die;
         //where (class_date) >= NOW() - INTERVAL 10 DAY AND class_date  < NOW() + INTERVAL 10 DAY
         //DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) and DATE_ADD(NOW(), INTERVAL +1 MONTH)
          return $res;
	  }
	  else{
		  return 0;
	  }
  }

	public function earning_list_search($data_taskpo,$facultyid){

        $this->db->simple_query("SET time_zone='UTC+05:30'");
        $query  = $this->db->select(['course_id','class_date',
          '(select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date',
          '(select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date',
          '(select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag',

          '(select CONCAT(first_name, " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty',
          '(select category from category where category.id=v2_course_class_detail.category_id)as category_id',
          '(select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id',
          '(select class from class where class.id=v2_course_class_detail.class_id)as class_id','subject_code',
          'class_start_time','class_end_time','class_duration_min','class_extend_time_min','time_zone','sum(per_class_earning)as total_earn'])
          ->from('v2_course_class_detail')
          ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
          ->where_in('class_presenter',$facultyid)
          ->group_by('course_id')
          ->order_by("v2_course_class_detail.id","asc");

        if(!empty($data_taskpo['category'])){
            $this->db->where('v2_course_class_detail.category_id',$data_taskpo['category']);
        }
        if(!empty($data_taskpo['class'])){
            $this->db->where('v2_course_class_detail.class_id', $data_taskpo['class']);
        }
        if(!empty($data_taskpo['subject'])){
            $this->db->where('v2_course_class_detail.subject_id', $data_taskpo['subject']);
        }
        if(!empty($data_taskpo['course_id'])){
            $this->db->where('v2_course_class_detail.course_id', $data_taskpo['course_id']);
        }
        $query=$this->db->get();
		//echo $this->db->last_query();die;
        if($query->num_rows()>0){
            return $query->result();
        }
        else{
            return $query->result();
        }
    }

	public function earning_list_search2($subject_code1,$facultyid){
        $offset = ($offset-1)*$limit;
      foreach($facultyid as $fs){$fs1.="'".$fs."',";}
      $fs    =   rtrim($fs1,",");
      $this->db->simple_query("SET time_zone='UTC+05:30'");
        $query  = $this->db->select(['course_id','class_date',
          '(select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date',
          '(select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date',
          '(select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag',

          '(select CONCAT(first_name, " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty',
          '(select category from category where category.id=v2_course_class_detail.category_id)as category_id',
          '(select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id',
          '(select class from class where class.id=v2_course_class_detail.class_id)as class_id','subject_code',
          'class_start_time','class_end_time','class_duration_min','class_extend_time_min','time_zone','sum(per_class_earning)as total_earn'])
          ->from('v2_course_class_detail')
          ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
          ->where_in('class_presenter',$facultyid)->where('v2_course_class_detail.subject_id',$subject_code1)
          ->group_by('course_id')
          ->order_by("v2_course_class_detail.id","asc");
            // echo $this->db->last_query();die;
        //echo "<pre>"; print_r($query->result_array());die;
        $query=$this->db->get();
	   //echo $this->db->last_query();die;
	        if($query->num_rows()>0){
                return $query->result();
            }
            else{
	            return $query->result();
            }



    }
    public function update_teacher_master($data_teacher_master,$user_id){
    $this->db->where('id',$user_id);
        $this->db->update('master_user', $data_teacher_master);
        //echo $this->db->last_query();die;
    return true;
  }

    public function update_teacher_basic($data_teacher_basic,$user_id){
    $this->db->where('user_id',$user_id);
        $this->db->update('mu_teacher_basic', $data_teacher_basic);
       // echo $this->db->last_query();die;
    return true;
  }


  public function update_teacher_pf_class($data_teacher_pf,$user_id,$id){
    $this->db->where('user_id',$user_id);
    $this->db->where('id',$id);
    $this->db->update('mu_teacher_pf_class', $data_teacher_pf);
    //echo $this->db->last_query();die;
    return true;
}

    public function insert_teacher_pf_class($data_teacher_pf_class0,$data_teacher_pf_class1,$data_teacher_pf_class2,$data_teacher_pf_class3
    ,$data_teacher_pf_class4){
        $this->db->insert('mu_teacher_pf_class', $data_teacher_pf_class0,$data_teacher_pf_class1,$data_teacher_pf_class2,$data_teacher_pf_class3
        ,$data_teacher_pf_class4);
       //echo $this->db->last_query();die;
    return $this->db->insert_id();
    }

    public function update_teacher_qualfication($data_teacher_qualfication,$user_id,$id){
        $this->db->where('user_id',$user_id);
        $this->db->where('id',$id);
        $this->db->update('mu_teacher_qualfication', $data_teacher_qualfication);
        //echo $this->db->last_query();die;
        return true;
    }
    public function insert_teacher_qualfication($data_teacher_qualfication){
        $this->db->insert('mu_teacher_qualfication', $data_teacher_qualfication);
        //echo $this->db->last_query();die;
    return $this->db->insert_id();
    }
    public function update_teacher_bank_detail($data_teacher_bank_detail,$user_id){
    $this->db->where('user_id',$user_id);
        $this->db->update('mu_teacher_bank_detail', $data_teacher_bank_detail);
       //echo $this->db->last_query();die;
    return true;
    }
    public function update_teacher_network_info($data_teacher_network_info,$user_id){
    $this->db->where('user_id',$user_id);
        $this->db->update('mu_teacher_extra_info', $data_teacher_network_info);
       // echo $this->db->last_query();die;
    return true;
    }

    public function num_teacher_qualfication($qualification,$university,$passing_year,$grade,$userid){
        $query  = $this->db->select(['mu_teacher_qualfication.id'])
        ->from('mu_teacher_qualfication')
        ->where('qualification',$qualification)
        ->where('university',$university)
        ->where('passing_year',$passing_year)
        ->where('grade',$grade)
        ->where('user_id',$userid)
        ->get();
        //echo $this->db->last_query();die;
        return $query->num_rows();
    }

    public function num_teacher_pf_class($class,$primary_sub,$secondary_sub,$other,$userid){
        $query  = $this->db->select(['mu_teacher_pf_class.id'])
        ->from('mu_teacher_pf_class')
        ->where('class',$class)
        ->where('primary_sub',$primary_sub)
        ->where('secondary_sub',$secondary_sub)
        ->where('other',$other)
        ->where('user_id',$userid)
        ->get();
        //echo $this->db->last_query();die;
        return $query->num_rows();
    }
    public function qualification_listing(){

		$query		=	  $this->db->select(['id','full_name'])->from('qualification_list')->order_by("id", "asc")->get();
		$return 	= 	array();
		if($query->num_rows() > 0) {
            $return[''] = ('Qualification List');
			foreach($query->result_array() as $row) {
				$return[$row['id']] = strtoupper($row['full_name']);
			}
		}
        return $return;
    }

    public function subjectshow_listing($header){

		$query		=	  $this->db->select(['id','full_name'])->from('subject_list_show')->order_by("id", "asc")->get();
		$return 	= 	array();
		if($query->num_rows() > 0) {
			foreach($query->result_array() as $row) {
				$return[$row['id']] = strtoupper($row['full_name']);
			}
		}
        return $return;
	}

	public function earning_dashboard($facultyid){

        $this->db->simple_query("SET time_zone='UTC+05:30'");
        $query  = $this->db->select(['course_id','class_date',
            '(select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date',
            '(select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date',
            '(select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag',
            '(select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id',
            '(select class from class where class.id=v2_course_class_detail.class_id)as class_id','subject_code',
            '(select CONCAT(first_name, " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty',
            'class_start_time','class_end_time','sum(per_class_earning)as total_earn'])
            ->from('v2_course_class_detail')
            ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
            ->where_in('class_presenter',$facultyid)
            ->group_by('course_id')
            ->order_by("v2_course_class_detail.id","desc")->get();
           // echo $this->db->last_query();die;
            return $query->result();

    }




    public function recent_classes($facultyid){

        $date  =   date("Y-m-d");
        foreach($facultyid as $fs){$fs1.="'".$fs."',";}
  	   $fs    =   rtrim($fs1,",");
  	   if(!empty($facultyid)){
        $this->db->simple_query("SET time_zone='UTC+05:30'");
        $sql="select v2_course_class_detail.id,course_id,class_tag_id,class_date,
            (select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date,
            (select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date,
            (select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag,
            class_strength,recording_url,method,
            (select CONCAT(first_name, ' ', last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty,
            (select category from category where category.id=v2_course_class_detail.category_id)as category_id,
            (select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id,
            (select class from class where class.id=v2_course_class_detail.class_id)as class_id,subject_code,
            class_start_time,class_end_time,class_duration_min,class_extend_time_min,time_zone,presenter_url from v2_course_class_detail
            join v2_course_presenter_data on v2_course_presenter_data.class_id=v2_course_class_detail.id
            where DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) AND class_date  < NOW() + INTERVAL 15 DAY
            and class_presenter in($fs)
            order by DATE(class_date),TIME(class_start_time) asc
          ";
           $res  = $this->db->query($sql)->result();
         //  echo $this->db->last_query();die;
           //where (class_date) >= NOW() - INTERVAL 10 DAY AND class_date  < NOW() + INTERVAL 10 DAY
           //DATE(class_date) >= DATE_SUB(NOW(), INTERVAL +1 day) and DATE_ADD(NOW(), INTERVAL +1 MONTH)
            return $res;
  	   }
  	    else{
  		  return 0;
  	  }
    } function cousre_running($facultyid){
        $this->db->simple_query('SET sql_mode=(SELECT REPLACE(@@sql_mode,"ONLY_FULL_GROUP_BY",""))');
        $query  = $this->db->select(['*'])
            ->from('v2_course_class_detail')
            ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
            ->join('v2_course_new as v2','v2.id=v2_course_class_detail.course_id')
            ->where_in('class_presenter',$facultyid)
            ->where("DATE(v2.course_start_date)<=DATE(NOW())")
            ->where("DATE(v2.course_end_date)>=DATE(NOW())")
            ->group_by('course_id')
            ->order_by("v2_course_class_detail.id","asc")->get();
            //echo $this->db->last_query();die;
            return $query->result();
    }

    public function class_history($facultyid){

        $this->db->simple_query('SET sql_mode=(SELECT REPLACE(@@sql_mode,"ONLY_FULL_GROUP_BY",""))');
        $query  = $this->db->select(['v2_course_class_detail.id','course_id','class_tag_id','class_date',
            '(select course_start_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_start_date',
            '(select course_end_date from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_end_date',
            '(select course_id_tag from v2_course_new where v2_course_class_detail.course_id=v2_course_new.id) as course_id_tag',
            'class_strength','recording_url','method',
            '(select CONCAT(first_name, " ", last_name) from v2_faculty  join master_user on master_user.id=v2_faculty.teacher_id where v2_course_presenter_data.class_presenter=v2_faculty.id) as faculty',
            '(select category from category where category.id=v2_course_class_detail.category_id)as category_id',
            '(select subject from subject where subject.id=v2_course_class_detail.subject_id)as subject_id',
            '(select class from class where class.id=v2_course_class_detail.class_id)as class_id','subject_code',
            'class_start_time','class_end_time','class_duration_min','class_extend_time_min','time_zone','presenter_url'])
            ->from('v2_course_class_detail')
            ->join('v2_course_presenter_data','v2_course_presenter_data.class_id=v2_course_class_detail.id')
            ->where_in('class_presenter',$facultyid)
              ->order_by("v2_course_class_detail.id","desc")->get();
            // echo $this->db->last_query();die;
            return $query->result();
    }

}
