<?php  
session_start(); 
if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}
	include("connect.php");	header("Access-Control-Allow-Origin: *");
	$umid1=$_SESSION['umid'];
	
	if($_SESSION['utype']=="admin")
	{
		 $eve = "select * from res_user_master,res_contact_master where res_user_master.umid=res_contact_master.clinkid and res_contact_master.clinktype = 'Agent'";
		$re = mysqli_query($conn, $eve);
	
		}else if( $_SESSION['utype']=='counseller') {
			 $eve = "select * from res_user_master,res_contact_master where  res_user_master.umid=res_contact_master.clinkid and res_contact_master.clinktype = 'Agent' and res_user_master.uagentcounsellorid=$umid1 ";
		$re = mysqli_query($conn, $eve);
		}
	
	
	
	
	$response = array();
	$posts = array();
	
	$result="0";
	
	if(mysqli_num_rows($re) > 0)
	{
		$i=1;
		while($rt = mysqli_fetch_assoc($re))
		{
			 	$umid=$rt['umid'];
				$uedit="<a href='agentedit.php?id=".$rt['umid']."'data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg' >  </a>";
				$view="<a href='agentdetail.php?id=".$rt['umid']."'data-toggle='tooltip' data-placement='top' title='View' class='fa fa-eye fa-lg' >  </a>";
				$udelete="<a href='userdelete.php?id=".$rt['umid']."' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' data-toggle='tooltip' data-placement='top' title='Delete' class='far fa-trash-alt fa-lg'>  </a>";
				$user="<a href='agentinquiry.php?id=".$rt['umid']."'data-toggle='tooltip' data-placement='top' title='View' class='fa fa-user fa-lg' >  </a>";
				
				//$cdelete="<a href='customeredit.php?id=$bumid' onClick=\"return confirm('are you sure you want to delete??');\">Delete</a>";
				
				
				
				
				
				$ufullname=$rt['contactname'].' '.$rt['cmiddlename'].' '.$rt['csurname'];
				$utype=$rt['utype'];
				$ustatus=$rt['ustatus'];
				$umobile=$rt['umobile'];
				$uemail=$rt['contactemail'];
				$umobile2=$rt['contactnumber'];
				$ubusinessname=$rt['ccompanyname'];
				$uagentcounsellorid=$rt['uagentcounsellorid'];
				
			
				
				
				if($utype=="branchmanager")
				{
					$utype1="<span class='label label-sm label-success'>Branch Manager</span>";
				}
				else if($utype=="receptionist")
				{
					$utype1="<span class='label label-sm label-info'>Receptionist</span>";
				}
				else if($utype=="counseller")
				{
					$utype1="<span class='label label-sm label-warning'>Counseller</span>";
				}
				else if($utype=="agent")
				{
					$utype1="<span class='label label-sm label-primary'>Agent</span>";
				}
				else
				{
					$utype1="<span class='label label-sm label-default'>$utype</span>";
				}
				
				
				if($ustatus=="Approved")
				{
					
					$ustatus1="<a href='userstatus.php?id=".$rt['umid']."' ><span class='label label-sm label-success'>Approved</span></a>";
				}
				else
				{
					$ustatus1="<a href='userstatus.php?id=".$rt['umid']."' ><span class='label label-sm label label-danger '>Blocked</span></a>";
				}
				
				$op=$user."&nbsp;&nbsp;&nbsp; ".$view."&nbsp;&nbsp;&nbsp; ".$uedit."&nbsp;&nbsp;&nbsp; ".$udelete;
				$ufullname1='';
				$eve1 = "select * from res_user_master where umid = '$uagentcounsellorid' ";
				$re1 = mysqli_query($conn, $eve1);
				while($rt1 = mysqli_fetch_assoc($re1))
				{											
					
					$ufullname1=$rt1['ufullname'];
					
				}
					
				
				$posts[] = array('srno'=> $i++, 'op'=> $op, 'ufullname'=> $ufullname,'utype'=> $utype1,'ustatus'=> $ustatus1,'umobile'=> $umobile,'uemail'=> $uemail,'umobile2'=>$umobile2,'ubusinessname'=>$ubusinessname,'counsellor'=>$ufullname1);
	
			
			
			
		}
		 
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('data' => $posts)));
		mysqli_close($conn);
		return;
	}
	
   else
	{
		$result="0";
		$msg="Invalid Error";
		
		$posts[] = array('p1'=> $result,'p2'=> $msg);
	
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('item' => $posts)));
	}
   
	mysqli_close($conn);	
?>