<?php  
session_start(); 

if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}
	
	$branchmid= $_SESSION['branchid'];

	include("connect.php");	header("Access-Control-Allow-Origin: *");
	
	if($_SESSION['utype']=="admin")
	{
		 $eve = "select * from res_bank_master,res_contact_master where res_bank_master.bankmid=res_contact_master.clinkid and res_contact_master.clinktype = 'Bank'";
		$re = mysqli_query($conn, $eve);
	
		}
	else
	{
		$eve = "select * from res_bank_master,res_contact_master where res_bank_masterbranchmid=$branchmid and res_bank_master.bankmid=res_contact_master.clinkid and res_contact_master.clinktype = 'Bank'";
		$re = mysqli_query($conn, $eve);
		}
	
	
	$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))
		 {
			 
				$bankmid=$rt['bankmid'];
				
				$companymid=$rt['companymid'];

					$companyname="";
					$eve55= "select * from   res_company_master where companymid=$companymid";
					$re55 = mysqli_query($conn, $eve55);
					 while($rt55 = mysqli_fetch_assoc($re55))
					{
			
						
						$companyname=$rt55['companyname'];
						
					}
				
				$piddetail='';
				$currentfile1 = basename($_SERVER['PHP_SELF']);
				 $currentfile = ltrim($currentfile1, 'json');
											$eve23 = "select * from res_moduleallocation_detail where smodulemid in (select smodulemid from res_submodule_master where smfilename='$currentfile') and maview=1 and  rolemid = ".$_SESSION['userrolemid'];
											$re23 = mysqli_query($conn, $eve23);
	
				if(mysqli_num_rows($re23)>0 || $_SESSION['utype'] == 'admin')
					{
				$piddetail="<a href='bankdetail.php?id=".$rt['bankmid']."' data-toggle='tooltip' data-placement='top' title='Detail' class='fa fa-eye fa-lg'>  </a>";
					}
				$eve23 = "select * from res_moduleallocation_detail where smodulemid in (select smodulemid from res_submodule_master where smfilename='$currentfile') and maedit=1 and  rolemid = ".$_SESSION['userrolemid'];
											$re23 = mysqli_query($conn, $eve23);
	
				if(mysqli_num_rows($re23)>0 || $_SESSION['utype'] == 'admin')
					{
				$pidedit="<a href='bankedit.php?id=".$rt['bankmid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'>  </a>";
				}
				
				$piddelete='';
				$eve23 = "select * from res_moduleallocation_detail where smodulemid in (select smodulemid from res_submodule_master where smfilename='$currentfile') and madelete=1 and  rolemid = ".$_SESSION['userrolemid'];
											$re23 = mysqli_query($conn, $eve23);
	
				if(mysqli_num_rows($re23)>0 || $_SESSION['utype'] == 'admin')
					{
				$piddelete="<a href='bankdelete.php?id=".$rt['bankmid']."'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;
								
				$bankname=str_replace ("'","'",$rt['bankname']);
				$bankname=str_replace ('"','\"',$bankname);
	
				$bankbranch=str_replace ("'","'",$rt['bankbranch']);
				$bankbranch=str_replace ('"','\"',$bankbranch);
	
	
				$citymid=$rt['ccity'];
				
				$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'];
					}
				}
				
				$areamid=$rt['carea'];
				
				$areaname='';
				
				$eve2 = "select * from res_area_master where areamid ='$areamid'";
			
				$re2 = mysqli_query($conn, $eve2);
				
				if(mysqli_num_rows($re2) > 0)
				{
					
					while($rt2 = mysqli_fetch_assoc($re2))
					{
							$areaname=$rt2['areaname'];
						
					}
				}
				
				$branchmid=$rt['branchmid'];
				
				$branchname='';
				
				$eve5 = "select * from res_branch_master where branchmid ='$branchmid'";

				$re5 = mysqli_query($conn, $eve5);
																			
				if(mysqli_num_rows($re5) > 0)

				{											
																				
				while($rt5 = mysqli_fetch_assoc($re5))
				{
					$branchname=$rt5['branchname'];
						
				}
																				 
				}
				
				
				
								
			$posts[] = array('srno'=> $i++,'op'=> $op,'piddelete'=> $piddelete, 'branchmid'=>$branchname,'companymid'=>$companyname,'bankname'=>$bankname,'bankbranch'=> $bankbranch,'citymid'=>$ciname,'areamid'=>$areaname);
		 }
		 
		$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);	
	
?>