<?php
class AdminModel extends CI_Model {
 
public function check_subscriber($email,$table){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('email',$email);
$info=$this->db->get()->result_array();
return $info;
} 

public function insert_data($data_array,$table){
$this->db->insert($table,$data_array);
return $this->db->insert_id();
}
 
public function add_new_subscriber($data_array,$table){
$this->db->insert($table,$data_array);
return $this->db->insert_id();
}

public function get_table_list($first_name,$last_name,$dob,$branch,$class,$mobile_number,$email,$table){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('first_name',$first_name);
$this->db->where('last_name',$last_name);
$this->db->where('dob',$dob);
// $this->db->where('branch',$branch);
$this->db->where('class',$class);
$this->db->where('mobile_number',$mobile_number);
$this->db->where('email',$email);
$info=$this->db->get()->result_array();
return $info;
}

public function check_short_enquiry($first_name,$last_name,$mobile_number,$table){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('mobile_number',$mobile_number);   
$this->db->where('first_name',$first_name);
$this->db->where('last_name',$last_name);
return $this->db->get()->num_rows();   
}
public function check_enquiry_uq($first_name,$last_name,$dob,$branch,$class,$mobile_number,$email,$table){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('mobile_number',$mobile_number);   
$this->db->where('email',$email);
$this->db->where('first_name',$first_name);
$this->db->where('dob',$dob);
return $this->db->get()->num_rows();   
}
public function add_enquiry($data_array,$table){
$this->db->insert('enquiry',$data_array);
return $this->db->insert_id();
}

public function add_course($data_array,$table){
$this->db->insert($table,$data_array);

echo   $this->db->insert_id();	
}
public function check_login($email, $mobile_number){
$info=array();
$this->db->select('*');
$this->db->from('enquiry');
$this->db->where('email',$email);
$this->db->where('mobile_number',$mobile_number);
$info=$this->db->get()->result_array();
return $info;	
}
public function check_enquiry_for_payment($enquiry_no,$table){
$this->db->where('id',$enquiry_no);
$this->db->where('pi_status',1);
$this->db->where('document_status',1);
$query = $this->db->get('enquiry');
if($query->num_rows() == 1) {
return $query->row();
}
else{return false;}	
}
public function fetch_student_data($table,$id){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('id',$id);
$info=$this->db->get()->result_array();
return $info;	
}

public function fetch_fee_data($table1,$admission_class){
$info=array();
$this->db->select('*');
$this->db->from($table1);
$this->db->where('class',$admission_class);
$info=$this->db->get()->result_array();
return $info;	
}
public function update_student_data_via_id($data_array_update,$id,$table)
{
$this->db->where("id",$id);
$this->db->update($table,$data_array_update);
return $this->db->affected_rows();
}
public function insert_payment_data($data_array){
$this->db->insert('enquiry_payment',$data_array);
return $this->db->insert_id();	
}


// $insert_payment_data = $this->AdminModel->insert_payment_data($payment_data_array);
// if($insert_payment_data){
// $update_student_data=$this->AdminModel->update_student_enquiry($order_id,$txnid,$status,$is_Success);
// if($update_student_data){
// redirect(base_url().'Enquiry/failed/'.$txnid.'/'.$status.'/'.$amount);    
// }


// }

public function update_student_enquiry($order_id,$txnid,$status,$is_Success){
$this->db->set($productinfo,1);
$this->db->set('payment_status',$status);
$this->db->set('is_Success',$is_Success);
if($status=='success'){
$this->db->set('enquiry_payment_status',1);
}else if($status=='failure'){
$this->db->set('enquiry_payment_status',0);    
}
$this->db->set('transaction_id',$txnid);    
$this->db->where('id',$order_id);
$this->db->update('enquiry');	
return $this->db->affected_rows();
}

public function check_consent_student($student_name,$admission_no){
$table='all_students';
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('Adm_No',$admission_no);
// $this->db->like('Name',$student_name);
$this->db->where('Name',$student_name);

$info=$this->db->get()->result_array();
return $info;    
}


public function get_consent_data($consent_id){
$table='all_students';
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('Adm_No',$consent_id);
// $this->db->like('Name',$student_name);
$info=$this->db->get()->result_array();
return $info;        
}
public function update_consent($consent_id,$choice){
$table='all_students';
$data_array_update=array("status"=>1,"CHOICE"=>$choice);
$this->db->where("Adm_No",$consent_id);
$this->db->update($table,$data_array_update);
return $this->db->affected_rows();    
}
public function update_consent_data(){
$table='all_students';
$data_array_update=array("status"=>0);
// $this->db->where("Adm_No",$consent_id);
$this->db->update($table,$data_array_update);
return $this->db->affected_rows();    
}

public function all_consent(){
$table='all_students';
// $table='mtmhss_students';
$info=array();
$this->db->select('*');
$this->db->from($table);
// $this->db->where('Adm_No',$consent_id);
// $this->db->like('Name',$student_name);
$info=$this->db->get()->result_array();
return $info;      
}
public function get_students_raw_data(){
$table='mtmhss_students';
$info=array();
$this->db->select('*');
$this->db->from($table);
// $this->db->where('Adm_No',0);
// $this->db->like('Name',$student_name);
$info=$this->db->get()->result_array();
return $info;          
}
public function update_consent_user_data($status,$adm_no,$CHOICE){
$table='all_students';
$data_array_update=array("status"=>$status,"CHOICE"=>$CHOICE);
$this->db->where("Adm_No",$adm_no);
$this->db->update($table,$data_array_update);
return $this->db->affected_rows();    
}


public function empty_consent_data($class){
$table='all_students';
$CHOICE='';
$status=0;
$data_array_update=array("status"=>$status,"CHOICE"=>$CHOICE);
$this->db->where("Class",$class);
$this->db->update($table,$data_array_update);
return $this->db->affected_rows();        
}
public function get_class_data($class,$section){
$table='all_students';
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('Class',$class);
$this->db->like('section',$section);
$info=$this->db->get()->result_array();
return $info;          
}

public function get_u2_class_data($class,$section){
$table='all_u2_students';
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('Class',$class);
$this->db->like('section',$section);
$info=$this->db->get()->result_array();
return $info;          
}

public function update_all_student_data($sch_no,$class,$section){
$table='all_students';
$unit=2;
$data_array_update=array("unit"=>$unit);
$this->db->where("Class",$class);
$this->db->where("Adm_No",$sch_no);
$this->db->where("section",$section);
$this->db->update($table,$data_array_update);
return $this->db->affected_rows();        
}

public function get_class_data_u2(){
$table='all_u2_students';
$info=array();
$this->db->select('*');
$this->db->from($table);
// $this->db->where('Class',$class);
// $this->db->like('section',$section);
$info=$this->db->get()->result_array();
return $info;              
}

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

public function courses(){
$table="kidwai_nagar_classes";
$info=array();
$this->db->select('*');
$this->db->from($table);
$info=$this->db->get()->result_array();
return $info;    
}

public function shedule_sms($data_array,$table,$id){
$this->db->where("id",$id);
$this->db->update($table,$data_array);
return $this->db->affected_rows();
}
public function get_data($table){
$info=array();
$this->db->select('*');
$this->db->from($table);
$info=$this->db->get()->result_array();
return $info;    
}
public function check_messege($host,$email,$contact_no,$subject,$table){
$info=array();
$this->db->select('*');
$this->db->from($table);
$this->db->where('host',$host);
$this->db->where('email',$email);
$this->db->where('contact_no',$contact_no);
$this->db->where('subject',$subject);
$info=$this->db->get()->result_array();
return $info;
}

public function fee_structure($table){
$info=array();
$this->db->select('*');
$this->db->from($table);
$info=$this->db->get()->result_array();
return $info;  
}

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

public function update_sms_data(){
$table='enquiry';
$data_array_update=array("shedule_sms"=>0);
$this->db->where("shedule_sms",1);
$this->db->update($table,$data_array_update);
return $this->db->affected_rows();    
}

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

}