<?php  
session_start(); 
if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}

	include("connect.php");	header("Access-Control-Allow-Origin: *");
	
	$eve = "select * from res_branch_master";
	$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))
		 {
			 
				$branchmid=$rt['branchmid'];
				
				$piddetail="<a href='branchdetail.php?id=".$rt['branchmid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-eye fa-lg'>  </a>";
				
				$pidedit="<a href='branchedit.php?id=".$rt['branchmid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'>  </a>";
	$eve11 = "select branchmid from res_user_master where branchmid=$branchmid";
				$re11 = mysqli_query($conn, $eve11);
	
				if(mysqli_num_rows($re11)>0 )
					{
						$piddelete='';
					}else{
				$piddelete="<a href='branchdelete.php?id=".$rt['branchmid']."'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>";	
					}				
                $op=$piddetail."&nbsp;&nbsp;&nbsp; ".$pidedit."&nbsp;&nbsp;&nbsp; ".$piddelete;
								
								
				$branchname=str_replace ("'","'",$rt['branchname']);
				$branchname=str_replace ('"','\"',$branchname);
				
				$branchaddress=str_replace ("'","'",$rt['branchaddress']);
				$branchaddress=str_replace ('"','\"',$branchaddress);
				
				
				$citymid=$rt['citymid'];
				
				$ciname='';
				
				$eve2 = "select * from res_city_master where citymid ='$citymid'";
				
				$re2 = mysqli_query($conn, $eve2);
				
				if(mysqli_num_rows($re2) > 0)
				{
					
					while($rt2 = mysqli_fetch_assoc($re2))
					{
							$ciname=$rt2['cityname'];
					}
				}
				
				$areaname=$rt['brancharea'];
				
				
				
				
				
				$branchphone=str_replace ("'","'",$rt['branchphone']);
				$branchphone=str_replace ('"','\"',$branchphone);
				
				
				$branchhead=str_replace ("'","'",$rt['branchhead']);
				$branchhead=str_replace ('"','\"',$branchhead);
				
				
				$branchheadcontact=str_replace ("'","'",$rt['branchheadcontact']);
				$branchheadcontact=str_replace ('"','\"',$branchheadcontact);
				
				
								
				$posts[] = array('srno'=> $i++,'op'=> $op,'piddelete'=> $piddelete, 'branchname'=> $branchname, 'branchaddress'=> $branchaddress,'citymid'=> $ciname, 'brancharea'=> $areaname, 'branchphone'=> $branchphone, 'branchhead'=> $branchhead,'branchheadcontact'=> $branchheadcontact);
		 }
		 
		$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);	
	
?>