<?php 
function checkLogin($email='',$password=''){
	$CI =& get_instance();
$CI->db->select("*");
$CI->db->from('tbl_lead_user');
if($email!=''){
$CI->db->where('email',$email);	
}
if($password!=''){
$CI->db->where('password',$password);	
}
$CI->db->where('status','Y');	  
$query = $CI->db->get();
$result= $query->result_array();
if(count($result) > 0){
	$timestamp= array('timestamp' => time());
	$CI->session->set_userdata('user_login', $result);
	$CI->session->set_userdata('loggedIn', TRUE);
	$CI->session->set_userdata($timestamp);
}	
 //print_r($CI->session->userdata('user_login'));
 //print_r($CI->session->userdata('loggedIn'));
 return $result;
}

function leadDistribution($post=''){
$CI =& get_instance();
$user=$CI->session->userdata('user_login');
if (strpos($post['caller_id'], 'tl') !== false) 
   {
$id=explode('-',$post['caller_id']);
$caller=$id[0];
 $sel="select tllc.*,tll.username from tbl_lead_tl_caller as tllc 
	join tbl_lead_user as tll on tll.id=tllc.cl_id 
	where tllc.tl_id='".$caller."'";
}else{
$caller=$post['caller_id'];	
 $sel="select tllc.*,tll.username from tbl_lead_tl_caller as tllc 
	join tbl_lead_user as tll on tll.id=tllc.cl_id 
	where tllc.cl_id='".$caller."'";
}

    $query = $CI->db->query($sel);	
	$studentData = $query->result();	
	return $studentData;	
}

function getTotal($id='',$lead=''){
$CI =& get_instance();
		$CI->db->select('id');
		$CI->db->from('tbl_lead_leads');
		if($id!=''){	
		$CI->db->where('caller_id',$id);	
		}
		if($lead!=''){	
		$CI->db->where('lead_status',$lead);	
		}
		$query = $CI->db->get();
		$studentData = $query->result();
		return count($studentData);	
}


function getTotalSource($id='',$lead='',$source='',$from_date='',$to_date=''){
$CI =& get_instance();
		$CI->db->select('id');
		$CI->db->from('tbl_lead_leads');
		if($id!=''){	
		$CI->db->where('caller_id',$id);	
		}
		if($lead!=''){	
		$CI->db->where('lead_status',$lead);	
		}
		if($source!=''){	
		$CI->db->where('source_id',$source);	
		}
		if(($from_date!= "") && ($to_date=="")){
		$CI->db->like('assigned_lead_time',date("Y-m-d", strtotime($from_date)));
		}
		if(($to_date!="") && ($from_date!= "")){
	 	$from1=$from_date.' 00:00:00';
		$to1=$to_date.' 23:59:00';
	   $CI->db->where("assigned_lead_time BETWEEN  '".$from1."' AND '".$to1."' ");	
	    }
		
		$query = $CI->db->get();//echo $CI->db->last_query();
		$studentData = $query->result();
		return count($studentData);	
}

function getTotalSourcecount($id='',$lead='',$source='',$from_date='',$to_date=''){

$CI =& get_instance();
		$CI->db->select('*');
		$CI->db->from('tbl_lead_leads_log');
		if($id!=''){	
		$CI->db->where('caller_id',$id);	
		}
		if($lead!=''){	
		$CI->db->where('lead_status',$lead);	
		}
		if($source!=''){	
		$CI->db->where('source_id',$source);	
		}
		if(($from_date!= "") && ($to_date=="")){
		$CI->db->like('recent_update',date("Y-m-d", strtotime($from_date)));
		}
		if(($to_date!="") && ($from_date!= "")){
	 	$from1=$from_date.' 00:00:00';
		$to1=$to_date.' 23:59:00';
	   $CI->db->where("recent_update BETWEEN  '".$from1."' AND '".$to1."' ");	
	    }
		$CI->db->group_by('user_id'); 
		$query = $CI->db->get();//echo $CI->db->last_query();
		$studentData = $query->result();
		$cc= $studentData;
		
	$leadstr='';$sourcestr='';	$sourcestr1='';
      if($lead!=''){	
		$leadstr=" AND `lead_status`=".$lead;
		}
		if($source!=''){	
		
		$sourcestr=" AND `source_id`=".$source;
		}
		if(($from_date!= "") && ($to_date=="")){
		$CI->db->like('assigned_lead_time',date("Y-m-d", strtotime($from_date)));
		$sourcestr=" AND `recent_update` like ".$from_date."%";
		}
		if(($to_date!="") && ($from_date!= "")){
	 	$from1=$from_date.' 00:00:00';
		$to1=$to_date.' 23:59:00';
	    $sourcestr1=" AND `recent_update` BETWEEN  '".$from1."' AND '".$to1."'";
	    }
		
		
$sel="SELECT * FROM tbl_lead_leads WHERE `caller_id`='".$id."' ".$leadstr." ".$sourcestr." ".$sourcestr1."  AND id NOT IN  (SELECT user_id  FROM tbl_lead_leads_log)"; 	
$query = $CI->db->query($sel);	
$studentData1 = $query->result();
return array($cc, $studentData1);
	//return ($cc+count($studentData1));
}


function getTotalreverted($id='',$lead='',$source='',$from_date='',$to_date=''){

$CI =& get_instance();
		$CI->db->select('*');
		$CI->db->from('tbl_lead_leads_log');
		if($id!=''){	
		$CI->db->where('caller_id',$id);	
		}
		if($lead!=''){	
		$CI->db->where('operation','revertupdate');	
		}
		if($source!=''){	
		$CI->db->where('source_id',$source);	
		}
		if(($from_date!= "") && ($to_date=="")){
		$CI->db->like('recent_update',date("Y-m-d", strtotime($from_date)));
		}
		if(($to_date!="") && ($from_date!= "")){
	 	$from1=$from_date.' 00:00:00';
		$to1=$to_date.' 23:59:00';
	   $CI->db->where("recent_update BETWEEN  '".$from1."' AND '".$to1."' ");	
	    }
		$CI->db->group_by('user_id'); 
		$query = $CI->db->get();//echo $CI->db->last_query();
		$studentData = $query->result();
		$cc= $studentData;
		
	$leadstr='';$sourcestr='';	$sourcestr1='';
      if($lead!=''){	
		$leadstr=" AND `lead_status`=".$lead;
		}
		if($source!=''){	
		
		$sourcestr=" AND `source_id`=".$source;
		}
		if(($from_date!= "") && ($to_date=="")){
		$CI->db->like('assigned_lead_time',date("Y-m-d", strtotime($from_date)));
		$sourcestr=" AND `recent_update` like ".$from_date."%";
		}
		if(($to_date!="") && ($from_date!= "")){
	 	$from1=$from_date.' 00:00:00';
		$to1=$to_date.' 23:59:00';
	    $sourcestr1=" AND `recent_update` BETWEEN  '".$from1."' AND '".$to1."'";
	    }
		
		
$sel="SELECT * FROM tbl_lead_leads WHERE `parent_caller_id`='".$id."' ".$leadstr." ".$sourcestr." ".$sourcestr1."  AND id NOT IN  (SELECT user_id  FROM tbl_lead_leads_log)"; 	
$query = $CI->db->query($sel);	
$studentData1 = $query->result();
return array($cc, $studentData1);
}


function getleadofmyteam($id,$tuid){
$CI =& get_instance();
$user=$CI->session->userdata('user_login');
$CI->db->select('*');
$CI->db->from('tbl_lead_tl_caller');
$CI->db->where('tl_id',$id);
$CI->db->where('cl_id',$tuid);
$query = $CI->db->get();
$studentData = $query->result();
return $studentData;	
	
}

function getTL($id=''){
$CI =& get_instance();
$user=$CI->session->userdata('user_login');
$CI->db->select('tu.username');
$CI->db->from('tbl_lead_tl_caller as tltc');
$CI->db->join('tbl_lead_user as tu','tu.id=tltc.tl_id');
$CI->db->where('tltc.cl_id',$id);

$query = $CI->db->get();
$studentData = $query->result();
return $studentData;	
}

function getsiteVisitVerify(){
$CI =& get_instance();
$user=$CI->session->userdata('user_login');
$CI->db->select('tll.id,tll.name,tll.phone,tll.site_visit_date,tll.site_visit_verify,tll.feedback,tu.username,tuy.user_type as utype,tu.id as tuid');
$CI->db->from('tbl_lead_leads as tll');
$CI->db->join('tbl_lead_user as tu','tu.id=tll.caller_id');
$CI->db->join('tbl_lead_user_type as tuy','tuy.id=tu.user_type');
$CI->db->where('tll.lead_status','14');
$CI->db->where('tll.site_visit_verify','N');
if($user[0]['user_type']==3){
		$CI->db->where('tll.caller_id',$user[0]['id']);	
		}
$query = $CI->db->get();
$studentData = $query->result();
return $studentData;	
}

function getUsertype(){
		$CI =& get_instance();
		$CI->db->select('*');
		$CI->db->from('tbl_lead_user_type');
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}
 function getCaller($id='',$usertype=''){
$CI =& get_instance();
		$CI->db->select('*');
		$CI->db->from('tbl_lead_user');
		if($usertype==1){
		$array=array('3','2');	
		$CI->db->where_in('user_type',$array);	
		}
		if($usertype==2){
		$array=('3');	
		$CI->db->where_in('user_type',$array);	
		}
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	 
 }
 function getCallers($id=''){
$CI =& get_instance();
		$CI->db->select('*');
		$CI->db->from('tbl_lead_user');
		if(($id!='') && ($id!=0)){	
		$CI->db->where('id',$id);	
		}
		$query = $CI->db->get();//echo $CI->db->last_query();
		$studentData = $query->result_array();
		return $studentData;	 
 }
function getCity(){
$CI =& get_instance();
		$CI->db->select('*');
		$CI->db->from('tbl_lead_city');
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}

function getStatus($id=''){
		$CI =& get_instance();
		$CI->db->select('*');
		$CI->db->from('tbl_lead_status');
		if($id!=''){
		$CI->db->where('id',$id);	
		}
		$CI->db->order_by('status','asc');
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}

function getCollegestat($id=''){//echo $id;
		$CI =& get_instance();
		$CI->db->select('*');
		$CI->db->from('tbl_lead_college');
		if($id!=''){
		$CI->db->where('id',$id);	
		//$CI->db->where('leadshare!=','');	
		}
		//$CI->db->order_by('status','asc');
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}

function getCollegesshare(){
		$CI =& get_instance();
		$CI->db->select('tl.*,tc.city_name');
		$CI->db->from('tbl_lead_college as tl');
		$CI->db->join('tbl_lead_city as tc', 'tc.id =tl.city');
		
		$CI->db->where('tl.leadshare !=','');	
	
		//$CI->db->order_by('status','asc');
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}

function getSource($id=''){
		$CI =& get_instance();
		$CI->db->select('*');
		$CI->db->from('tbl_lead_source');
		if($id!=''){
		$CI->db->where('id',$id);	
		}
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}
function leadsite(){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$caller=getCallerLists($user[0]['id']);
		 foreach($caller as $get){
		$ids .=$get->cl_id.',';
		}
		 $ids = rtrim($ids,',');
		$CI->db->select('id');
		$CI->db->from('tbl_lead_leads');
		//$CI->db->where('lead_status', '14');
		//$CI->db->where('site_visit_date !=', '0000-00-00 00:00:00');
		$CI->db->where('site_visit_verify', 'Y');
		if($user[0]['user_type']!=1 && $user[0]['user_type']!=2){
		$CI->db->where('caller_id',$user[0]['id']);	
		}
		
		if($user[0]['user_type']==2){
		$setid=explode(',',$ids);//echo $ids;	print_r($setid);
		$CI->db->where_in('caller_id', $setid);
		}
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}
function leadListcounts($id=''){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$CI->db->select('id');
		$CI->db->from('tbl_lead_leads');
		if($id!=''){
		$CI->db->where('lead_status', $id);
		}
		if($user[0]['user_type']!=1){
		$CI->db->where('caller_id',$user[0]['id']);	
		}
	
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}

function leadListcountstl($id=''){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$caller=getCallerLists($user[0]['id']);
		 foreach($caller as $get){
		$ids .=$get->cl_id.',';
		}
		 $ids = rtrim($ids,',');
		$CI->db->select('id');
		$CI->db->from('tbl_lead_leads');
		if($id!=''){
		$CI->db->where('lead_status', $id);
		}
		if($user[0]['user_type']==2){
		$setid=explode(',',$ids);//echo $ids;	print_r($setid);
		$CI->db->where_in('caller_id', $setid);
		}
	
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}
function leadsale(){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$CI->db->select('id');
		$CI->db->from('tbl_lead_leads');
		$CI->db->where('lead_status', '7');
		if($user[0]['user_type']!=1){
		$CI->db->where('caller_id',$user[0]['id']);	
		}
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}
function leadListcount($id='',$post='',$limit='',$starts='',$ids=''){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
//print_r($user);
//		print_r($post);
		$CI->db->select('tl.id');
		$CI->db->from('tbl_lead_leads as tl');
		$CI->db->join('tbl_lead_source as tso','tso.id=tl.source_id');
		if($id!=''){
		$CI->db->where_in('tl.id', $id);
		}
		if($post!=''){
		if($post['name']!=''){
		$CI->db->like('tl.name', $post['name']);
		}
		if($post['college']!=''){
		$CI->db->like('tl.college', $post['college']);
		}
		if($post['course']!=''){
		$CI->db->like('tl.course', $post['course']);
		}
		if($post['email']!=''){
		$CI->db->like('tl.email', $post['email']);
		}
		if($post['phone']!=''){
		$CI->db->where('tl.phone', $post['phone']);
		}
		if($post['added_on']!=''){
		$CI->db->like('tl.added_on',date("Y-m-d", strtotime($post['added_on'])));
		}
		if($post['followup_date']!=''){
		$CI->db->like('tl.followup_date',date("Y-m-d", strtotime($post['followup_date'])));
		}
		if($post['city']!=''){
		$CI->db->where('tl.city', $post['city']);
		}
		if($post['lead_status']!=''){
		$CI->db->where('tl.lead_status', $post['lead_status']);
		}
		if($post['source_id']!=''){
		$CI->db->where('tl.source_id', $post['source_id']);
		}
		if($post['site_visit_verify']!=''){
		if($post['site_visit_verify']=='Y'){
		$CI->db->where('tl.site_visit_verify', $post['site_visit_verify']);
		}
		if($post['site_visit_verify']=='N'){
			$arr=array(5,14);
		$CI->db->where('tl.site_visit_verify', $post['site_visit_verify']);
		$CI->db->where_in('tl.lead_status', $arr);
		}
		}
		if(($post['to_date1']!="") && ($post['from_date1']!= "")){
	 	$from1=$post['from_date1'].' 00:00:00';
		$to1=$post['to_date1'].' 23:59:00';
	   $CI->db->where("tl.added_on BETWEEN  '".$from1."' AND '".$to1."' ");
	
	    }
		
	    if($user[0]['user_type']!=3){
			if($post['caller_id']!=''){
		$CI->db->where('tl.caller_id', $post['caller_id']);
		}

		}
		if(($post['to_date']!="") && ($post['from_date']!= "")){
	 	$from=$post['from_date'].' 00:00:00';
		$to=$post['to_date'].' 23:59:00';
	   $CI->db->where("tl.followup_date BETWEEN  '".$from."' AND '".$to."' ");
	    }
		}
		if(!empty($ids)){
		$setid=explode(',',$ids);//echo $ids;	print_r($setid);
		$CI->db->where_in('tl.caller_id', $setid);
		}
		
		if (is_array($post) && isset($post['caller_id']) &&
    is_array($user) && isset($user[0]['user_type'], $user[0]['id']) &&
    $post['caller_id'] == '' &&
    $user[0]['user_type'] != 1 &&
    empty($ids)) {
    $CI->db->where('tl.caller_id', $user[0]['id']);
}

		$CI->db->order_by('tl.id','desc');
		$query = $CI->db->get();//echo $CI->db->last_query();
		$studentData = $query->result();
		return count($studentData);	
}

function leadList($id='',$post='',$limit='',$starts=''){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$CI->db->select('tl.*,tso.source,tu.username,tu.phone as phones');
		$CI->db->from('tbl_lead_leads as tl');
		$CI->db->join('tbl_lead_source as tso','tso.id=tl.source_id');
		$CI->db->join('tbl_lead_user as tu','tu.id=tl.caller_id');
		if($id!=''){
		$CI->db->where_in('tl.id', $id);
		}
		if($post!=''){
		if($post['name']!=''){
		$CI->db->like('tl.name', $post['name']);
		}
		if($post['college']!=''){
		$CI->db->like('tl.college', $post['college']);
		}
		if($post['course']!=''){
		$CI->db->like('tl.course', $post['course']);
		}
		if($post['email']!=''){
		$CI->db->like('tl.email', $post['email']);
		}
		if($post['phone']!=''){
		$CI->db->where('tl.phone', $post['phone']);
		}
		if($post['added_on']!=''){
		$CI->db->like('tl.added_on',date("Y-m-d", strtotime($post['added_on'])));
		}
		if($post['followup_date']!=''){
		$CI->db->like('tl.followup_date',date("Y-m-d", strtotime($post['followup_date'])));
		}
		if($post['city']!=''){
		$CI->db->where('tl.city', $post['city']);
		}
		if($post['lead_status']!=''){
		$CI->db->where('tl.lead_status', $post['lead_status']);
		}
		if($post['source_id']!=''){
		$CI->db->where('tl.source_id', $post['source_id']);
		}
		if($post['site_visit_verify']!=''){
		if($post['site_visit_verify']=='Y'){
		$CI->db->where('tl.site_visit_verify', $post['site_visit_verify']);
		}
		if($post['site_visit_verify']=='N'){
			$arr=array(5,14);
		$CI->db->where('tl.site_visit_verify', $post['site_visit_verify']);
		$CI->db->where_in('tl.lead_status', $arr);
		}
		}		
	    if($user[0]['user_type']!=3){
		if($post['caller_id']!=''){
		$CI->db->where('tl.caller_id', $post['caller_id']);
		}
		
		}
		if(($post['to_date']!="") && ($post['from_date']!= "")){
	 	$from=$post['from_date'].' 00:00:00';
		$to=$post['to_date'].' 23:59:00';
		if($post['lead_status']==14){
	   $CI->db->where("tl.site_visit_date BETWEEN  '".$from."' AND '".$to."' ");
		}else{
		$CI->db->where("tl.followup_date BETWEEN  '".$from."' AND '".$to."' ");	
		}
	    }
		
		if(($post['to_date1']!="") && ($post['from_date1']!= "")){
	 	$from1=$post['from_date1'].' 00:00:00';
		$to1=$post['to_date1'].' 23:59:00';
	   $CI->db->where("tl.added_on BETWEEN  '".$from1."' AND '".$to1."' ");
	
	    }
				
		}
	if (is_array($post) && isset($post['caller_id']) &&
    is_array($user) && isset($user[0]['user_type'], $user[0]['id']) &&
    $post['caller_id'] == '' &&
    $user[0]['user_type'] != 1) {
    $CI->db->where('tl.caller_id', $user[0]['id']);
}
		
		$CI->db->order_by('tl.id','desc');
		$CI->db->limit($limit,$starts);
		$query = $CI->db->get();//echo $CI->db->last_query();
		$studentData = $query->result();
		return $studentData;	
}


function leadListt($id='',$post='',$limit='',$starts=''){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$CI->db->select('tl.*,tso.source,tu.username,tu.phone as phones');
		$CI->db->from('tbl_lead_leads as tl');
		$CI->db->join('tbl_lead_source as tso','tso.id=tl.source_id');
		$CI->db->join('tbl_lead_user as tu','tu.id=tl.caller_id');
		if($id!=''){
		$CI->db->where_in('tl.id', $id);
		}
		if($post!=''){
		if($post['name']!=''){
		$CI->db->like('tl.name', $post['name']);
		}
		if($post['email']!=''){
		$CI->db->like('tl.email', $post['email']);
		}
		if($post['phone']!=''){
		$CI->db->where('tl.phone', $post['phone']);
		}
		if($post['added_on']!=''){
		$CI->db->like('tl.added_on',date("Y-m-d", strtotime($post['added_on'])));
		}
		if($post['followup_date']!=''){
		$CI->db->like('tl.followup_date',date("Y-m-d", strtotime($post['followup_date'])));
		}
		if($post['city']!=''){
		$CI->db->where('tl.city', $post['city']);
		}
		if($post['lead_status']!=''){
		$CI->db->where('tl.lead_status', $post['lead_status']);
		}
		if($post['source_id']!=''){
		$CI->db->where('tl.source_id', $post['source_id']);
		}
		if($post['site_visit_verify']!=''){
		if($post['site_visit_verify']=='Y'){
		$CI->db->where('tl.site_visit_verify', $post['site_visit_verify']);
		}
		if($post['site_visit_verify']=='N'){
			$arr=array(5,14);
		$CI->db->where('tl.site_visit_verify', $post['site_visit_verify']);
		$CI->db->where_in('tl.lead_status', $arr);
		}
		}		
	    if($user[0]['user_type']!=3){
		if($post['caller_id']!=''){
		$CI->db->where('tl.caller_id', $post['caller_id']);
		}
		
		}
		if(($post['to_date']!="") && ($post['from_date']!= "")){
	 	$from=$post['from_date'].' 00:00:00';
		$to=$post['to_date'].' 23:59:00';
		if($post['lead_status']==14){
	   $CI->db->where("tl.site_visit_date BETWEEN  '".$from."' AND '".$to."' ");
		}else{
		$CI->db->where("tl.followup_date BETWEEN  '".$from."' AND '".$to."' ");	
		}
	    }
		
		if(($post['to_date1']!="") && ($post['from_date1']!= "")){
	 	$from1=$post['from_date1'].' 00:00:00';
		$to1=$post['to_date1'].' 23:59:00';
	   $CI->db->where("tl.added_on BETWEEN  '".$from1."' AND '".$to1."' ");
	
	    }
				
		}
	
		$CI->db->order_by('tl.id','desc');
		$CI->db->limit($limit,$starts);
		$query = $CI->db->get();//echo $CI->db->last_query();
		$studentData = $query->result();
		return $studentData;	
}


function myleadList($id='',$post='',$limit='',$starts='',$ids=''){
		$CI =& get_instance();//echo $ids;
		$setid=explode(',',$ids);
		$user=$CI->session->userdata('user_login');
		$CI->db->select('tl.*,tso.source,tu.username,tu.phone as phones');
		$CI->db->from('tbl_lead_leads as tl');
		$CI->db->join('tbl_lead_source as tso','tso.id=tl.source_id');
		$CI->db->join('tbl_lead_user as tu','tu.id=tl.caller_id');
		if($id!=''){
		$CI->db->where_in('tl.id', $id);
		}
		if($post!=''){
		if($post['name']!=''){
		$CI->db->like('tl.name', $post['name']);
		}
		if($post['email']!=''){
		$CI->db->like('tl.email', $post['email']);
		}
		if($post['phone']!=''){
		$CI->db->where('tl.phone', $post['phone']);
		}
		if($post['added_on']!=''){
		$CI->db->like('tl.added_on',date("Y-m-d", strtotime($post['added_on'])));
		}
		if($post['followup_date']!=''){
		$CI->db->like('tl.followup_date',date("Y-m-d", strtotime($post['followup_date'])));
		}
		if($post['city']!=''){
		$CI->db->where('tl.city', $post['city']);
		}
		if($post['lead_status']!=''){
		$CI->db->where('tl.lead_status', $post['lead_status']);
		}
		if($post['source_id']!=''){
		$CI->db->where('tl.source_id', $post['source_id']);
		}
		if($post['site_visit_verify']!=''){
		if($post['site_visit_verify']=='Y'){
		$CI->db->where('tl.site_visit_verify', $post['site_visit_verify']);
		}
		if($post['site_visit_verify']=='N'){
			$arr=array(5,14);
		$CI->db->where('tl.site_visit_verify', $post['site_visit_verify']);
		$CI->db->where_in('tl.lead_status', $arr);
		}
		}
		if(($post['to_date1']!="") && ($post['from_date1']!= "")){
	 	$from1=$post['from_date1'].' 00:00:00';
		$to1=$post['to_date1'].' 23:59:00';
	   $CI->db->where("tl.added_on BETWEEN  '".$from1."' AND '".$to1."' ");
	
	    }
		
	 	if($post['caller_id']!=''){
		$CI->db->where('tl.caller_id', $post['caller_id']);
		}
		if(($post['to_date']!="") && ($post['from_date']!= "")){
	 	$from=$post['from_date'].' 00:00:00';
		$to=$post['to_date'].' 23:59:00';
	   $CI->db->where("tl.followup_date BETWEEN  '".$from."' AND '".$to."' ");
	    }
		}
		if($post['caller_id']==''){
		if(count($setid)>0){
		$CI->db->where_in('tl.caller_id', $setid);
		}
		}
		
		$CI->db->order_by('tl.id','desc');
		$CI->db->limit($limit,$starts);
		$query = $CI->db->get();//echo $CI->db->last_query();
		$studentData = $query->result();
		return $studentData;	
}
function getTemplates($template=''){
	    $CI =& get_instance();
		$CI->db->select('sms');
		$CI->db->from('tbl_lead_template');
		if($template!=''){
		$CI->db->where_in('template_type', $template);
		}
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData[0]->sms;
}
function GetCounsellorName($id=''){
$CI =& get_instance();
		$CI->db->select('username');
		$CI->db->from('tbl_lead_user');
		if($id!=''){
		$CI->db->where_in('id', $id);
		}
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData[0]->username;		
}
function getUser($id=''){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$CI->db->select('tl.*,tlu.user_type as user');
		$CI->db->from('tbl_lead_user as tl');
		$CI->db->join('tbl_lead_user_type as tlu', 'tlu.id =tl.user_type');
		if($id!=''){
		$CI->db->where_in('tl.user_type', $id);
		}
		if($user[0]['user_type']!=1){
		$CI->db->where('tl.id',$user[0]['id']);	
		}
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;		
}

function getUsersfilter($id='',$post='',$limit='',$starts=''){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$CI->db->select('tl.*,tlu.user_type as user');
		$CI->db->from('tbl_lead_user as tl');
		$CI->db->join('tbl_lead_user_type as tlu', 'tlu.id =tl.user_type');
		if($id!=''){
		$CI->db->where_in('tl.id', $id);
		}
		if($post!=''){
		if($post['name']!=''){
		$CI->db->like('tl.username', $post['name']);
		}
		if($post['email']!=''){
		$CI->db->like('tl.email', $post['email']);
		}
		if($post['phone']!=''){
		$CI->db->where('tl.phone', $post['phone']);
		}
		if($post['added_on']!=''){
		$CI->db->like('tl.added_on',date("Y-m-d", strtotime($post['added_on'])));
		}
		if($post['user_type']!=''){
		$CI->db->where('tl.user_type', $post['user_type']);
		}
		}		
		$CI->db->order_by('tl.id','desc');
		$CI->db->limit($limit,$starts);
		$query = $CI->db->get();//echo $CI->db->last_query();
		$studentData = $query->result();
		return $studentData;	
}
 function getCallerLists($id=''){	
	 $CI =& get_instance();
    $sel="select tllc.*,tll.username from tbl_lead_tl_caller as tllc 
	join tbl_lead_user as tll on tll.id=tllc.cl_id 
	where tllc.tl_id='".$id."'";
    $query = $CI->db->query($sel);	
 return $studentData = $query->result();
 }
function getTeamLeader($id=''){
	 $CI =& get_instance();
	  $CI->db->select("tl_id");
      $CI->db->from('tbl_lead_tl_caller');
	  if($id!=''){
		$CI->db->where('cl_id', $id);
		}
	   $CI->db->order_by('id','desc');
   	   $query = $CI->db->get();//echo $CI->db->last_query();
	   $result=$query->result();
	   return $result[0]->tl_id;
}
function getHeadingarray(){
	  $CI =& get_instance();
	  $CI->db->select("field");
      $CI->db->from('tbl_csv_header');
   	   $query = $CI->db->get();
	   $result=$query->result();
	   return $result;
}
function isSubset($arr1, $arr2, $m, $n) 
{   $i = 0; 
    $j = 0; 
    for ($i = 0; $i < $n; $i++) 
    { 
        for ($j = 0; $j < $m; $j++) 
        { 
            if($arr2[$i] == $arr1[$j]) 
                break; 
        } 
           if ($j == $m) 
            return 0; 
    } 
    return 1; 
}
function getProjects($id=''){
		$CI =& get_instance();
		$CI->db->select('tl.*');
		$CI->db->from('tbl_lead_course as tl');
		//$CI->db->join('tbl_lead_city as tc', 'tc.id =tl.city');
		if($id!=''){
		$CI->db->where_in('tl.id', $id);
		}
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}
function getColleges($id=''){
		$CI =& get_instance();
		$CI->db->select('tl.*,tc.city_name');
		$CI->db->from('tbl_lead_college as tl');
		$CI->db->join('tbl_lead_city as tc', 'tc.id =tl.city');
		if($id!=''){
		$CI->db->where_in('tl.id', $id);
		}
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}

function getProjectsfilter($id='',$post='',$limit='',$starts=''){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$CI->db->select('tl.*,tc.city_name');
		$CI->db->from('tbl_lead_college as tl');
		$CI->db->join('tbl_lead_city as tc', 'tc.id =tl.city');
		if($id!=''){
		$CI->db->where_in('tl.id', $id);
		}
		if($post!=''){
		if($post['name']!=''){
		$CI->db->like('tl.name', $post['name']);
		}

		if($post['added_on']!=''){
		$CI->db->like('tl.added_on',date("Y-m-d", strtotime($post['added_on'])));
		}
	
		}		
		$CI->db->order_by('tl.id','desc');
		$CI->db->limit($limit,$starts);
		$query = $CI->db->get();//echo $CI->db->last_query();
		$studentData = $query->result();
		return $studentData;	
}

function getCoursefilter($id='',$post='',$limit='',$starts=''){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$CI->db->select('tl.*');
		$CI->db->from('tbl_lead_course as tl');
		if($id!=''){
		$CI->db->where_in('tl.id', $id);
		}
		if($post!=''){
		if($post['name']!=''){
		$CI->db->like('tl.name', $post['name']);
		}

		if($post['added_on']!=''){
		$CI->db->like('tl.added_on',date("Y-m-d", strtotime($post['added_on'])));
		}
	
		}		
		$CI->db->order_by('tl.id','desc');
		$CI->db->limit($limit,$starts);
		$query = $CI->db->get();//echo $CI->db->last_query();
		$studentData = $query->result();
		return $studentData;	
}

	function activitys(){
		$CI =& get_instance();//print_r($CI->session->userdata);
		if($CI->session->userdata['timestamp']!=''){
		if(time() - ($CI->session->userdata['timestamp']) > 5400) {
		 $update="update tbl_lead_user set `logged_in`='0' where `id`='".$id."'"; 
		 $CI->db->query($update);	
		 echo" <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'></script>
			 <script>$(document).ready(function(){
			 $('#alert_model').modal('show');
			 });</script>";
           $CI->session->sess_destroy();
           redirect('home');
		   exit;
		}
		else{$date=time();
		$id=$CI->session->userdata('user_login');
		     $update="update tbl_lead_user set `logged_in`='".$date."' where `id`='".$id[0]['id']."'"; 
			 $CI->db->query($update);
		      $userData = array('timestamp' => time());
			  $CI->session->set_userdata($userData);
		}
		}else{
		$set="loggedout";	
		return $set;	
		}
	}
	 function getDatas($table,$ids) {
		$CI =& get_instance();
		$stu_id = explode(",",$ids);
		$CI->db->select('*');
		$CI->db->from($table);
		$CI->db->where_in('id', $stu_id);
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;
	}
	
		 function getDatass($table,$ids) {
		$CI =& get_instance();
		$stu_id = explode(",",$ids);
		$CI->db->select('*');
		$CI->db->from($table);
		$CI->db->where_in('id', $stu_id);
		$query = $CI->db->get();
		$studentData = $query->result_array();
		return $studentData;
	}
function generate_table_log($id,$operate,$table,$operation,$date,$fromtable){
	$CI =& get_instance();
	$ids=$CI->session->userdata('user_login');
		$studentData = getDatass($fromtable,$id,$operate);
	  $string='';	 
	  foreach($studentData as $val){
	  foreach($val as $keys =>$value){//print_r($keys);print_r($value);
		if($keys=='id'){
			$keys='user_id';
		}  
		 $string .='`'.$keys.'`,' ;
		 $val .='"'.$value.'",';
	  }}
	   if($ids[0]['user_type']=='1'){
	       $operation='adminupdate';
	   }
	   $string=rtrim($string,',').',`operation`,`change_date`'; 
	   $val=str_replace('Array','',$val);
      $val=rtrim($val,',').',"'.$operation.'","'.$date.'"';
	  $insert="insert into ".$table." (".$string.") values (".$val.")";
	  $CI->db->query($insert);
} 
function getStuBackTrackerData($id) {
	$CI =& get_instance();$student='';
    $CI->db->select('tlll.*,tls.status');
		$CI->db->from('tbl_lead_leads_log as tlll');
		$CI->db->join('tbl_lead_status as tls','tls.id=tlll.lead_status');
		$CI->db->where('tlll.user_id', $id);
		$CI->db->order_by("tlll.id","desc");
		$CI->db->limit(100, 0);
		$query = $CI->db->get();//echo $CI->db->last_query();
	    $studentData = $query->result();
		/*if(count($studentData) > 0){
		 $sql="SELECT tlll.*,tls.status
		 FROM tbl_lead_leads_log tlll 
		 JOIN tbl_lead_status tls on tls.id = tlll.lead_status 
		 WHERE `tlll`.`user_id` = '".$id."' and tlll.id in ( SELECT min(id) from tbl_lead_leads_log where `user_id` = '".$id."' group by lead_status,followup_date,site_visit_date,site_visit_verify,feedback,phone,caller_id,name,email)";
		$query1 = $CI->db->query($sql);
	    $student= $query1->result();
		}  */    
        return $studentData;
}	

function getWhatsappmsg($id='',$name=''){
		$CI =& get_instance();
		$CI->db->select('tl.*,tc.city_name');
		$CI->db->from('tbl_lead_property as tl');
		$CI->db->join('tbl_lead_city as tc', 'tc.id =tl.city');
		if($id!=''){
		$CI->db->where_in('tl.id', $id);
		}
		$query = $CI->db->get();
		$studentData = $query->result();
		$msg = "Hello ".$name." sharing you the detail of property you are interested in. Property Name : ".$studentData[0]->property_name.", Area : ".$studentData[0]->area.", City : ".$studentData[0]->city_name.", Fetaures : ".$studentData[0]->features." , Builder : ".$studentData[0]->builder.", Brouchure : https://edificereality.com/lead-mgmt/assets/uploads/property/".$studentData[0]->brochure ." ";
return $msg;		
}

function Notificationlist($id=''){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$CI->db->select('tl.*,tso.source,tu.username');
		$CI->db->from('tbl_lead_leads as tl');
		$CI->db->join('tbl_lead_source as tso','tso.id=tl.source_id');
		$CI->db->join('tbl_lead_user as tu','tu.id=tl.caller_id');
        $CI->db->where("(tl.followup_date='".date('Y-m-d')."' OR tl.followup_date <='".date('Y-m-d')."')");
		$CI->db->where('tl.lead_status!=',1);	
		if($user[0]['user_type']!=1){
		$CI->db->where('tl.caller_id',$user[0]['id']);	
		}
		$CI->db->order_by('tl.id','desc');
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}
function TodaysNotificationlist($id=''){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$caller=getCallerLists($user[0]['id']);
		 foreach($caller as $get){
		$ids .=$get->cl_id.',';
		}
		 $ids = rtrim($ids,',');
		$CI->db->select('tl.*,tso.source,tu.username');
		$CI->db->from('tbl_lead_leads as tl');
		$CI->db->join('tbl_lead_source as tso','tso.id=tl.source_id');
		$CI->db->join('tbl_lead_user as tu','tu.id=tl.caller_id');
		$CI->db->where('tl.lead_status=',3);	
		$CI->db->like('tl.followup_date',date("Y-m-d", strtotime(date('Y-m-d'))));
		if(($user[0]['user_type']!=1) && ($user[0]['user_type']!=2)){
		$CI->db->where('tl.caller_id',$user[0]['id']);	
		}
	    
	    if($user[0]['user_type']==2){
		$setid=explode(',',$ids);//echo $ids;	print_r($setid);
		$CI->db->where_in('caller_id', $setid);
		}
		$CI->db->order_by('tl.id','desc');
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}
function TodaysSitevisit($id=''){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$caller=getCallerLists($user[0]['id']);
		 foreach($caller as $get){
		$ids .=$get->cl_id.',';
		}
		 $ids = rtrim($ids,',');
		$CI->db->select('tl.*,tso.source,tu.username');
		$CI->db->from('tbl_lead_leads as tl');
		$CI->db->join('tbl_lead_source as tso','tso.id=tl.source_id');
		$CI->db->join('tbl_lead_user as tu','tu.id=tl.caller_id');
		$CI->db->like('tl.site_visit_date',date("Y-m-d", strtotime(date('Y-m-d'))));
		$CI->db->where('tl.site_visit_verify!=','Y');	
			if(($user[0]['user_type']!=1) && ($user[0]['user_type']!=2)){
		$CI->db->where('tl.caller_id',$user[0]['id']);	
		}
	    
	    if($user[0]['user_type']==2){
		$setid=explode(',',$ids);//echo $ids;	print_r($setid);
		$CI->db->where_in('caller_id', $setid);
		}
		$CI->db->order_by('tl.id','desc');
		$query = $CI->db->get();//echo $CI->db->last_query();
		$studentData = $query->result();
		return $studentData;	
}
function getSMScount(){
$CI =& get_instance();
		$CI->db->select('sms');
		$CI->db->from('tbl_lead_sms');
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData[0]->sms;	
}

function newNotificationlist($id=''){
		$CI =& get_instance();
		$user=$CI->session->userdata('user_login');
		$CI->db->select('tl.*,tso.source,tu.username');
		$CI->db->from('tbl_lead_leads as tl');
		$CI->db->join('tbl_lead_source as tso','tso.id=tl.source_id');
		$CI->db->join('tbl_lead_user as tu','tu.id=tl.caller_id');
		$CI->db->where('tl.lead_status',1);	
		if($user[0]['user_type']!=1){
		$CI->db->where('tl.caller_id',$user[0]['id']);	
		}
		$CI->db->order_by('tl.id','desc');
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}
function getCSVData($field=null,$fields='',$start_id='',$last_id=''){
	    $CI =& get_instance();
		if($start_id!=''){
		if($field!=''){
		$field=str_replace('}',',',$field);	
	   	$CI->db->distinct();
		$CI->db->select($field);
		}
		else{
        $CI->db->select('id,'.$fields);
		}
		$CI->db->from('tbl_csvimport_helper');
		$CI->db->where("id BETWEEN ".$start_id." AND ".$last_id."");
		$query = $CI->db->get();
		$nums   = $query->num_rows();
if ($nums > 0) {return $resultData = $query->result();}
}	
}

function lpushare($id=''){
	  $CI =& get_instance();	
$student_data =getStudentDatahelper($id);
echo $student_data[0]->course_id.'--';
//echo $data='{"college_id":"524","name":"'.$student_data[0]->name.'","email":"'.$student_data[0]->email.'","country_dial_code":"91","mobile":"'.$student_data[0]->phone.'","source":"blessings_always_guruji_associates","state":"'.$student_data[0]->state_name.'","city":"'.$student_data[0]->city_name.'","secret_key":"b061b6abae687fbd43e1bc2260c04b6a","field_program":"'.$courseid[0]->course.'","field_session":"Session 2026"}';
echo $data='{"college_id":"524","name":"'.$student_data[0]->name.'","email":"'.$student_data[0]->email.'","country_dial_code":"91","mobile":"'.$student_data[0]->phone.'","source":"blessings_always_guruji_associates","state":"'.$student_data[0]->state_name.'","city":"'.$student_data[0]->city_name.'","secret_key":"b061b6abae687fbd43e1bc2260c04b6a","field_session":"Session 2026","field_program":"'.$student_data[0]->course_name.'"}';
callcurlforsharing($id,'https://lpuapi.nopaperforms.com/dataporting/524/blessings_always_guruji_associates',$data);
}


function isbrshare($id=''){
	  $CI =& get_instance();	
$student_data =getStudentDatahelper($id);
print_r($student_data);
echo $student_data[0]->course_id.'--';
echo $data='{"college_id":"294","name":"'.$student_data[0]->name.'","email":"'.$student_data[0]->email.'","country_dial_code":"91","mobile":"'.$student_data[0]->phone.'","source":"blessings_always_guruji_associates","state":"'.$student_data[0]->state_name.'","city":"'.$student_data[0]->city_name.'","secret_key":"855e06911ca5e6799da91d7ccd964466","course":"'.$courseid[0]->course.'","campus":"ISBR College"}';
callcurlforsharing($id,'https://api.nopaperforms.com/dataporting/294/blessings_always_guruji_associates',$data);
}

function manavLeadshare($id=''){
	  $CI =& get_instance();	
$student_data =getStudentDatahelper($id);
$courseid=getPartnermappedCourse($student_data[0]->course,$student_data[0]->college);
print_r($student_data);
echo $student_data[0]->course_id.'--';
echo $data='{"college_id":"78","name":"'.$student_data[0]->name.'","email":"'.$student_data[0]->email.'","country_dial_code":"91","mobile":"'.$student_data[0]->phone.'","source":"blessings_always_guruji_associates","state":"'.$student_data[0]->state_name.'","city":"'.$student_data[0]->city_name.'","secret_key":"8ebdd42265b7ad190beab87f9d13d3bd","campus":"'.$courseid[0]->campus.'","course":"'.$courseid[0]->course.'","specialization":"'.$courseid[0]->specialization.'"}';
callcurlforsharing($id,'https://api.nopaperforms.com/dataporting/78/blessings_always_guruji_associates',$data);
}

function mbuLeadshare($id=''){
	  $CI =& get_instance();	
$student_data =getStudentDatahelper($id);
$courseid=getPartnermappedCourse($student_data[0]->course,$student_data[0]->college);
print_r($student_data);
echo $student_data[0]->course_id.'--';
echo $data='{"college_id":"5526","name":"'.$student_data[0]->name.'","email":"'.$student_data[0]->email.'","country_dial_code":"91","mobile":"'.$student_data[0]->phone.'","source":"guruji_associates","state":"'.$student_data[0]->state_name.'","city":"'.$student_data[0]->city_name.'","secret_key":"5ebc58fd1de3c795c21cf152f19dbf77","campus":"'.$courseid[0]->campus.'","course":"'.$courseid[0]->course.'","specialization":"'.$courseid[0]->specialization.'"}';
callcurlforsharing($id,'https://api.in5.nopaperforms.com/dataporting/5526/guruji_associates',$data);
}

function futureLeadshare($id=''){
	  $CI =& get_instance();	
$student_data =getStudentDatahelper($id);
$courseid=getPartnermappedCourse($student_data[0]->course,$student_data[0]->college);
print_r($student_data);
echo $student_data[0]->course_id.'--';
echo $data='{"college_id":"6592","name":"'.$student_data[0]->name.'","email":"'.$student_data[0]->email.'","country_dial_code":"91","mobile":"'.$student_data[0]->phone.'","source":"guruji_assosate","state":"'.$student_data[0]->state_name.'","city":"'.$student_data[0]->city_name.'","secret_key":"7ccf7127611049c78174a119b34ca9e1","course":"'.$courseid[0]->course.'","specialization":"'.$courseid[0]->specialization.'","campus":"'.$courseid[0]->campus.'"}';
callcurlforsharing($id,'https://api.in6.nopaperforms.com/dataporting/6592/guruji_assosate',$data);
}



function callcurlforsharing($id,$url,$data){
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => $data,
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
     ),
));
$response = curl_exec($curl);
curl_close($curl);
saveSharedstatusforAll($id,json_encode($response));
echo json_encode($response);	
}


function saveSharedstatusforAll($id,$response){
	$CI =& get_instance();

	$select="select id,email,phone,lead_status,college,lead_share_apistatus from tbl_lead_leads where `id`='".$id."'";
	$sel=$CI->db->query($select);
	$studentData = $sel->result();
	if($studentData[0]->lead_share_apistatus=='' && $studentData[0]->lead_status==17){
	    $update_status="update `tbl_lead_leads` set `lead_status` ='69', `followup_date` = NOW(),`lead_share_apistatus` = '".$response."',`lead_share_date`=NOW() where `id`=".$id." ";
        $updates=$CI->db->query($update_status);
	}
	else if($studentData[0]->lead_share_apistatus=='' && $studentData[0]->lead_status!=17){
	    $update_status="update `tbl_lead_leads` set `followup_date` = NOW(),`lead_share_apistatus` = '".$response."',`lead_share_date`=NOW() where `id`=".$id." ";
        $updates=$CI->db->query($update_status);
	}

else {
	 $update_status="update `tbl_lead_leads` set `followup_date` = NOW(),`lead_share_apistatus` = '".$response."',`lead_share_date`=NOW() where `id`=".$id." ";
        $updates=$CI->db->query($update_status);
}	
}


function getStudentDatahelper($id) {
	 $CI =& get_instance();	
		$CI->db->select('tbl_lead_leads.*,tbl_lead_city.city_name,tbl_lead_city.state_name as state_name,tbl_lead_course.name as course_name');
		$CI->db->from('tbl_lead_leads');
		$CI->db->join('tbl_lead_city', 'tbl_lead_leads.city = tbl_lead_city.id');  
		$CI->db->join('tbl_lead_course', 'tbl_lead_leads.course = tbl_lead_course.id'); 
		$CI->db->where('tbl_lead_leads.id', $id);
		$query = $CI->db->get();	
		$CI->db->last_query();
	    $studentData = $query->result();
		return $studentData;		 
	}
	
function getPartnermappedCourse($course,$clg){
 $CI =& get_instance();
 		$CI->db->select('*');
		$CI->db->from('tbl_clg_course_map');
		$CI->db->where('clg_id', $clg);
		$CI->db->where('course_id', $course);
		$query = $CI->db->get();
		$studentData = $query->result();
		return $studentData;	
}	
	
function chguniLeadshare($id='',$clg_id=''){
	  $CI =& get_instance();	
$student_data =getStudentDatahelper($id);//print_r($student_data);
//$category =getCategoryfromcourse($student_data[0]->course_id);
$courseid=getPartnermappedCourse($student_data[0]->course,$student_data[0]->college);
echo '[
    {"Attribute": "FirstName","Value": "'.$student_data[0]->name.'"},
    {"Attribute": "EmailAddress","Value": "'.$student_data[0]->email.'"},
    {"Attribute": "Phone","Value": "'.$student_data[0]->phone.'"},
    {"Attribute": "mx_Program_Code_New","Value":"'.$courseid[0]->code.'" },
    {"Attribute": "mx_Program_New","Value": "'.$courseid[0]->course.'"},
    {"Attribute": "mx_Discipline_New","Value": "'.$courseid[0]->specialization.'"},
    {"Attribute": "mx_State_New","Value":"'.$student_data[0]->state_name.'"},
    {"Attribute": "mx_City_New","Value": "'.$student_data[0]->city_name.'"},
    {"Attribute": "mx_Date_Of_Birth", "Value": "'.$student_data[0]->dob.'"},
    {"Attribute": "mx_Campus","Value": "'.$courseid[0]->campus.'"},
    {"Attribute": "Source","Value": "gurujiassociates"}
   
]';
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://publisher-api.customui.leadsquared.com/api/leadCapture/NzA4MjM=/?token=edb4ba01-decf-4303-91dd-412059306305',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'[
    {"Attribute": "FirstName","Value": "'.$student_data[0]->name.'"},
    {"Attribute": "EmailAddress","Value": "'.$student_data[0]->email.'"},
    {"Attribute": "Phone","Value": "'.$student_data[0]->phone.'"},
    {"Attribute": "mx_Program_Code_New","Value":"'.$courseid[0]->code.'" },
    {"Attribute": "mx_Program_New","Value": "'.$courseid[0]->specialization.'"},
    {"Attribute": "mx_Discipline_New","Value": "'.$courseid[0]->course.'"},
    {"Attribute": "mx_State_New","Value":"'.$student_data[0]->state_name.'"},
    {"Attribute": "mx_City_New","Value": "'.$student_data[0]->city_name.'"},
    {"Attribute": "mx_Date_Of_Birth", "Value": "'.$student_data[0]->dob.'"},
    {"Attribute": "mx_Campus","Value": "'.$courseid[0]->campus.'"},
    {"Attribute": "Source","Value": "gurujiassociates"}
   
]',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
)); 
$response = curl_exec($curl);
$resp =str_replace("'",'',$response);
saveSharedstatusforAll($id,$resp);
echo $response;
}
	
	
	
	
?>