<?php
session_start();
if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
	include("connect.php");	header("Access-Control-Allow-Origin: *");
		
		$cmpmid=$_SESSION['linkarisecmpmid'];
			$umid = $_SESSION['linkariseumid'];

	
		$tt="";
		if($_SESSION['linkariseutype']=='User')
		{
			$tt=" and usermid=$umid";
		}
	  $eve = "select * from res_user_master where companymid=$cmpmid and userdesignation='User' order by usermid DESC";

	$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))
		{
			 	$usermid=$rt['usermid'];
			 	$username=$rt['username'];
			 	$userdesignation=$rt['userdesignation'];

			
				$iedit="<a href='useredit.php?id=".$rt['usermid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'>  </a>";
			
	
						$idelete="<a href='userdelete.php?id=".$rt['usermid']."' 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>";
					
				
				
				$idetail="<a href='userdetail.php?id=".$rt['usermid']."' data-toggle='tooltip' data-placement='top' title='Detail' class='fa fa-eye fa-lg'>  </a>";
			

				$op=$idetail."&nbsp".$iedit."&nbsp".$idelete;



				$usermobile=$rt['usermobile'];
				$userloginid=$rt['userloginid'];
			
				$userstatus=$rt['userstatus'];
				$addedby=$rt['addedby'];
				
					if($userstatus=="Active")
					{
						if($_SESSION['linkariseutype']=='Admin')
						{
						$userstatus1 = "<div class='badge badge-light-primary fw-bold'><a href='userstatus.php?id=$usermid'>Active</a></div>";
						}
						else
						{
							$userstatus1 = "<div class='badge badge-light-primary fw-bold'>Active</div>";
						}
						
					}
					else 
					{
						$userstatus1 = "<div class='badge badge-warning'><a href='userstatus.php?id=$usermid'>Blocked</a></div>";
					}
			
				
				$addedbyname="";
				 $eve1 = "select * from res_user_master where companymid=$cmpmid  and usermid=$addedby";

	$re1 = mysqli_query($conn, $eve1);
				while($rt1 = mysqli_fetch_assoc($re1))
		{
			 	$addedbyname=$rt1['username'];
		}
			
				$posts[] = array('srno'=> $i++,'usermid'=> $usermid, 'op'=> $op,'username'=> $username,'userdesignation'=> $userdesignation,'usermobile'=> $usermobile,'userstatus'=> $userstatus1,'loginid'=> $userloginid);

		


		}

		$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);
?>
